Slide 1

Slide 1 text

Exchanging third-party tokens in Dex MAKSIM NABOKIKH Platform Lead and how it helps you to build a secure cloud native environment

Slide 2

Slide 2 text

Introduce yourself with a couple of jokes Tell what Dex is about Explain what Token Exchange is Show how applicable to the existing cloud-native infrastructure it is TODO LIST FOR THE TALK

Slide 3

Slide 3 text

Introduce yourself with a couple of jokes Tell what Dex is about Explain what Token Exchange is Show how applicable to the existing cloud-native infrastructure it is TODO LIST FOR THE TALK

Slide 4

Slide 4 text

Originally developed by CoreOS in 2015 (9 y.o.) FACTS CNCF Sandbox project since Jun 26, 2020 Community driven project since 2018 after CoreOS acquisition ~9K ~1.6K >25

Slide 5

Slide 5 text

THE MAIN IDEA OF DEX

Slide 6

Slide 6 text

THE MAIN IDEA OF DEX Dex acts as a portal to other identity providers through "connectors"; This lets Dex defer authentication to LDAP servers, SAML providers, or established identity providers like GitHub, Google, and Active Directory; Clients write their authentication logic once to talk to Dex, then Dex handles the protocols for a given backend.

Slide 7

Slide 7 text

THE MAIN IDEA

Slide 8

Slide 8 text

THE MAIN IDEA

Slide 9

Slide 9 text

THE MAIN IDEA

Slide 10

Slide 10 text

THE MAIN IDEA

Slide 11

Slide 11 text

WHY DO ENGINEERS LOVE DEX?

Slide 12

Slide 12 text

WHY DO ENGINEERS LOVE DEX? Ultra light: single binary in Go (~35 Mb) Simple: code that you can understand spending a couple of hours Kubernetes-native: integrates well with Kubernetes Community’s building block: used by projects like Argo CD or Sigstore True Open Source: community-driven project not owned by a company

Slide 13

Slide 13 text

WHY DO ENGINEERS LOVE DEX? Ultra light: single binary in Go (~35 Mb) Simple: code that you can understand spending a couple of hours Kubernetes-native: integrates well with Kubernetes Community’s building block: used by projects like Argo CD or Sigstore True Open Source: community-driven project not owned by a company

Slide 14

Slide 14 text

WHY DO ENGINEERS LOVE DEX? Ultra light: single binary in Go (~35 Mb) Simple: code that you can understand spending a couple of hours Kubernetes-native: integrates well with Kubernetes Community’s building block: used by projects like Argo CD or Sigstore True Open Source: community-driven project not owned by a company

Slide 15

Slide 15 text

WHY DO ENGINEERS LOVE DEX? Ultra light: single binary in Go (~35 Mb) Simple: code that you can understand spending a couple of hours Kubernetes-native: integrates well with Kubernetes Community’s building block: used by projects like Argo CD or Sigstore True Open Source: community-driven project not owned by a company

Slide 16

Slide 16 text

WHY DO ENGINEERS LOVE DEX? Ultra light: single binary in Go (~35 Mb) Simple: code that you can understand spending a couple of hours Kubernetes-native: integrates well with Kubernetes Community’s building block: used by projects like Argo CD or Sigstore True Open Source: community-driven project not owned by a company

Slide 17

Slide 17 text

WHY DO ENGINEERS LOVE DEX? Ultra light: single binary in Go (~35 Mb) Simple: code that you can understand spending a couple of hours Kubernetes-native: integrates well with Kubernetes Community’s building block: used by projects like Argo CD or Sigstore True Open Source: community-driven project not owned by a company

Slide 18

Slide 18 text

DEX ARCHITECTURE

Slide 19

Slide 19 text

DEX ARCHITECTURE

Slide 20

Slide 20 text

DEX ARCHITECTURE OIDC

Slide 21

Slide 21 text

DEX ARCHITECTURE OIDC USER AUTHN

Slide 22

Slide 22 text

DEX ARCHITECTURE OIDC USER AUTHN MACHINE AUTHN

Slide 23

Slide 23 text

DEX ARCHITECTURE OIDC Storage USER AUTHN MACHINE AUTHN

Slide 24

Slide 24 text

DEX ARCHITECTURE OIDC Storage USER AUTHN MACHINE AUTHN

Slide 25

