OIDC Configuration for Shoot clusters
OpenID Connect
For older Shoot clusters (Kubernetes version < 1.32), the kube-apiserver of Shoot clusters can be provided with OpenID Connect configuration by providing specific label within the Shoot spec during the Shoot creation. The label in the Shoot manifest must match name of the seed cluster on which your Shoot should reside:
If the label was not specified in Shoot's YAML manifest during creation time, it will be added automatically by webhook.
Starting with Kubernetes v1.30, Gardener (and Kubernetes) encourages
configuration from OIDC-based config to the Structured Authentication approach,
where authentication is configured via a ConfigMap in the project namespace and
referenced from the Shoot spec via
spec.kubernetes.kubeAPIServer.structuredAuthentication.configMapName. For
further information please visit Gardener Documentation
OIDC kubeconfig
OIDC kubeconfig is stored in shoot-name.kubeconfig-oidc secret in the Shoot's Project namespace in the Garden cluster.
Only users with an owner or an admin role assigned within a specific Project are able to retrieve secrets within Project's namespace.
Even though the OIDC configuration inside the Shoot manifest is deprecated (kubernetes version >= 1.31), you can still download a valid OIDC-based kubeconfig also from the OSC Dashboard.
The recommended way to use OIDC kubeconfig is the kubectl plugin called kubectl oidc-login.
Static Token kubeconfig
This kubeconfig contains a static token and provides cluster-admin privileges. It is stored in the shoot-name.kubeconfig secret in the Shoot's Project namespace in the Garden cluster.
Static token kubeconfig is not available for Shoot clusters using Kubernetes version >= 1.27.
It is not the recommended method to access the shoot cluster with the static kubeconfig since there are security flaws associated with it:
- The static token in the kubeconfig doesn't have any expiration date.
- The static token doesn't have any user identity associated with it. The user associated with that token will always be system:cluster-admin, irrespective of the person accessing the cluster. Hence, it is impossible to audit the events in cluster.
When enableStaticTokenKubeconfig field is not explicitly set in the Shoot spec:
-
for Shoot clusters using Kubernetes version < 1.26 the field is defaulted to true.
-
for Shoot clusters using Kubernetes version >= 1.26 the field is defaulted to false.
-
for Shoot clusters using Kubernetes version >= 1.27 the field is locked to false.
Example of OIDC configuration in Shoot YAML manifest
How to create custom kubeconfig with limited access to cluster
-
Create custom
sa (ServiceAccount) -
Verify that
sawas created successfullyexample output:
-
Create a token for custom ServiceAccount
Validity of the created token is 1 year.
- Create a custom role in namespace
my-namespacewhich will allow the ServiceAccount to only access selected resources(e.g., pods,pods logs, shoots, ...) from namespacemy-namespace
Example for pods and pods logs:
5. Create RoleBinding to bind created role my-role with
ServiceAccount my-service-account
6. Generate custom kubeconfig
In the command above you can change my-cluster and my-context to any desired name, preferably use your cluster name to easily distinguish more contexts.
Custom kubeconfig will be saved into file my-sa-kubeconfig.yaml.
-
Test of newly created kubeconfig
Conclusion: As we can see from this short demo, we can define a limited access to a cluster, based on security policy defined within the customer organization.
We strongly recommended to create tokens with limited lifespan.
For more details about RBAC please refer to the official Kubernetes documentation