Open
Description
I followed the Keycloak documentation, but cant really seem to make it work.
Keycloak is setup as pr. the docs, and when I run below command, it looks like I'm getting the response that I should.
kubectl oidc-login get-token -v1 \
--oidc-issuer-url=https://keycloak-domain.org/auth/realms/kubernetes \
--oidc-client-id=kubernetes \
--oidc-client-secret=secret-goes-here
...
I0927 21:37:02.504991 32273 get_token.go:81] the ID token has the claim: groups=[kubernetes:admin]
I0927 21:37:02.504973 32273 get_token.go:81] the ID token has the claim: aud=kubernetes
I0927 21:37:02.505052 32273 get_token.go:81] the ID token has the claim: iss=https://keycloak-domain.org/auth/realms/kubernetes
I0927 21:37:02.505037 32273 get_token.go:81] the ID token has the claim: sub=uuid-goes-here
...
kube-api is configured.
$ cat /etc/kubernetes/manifests/kube-apiserver.yaml
...
- --oidc-client-id=kubernetes
- --oidc-groups-claim=groups
- --oidc-issuer-url=https://keycloak-domain.org/auth/realms/kubernetes
- --oidc-username-claim=email
...
I applied below to kubernetes.
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: keycloak-admin-group
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: Group
name: kubernetes:admin
And added below to my kubeconfig
file, which I have exported with export KUBECONFIG=./kubeconfig
...
contexts:
- context:
cluster: green-bird-3416
user: keycloak
name: keycloak@green-bird-3416
current-context: keycloak@green-bird-3416
kind: Config
preferences: {}
users:
- name: keycloak
user:
exec:
apiVersion: client.authentication.k8s.io/v1beta1
command: kubelogin
args:
- get-token
- --oidc-issuer-url=https://keycloak-domain.org/auth/realms/kubernetes
- --oidc-client-id=kubernetes
- --oidc-client-secret=secret-goes-here
It generates a temp file at ~/.kube/cache/oidc-login/d721553ba91f6078f86a5cb2caa2f78eb4d27898b238dfad310b87f01ecdd117
with what looks like correct content.
But when i try and execute kubectl
commands I just get:
$ kubectl get pods
You got a valid token until 2019-09-27 21:50:29 +0200 CEST
error: You must be logged in to the server (Unauthorized)
What am I missing here ?