This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.8.5. Configuring dynamic admission
This procedure outlines high-level steps to configure dynamic admission. The functionality of the admission chain is extended by configuring a webhook admission plug-in to call out to a webhook server.
The webhook server is also configured as an aggregated API server. This allows other OpenShift Container Platform components to communicate with the webhook using internal credentials and facilitates testing using the oc command. Additionally, this enables role based access control (RBAC) into the webhook and prevents token information from other API servers from being disclosed to the webhook.
Prerequisites
- An OpenShift Container Platform account with cluster administrator access.
-
The OpenShift Container Platform CLI (
oc) installed. - A published webhook server container image.
Procedure
- Build a webhook server container image and make it available to the cluster using an image registry.
- Create a local CA key and certificate and use them to sign the webhook server’s certificate signing request (CSR).
Create a new project for webhook resources:
oc new-project my-webhook-namespace
$ oc new-project my-webhook-namespace1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Note that the webhook server might expect a specific name.
Define RBAC rules for the aggregated API service in a file called
rbac.yaml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Delegates authentication and authorization to the webhook server API.
- 2
- Allows the webhook server to access cluster resources.
- 3
- Points to resources. This example points to the
namespacereservationsresource. - 4
- Enables the aggregated API server to create admission reviews.
- 5
- Points to resources. This example points to the
namespacereservationsresource. - 6
- Enables the webhook server to access cluster resources.
- 7
- Role binding to read the configuration for terminating authentication.
- 8
- Default cluster role and cluster role bindings for an aggregated API server.
Apply those RBAC rules to the cluster:
oc auth reconcile -f rbac.yaml
$ oc auth reconcile -f rbac.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file called
webhook-daemonset.yamlthat is used to deploy a webhook as a daemon set server in a namespace:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Note that the webhook server might expect a specific container name.
- 2
- Points to a webhook server container image. Replace
<image_registry_username>/<image_path>:<tag>with the appropriate value. - 3
- Specifies webhook container run commands. Replace
<container_commands>with the appropriate value. - 4
- Defines the target port within pods. This example uses port 8443.
- 5
- Specifies the port used by the readiness probe. This example uses port 8443.
Deploy the daemon set:
oc apply -f webhook-daemonset.yaml
$ oc apply -f webhook-daemonset.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Define a secret for the service serving certificate signer, within a YAML file called
webhook-secret.yaml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the secret:
oc apply -f webhook-secret.yaml
$ oc apply -f webhook-secret.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Define a service account and service, within a YAML file called
webhook-service.yaml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Expose the webhook server within the cluster:
oc apply -f webhook-service.yaml
$ oc apply -f webhook-service.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Define a custom resource definition for the webhook server, in a file called
webhook-crd.yaml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Reflects
CustomResourceDefinitionspecvalues and is in the format<plural>.<group>. This example uses thenamespacereservationsresource. - 2
- REST API group name.
- 3
- REST API version name.
- 4
- Accepted values are
NamespacedorCluster. - 5
- Plural name to be included in URL.
- 6
- Alias seen in
ocoutput. - 7
- The reference for resource manifests.
Apply the custom resource definition:
oc apply -f webhook-crd.yaml
$ oc apply -f webhook-crd.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Configure the webhook server also as an aggregated API server, within a file called
webhook-api-service.yaml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- A PEM-encoded CA certificate that signs the server certificate that is used by the webhook server. Replace
<ca_signing_certificate>with the appropriate certificate in base64 format.
Deploy the aggregated API service:
oc apply -f webhook-api-service.yaml
$ oc apply -f webhook-api-service.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Define the webhook admission plug-in configuration within a file called
webhook-config.yaml. This example uses the validating admission plug-in:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Name for the
ValidatingWebhookConfigurationobject. This example uses thenamespacereservationsresource. - 2
- Name of the webhook to call. This example uses the
namespacereservationsresource. - 3
- Enables access to the webhook server through the aggregated API.
- 4
- The webhook URL used for admission requests. This example uses the
namespacereservationresource. - 5
- A PEM-encoded CA certificate that signs the server certificate that is used by the webhook server. Replace
<ca_signing_certificate>with the appropriate certificate in base64 format.
Deploy the webhook:
oc apply -f webhook-config.yaml
$ oc apply -f webhook-config.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Verify that the webhook is functioning as expected. For example, if you have configured dynamic admission to reserve specific namespaces, confirm that requests to create those namespaces are rejected and that requests to create non-reserved namespaces succeed.