This is an automated test for verifying behavior of the plugin with a real Kubernetes cluster and OIDC provider.
This test checks the following points:
- User can set up Kubernetes OIDC authentication using setup guide.
- User can log in to an OIDC provider on a browser.
- User can access the cluster using a token returned from the plugin.
It depends on the following components:
- Kubernetes cluster (Kind)
- OIDC provider (Dex)
- Browser (Chrome)
- kubectl command
Let's take a look at the diagram.
It prepares the following resources:
- Generate a pair of CA certificate and TLS server certificate for Dex.
- Run Dex on a container.
- Create a Kubernetes cluster using Kind.
- Mutate
/etc/hosts
of the machine so that the browser access Dex. - Mutate
/etc/hosts
of the kind container so that kube-apiserver access Dex.
It performs the test by the following steps:
- Run kubectl.
- kubectl automatically runs kubelogin.
- kubelogin automatically runs chromelogin.
- chromelogin opens the browser, navigates to
http://localhost:8000
and enter the username and password. - kubelogin gets an authorization code from the browser.
- kubelogin gets a token.
- kubectl accesses an API with the token.
- kube-apiserver verifies the token by Dex.
- Check if kubectl exited with code 0.
You need to set up the following components:
- Docker
- Kind
- Chrome or Chromium
Add the following line to /etc/hosts
so that the browser can access the Dex.
127.0.0.1 dex-server
Generate CA certificate and add cert/ca.crt
into your trust store.
For macOS, you can add it by Keychain.
make -C cert
Run the test.
make
Clean up.
make terminate
make clean
Consider the following issues:
- kube-apiserver runs on the host network of the kind container.
- kube-apiserver cannot resolve a service name by kube-dns.
- kube-apiserver cannot access a cluster IP.
- kube-apiserver can access another container via the Docker network.
- Chrome requires exactly match of domain name between Dex URL and a server certificate.
Consequently,
- kube-apiserver accesses Dex by resolving
/etc/hosts
and via the Docker network. - kubelogin and Chrome accesses Dex by resolving
/etc/hosts
and via the Docker network.
Consider the following issues:
- kube-apiserver requires
--oidc-issuer
is HTTPS URL. - kube-apiserver requires a CA certificate at startup, if
--oidc-ca-file
is given. - kube-apiserver mounts
/usr/local/share/ca-certificates
from the kind container. - It is possible to mount a file from the CI machine.
- It is not possible to issue a certificate using Let's Encrypt in runtime.
- Chrome requires a valid certificate in
~/.pki/nssdb
.
As a result,
- kube-apiserver uses the CA certificate of
/usr/local/share/ca-certificates/dex-ca.crt
. See theextraMounts
section ofcluster.yaml
. - kubelogin uses the CA certificate in
output/ca.crt
. - Chrome uses the CA certificate in
~/.pki/nssdb
.
- Set the issuer URL to kube-apiserver. See
cluster.yaml
. - Set
BROWSER
environment variable to runchromelogin
byxdg-open
.