-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for mutual TLS on kubewarden controller #638
Conversation
How to setup k3d with mTLSCreate certificates: FQDN=mtls.kubewarden.io
# Create CA
openssl req -nodes -batch -x509 -sha256 -days 365 -newkey rsa:2048 -keyout rootCA.key -out rootCA.crt
# Create CSR
openssl req -nodes -batch -newkey rsa:2048 -keyout domain.key -out domain.csr \
-addext "subjectAltName = DNS:$FQDN"
# Create CRT
openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in domain.csr -out domain.crt -days 365 -CAcreateserial \
-extfile <(echo "subjectAltName=DNS:$FQDN")
# Print CRT
openssl x509 -text -noout -in domain.crt Create config files: # mtls/admission.yaml
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: ValidatingAdmissionWebhook
configuration:
apiVersion: apiserver.config.k8s.io/v1
kind: WebhookAdmissionConfiguration
kubeConfigFile: "/etc/mtls/kubeconfig"
- name: MutatingAdmissionWebhook
configuration:
apiVersion: apiserver.config.k8s.io/v1
kind: WebhookAdmissionConfiguration
kubeConfigFile: "/etc/mtls/kubeconfig"
# mtls/kubeconfig
apiVersion: v1
kind: Config
users:
- name: 'rancher-webhook.cattle-system.svc'
user:
client-certificate: /etc/mtls/domain.crt
client-key: /etc/mtls/domain.key Provide configuration and volume to k3s: k3d cluster create mtls-cluster \
--k3s-arg '--kube-apiserver-arg=admission-control-config-file=/etc/mtls/admission.yaml@server:*' \
--volume '/home/username/mtls:/etc/mtls@server:*' Create configmap and install kubewarden with mTLS support: kubectl create configmap -n kubewarden mtlscm --from-file=client-ca.crt=mtls/rootCA.crt
# Install controller (helm chart from this PR)
helm install --wait -n kubewarden kubewarden-controller ./charts/kubewarden-controller \
--set mTLS.enable=true --set mTLS.configMapName=mtlscm \
--set image.tag=latest --set auditScanner.image.tag=latest Workaround & Bug:Controller looks for client-ca.crt in a mount from secret where it does not exist. kubectl patch secret -n kubewarden kubewarden-webhook-server-cert --type='merge' -p "{\"data\":{\"client-ca.crt\":\"$(cat mtls/rootCA.crt | base64 -w0)\"}}"
k delete pod -n kubewarden kubewarden-controller-656c6b45f-rc4gx After this controller starts, but kubewarden-defaults shows another issues:
|
Currently, I'm getting |
I updated howto with complete steps. I got the same result as you. |
@fabriziosestito found an issue with the chart (missing mount) and I am fixing an issue with otel tests |
81d566f
to
c074b51
Compare
Amended the helm-chart with the correct mounting point for the upcoming controller change. |
The To summarize so far what I'm doing: Toggle meCreate certs: #!/usr/bin/env bash
set -aeEuo pipefail
FQDN=mtls.kubewarden.io
# Create CA
openssl req -nodes -batch -x509 -sha256 -days 365 -newkey rsa:2048 -keyout rootCA.key -out rootCA.crt
# Create CSR
openssl req -nodes -batch -newkey rsa:2048 -keyout domain.key -out domain.csr \
-addext "subjectAltName = DNS:$FQDN"
# Create CRT
openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in domain.csr -out domain.crt -days 365 -CAcreateserial \
-extfile <(echo "subjectAltName=DNS:$FQDN")
# Print CRT
openssl x509 -text -noout -in domain.crt Creates Needed files: # ./admission.yaml
---
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: ValidatingAdmissionWebhook
configuration:
apiVersion: apiserver.config.k8s.io/v1
kind: WebhookAdmissionConfiguration
kubeConfigFile: "/etc/mtls/kubeconfig"
- name: MutatingAdmissionWebhook
configuration:
apiVersion: apiserver.config.k8s.io/v1
kind: WebhookAdmissionConfiguration
kubeConfigFile: "/etc/mtls/kubeconfig" # ./kubeconfig
---
apiVersion: v1
kind: Config
users:
# Config for the controller webhook servive, in the shape of
# <controller chart name>-webhook-service.<kubewarden ns>.svc:443
- name: "kubewarden-controller-webhook-service.kubewarden.svc:443"
user:
client-certificate: /etc/mtls/domain.crt
client-key: /etc/mtls/domain.key
# Config for all policy servers, in the shape of
# policy-server-<policy-server name>.<policy-server ns>.svc:8443
- name: "*.kubewarden.svc:8443"
user:
client-certificate: /etc/mtls/domain.crt
client-key: /etc/mtls/domain.key # ./mtls-configmap.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mtls-configmap
namespace: kubewarden
data:
client-ca.crt: |
<rootCA.crt in PEM format, not base64> Then, do: $ k3d cluster create \
--k3s-arg '--kube-apiserver-arg=admission-control-config-file=/etc/mtls/admission.yaml@server:*' \
--volume "$(pwd):/etc/mtls@server:*" Apply the configmap: $ kubectl apply -f mtls-configmap.yml Upgrade the helm chart: $ helm upgrade -i --wait --namespace kubewarden --create-namespace kubewarden-controller \
./charts/kubewarden-controller \
--set auditScanner.cronJob.schedule="*/2 * * * *" --set auditScanner.policyReporter=true \
--set mTLS.enable=true --set mTLS.configMapName=mtls-configmap \
--set image.tag=latest With this, I see the correct logs in policy-server:
Yet creating a policy gives me:
|
@viccuad I think this is failing because the request is sent to - name: "kubewarden-controller-webhook-service.kubewarden.svc.cluster.local:443" If I were you, I would drop the |
Thanks! I left the :443 for completeness, indeed can be out. Updated the instructions on the other message for completion, rebased changing the order of the volumes in the template. Policy-server itself works fine.
|
For kubewarden-controller chart, add a new `.Values.mtls` section, where one can enable mutual TLS on the controller image. The controller expects a ConfigMap with a Certificate Authority that is valid in the Kubernetes API server. It will use this CA to create client certificates and keys that will be used by the policy-servers, so they can communicate via mTLS with the API server. Signed-off-by: Víctor Cuadrado Juan <[email protected]>
Signed-off-by: Víctor Cuadrado Juan <[email protected]>
5b6164e
to
b288579
Compare
Signed-off-by: Víctor Cuadrado Juan <[email protected]> Co-Authored-by: Flavio Castelli <[email protected]>
Signed-off-by: Víctor Cuadrado Juan <[email protected]>
Use real certificates and keys, since we use `buildCustomCert` to construct the ca variable and it expects real certs. Set the namespace on on webhooks_test.yaml so controllerDNSName is correctly initialized. Signed-off-by: Víctor Cuadrado Juan <[email protected]>
Updated tests and one variable assignment on the shared commit, ready for review. Current e2e tests check the non-mtls enabled path. Tested locally with an mTLS cluster. Needs
Where the
Then the audit-scanner should be working. |
Description
Part of #630.
For kubewarden-controller chart, add a new
.Values.mTLS
section, where one can enable mutual TLS on the controller image.The controller expects a ConfigMap with a Certificate Authority that is valid in the Kubernetes API server.
It will use this CA to create client certificates and keys that will be used by the policy-servers, so they can communicate via mTLS with the API server.
Test
TODO
Additional Information
Tradeoff
Potential improvement