Skip to content

Commit 03f0cda

Browse files
committed
webhook: use cert-manager for self-signed cert
This patch uses the cert-manager operator to automatically generate the self-signed CA, cert, and key and mount it within the webhook deployment. It also uses cert-manager to inject the CA cert into the mutatatingwebhookconfiguration.
1 parent 4a8239d commit 03f0cda

File tree

6 files changed

+35
-54
lines changed

6 files changed

+35
-54
lines changed

README.md

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -142,57 +142,13 @@ In order to modify the deployment follow these steps:
142142
143143
1. Modify the GROUPS env variable to contain the list of classes (openshift groups) of which you would like to assign class labels. This file is found here: webhooks/assign-class-label/deployment.yaml
144144
145-
2. Generate a new OpenSSL certificate
145+
2. Change namespace variable in the kubernetes manifests to match namespace you want the webhook to be deployed to.
146146
147-
```
148-
openssl req -x509 -sha256 -newkey rsa:2048 -keyout webhook.key -out webhook.crt -days 1024 -nodes -addext "subjectAltName = DNS.1:service_name.namespace.svc"
149-
```
150-
151-
When deployed to rhods-notebooks the command was specified as such:
152-
153-
```
154-
openssl req -x509 -sha256 -newkey rsa:2048 -keyout webhook.key -out webhook.crt -days 1024 -nodes -addext "subjectAltName = DNS.1:assign-class-label-webhook.rhods-notebooks.svc"
155-
```
156-
157-
3. Add the cert and key to the required resources:
158-
159-
```
160-
cat webhook.crt | base64 | tr -d '\n'
161-
```
162-
163-
```
164-
cat webhook.key | base64 | tr -d '\n'
165-
```
166-
167-
This will encode the certificate and key in base64 format which is required. Copy the output of the webhook.crt to the caBundle in webhooks/assign-class-label/webhook-config.yaml. Then create a secret.yaml that looks like this
168-
169-
```
170-
apiVersion: v1
171-
kind: Secret
172-
metadata:
173-
name: webhook-cert
174-
type: Opaque
175-
data:
176-
webhook.crt:
177-
webhook.key:
178-
```
179-
180-
Copy and paste the output of the cat command to the respective fields for webhook.crt and webhook.key. Then execute
181-
182-
```
183-
oc apply -f secret.yaml --as system:admin
184-
```
185-
186-
within the same namespace that your webhook will be deployed to.
187-
188-
189-
4. Change namespace variable in the kubernetes manifests to match namespace you want the webhook to be deployed to.
190-
191-
5. From webhooks/assign-class-label/ directory run:
147+
3. From webhooks/assign-class-label/ directory run:
192148
```
193149
oc apply -k . --as system:admin
194150
```
195151
196-
***Steps 2, 3, and 4 are only required if you are deploying to a new namespace/environment.***
152+
***Step 2 is only required if you are deploying to a new namespace/environment.***
197153
198154
The python script and docker image used for the webserver should not need changes made to it. But in the case that changes must be made, the Dockerfile and python script can be found at docker/src/python/assign-class-label/.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Certificate
3+
metadata:
4+
name: assign-class-label-tls
5+
spec:
6+
secretName: assign-class-label-tls
7+
issuerRef:
8+
name: assign-class-label-issuer
9+
kind: Issuer
10+
commonName: "rhods-notebooks.svc"
11+
dnsNames:
12+
- assign-class-label-webhook.rhods-notebooks.svc

webhooks/assign-class-label/deployment.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ spec:
1717
ports:
1818
- containerPort: 443
1919
volumeMounts:
20-
- name: cert
21-
mountPath: /certs
20+
- name: tls
21+
mountPath: /certs/webhook.crt
22+
subPath: tls.crt
23+
readOnly: true
24+
- name: tls
25+
mountPath: /certs/webhook.key
26+
subPath: tls.key
2227
readOnly: true
2328
resources:
2429
limits:
@@ -30,6 +35,6 @@ spec:
3035
value: "cs210,cs599-pmpp"
3136
serviceAccountName: webhook-sa
3237
volumes:
33-
- name: cert
38+
- name: tls
3439
secret:
35-
secretName: webhook-cert
40+
secretName: assign-class-label-tls
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Issuer
3+
metadata:
4+
name: assign-class-label-issuer
5+
spec:
6+
selfSigned: {}

webhooks/assign-class-label/kustomization.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ commonLabels:
55
app: assign-class-label-webhook
66

77
resources:
8+
- issuer.yaml
9+
- certificate.yaml
810
- deployment.yaml
911
- service.yaml
1012
- webhook-config.yaml
1113
- serviceaccount.yaml
1214
- role.yaml
1315
- rolebinding.yaml
14-
- secret.yaml

webhooks/assign-class-label/webhook-config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ apiVersion: admissionregistration.k8s.io/v1
22
kind: MutatingWebhookConfiguration
33
metadata:
44
name: assign-class-label-webhook
5+
annotations:
6+
cert-manager.io/inject-ca-from: rhods-notebooks/assign-class-label-tls
57
webhooks:
6-
- name: assign-class-label-webhook.nerc.com
8+
- name: assign-class-label-webhook.rhods-notebooks.svc
79
clientConfig:
810
service:
911
namespace: rhods-notebooks
1012
name: assign-class-label-webhook
1113
path: /mutate
12-
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURvakNDQW9xZ0F3SUJBZ0lVZjBXOXFOVS92OERkdjNKSktJVWV6Z1Z0YTJVd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1FqRUxNQWtHQTFVRUJoTUNXRmd4RlRBVEJnTlZCQWNNREVSbFptRjFiSFFnUTJsMGVURWNNQm9HQTFVRQpDZ3dUUkdWbVlYVnNkQ0JEYjIxd1lXNTVJRXgwWkRBZUZ3MHlOVEEyTVRFeE5qVXdOVGRhRncweU9EQXpNekV4Ck5qVXdOVGRhTUVJeEN6QUpCZ05WQkFZVEFsaFlNUlV3RXdZRFZRUUhEQXhFWldaaGRXeDBJRU5wZEhreEhEQWEKQmdOVkJBb01FMFJsWm1GMWJIUWdRMjl0Y0dGdWVTQk1kR1F3Z2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQgpEd0F3Z2dFS0FvSUJBUUMweklTVkZLc2EyUWoxRmR3UE4rVkh2VnlyUnlRbWJycGgxVklRWWhOY21UaGpBenFaClFOQURMbXlyZzFrcnI4RysrQWhmVzl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