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

Allow setting automountServiceAccountToken #1284

Merged
merged 4 commits into from
Jan 20, 2025
Merged

Conversation

Aransh
Copy link
Contributor

@Aransh Aransh commented Jan 20, 2025

What does this PR do?

By default, kubernetes enables "automountServiceAccountToken" for all pods, see https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#opt-out-of-api-credential-automounting.
This poses a security risk, as pods might get kube-api permissions unintentionally.
More specifically, this fails security compliance tests:
https://learn.microsoft.com/en-us/azure/governance/policy/samples/built-in-policies
https://www.azadvertizer.net/azpolicyadvertizer/kubernetes_block-automount-token.html

Solution - Disable "automountServiceAccountToken", create projected volume for the token, and mount it on relevant containers

Submitter checklist

  • I bumped the "version" key in ./charts/jenkins/Chart.yaml.
  • I added a new changelog entry to ./charts/jenkins/CHANGELOG.md.
  • I followed the technical requirements.
  • I ran .github/helm-docs.sh from the project root.

Special notes for your reviewer

This does not effect default behavior, though if someone is looking to comply with security requirements and disable this, they must also manually mount the serviceAccount token, with the following values.yaml:

serviceAccount:
  automountServiceAccountToken: false
persistence:
  volumes:
    - name: kube-api-access
      projected:
        defaultMode: 420
        sources:
          - serviceAccountToken:
              expirationSeconds: 3607
              path: token
          - configMap:
              items:
                - key: ca.crt
                  path: ca.crt
              name: kube-root-ca.crt
          - downwardAPI:
              items:
                - fieldRef:
                    apiVersion: v1
                    fieldPath: metadata.namespace
                  path: namespace
  mounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access
      readOnly: true
controller:
  sidecars:
    configAutoReload:
      additionalVolumeMounts:
        - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
          name: kube-api-access
          readOnly: true

@Aransh Aransh requested a review from a team as a code owner January 20, 2025 11:39
@malki-akamai
Copy link

+1

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Thanks

@timja timja merged commit c6f0731 into jenkinsci:main Jan 20, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants