Slide 1

Slide 1 text

LDAP Authentication for Kubernetes Using Webhook Token Authentication Plugin `DRIDI WALID`

Slide 2

Slide 2 text

WHO AM I ?

Slide 3

Slide 3 text

DRIDI WALID Kubernetes Consultant/Trainer Lead Ops @FnacDarty Linkedin: https://www.linkedin.com/in/dridi-walid

Slide 4

Slide 4 text

Agenda: ❏ Kubernetes Access Stages ❏ LDAP Integration Flow ❏ DEMO!

Slide 5

Slide 5 text

Kubernetes Access Stages

Slide 6

Slide 6 text

kubectl request Overview of controlling access to the kubernetes api ... Authn Authz Admission Control 1. Authn: Checks the credentials, 2. Authz: Checks if user is allowed to perform the action, 3. Admission Control: Checks if the request conforms policies

Slide 7

Slide 7 text

kubectl request Overview of controlling access to the kubernetes api ... Authn Authz Admission Control 1. Authn: Checks the credentials, 2. Authz: Checks if user is allowed to perform the action, 3. Admission Control: Checks if the request conforms policies

Slide 8

Slide 8 text

kubectl request Overview of controlling access to the kubernetes api ... Authn Authz Admission Control 1. Authn: Checks the credentials, 2. Authz: Checks if user is allowed to perform the action, 3. Admission Control: Checks if the request conforms policies

Slide 9

Slide 9 text

LDAP Integration Flow

Slide 10

Slide 10 text

PRE-FLIGHT

Slide 11

Slide 11 text

Create new user entry // foo.ldif dn: cn=foo,dc=mycompany,dc=co objectClass: top objectClass: inetOrgPerson cn: foo gn: Foo sn: Bar userPassword: foopassword ou: intern cn → username userPassword → password ou → groups ldapadd -H ldap:// -x -D cn=admin,dc=mycompany,dc=co -w adminpassword -f foo.ldif ldapsearch -LLL -H ldap:// -x -D cn=admin,dc=mycompany,dc=co -w adminpassword -b dc=mycompany,dc=co '(&(objectClass=inetOrgPerson)(cn=foo)(userPassword=foopassword))'

Slide 12

Slide 12 text

Kubectl config file using token authn apiVersion: v1 clusters: - cluster: certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JS... server: https://:6443 name: cluster.local contexts: - context: cluster: cluster.local user: foo name: [email protected] current-context: [email protected] kind: Config preferences: {} users: - name: foo user: token: foo:foopassword

Slide 13

Slide 13 text

Enable webhook token authn on api-server apiVersion: v1 kind: Pod metadata: name: kube-apiserver-k8s-master namespace: kube-system spec: containers: - command: - kube-apiserver - --authentication-token-webhook-config-file=/etc/kubernetes/webhook-token-auth-config.yaml ...

Slide 14

Slide 14 text

Webhook token config file # clusters refers to the remote service. clusters: - name: webhook-token-auth-cluster cluster: insecure-skip-tls-verify: true // We use self-signed tls certs server: https:// // Node.js Authentication Service # users refers to the API server's webhook configuration. users: - name: webhook-token-auth-user # kubeconfig files require a context. Provide one for the API server. current-context: webhook-token-auth contexts: - context: cluster: webhook-token-auth-cluster user: webhook-token-auth-user name: webhook-token-auth

Slide 15

Slide 15 text

Webhook Token Plugin Interface // Request { "apiVersion": "authentication.k8s.io/v1beta1", "kind": "TokenReview", "spec": { "token": "username:password" } }

Slide 16

Slide 16 text

Webhook Token Plugin Interface { // Expected Response "apiVersion": "authentication.k8s.io/v1beta1", "kind": "TokenReview", "spec": { "token": "e2ede302-9af2-4638-b492-32a34231cdbe" } "status": { "authenticated": true, "user": { "username": "", "uid": "1", "groups": [ "intern" ] }, } }

Slide 17

Slide 17 text

Node.js Authentication Service Gist: https://gist.github.com/pocteo-co/acdbd7666bfdb1d5d15e9b611fcaa55f

Slide 18

Slide 18 text

FLOW

Slide 19

Slide 19 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token trigger ldapsearch (cn,password) load request (username,password) status[,userinfo} request token:“username:password” 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 20

Slide 20 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token request token:“username:password” ldapsearch (cn,password) load request (username,password) status[,userinfo} trigger 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 21

Slide 21 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token request token:“username:password” trigger ldapsearch (cn,password) load request (username,password) status[,userinfo} 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 22

Slide 22 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token request token:“username:password” trigger ldapsearch (cn,password) load request (username,password) status[,userinfo} 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 23

Slide 23 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token request token:“username:password” trigger ldapsearch (cn,password) load request (username,password) status[,userinfo} 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 24

Slide 24 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token request token:“username:password” trigger ldapsearch (cn,password) load request (username,password) status[,userinfo} 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 25

Slide 25 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token request token:“username:password” trigger ldapsearch (cn,password) load request (username,password) status[,userinfo} 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 26

Slide 26 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token request token:“username:password” trigger ldapsearch (cn,password) load request (username,password) status[,userinfo} 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 27

Slide 27 text

kubectl kubernetes Authn SVC ldap server Config File Webhook Token request token:“username:password” trigger ldapsearch (cn,password) load request (username,password) status[,userinfo} 1. Use kubectl cli k8s client and point to the right configfile using --kubeconfig flag, 2. Make a request using bearer token, 3. API-Server receives a request and triggers a Webhook Token, 4. Webhook Token Plugin forwards credentials to Authn service for validation, 5. Authn service makes an ldapsearch operation, 6. LDAP-Server send status and userinfo if token is valid, 7. Authn service send back to api-server the result, 8. API-Server send 401 to user if token is invalid, 9. API-server pass userinfo to Authz stage for role/rolebinding mapping

Slide 28

Slide 28 text

DEMO!!

Slide 29

Slide 29 text

Thanks to Abir Hamzi & Majd Mimoun for the Node.js authn service quick implementation

Slide 30

Slide 30 text

Question ?