Slide 25 text

DEX ARCHITECTURE OIDC Storage USER AUTHN MACHINE AUTHN

Slide 26

Slide 26 text

DEX ARCHITECTURE OIDC Storage USER AUTHN MACHINE AUTHN

Slide 27

Slide 27 text

DEX ARCHITECTURE OIDC Storage USER AUTHN MACHINE AUTHN

Slide 28

Slide 28 text

DEX ARCHITECTURE OIDC Storage Connectors USER AUTHN MACHINE AUTHN

Slide 29

Slide 29 text

DEX ARCHITECTURE OIDC Storage Connectors USER AUTHN MACHINE AUTHN

Slide 30

Slide 30 text

DEX ARCHITECTURE OIDC Storage Connectors USER AUTHN MACHINE AUTHN

Slide 31

Slide 31 text

DEX ARCHITECTURE OIDC Storage Mock Connectors USER AUTHN MACHINE AUTHN Local

Slide 32

Slide 32 text

DEX ARCHITECTURE OIDC Storage Mock Connectors USER AUTHN MACHINE AUTHN Local

Slide 33

Slide 33 text

Introduce yourself with a couple of jokes Tell what Dex is about Explain what Token Exchange is Show how applicable to the existing cloud-native infrastructure it is TODO LIST FOR THE TALK

Slide 34

Slide 34 text

Introduce yourself with a couple of jokes Tell what Dex is about Explain what Token Exchange is Show how applicable to the existing cloud-native infrastructure it is TODO LIST FOR THE TALK

Slide 35

Slide 35 text

TOKEN EXCHANGE GRANT

Slide 36

Slide 36 text

TOKEN EXCHANGE GRANT RFC8936: OAuth 2.0 Token Exchange Published in January 2020

Slide 37

Slide 37 text

CURRENCY EXCHANGE

Slide 38

Slide 38 text

CURRENCY EXCHANGE

Slide 39

Slide 39 text

CURRENCY EXCHANGE

Slide 40

Slide 40 text

CURRENCY EXCHANGE

Slide 41

Slide 41 text

CURRENCY EXCHANGE

Slide 42

Slide 42 text

CURRENCY EXCHANGE

Slide 43

Slide 43 text

CURRENCY EXCHANGE

Slide 44

Slide 44 text

CURRENCY EXCHANGE

Slide 45

Slide 45 text

CURRENCY EXCHANGE

Slide 46

Slide 46 text

CURRENCY EXCHANGE

Slide 47

Slide 47 text

CURRENCY EXCHANGE

Slide 48

Slide 48 text

CURRENCY EXCHANGE Currency Exchange

Slide 49

Slide 49 text

CURRENCY EXCHANGE Currency Exchange

Slide 50

Slide 50 text

CURRENCY EXCHANGE Currency Exchange

Slide 51

Slide 51 text

CURRENCY EXCHANGE Currency Exchange

Slide 52

Slide 52 text

CURRENCY EXCHANGE Currency Exchange

Slide 53

Slide 53 text

CURRENCY EXCHANGE

Slide 54

Slide 54 text

JWT TOKEN EXCHANGE Token Exchange JWT JWT JWT

Slide 55

Slide 55 text

TOKEN EXCHANGE IN DEX

Slide 56

Slide 56 text

TOKEN EXCHANGE IN DEX Implemented by Sean Liao Merged in November 2023 Available in January 2024 (Dex v2.38.0) Works with JWT tokens Works with providers that have OIDC discovery endpoint github.com/seankhliao

Slide 57

Slide 57 text

TOKEN EXCHANGE IN DEX Implemented by Sean Liao Merged in November 2023 Available in January 2024 (Dex v2.38.0) Works with JWT tokens Works with providers that have OIDC discovery endpoint github.com/seankhliao

Slide 58

Slide 58 text

TOKEN EXCHANGE IN DEX dexidp.io/docs/token-exchange/ JWT sub: sys:s4:: exp: 1768243 sub: xxx name: sys:s4:: exp: 1769961 Signed by Signed by JWT

Slide 59

Slide 59 text

TOKEN EXCHANGE IN DEX dexidp.io/docs/token-exchange/ JWT sub: sys:s4:: exp: 1768243 sub: xxx name: sys:s4:: exp: 1769961 Signed by Signed by JWT

Slide 60

