Skip to content

Commit

Permalink
clean up provisioner RBAC and reuse Contour RBAC for it (#4438)
Browse files Browse the repository at this point in the history
Tidies up provisioner RBAC markers and reuses
the Contour RBAC file when generating the
provisioner RBAC YAML instead of requiring all
markers to be duplicated in the provisioner's
file.

Signed-off-by: Steve Kriss <krisss@vmware.com>
  • Loading branch information
skriss authored Mar 31, 2022
1 parent a40bfc4 commit 105f6e5
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 70 deletions.
45 changes: 19 additions & 26 deletions examples/gateway-provisioner/01-roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rules:
- ""
resources:
- configmaps
- secrets
- serviceaccounts
- services
verbs:
- create
- delete
Expand All @@ -24,6 +27,9 @@ rules:
- ""
resources:
- endpoints
- namespaces
- secrets
- services
verbs:
- get
- list
Expand All @@ -36,24 +42,11 @@ rules:
- create
- get
- update
- apiGroups:
- ""
resources:
- namespaces
- secrets
- serviceaccounts
- services
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- apps
resources:
- daemonsets
- deployments
verbs:
- create
- delete
Expand All @@ -62,25 +55,21 @@ rules:
- update
- watch
- apiGroups:
- apps
- coordination.k8s.io
resources:
- deployments
- leases
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- coordination.k8s.io
- gateway.networking.k8s.io
resources:
- leases
- gatewayclasses
- gateways
verbs:
- create
- get
- list
- update
- watch
- apiGroups:
- gateway.networking.k8s.io
Expand All @@ -93,8 +82,14 @@ rules:
verbs:
- get
- list
- update
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
- gatewayclasses/status
- gateways/status
verbs:
- update
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand All @@ -103,8 +98,6 @@ rules:
- httproutes/status
- tlsroutes/status
verbs:
- create
- get
- update
- apiGroups:
- networking.k8s.io
Expand Down
45 changes: 19 additions & 26 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8448,6 +8448,9 @@ rules:
- ""
resources:
- configmaps
- secrets
- serviceaccounts
- services
verbs:
- create
- delete
Expand All @@ -8459,6 +8462,9 @@ rules:
- ""
resources:
- endpoints
- namespaces
- secrets
- services
verbs:
- get
- list
Expand All @@ -8471,24 +8477,11 @@ rules:
- create
- get
- update
- apiGroups:
- ""
resources:
- namespaces
- secrets
- serviceaccounts
- services
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- apps
resources:
- daemonsets
- deployments
verbs:
- create
- delete
Expand All @@ -8497,25 +8490,21 @@ rules:
- update
- watch
- apiGroups:
- apps
- coordination.k8s.io
resources:
- deployments
- leases
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- coordination.k8s.io
- gateway.networking.k8s.io
resources:
- leases
- gatewayclasses
- gateways
verbs:
- create
- get
- list
- update
- watch
- apiGroups:
- gateway.networking.k8s.io
Expand All @@ -8528,8 +8517,14 @@ rules:
verbs:
- get
- list
- update
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
- gatewayclasses/status
- gateways/status
verbs:
- update
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand All @@ -8538,8 +8533,6 @@ rules:
- httproutes/status
- tlsroutes/status
verbs:
- create
- get
- update
- apiGroups:
- networking.k8s.io
Expand Down
2 changes: 1 addition & 1 deletion hack/generate-rbac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ EOF
go run sigs.k8s.io/controller-tools/cmd/controller-gen \
rbac:roleName=contour-gateway-provisioner \
output:stdout \
paths="./internal/provisioner/rbac" \
paths="./internal/provisioner/rbac;./internal/k8s" \
>> "${REPO}/examples/gateway-provisioner/01-roles.yaml"
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func desiredClusterRole(name string, contour *model.Contour) *rbacv1.ClusterRole
var (
createGetUpdate = []string{"create", "get", "update"}
getListWatch = []string{"get", "list", "watch"}
update = []string{"update"}
)

policyRuleFor := func(apiGroup string, verbs []string, resources ...string) rbacv1.PolicyRule {
Expand All @@ -87,7 +88,7 @@ func desiredClusterRole(name string, contour *model.Contour) *rbacv1.ClusterRole
// Gateway API resources.
// Note, ReferencePolicy does not currently have a .status field so it's omitted from the status rule.
policyRuleFor(gatewayv1alpha2.GroupName, getListWatch, "gatewayclasses", "gateways", "httproutes", "tlsroutes", "referencepolicies"),
policyRuleFor(gatewayv1alpha2.GroupName, createGetUpdate, "gatewayclasses/status", "gateways/status", "httproutes/status", "tlsroutes/status"),
policyRuleFor(gatewayv1alpha2.GroupName, update, "gatewayclasses/status", "gateways/status", "httproutes/status", "tlsroutes/status"),

// Ingress resources.
policyRuleFor(networkingv1.GroupName, getListWatch, "ingresses"),
Expand Down
39 changes: 23 additions & 16 deletions internal/provisioner/rbac/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,29 @@

package rbac

// +kubebuilder:rbac:groups="",resources=namespaces;secrets;serviceaccounts;services,verbs=get;list;watch;delete;create;update
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;delete;create;update
// +kubebuilder:rbac:groups="",resources=events,verbs=get;create;update
// +kubebuilder:rbac:groups="",resources=endpoints,verbs=get;list;watch
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;watch;create;update
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses;gateways;httproutes;tlsroutes;referencepolicies,verbs=get;list;watch;update
// Note, ReferencePolicy does not currently have a .status field so it's omitted from the below.
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses/status;gateways/status;httproutes/status;tlsroutes/status,verbs=create;get;update
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses/status,verbs=create;get;update
// +kubebuilder:rbac:groups=projectcontour.io,resources=httpproxies;tlscertificatedelegations;extensionservices;contourconfigurations,verbs=get;list;watch
// +kubebuilder:rbac:groups=projectcontour.io,resources=httpproxies/status;extensionservices/status;contourconfigurations/status,verbs=create;get;update
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterroles;clusterrolebindings;roles;rolebindings,verbs=get;list;delete;create;update;watch
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;delete;create;update
// +kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=get;list;watch;delete;create;update
// This file only contains entries for RBAC that the Provisioner needs itself directly.
// Transitive requirements, i.e. RBAC the Provisioner needs in order to be able to create
// the Contour ClusterRoles/Roles, are handled at YAML generation time by pulling in Contour's
// RBAC entries as well.

// Add RBAC policy to support leader election.
// RBAC for Gateway API.
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses;gateways,verbs=get;list;watch
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses/status;gateways/status,verbs=update
// ---

// RBAC for core Contour resources to be provisioned.
// +kubebuilder:rbac:groups="",resources=configmaps;secrets;services;serviceaccounts,verbs=get;list;watch;create;update;delete
// +kubebuilder:rbac:groups=apps,resources=deployments;daemonsets,verbs=get;list;watch;create;update;delete
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterroles;clusterrolebindings;roles;rolebindings,verbs=get;list;watch;create;update;delete
// ---

// RBAC for leader election for the provisioner.
// +kubebuilder:rbac:groups="",resources=events,verbs=create;get;update,namespace=projectcontour
// +kubebuilder:rbac:groups="coordination.k8s.io",resources=leases,verbs=create;get;update,namespace=projectcontour
// ---

// Contour itself has leader election RBAC scoped to a single namespace, but the provisioner
// needs it for all namespaces in order to be able to create those Roles.
// +kubebuilder:rbac:groups="",resources=events,verbs=create;get;update
// +kubebuilder:rbac:groups="coordination.k8s.io",resources=leases,verbs=create;get;update
// ---

0 comments on commit 105f6e5

Please sign in to comment.