Skip to content

Commit

Permalink
Restrict admission controller permissions
Browse files Browse the repository at this point in the history
This change is mostly relevant for deployments without a virtual Garden cluster:
In this case, the admission controller needed cluster-wide list/watch permissions
for secrets. Restricting the cache to the `--webhook-config-namespace` namespace
eliminates this requirement.
  • Loading branch information
timuthy committed Jan 9, 2024
1 parent dbc7ed8 commit d1a0f2a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/gardener-extension-admission-openstack/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import (
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
gardenerhealthz "github.com/gardener/gardener/pkg/healthz"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
componentbaseconfig "k8s.io/component-base/config"
"k8s.io/component-base/version/verflag"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/healthz"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -115,6 +117,13 @@ func NewAdmissionCommand(ctx context.Context) *cobra.Command {
return err
}
managerOptions.LeaderElectionConfig = sourceClusterConfig
} else {
// Restrict the cache for secrets to the configured namespace to avoid the need for cluster-wide list/watch permissions.
managerOptions.Cache = cache.Options{
ByObject: map[client.Object]cache.ByObject{
&corev1.Secret{}: {Namespaces: map[string]cache.Config{webhookOptions.Server.Completed().Namespace: {}}},
},
}
}

mgr, err := manager.New(restOpts.Completed().Config, managerOptions)
Expand Down

0 comments on commit d1a0f2a

Please sign in to comment.