Slide 60 text

TOKEN EXCHANGE IN DEX dexidp.io/docs/token-exchange/ outh2: grantTypes: # ensure grantTypes includes the token-exchange grant (default) - "urn:ietf:params:oauth:grant-type:token-exchange"

Slide 61

Slide 61 text

TOKEN EXCHANGE IN DEX dexidp.io/docs/token-exchange/ connectors: - name: Exchange Provider type: oidc id: exchange config: issuer: https://oidc.example.com scopes: - profile - groups - federated:id userNameKey: sub claimMappings: groups: roles

Slide 62

Slide 62 text

TOKEN EXCHANGE IN DEX Easy to understand Easy to configure Easy to start A field for experiments!

Slide 63

Slide 63 text

Introduce yourself with a couple of jokes Tell what Dex is about Explain what Token Exchange is Show how applicable to the existing cloud-native infrastructure it is TODO LIST FOR THE TALK

Slide 64

Slide 64 text

Introduce yourself with a couple of jokes Tell what Dex is about Explain what Token Exchange is Show how applicable to the existing cloud-native infrastructure it is TODO LIST FOR THE TALK

Slide 65

Slide 65 text

CASE 1: CI/CD INTEGRATION

Slide 66

Slide 66 text

CI/CD INTEGRATION The goal: to deploy to a Kubernetes cluster Common anti-patterns: Save admin kubeconfig with certificates in the CI/CD system Use ServiceAccount token with an infinite lifetime

Slide 67

Slide 67 text

CI/CD INTEGRATION The goal: to deploy to a Kubernetes cluster Common anti-patterns: Save admin kubeconfig with certificates in the CI/CD system Use ServiceAccount token with an infinite lifetime

Slide 68

Slide 68 text

CI/CD INTEGRATION Actors: ● GitLab CI/CD ● Dex ● Kubernetes DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN

Slide 69

Slide 69 text

CI/CD INTEGRATION Kubernetes comes to Dex and discovers its JWKS endpoint DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN

Slide 70

Slide 70 text

CI/CD INTEGRATION GitLab pipeline is triggered. But there is NO ACCESS to Kubernetes DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN

Slide 71

Slide 71 text

CI/CD INTEGRATION Dex comes to GitLab and discovers its JWKS endpoint DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN

Slide 72

Slide 72 text

CI/CD INTEGRATION GitLab EXCHANGES tokens with Dex DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN

Slide 73

Slide 73 text

CI/CD INTEGRATION DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN Finally, using the Dex token, GitLab can access Kubernetes

Slide 74

Slide 74 text

CI/CD INTEGRATION DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN Finally, using the Dex token, GitLab can access Kubernetes

Slide 75

Slide 75 text

It’s not only GitLab that can be used. It will work with other CI/CD systems (GitHub Actions, etc.) as well CI/CD INTEGRATION

Slide 76

Slide 76 text

It’s not only GitLab that can be used. It will work with other CI/CD systems (GitHub Actions, etc.) as well CI/CD INTEGRATION All major cloud providers allow authenticating using the CI/CD tokens, and, thanks to Dex, so does K8s

Slide 77

Slide 77 text

It’s not only GitLab that can be used. It will work with other CI/CD systems (GitHub Actions, etc.) as well CI/CD INTEGRATION All major cloud providers allow authenticating using the CI/CD tokens, and, thanks to Dex, so does K8s No more anti-patterns!

Slide 78

Slide 78 text

CASE 2: KUBERNETES AUTHMESH

Slide 79

Slide 79 text

KUBERNETES AUTHMESH The goal: to give access to a service from one cluster to another

Slide 80

Slide 80 text

KUBERNETES AUTHMESH The goal: to give access to a service from one cluster to another

Slide 81

Slide 81 text

KUBERNETES AUTHMESH The goal: to give access to a service from one cluster to another

Slide 82

Slide 82 text

The goal: to give access to a service from one cluster to another KUBERNETES AUTHMESH Common anti-patterns: Save admin kubeconfig with the certificates in another cluster Use ServiceAccount token with an infinite lifetime

Slide 83

Slide 83 text

KUBERNETES AUTHMESH DISCOVERY KEYS Actors: ● Dex ● Kubernetes-1 ● Kubernetes-2 ● Kubernetes-3 DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2 3

Slide 84

Slide 84 text

