Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workload Identity: Kubernetes Workload Attestation #44209

Merged
merged 35 commits into from
Jul 31, 2024

Conversation

strideynet
Copy link
Contributor

@strideynet strideynet commented Jul 15, 2024

Closes #41892

Manifests used in manual testing:

# Required cluster role to allow spire-agent to query k8s API server
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tbot
rules:
  - apiGroups: [""]
    resources: ["pods","nodes","nodes/proxy"]
    verbs: ["get"]
---
# Binds above cluster role to spire-agent service account
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tbot
subjects:
  - kind: ServiceAccount
    name: tbot
    namespace: default
roleRef:
  kind: ClusterRole
  name: tbot
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tbot
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: tbot-config-1
  namespace: default
data:
  tbot.yaml: |
    version: v2
    onboarding:
      join_method: kubernetes
      # ensure token is set to the name of the join token you created earlier
      token: workload-attestation-bot
    storage:
      # a memory destination is used for the bots own state since the kubernetes
      # join method does not require persistence.
      type: memory
    # ensure this is configured to the address of your Teleport Proxy Service.
    proxy_server: redacted
    services:
      - type: spiffe-workload-api
        listen: unix:///run/tbot/sockets/workload.sock
        attestor:
          kubernetes:
            enabled: true
            # If there's any configuration needed for the k8s attestor, it can
            # be added here - but it should work out of the box like this for
            # most clusters.
        svids:
          - path: /my-service
            rules:
              - kubernetes:
                  namespace: default
                  service_account: tbot
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: tbot
spec:
  selector:
      matchLabels:
        app: tbot
  template:
    metadata:
      labels:
        app: tbot
    spec:
      securityContext:
        runAsUser: 0
        runAsGroup: 0
      hostPID: true
      containers:
        - name: tbot
          image: tbot-distroless
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
          args:
            - start
            - -c
            - /config/tbot.yaml
            - --log-format
            - json
          volumeMounts:
            - mountPath: /config
              name: config
            - mountPath: /var/run/secrets/tokens
              name: join-sa-token
            - name: tbot-sockets
              mountPath: /run/tbot/sockets
              readOnly: false
          env:
            - name: TELEPORT_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: KUBERNETES_TOKEN_PATH
              value: /var/run/secrets/tokens/join-sa-token
      serviceAccountName: tbot
      volumes:
        - name: tbot-sockets
          hostPath:
            path: /run/tbot/sockets
            type: DirectoryOrCreate
        - name: config
          configMap:
            name: tbot-config-1
        - name: join-sa-token
          projected:
            sources:
              - serviceAccountToken:
                  path: join-sa-token
                  # 600 seconds is the minimum that Kubernetes supports. We
                  # recommend this value is used.
                  expirationSeconds: 600
                  # `example.teleport.sh` must be replaced with the name of
                  # your Teleport cluster.
                  audience: redacted

Tested on GCP and my local docker desktop cluster.

changelog: Added support for Kubernetes Workload Attestation into Teleport Workload Identity to allow the authentication of pods running within Kubernetes without secrets.

@strideynet
Copy link
Contributor Author

I'd like to get this manually tested on EKS and AKS before releasing this.

@strideynet strideynet marked this pull request as ready for review July 19, 2024 15:17
Copy link
Contributor

@timothyb89 timothyb89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed my issue offline, turns out my bot role was misconfigured. spiffe-helper is happily issuing SVIDs now that there is in fact a valid allow: rule for the path.

LGTM otherwise!

Copy link

@orca-security-us orca-security-us bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Failed Failed Vulnerabilities high 1   medium 0   low 0   info 0 View in Orca
☢️ The following Vulnerabilities (CVEs) have been detected
PACKAGE FILE CVE ID INSTALLED VERSION FIXED VERSION
critical github.com/docker/docker ./go.mod CVE-2024-41110 26.1.1+incompatible 23.0.14, 26.1.4, 27.1.0 View in code

@strideynet
Copy link
Contributor Author

strideynet commented Jul 31, 2024

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Failed Failed Vulnerabilities high 1   medium 0   low 0   info 0 View in Orca
☢️ The following Vulnerabilities (CVEs) have been detected

PACKAGE FILE CVE ID INSTALLED VERSION FIXED VERSION
critical github.com/docker/docker ./go.mod CVE-2024-41110 26.1.1+incompatible 23.0.14, 26.1.4, 27.1.0 View in code

This is fixed on master, will merge master in this branch.

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from fheinecke July 31, 2024 10:29
@strideynet strideynet added this pull request to the merge queue Jul 31, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 31, 2024
@strideynet strideynet enabled auto-merge July 31, 2024 12:37
@strideynet strideynet added this pull request to the merge queue Jul 31, 2024
Merged via the queue into master with commit 6922aa0 Jul 31, 2024
41 checks passed
@strideynet strideynet deleted the strideynet/kubernetes-workload-attestation branch July 31, 2024 14:52
@public-teleport-github-review-bot

