Certificate:
Data:
Version: 3 (0x2)
Serial Number:
# ...
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = , ST = , O = , CN =
Validity
Not Before: Nov 18 20:29:01 2020 GMT
Not After : Nov 16 20:29:01 2030 GMT
Subject: C = , ST = , O = , CN = kube-keycloak.
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public-Key: (2048 bit)
Modulus:
# ...
Exponent: # ...
X509v3 extensions:
X509v3 Subject Alternative Name:
DNS:kube-keycloak.
Signature Algorithm: sha256WithRSAEncryption
# ...
The important part is that your certificate contains the correct X509v3 Subject Alternative Name field. If it is missing, Go will complain to you that the certificate use obsolete Common Name.
Go deprecated use of Common Name by default since v1.15 via
this commit.
Pass certificates to keycloak
The
keycloak docker container indicates that keycloak will use certificate and private keys from /etc/x509/https/tls.{crt,key}. So, we are going to pass those via a secret mounted at the desired directory.
First, create the secret
1
2
# Create our secret that will be mounted into our podkubectl create secret generic certs -n keycloak --from-file keycloak.crt --from-file keycloak.key
Then, update your keycloak chart values to mount this new secret.
extraEnv:| - name: PROXY_ADDRESS_FORWARDING
value: "true"
- name: KEYCLOAK_USER
value:
- name: KEYCLOAK_PASSWORD
value: podLabels:app:keycloakcomponent:keycloakservice:labels:app:keycloakcomponent:keycloakhttpsPort:443# 8443 by default, but it should be reachable via the same URL from outside than inside, eg `https://keycloak.`ingress:labels:app:keycloakcomponent:keycloaktls:- hosts:- keycloak.- kube-keycloak.postgresql:postgresqlPassword:keycloakpostgresqlDatabase:keycloakenabled:truepersistence:existingClaim:postgresql-dataextraVolumes:| - name: certs
secret:
secretName: certs
items:
# Map keycloak.crt => tls.crt
- key: keycloak.crt
path: tls.crt
# Map keycloak.key => tls.key
- key: keycloak.key
path: tls.keyextraVolumeMounts:| - name: certs
mountPath: "/etc/x509/https"
readOnly: true
Finally, update your chart.
1
2
# Update our release to use the certificateshelm upgrade -n keycloak -f ./kubernetes/authentication/01-KeycloakChartValues.yaml keycloak codecentric/keycloak
# Add a new route from "kube-keycloak." that delegates to the TLS connection using the certs declared abovekubectl apply -f ./kubernetes/authentication/03-InternalRoute.yaml
Go to https://kube-keycloak.. It should show you a security erro SEC_ERROR_UNKNOWN_ISSUER.
Don’t worry, this is normal since keycloak’s certificate was signed by our custom Certificate Authority (CA). For curiosity, click on View Certificate.
The certificate correctly shows the Subject Alt Names extension, and is signed by our custom CA.
A last verification step: ensure that requests are correctly trusted if using our custom CA.
kubectl oidc-login setup \
--oidc-issuer-url=https://kube-keycloak./auth/realms/ \
--oidc-client-id=\
--oidc-client-secret=\
--certificate-authority=/etc/kubernetes/auth-cert/ca.crt
# Add the parameter below if running from an environment where browser is unavailable. Don't forget to add ` \` above# --grant-type=authcode-keyboard
The command above will output you installation instruction. Don’t pay attention to the ## 3.cluster role setup part, we are getting to it, in a more generic way.
And we already did the ## 4. API server setup above. Just run the step ## 5. to set credentials for our oidc user.
Finally, create a new context for your user (and optionally switch to this context)
1
2
3
4
5
6
# Create the contextkubectl config set-context oidc@ --cluster="" --user="oidc"# Switch to the contextkubectl config use-context oidc@
# Go back to the admin contextkubectl config use-context kubernetes-admin@
1
2
3
4
5
6
# Get the current contextkubectl config current-context
# List contextskubectl config get-contexts
# Switch to other contextkubectl config use-context
Hey, we’ve done important things here ! Maybe it’s time to commit…
1
2
3
4
git add .
git commit -m "Administrate the cluster with authentication
Following guide @ https://gerkindev.github.io/devblog/walkthroughs/kubernetes/08-kubernetes-user-management/"