Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOSTEDCP-1536: feat(install): expose hypershift-readers ClusterRole at install time #3913

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 32 additions & 20 deletions cmd/install/assets/hypershift_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ var (
// privileged is used to set the container security
// context to run container as unprivileged.
privileged = false

// readOnlyVerbs are RBAC related verbs limited to read actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that this change is necessary, you could reduce your diff by leaving it out. It's not like we will be changing the list at any time (and therefore benefiting from having a slice for it).

readOnlyVerbs = []string{"get", "list", "watch"}
)

type HyperShiftNamespace struct {
Expand Down Expand Up @@ -815,7 +818,7 @@ func (o ExternalDNSClusterRole) Build() *rbacv1.ClusterRole {
{
APIGroups: []string{"route.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{""},
Expand All @@ -825,7 +828,7 @@ func (o ExternalDNSClusterRole) Build() *rbacv1.ClusterRole {
"nodes",
"pods",
},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
},
}
Expand Down Expand Up @@ -912,7 +915,7 @@ func (o HyperShiftOperatorClusterRole) Build() *rbacv1.ClusterRole {
{
APIGroups: []string{"config.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"apiextensions.k8s.io"},
Expand Down Expand Up @@ -1046,7 +1049,7 @@ func (o HyperShiftOperatorClusterRole) Build() *rbacv1.ClusterRole {
{
APIGroups: []string{cdicore.GroupName},
Resources: []string{"datavolumes"},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{ // This allows the kubevirt csi driver to hotplug volumes to KubeVirt VMs.
APIGroups: []string{"subresources.kubevirt.io"},
Expand Down Expand Up @@ -1090,7 +1093,7 @@ func (o HyperShiftOperatorClusterRole) Build() *rbacv1.ClusterRole {
{
APIGroups: []string{"certificates.k8s.io"},
Resources: []string{"certificatesigningrequests"},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"certificates.k8s.io"},
Expand Down Expand Up @@ -1296,7 +1299,7 @@ func (o HyperShiftPrometheusRole) Build() *rbacv1.Role {
"endpoints",
"pods",
},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
},
}
Expand Down Expand Up @@ -1495,27 +1498,36 @@ func (o HyperShiftReaderClusterRole) Build() *rbacv1.ClusterRole {
},
ObjectMeta: metav1.ObjectMeta{
Name: "hypershift-readers",
Labels: map[string]string{
"managed.openshift.io/aggregate-to-dedicated-readers": "true",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the names of roles that are used in one deployment of HyperShift hard-coded here seems like the wrong choice - perhaps expose which roles this should aggregate into as an option for the install command.

"managed.openshift.io/aggregate-to-backplane-srep": "true",
},
},
Rules: []rbacv1.PolicyRule{
{
APIGroups: []string{"hypershift.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"certificates.hypershift.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"config.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"apiextensions.k8s.io"},
Resources: []string{"customresourcedefinitions"},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"networking.k8s.io"},
Resources: []string{"networkpolicies"},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{
Expand All @@ -1529,17 +1541,17 @@ func (o HyperShiftReaderClusterRole) Build() *rbacv1.ClusterRole {
"cluster.x-k8s.io",
},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"operator.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"route.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"security.openshift.io"},
Expand All @@ -1549,7 +1561,7 @@ func (o HyperShiftReaderClusterRole) Build() *rbacv1.ClusterRole {
{
APIGroups: []string{"rbac.authorization.k8s.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{""},
Expand All @@ -1563,32 +1575,32 @@ func (o HyperShiftReaderClusterRole) Build() *rbacv1.ClusterRole {
"serviceaccounts",
"services",
},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"apps"},
Resources: []string{"deployments"},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"etcd.database.coreos.com"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"machine.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"monitoring.coreos.com", "monitoring.rhobs"},
Resources: []string{"podmonitors"},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
{
APIGroups: []string{"capi-provider.agent-install.openshift.io"},
Resources: []string{rbacv1.ResourceAll},
Verbs: []string{"get", "list", "watch"},
Verbs: readOnlyVerbs,
},
},
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Options struct {
ExternalDNSTxtOwnerId string
ExternalDNSImage string
EnableAdminRBACGeneration bool
EnableReaderRBACGeneration bool
EnableUWMTelemetryRemoteWrite bool
EnableCVOManagementClusterMetricsAccess bool
MetricsSet metrics.MetricsSet
Expand Down Expand Up @@ -210,6 +211,7 @@ func NewCommand() *cobra.Command {
cmd.PersistentFlags().StringVar(&opts.ExternalDNSTxtOwnerId, "external-dns-txt-owner-id", "", "external-dns TXT registry owner ID.")
cmd.PersistentFlags().StringVar(&opts.ExternalDNSImage, "external-dns-image", opts.ExternalDNSImage, "Image to use for external-dns")
cmd.PersistentFlags().BoolVar(&opts.EnableAdminRBACGeneration, "enable-admin-rbac-generation", false, "Generate RBAC manifests for hosted cluster admins")
cmd.PersistentFlags().BoolVar(&opts.EnableReaderRBACGeneration, "enable-reader-rbac-generation", false, "Generate RBAC manifests for hypershift readers")
cmd.PersistentFlags().StringVar(&opts.ImageRefsFile, "image-refs", opts.ImageRefsFile, "Image references to user in Hypershift installation")
cmd.PersistentFlags().StringVar(&opts.AdditionalTrustBundle, "additional-trust-bundle", opts.AdditionalTrustBundle, "Path to a file with user CA bundle")
cmd.PersistentFlags().Var(&opts.MetricsSet, "metrics-set", "The set of metrics to produce for each HyperShift control plane. Valid values are: Telemetry, SRE, All")
Expand Down Expand Up @@ -775,6 +777,12 @@ func hyperShiftOperatorManifests(opts Options) ([]crclient.Object, []crclient.Ob
objects = append(objects, readerRoleBinding)
}

if opts.EnableReaderRBACGeneration {
// add a ClusterRole that contains read-only resources for HyperShift resources
readerClusterRole := assets.HyperShiftReaderClusterRole{}.Build()
objects = append(objects, readerClusterRole)
}

if opts.OIDCStorageProviderS3BucketName != "" {
objects = append(objects, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down
11 changes: 11 additions & 0 deletions hack/app-sre/saas_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,9 @@ objects:
kind: ClusterRole
metadata:
creationTimestamp: null
labels:
managed.openshift.io/aggregate-to-backplane-srep: "true"
managed.openshift.io/aggregate-to-dedicated-readers: "true"
name: hypershift-readers
rules:
- apiGroups:
Expand All @@ -836,6 +839,14 @@ objects:
- get
- list
- watch
- apiGroups:
- certificates.hypershift.openshift.io
resources:
- '*'
verbs:
- get
- list
- watch
- apiGroups:
- config.openshift.io
resources:
Expand Down