Skip to content

Commit

Permalink
rbac: Add update privilege for secrets
Browse files Browse the repository at this point in the history
This is required to add finalizers to secrets. If there is ever a way to
do this with fewer privileges we should do that instead.
  • Loading branch information
mdbooth committed Feb 7, 2025
1 parent a19bd9a commit a2d5ce9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ rules:
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- openstack.k-orc.cloud
Expand Down
2 changes: 0 additions & 2 deletions internal/scope/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ func (g gophercloudLogger) Printf(format string, args ...interface{}) {
g.logger.Info(fmt.Sprintf(format, args...))
}

// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch

// getCloudFromSecret extract a Cloud from the given namespace:secretName.
func getCloudFromSecret(ctx context.Context, ctrlClient client.Client, secretNamespace string, secretName string, cloudName string) (clientconfig.Cloud, []byte, error) {
emptyCloud := clientconfig.Cloud{}
Expand Down
18 changes: 18 additions & 0 deletions internal/util/credentials/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ import (
"github.com/k-orc/openstack-resource-controller/internal/util/dependency"
)

/*
NOTE: These are cluster-wide permissions on secrets, which is not ideal.
On the update privilege: we only need this for adding finalizers. Although
the OwnerReferencesPermissionEnforcement
(https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#ownerreferencespermissionenforcement)
may make it look like there is, there is no real finalizers subresource, so
we can't confine this to the ability to write the finalizer.
I (mdbooth) suspect that the future may bring new capabilities, either in
kube or its supporting ecosystem, which may allow us to reduce these
privileges in the future. We should periodically take some time to find out
if that has happened yet.
*/

// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=secrets,verbs=update;patch

func AddCredentialsWatch[
objectTP dependency.ObjectType[objectT],
objectListTP dependency.ObjectListType[objectListT, objectT],
Expand Down

0 comments on commit a2d5ce9

Please sign in to comment.