|
| 1 | +# Integration kubelogin and Active Directory |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +kubelogin is helper tool for kubernetes and oidc integration. |
| 6 | +It makes easy to login Open ID Provider. |
| 7 | +This document describes how dex work with kubelogin and Active Directory. |
| 8 | + |
| 9 | +examples/config-ad-kubelogin.yaml is sample configuration to integrate Active Directory and kubelogin. |
| 10 | + |
| 11 | +## Precondition |
| 12 | + |
| 13 | +1. Active Directory |
| 14 | +You should have Active Directory or LDAP has Active Directory compatible schema such as samba ad. |
| 15 | +You may have user objects and group objects in AD. Please ensure TLS is enabled. |
| 16 | + |
| 17 | +2. Install kubelogin |
| 18 | +Download kubelogin from https://github.com/int128/kubelogin/releases. |
| 19 | +Install it to your terminal. |
| 20 | + |
| 21 | +## Getting started |
| 22 | + |
| 23 | +### Generate certificate and private key |
| 24 | + |
| 25 | +Create OpenSSL conf req.conf as follow: |
| 26 | + |
| 27 | +``` |
| 28 | +[req] |
| 29 | +req_extensions = v3_req |
| 30 | +distinguished_name = req_distinguished_name |
| 31 | +
|
| 32 | +[req_distinguished_name] |
| 33 | +
|
| 34 | +[ v3_req ] |
| 35 | +basicConstraints = CA:FALSE |
| 36 | +keyUsage = nonRepudiation, digitalSignature, keyEncipherment |
| 37 | +subjectAltName = @alt_names |
| 38 | +
|
| 39 | +[alt_names] |
| 40 | +DNS.1 = dex.example.com |
| 41 | +``` |
| 42 | + |
| 43 | +Please replace dex.example.com to your favorite hostname. |
| 44 | +Generate certificate and private key by following command. |
| 45 | + |
| 46 | +```console |
| 47 | +$ openssl req -new -x509 -sha256 -days 3650 -newkey rsa:4096 -extensions v3_req -out openid-ca.pem -keyout openid-key.pem -config req.cnf -subj "/CN=kube-ca" -nodes |
| 48 | +$ ls openid* |
| 49 | +openid-ca.pem openid-key.pem |
| 50 | +``` |
| 51 | + |
| 52 | +### Modify dex config |
| 53 | + |
| 54 | +Modify following host, bindDN and bindPW in examples/config-ad-kubelogin.yaml. |
| 55 | + |
| 56 | +```yaml |
| 57 | +connectors: |
| 58 | +- type: ldap |
| 59 | + name: OpenLDAP |
| 60 | + id: ldap |
| 61 | + config: |
| 62 | + host: ldap.example.com:636 |
| 63 | + |
| 64 | + # No TLS for this setup. |
| 65 | + insecureNoSSL: false |
| 66 | + insecureSkipVerify: true |
| 67 | + |
| 68 | + # This would normally be a read-only user. |
| 69 | + bindDN: cn=Administrator,cn=users,dc=example,dc=com |
| 70 | + bindPW: admin0! |
| 71 | +``` |
| 72 | +
|
| 73 | +### Run dex |
| 74 | +
|
| 75 | +``` |
| 76 | +$ bin/dex serve examples/config-ad-kubelogin.yaml |
| 77 | +``` |
| 78 | + |
| 79 | +### Configure kubernetes with oidc |
| 80 | + |
| 81 | +Copy openid-ca.pem to /etc/ssl/certs/openid-ca.pem on master node. |
| 82 | + |
| 83 | +Use the following flags to point your API server(s) at dex. `dex.example.com` should be replaced by whatever DNS name or IP address dex is running under. |
| 84 | + |
| 85 | +``` |
| 86 | +--oidc-issuer-url=https://dex.example.com:32000/dex |
| 87 | +--oidc-client-id=kubernetes |
| 88 | +--oidc-ca-file=/etc/ssl/certs/openid-ca.pem |
| 89 | +--oidc-username-claim=email |
| 90 | +--oidc-groups-claim=groups |
| 91 | +``` |
| 92 | + |
| 93 | +Then restart API server(s). |
| 94 | + |
| 95 | + |
| 96 | +See https://kubernetes.io/docs/reference/access-authn-authz/authentication/ for more detail. |
| 97 | + |
| 98 | +### kubelogin |
| 99 | + |
| 100 | +Create context for dex authentication: |
| 101 | + |
| 102 | +```console |
| 103 | +$ kubectl config set-context oidc-ctx --cluster=cluster.local --user=test |
| 104 | +$ kubectl config set-credentials test \ |
| 105 | + --auth-provider=oidc \ |
| 106 | + --auth-provider-arg=idp-issuer-url=https://dex.example.com:32000/dex \ |
| 107 | + --auth-provider-arg=client-id=kubernetes \ |
| 108 | + --auth-provider-arg=client-secret=ZXhhbXBsZS1hcHAtc2VjcmV0 \ |
| 109 | + --auth-provider-arg=idp-certificate-authority-data=$(base64 -w 0 openid-ca.pem) \ |
| 110 | + --auth-provider-arg=extra-scopes="offline_access openid profile email group" |
| 111 | +$ kubectl config use-context oidc-ctx |
| 112 | +``` |
| 113 | + |
| 114 | +Please confirm idp-issuer-url, client-id, client-secret and idp-certificate-authority-data value is same as config-ad-kubelogin.yaml's value. |
| 115 | + |
| 116 | +Then run kubelogin: |
| 117 | + |
| 118 | +```console |
| 119 | +$ kubelogin |
| 120 | +``` |
| 121 | + |
| 122 | +Access http://localhost:8000 by web browser and login with your AD account (eg. test@example.com) and password. |
| 123 | +After login and grant, you have following token in ~/.kube/config: |
| 124 | + |
| 125 | +``` |
| 126 | + id-token: eyJhbGciOiJSUzICuU4dCcilDDWlw2lfr8mg... |
| 127 | + refresh-token: ChlxY2EzeGhKEB4492EzecdKJOElECK... |
| 128 | +``` |
| 129 | + |
0 commit comments