KUBERNETES AUTHMESH DISCOVERY KEYS One by one, Kubernetes clusters come to Dex and discover its JWKS endpoint (#1) DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 2 3 1

Slide 85

Slide 85 text

KUBERNETES AUTHMESH DISCOVERY KEYS One by one, Kubernetes clusters come to Dex and discover its JWKS endpoint (#2) DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 3 1 2

Slide 86

Slide 86 text

KUBERNETES AUTHMESH DISCOVERY KEYS One by one, Kubernetes clusters come to Dex and discover its JWKS endpoint (#3) DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2 3

Slide 87

Slide 87 text

KUBERNETES AUTHMESH DISCOVERY KEYS Then, Dex discovers Kubernetes each JWKS endpoint, one by one again DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2 3

Slide 88

Slide 88 text

KUBERNETES AUTHMESH DISCOVERY KEYS Then, Dex discovers Kubernetes each JWKS endpoint, one by one again (#1) DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 2 3 1

Slide 89

Slide 89 text

3 KUBERNETES AUTHMESH DISCOVERY KEYS Then, Dex discovers Kubernetes each JWKS endpoint, one by one again (#2) DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2

Slide 90

Slide 90 text

KUBERNETES AUTHMESH DISCOVERY KEYS Then, Dex discovers Kubernetes each JWKS endpoint, one by one again (#3) DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2 3

Slide 91

Slide 91 text

KUBERNETES AUTHMESH DISCOVERY KEYS Then, Dex discovers Kubernetes each JWKS endpoint, one by one again (#3) DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2 3

Slide 92

Slide 92 text

KUBERNETES AUTHMESH DISCOVERY KEYS Kubernetes-1 workloads have NO DIRECT ACCESS to the Kubernetes-3 API DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2 3

Slide 93

Slide 93 text

KUBERNETES AUTHMESH DISCOVERY KEYS However, they can EXCHANGE their Service Account tokens to a Dex token DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 2 3 1

Slide 94

Slide 94 text

KUBERNETES AUTHMESH DISCOVERY KEYS Finally, the access is provided DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2 3

Slide 95

Slide 95 text

KUBERNETES AUTHMESH DISCOVERY KEYS Finally, the access is provided DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS DISCOVERY KEYS TOKEN TOKEN 1 2 3

Slide 96

Slide 96 text

KUBERNETES AUTHMESH kubernetes.io/docs/reference/access-authn-authz/authentication/#configuration

Slide 97

Slide 97 text

KUBERNETES AUTHMESH kubernetes.io/docs/reference/access-authn-authz/authentication/#configuration $ initial_token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)

Slide 98

Slide 98 text

KUBERNETES AUTHMESH kubernetes.io/docs/reference/access-authn-authz/authentication/#configuration $ initial_token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) $ token=$(curl $dex_url/token \ … \ –data_urlencode grant_type=urn:ietf:params:oauth:grant-type:token-exchange \ –data_urlencode subject_token=$initial_token | jq .access_token)

Slide 99

Slide 99 text

KUBERNETES AUTHMESH kubernetes.io/docs/reference/access-authn-authz/authentication/#configuration $ initial_token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) $ token=$(curl $dex_url/token \ … \ –data_urlencode grant_type=urn:ietf:params:oauth:grant-type:token-exchange \ –data_urlencode subject_token=$initial_token | jq .access_token) $ cat <

Slide 100

Slide 100 text

KUBERNETES AUTHMESH kubernetes.io/docs/reference/access-authn-authz/authentication/#configuration Save to /bin/token-exchange Use in your kubeconfigs: users: - name: kubernetes-exchange user: exec: command: token-exchange apiVersion: "client.authentication.k8s.io/v1" interactiveMode: Never This is an example NOT for production use

Slide 101

Slide 101 text

CASE 3: SPIFFE TOKENS

Slide 102

Slide 102 text

SPIFFE TOKENS The goal: to use SPIFFE tokens to have an access to a Kubernetes API

Slide 103

Slide 103 text

SPIFFE TOKENS The goal: to use SPIFFE tokens to have an access to a Kubernetes API We already have IDs of all our services. Why cannot we reuse them to access Kubernetes?

Slide 104

Slide 104 text

DISCOVERY DISCOVERY KEYS KEYS REGISTRATION UNIX SOCKET SPIFFE TOKEN SPIFFE TOKENS Actors: ● Dex ● SPIRE server ● SPIRE agent ● Application ● Kubernetes SERVER AGENT APP SPIFFE TOKEN TOKEN

Slide 105

Slide 105 text

DISCOVERY DISCOVERY KEYS KEYS REGISTRATION UNIX SOCKET SPIFFE TOKEN SPIFFE TOKENS SPIRE agent on a node connects to the SPIRE server SERVER AGENT APP SPIFFE TOKEN TOKEN

Slide 106

Slide 106 text

DISCOVERY KEYS KEYS REGISTRATION UNIX SOCKET SPIFFE TOKEN SPIFFE TOKENS Dex comes to SPIRE server and discovers its JWKS endpoint SERVER AGENT APP SPIFFE TOKEN TOKEN DISCOVERY

Slide 107

Slide 107 text

DISCOVERY KEYS KEYS REGISTRATION UNIX SOCKET SPIFFE TOKEN SPIFFE TOKENS Kubernetes comes to Dex and discovers its JWKS endpoint SERVER AGENT APP SPIFFE TOKEN TOKEN DISCOVERY

Slide 108

Slide 108 text

DISCOVERY KEYS DISCOVERY KEYS REGISTRATION UNIX SOCKET SPIFFE TOKEN SPIFFE TOKENS Application on a node comes to the SPIRE agent and requests its SPIRE JWT token SERVER AGENT APP SPIFFE TOKEN TOKEN

Slide 109

Slide 109 text

DISCOVERY KEYS DISCOVERY KEYS REGISTRATION UNIX SOCKET SPIFFE TOKEN SPIFFE TOKENS Using this token, Application cannot access Kubernetes API SERVER AGENT APP SPIFFE TOKEN TOKEN

Slide 110

Slide 110 text

DISCOVERY KEYS DISCOVERY KEYS REGISTRATION UNIX SOCKET SPIFFE TOKEN SPIFFE TOKENS Application makes an EXCHANGE and gets the Dex token SERVER AGENT APP SPIFFE TOKEN TOKEN

Slide 111

Slide 111 text

SPIFFE TOKENS DISCOVERY KEYS DISCOVERY KEYS SERVER AGENT APP REGISTRATION UNIX SOCKET SPIFFE TOKEN SPIFFE TOKEN TOKEN Finally, our Application can access Kubernetes API

Slide 112

Slide 112 text

SPIFFE TOKENS SPIFFE ID can be used in RBAC as a username subjects: - kind: User name: spiffe://example.org/reports It makes Service Accounts in Kubernetes obsolete

Slide 113

Slide 113 text

Introduce yourself with a couple of jokes Tell what Dex is about Explain what Token Exchange is Show how applicable to the existing cloud-native infrastructure it is TODO LIST FOR THE TALK

Slide 114

Slide 114 text

Introduce yourself with a couple of jokes Tell what Dex is about Explain what Token Exchange is Show how applicable to the existing cloud-native infrastructure it is TODO LIST FOR THE TALK We finally made it to the finals!

Slide 115

Slide 115 text

The Token Exchange feature is a glue between different authentication providers WRAPPING UP

Slide 116

Slide 116 text

WRAPPING UP Dex is lightweight and can be used to add this capability to any Kubernetes cluster with literally no overhead The Token Exchange feature is a glue between different authentication providers

Slide 117

Slide 117 text

WRAPPING UP Not only Dex benefits from it, yet the whole ecosystem Dex is lightweight and can be used to add this capability to any Kubernetes cluster with literally no overhead The Token Exchange feature is a glue between different authentication providers

Slide 118

Slide 118 text

WRAPPING UP If security features are convenient, it improves the security in the world in general Not only Dex benefits from it, yet the whole ecosystem Dex is lightweight and can be used to add this capability to any Kubernetes cluster with literally no overhead The Token Exchange feature is a glue between different authentication providers

Slide 119

Slide 119 text

github.com/werf github.com/palark GOTTA AUTHENTICATE ‘EM ALL! THANK YOU! @nabokihms [email protected] OPEN SOURCE TOOLS OUR BLOGS AND SOCIAL MEDIA palark.com twitter.com/palark_com MAKSIM NABOKIKH Platform Lead dexidp.io github.com/dexidp/dex DEX SOURCES