Skip to content

Kubernetes External Joining: static_jwks implementation#30225

Merged
strideynet merged 24 commits intomasterfrom
strideynet/simplified-kubernetes-external-join
Sep 11, 2023
Merged

Kubernetes External Joining: static_jwks implementation#30225
strideynet merged 24 commits intomasterfrom
strideynet/simplified-kubernetes-external-join

Conversation

@strideynet
Copy link
Copy Markdown
Contributor

@strideynet strideynet commented Aug 9, 2023

Adds a static_jwks sub-variant of the kubernetes join method to support pods joining in clusters other than the one the Teleport Auth Server is running in.

Closes #25543
As per RFD: #29225

Example Token config:

kind: token
version: v2
metadata:
  name: docker-desktop-jwks
spec:
  roles: [Bot]
  bot_name: docker-desktop
  join_method: kubernetes
  kubernetes:
    type: static_jwks
    static_jwks:
      jwks: |
        {"keys":[{"use":"sig","kty":"RSA","kid":"KCk4tlf5yXj7GJ20L9XcvviNIiCf1QaUhw1Cyzd5VjA","alg":"RS256","n":"vYiAKomeNl--3-HaQ24DhJLlgg05gWIKmYRUxPx5vg4NLTdezUHxl70mygFNSYQrSgRqGpUp1j3_fOQYVKhWOVMPLtIYz4pnH-3mUBhNhpfLZiyMUqtjhijekqGOhlbEwHDvCm0tAMESSJBNHneR2tqEugsnDOpPmi3Z220MPJFO9FotFNd4vhmwEp9raWEIRSW3tRZiBoZ_1DAgR5LlO4q__sr125WL0n3s9exVrjQJxpkkUD4ECdO9020VtgPXL3sw__bE0UMuOWDvAY2sCb6rIN76rRLUbGc_IIP1ahLoFVDqdef-tsFM4pW_dbXu77YpfTfK_sTKOEVeGtKBJQ","e":"AQAB"}]}
    allow:
    - service_account: "default:tbot"

Example Audit Event:

{
  "attributes": {
    "raw": {
      "aud": [
        "leaf.tele.ottr.sh"
      ],
      "exp": 1692026408,
      "iat": 1692025808,
      "iss": "https://kubernetes.default.svc.cluster.local",
      "kubernetes.io": {
        "namespace": "default",
        "pod": {
          "name": "ubuntu",
          "uid": "f6dd8b5e-cafc-4d92-b5ac-1a124a019d72"
        },
        "serviceaccount": {
          "name": "tbot",
          "uid": "8b77ea6d-3144-4203-9a8b-36eb5ad65596"
        }
      },
      "nbf": 1692025808,
      "sub": "system:serviceaccount:default:tbot"
    },
    "type": "static_jwks",
    "username": "system:serviceaccount:default:tbot"
  },
  "bot_name": "docker-desktop",
  "cluster_name": "leaf.tele.ottr.sh",
  "code": "TJ001I",
  "ei": 0,
  "event": "bot.join",
  "method": "kubernetes",
  "success": true,
  "time": "2023-08-14T15:15:59.91Z",
  "token_name": "docker-desktop-jwks",
  "uid": "84922598-1ba6-499f-a8cf-0dba96cab1d5"
}

Example pod spec

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu
spec:
  containers:
    - image: ubuntu
      command:
        - "sleep"
        - "604800"
      imagePullPolicy: IfNotPresent
      name: ubuntu
      volumeMounts:
        - mountPath: /var/run/secrets/tokens
          name: tbot-sa
  serviceAccountName: tbot
  restartPolicy: Always
  volumes:
    - name: tbot-sa
      projected:
        sources:
          - serviceAccountToken:
              path: tbot
              expirationSeconds: 600
              audience: leaf.tele.ottr.sh

Example invocation:

export KUBERNETES_TOKEN_PATH=/var/run/secrets/tokens/tbot
./tbot start  --destination-dir=./tbot-user  --token=docker-desktop-jwks  --auth-server=leaf.tele.ottr.sh:443  --join-method=kubernetes

Comment thread lib/kubernetestoken/token_validator.go Outdated
@strideynet strideynet added the blocked is blocked by another item - please include the blocker label Aug 14, 2023
@strideynet
Copy link
Copy Markdown
Contributor Author

Blocked pending security review of #29225

@strideynet
Copy link
Copy Markdown
Contributor Author

Docs will follow in a future PR

Comment thread api/types/provisioning.go
@strideynet strideynet added this pull request to the merge queue Sep 11, 2023
Merged via the queue into master with commit 64f703a Sep 11, 2023
@strideynet strideynet deleted the strideynet/simplified-kubernetes-external-join branch September 11, 2023 11:16
@public-teleport-github-review-bot
Copy link
Copy Markdown

@strideynet See the table below for backport results.

Branch Result
branch/v12 Failed
branch/v13 Failed
branch/v14 Failed

strideynet added a commit that referenced this pull request Sep 11, 2023
* Add JWKS baseed kubernetes toekn validator

* Add types for static_jwks kubernetes join type

* Add validation for new fields on Provisiontoken

* SPAG

* Add support into tbot for kubernetes join method

* Wire static_jwks implementation into auth.Server.checkKubernetesJoinRequest

* fix-imports

* Add JWKS tests for `kubernetestoken`

* Fix TestIDTokenValidator_Validate

* Ensure token is bound

* Fix mistakenely renamed comments