@strideynet See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed

strideynet added a commit that referenced this pull request Jul 31, 2024
* Start hacking on resolving pod/container id from pid

* Add godoc comments

* Tidy attestation into well defined types

* Use gopsutil to determine gid/uid on unix systems

* Start threading through config

* Update tests

* Start working TLS support into kubelet api client

* Thread through configuration to yaml

* Support loading the CA

* Start testing with real cluster/bug fixes

* Simplify by removing container lookup

* Add new attestation rules/tests for new attestation rules

* Add test that leverages example mountfiles

* Start handling kubelet client auth more elegantly

* Add handling of custom CA values

* Tie together configuration validation

* Update YAML tests

* Go mod/sum

* Ensure we use the Effective UID/GID rather than "Real" UID/GID in Unix attestation

* Add testdata from GCP

* Add test of Kubernetes attestation with mock kubelet API

* Add test for UnixAttestor

* Update YAML goldenfile

* Appease liinter

* Remove change to session.go

* Add timeout to Kubelet client

* Import `time`

* Go mod tidy

* Go mod tidy

* Remove TODO about renaming

* Rename attestor -> attestors

* Add stubs on windows

* Add missing license header
strideynet added a commit that referenced this pull request Jul 31, 2024
* Start hacking on resolving pod/container id from pid

* Add godoc comments

* Tidy attestation into well defined types

* Use gopsutil to determine gid/uid on unix systems

* Start threading through config

* Update tests

* Start working TLS support into kubelet api client

* Thread through configuration to yaml

* Support loading the CA

* Start testing with real cluster/bug fixes

* Simplify by removing container lookup

* Add new attestation rules/tests for new attestation rules

* Add test that leverages example mountfiles

* Start handling kubelet client auth more elegantly

* Add handling of custom CA values

* Tie together configuration validation

* Update YAML tests

* Go mod/sum

* Ensure we use the Effective UID/GID rather than "Real" UID/GID in Unix attestation

* Add testdata from GCP

* Add test of Kubernetes attestation with mock kubelet API

* Add test for UnixAttestor

* Update YAML goldenfile

* Appease liinter

* Remove change to session.go

* Add timeout to Kubelet client

* Import `time`

* Go mod tidy

* Go mod tidy

* Remove TODO about renaming

* Rename attestor -> attestors

* Add stubs on windows

* Add missing license header
github-merge-queue bot pushed a commit that referenced this pull request Aug 1, 2024
* Start hacking on resolving pod/container id from pid

* Add godoc comments

* Tidy attestation into well defined types

* Use gopsutil to determine gid/uid on unix systems

* Start threading through config

* Update tests

* Start working TLS support into kubelet api client

* Thread through configuration to yaml

* Support loading the CA

* Start testing with real cluster/bug fixes

* Simplify by removing container lookup

* Add new attestation rules/tests for new attestation rules

* Add test that leverages example mountfiles

* Start handling kubelet client auth more elegantly

* Add handling of custom CA values

* Tie together configuration validation

* Update YAML tests

* Go mod/sum

* Ensure we use the Effective UID/GID rather than "Real" UID/GID in Unix attestation

* Add testdata from GCP

* Add test of Kubernetes attestation with mock kubelet API

* Add test for UnixAttestor

* Update YAML goldenfile

* Appease liinter

* Remove change to session.go

* Add timeout to Kubelet client

* Import `time`

* Go mod tidy

* Go mod tidy

* Remove TODO about renaming

* Rename attestor -> attestors

* Add stubs on windows

* Add missing license header
github-merge-queue bot pushed a commit that referenced this pull request Aug 1, 2024
…4884)

* Workload Identity: Kubernetes Workload Attestation (#44209)

* Start hacking on resolving pod/container id from pid

* Add godoc comments

* Tidy attestation into well defined types

* Use gopsutil to determine gid/uid on unix systems

* Start threading through config

* Update tests

* Start working TLS support into kubelet api client

* Thread through configuration to yaml

* Support loading the CA

* Start testing with real cluster/bug fixes

* Simplify by removing container lookup

* Add new attestation rules/tests for new attestation rules

* Add test that leverages example mountfiles

* Start handling kubelet client auth more elegantly

* Add handling of custom CA values

* Tie together configuration validation

* Update YAML tests

* Go mod/sum

* Ensure we use the Effective UID/GID rather than "Real" UID/GID in Unix attestation

* Add testdata from GCP

* Add test of Kubernetes attestation with mock kubelet API

* Add test for UnixAttestor

* Update YAML goldenfile

* Appease liinter

* Remove change to session.go

* Add timeout to Kubelet client

* Import `time`

* Go mod tidy

* Go mod tidy

* Remove TODO about renaming

* Rename attestor -> attestors

* Add stubs on windows

* Add missing license header

* Update go.mod go.sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workload ID: Kubernetes Workload Attestation
4 participants