* Tidier return type

* Refactor tests for slicker UI

* Inject jwks token validator for test substitution

* Add test cases for static_jwks to lib/auth kube joining test

* Remove TODO

* Add more test cases to token validation

* Add enforcement of maximum TTL

* Regenerate operator crd

* Improve comments on proto

* Rerun ?? generation ?? of ?? operator ?? protos ??

* Remove outdated comment
strideynet added a commit that referenced this pull request Sep 11, 2023
* Add JWKS baseed kubernetes toekn validator

* Add types for static_jwks kubernetes join type

* Add validation for new fields on Provisiontoken

* SPAG

* Add support into tbot for kubernetes join method

* Wire static_jwks implementation into auth.Server.checkKubernetesJoinRequest

* fix-imports

* Add JWKS tests for `kubernetestoken`

* Fix TestIDTokenValidator_Validate

* Ensure token is bound

* Fix mistakenely renamed comments

* Tidier return type

* Refactor tests for slicker UI

* Inject jwks token validator for test substitution

* Add test cases for static_jwks to lib/auth kube joining test

* Remove TODO

* Add more test cases to token validation

* Add enforcement of maximum TTL

* Regenerate operator crd

* Improve comments on proto

* Rerun ?? generation ?? of ?? operator ?? protos ??

* Remove outdated comment
strideynet added a commit that referenced this pull request Sep 11, 2023
* Add JWKS baseed kubernetes toekn validator

* Add types for static_jwks kubernetes join type

* Add validation for new fields on Provisiontoken

* SPAG

* Add support into tbot for kubernetes join method

* Wire static_jwks implementation into auth.Server.checkKubernetesJoinRequest

* fix-imports

* Add JWKS tests for `kubernetestoken`

* Fix TestIDTokenValidator_Validate

* Ensure token is bound

* Fix mistakenely renamed comments

* Tidier return type

* Refactor tests for slicker UI

* Inject jwks token validator for test substitution

* Add test cases for static_jwks to lib/auth kube joining test

* Remove TODO

* Add more test cases to token validation

* Add enforcement of maximum TTL

* Regenerate operator crd

* Improve comments on proto

* Rerun ?? generation ?? of ?? operator ?? protos ??

* Remove outdated comment
github-merge-queue Bot pushed a commit that referenced this pull request Sep 12, 2023
…) (#31704)

* Kubernetes External Joining: `static_jwks` implementation (#30225)

* Add JWKS baseed kubernetes toekn validator

* Add types for static_jwks kubernetes join type

* Add validation for new fields on Provisiontoken

* SPAG

* Add support into tbot for kubernetes join method

* Wire static_jwks implementation into auth.Server.checkKubernetesJoinRequest

* fix-imports

* Add JWKS tests for `kubernetestoken`

* Fix TestIDTokenValidator_Validate

* Ensure token is bound

* Fix mistakenely renamed comments

* Tidier return type

* Refactor tests for slicker UI

* Inject jwks token validator for test substitution

* Add test cases for static_jwks to lib/auth kube joining test

* Remove TODO

* Add more test cases to token validation

* Add enforcement of maximum TTL

* Regenerate operator crd

* Improve comments on proto

* Rerun ?? generation ?? of ?? operator ?? protos ??

* Remove outdated comment

* Go mod tidy
github-merge-queue Bot pushed a commit that referenced this pull request Sep 12, 2023
…) (#31703)

* Kubernetes External Joining: `static_jwks` implementation (#30225)

* Add JWKS baseed kubernetes toekn validator

* Add types for static_jwks kubernetes join type

* Add validation for new fields on Provisiontoken

* SPAG

* Add support into tbot for kubernetes join method

* Wire static_jwks implementation into auth.Server.checkKubernetesJoinRequest

* fix-imports

* Add JWKS tests for `kubernetestoken`

* Fix TestIDTokenValidator_Validate

* Ensure token is bound

* Fix mistakenely renamed comments

* Tidier return type

* Refactor tests for slicker UI

* Inject jwks token validator for test substitution

* Add test cases for static_jwks to lib/auth kube joining test

* Remove TODO

* Add more test cases to token validation

* Add enforcement of maximum TTL

* Regenerate operator crd

* Improve comments on proto

* Rerun ?? generation ?? of ?? operator ?? protos ??

* Remove outdated comment

* Add Kubernetes to repeatable bot join types

* Go mod tidy
github-merge-queue Bot pushed a commit that referenced this pull request Sep 13, 2023
…31702)

* Add JWKS baseed kubernetes toekn validator

* Add types for static_jwks kubernetes join type

* Add validation for new fields on Provisiontoken

* SPAG

* Add support into tbot for kubernetes join method

* Wire static_jwks implementation into auth.Server.checkKubernetesJoinRequest

* fix-imports

* Add JWKS tests for `kubernetestoken`

* Fix TestIDTokenValidator_Validate

* Ensure token is bound

* Fix mistakenely renamed comments

* Tidier return type

* Refactor tests for slicker UI

* Inject jwks token validator for test substitution

* Add test cases for static_jwks to lib/auth kube joining test

* Remove TODO

* Add more test cases to token validation

* Add enforcement of maximum TTL

* Regenerate operator crd

* Improve comments on proto

* Rerun ?? generation ?? of ?? operator ?? protos ??

* Remove outdated comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked is blocked by another item - please include the blocker helm kubernetes-access machine-id size/lg

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kubernetes delegated joining support with external Auth Server

4 participants