Skip to content

implement ServiceAccountTokenProjection#62005

Merged
k8s-github-robot merged 1 commit intokubernetes:masterfrom
mikedanese:svcacctproj
Jun 5, 2018
Merged

implement ServiceAccountTokenProjection#62005
k8s-github-robot merged 1 commit intokubernetes:masterfrom
mikedanese:svcacctproj

Conversation

@mikedanese
Copy link
Copy Markdown
Member

@mikedanese mikedanese commented Apr 2, 2018

design here: kubernetes/community#1973

part of #61858

Add a volume projection that is able to project service account tokens.

part of #48408

@kubernetes/sig-auth-pr-reviews @kubernetes/sig-storage-pr-reviews

@mikedanese mikedanese self-assigned this Apr 2, 2018
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@mikedanese: Adding do-not-merge/release-note-label-needed because the release note process has not been followed.

Details

One of the following labels is required "release-note", "release-note-action-required", or "release-note-none".
Please see: https://git.k8s.io/community/contributors/devel/pull-requests.md#write-release-notes-if-needed.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 2, 2018
@mikedanese mikedanese added sig/auth Categorizes an issue or PR as relevant to SIG Auth. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Apr 2, 2018
@k8s-github-robot k8s-github-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Apr 2, 2018
@mikedanese mikedanese force-pushed the svcacctproj branch 2 times, most recently from 5f43d74 to 06ece83 Compare April 2, 2018 04:47
@CaoShuFeng
Copy link
Copy Markdown
Contributor

/assign @CaoShuFeng

@mikedanese
Copy link
Copy Markdown
Member Author

Currently working on testing.

example config:

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    run: nginx
  name: nginx
spec:
  replicas: 30
  selector:
    matchLabels:
      run: nginx
  template:
    metadata:
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        volumeMounts:
        - mountPath: /var/run/secrets/tokens
          name: token
      volumes:
      - name: token
        projected:
          sources:
          - serviceAccountToken:
              path: token
              expirationSeconds: 60
              audiences:
                - hi

@jbeda
Copy link
Copy Markdown
Contributor

jbeda commented Apr 2, 2018

/hold

I'd like to see an agreed upon and checked in design doc here. As this also impacts our API, I'd also like to see a heads up to the API review folks to make sure they are aware of the context. A checked in design doc will also help with release notes and documentation.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 2, 2018
@mikedanese
Copy link
Copy Markdown
Member Author

mikedanese commented Apr 2, 2018

@jbeda this will go through the normal API review process. This is self assigned and and already labeled WIP. I'll be presenting the design (here) at the next sig-storage. Only opened for early feedback

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 2, 2018
@mikedanese mikedanese force-pushed the svcacctproj branch 2 times, most recently from f5df59a to c20d417 Compare May 31, 2018 18:27
@awly
Copy link
Copy Markdown
Contributor

awly commented May 31, 2018

/lgtm

@mikedanese
Copy link
Copy Markdown
Member Author

/retest

@tallclair
Copy link
Copy Markdown
Member

tallclair commented Jun 1, 2018

/milestone v1.11
/kind feature
/priority important-soon

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@tallclair: The provided milestone is not valid for this repository. Milestones in this repository: [next-candidate, v1.10, v1.11, v1.12, v1.13, v1.4, v1.5, v1.6, v1.7, v1.8, v1.9]

Use /milestone clear to clear the milestone.

Details

In response to this:

/milestone 1.11
/kind feature
/priority important-soon

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Copy Markdown
Member

@saad-ali saad-ali left a comment

Choose a reason for hiding this comment

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

Volume changes LGTM

/lgtm
/approve

@mikedanese
Copy link
Copy Markdown
Member Author

/retest

Copy link
Copy Markdown
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

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

I think the service account admission controller needs to be updated too: https://github.com/kubernetes/kubernetes/blob/master/plugin/pkg/admission/serviceaccount/admission.go#L198

How do we prevent static pods from mounting serviceAccountTokenProjections?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: move this down to where it's used

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to add an OWNERS file too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: prefer cacheLock

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, better safe than sorry. I don't think static pods go through defaulting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: what is iat? Use a more descriptive variable name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

iat is a common abbreviation in oauth/jose world https://tools.ietf.org/html/rfc7519#section-4.1.6

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: add a comment: // Require a refresh if within 20% of the TTL from the expiration time.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nit: move division to the outer expression for finer accuracy

This hurts readability because we have to cast back and forth between (duration,int64,float64) if the accuracy gain is +- half a second, I don't think it's worth it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean -1 * time.Duration(*tr.Spec.ExpirationSeconds) * time.Second * 20 / 100, which resolves to a time.Duration. But yeah, the accuracy isn't worth the time it took me to write this comment ;-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is name the service account name, or pod name? In either case, should this include a UID?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The name, namespace are of the service account. The actual TokenRequest has pod name and pod UID included in the object binding, which is validated on the apiserver. We can't include service account UID because that information is not present on the pod object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this need to include expiration time? If it's encoded in the token, then I think the answer is yes. If it just controls the cache, then maybe not?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It doesn't need an expiration time. The cache is essentially a map from TokenRequestSpec to TokenRequestStatus so an expiration timestamp is an attribute of the status.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Er, sorry, I meant ExpirationSeconds. I.e. I'm wondering if 2 volumes with the same spec but different expirations could share a cache entry. I expect this to be a pretty unlikely scenario, so it's probably not worth changing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The ExpirationSeconds is in tr.Spec so the requested expiration is included in the cache key. Right now the requested expiration seconds will always be the expiration seconds, because we aren't implementing any sort of softmax. Two volume projections with the same spec should always project the same token.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: use the assert/require library? require.NoError(t, err)

same below.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

optional: use k8s.io/apimachinery/pkg/util/clock.FakeClock

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@mikedanese
Copy link
Copy Markdown
Member Author

How do we prevent static pods from mounting serviceAccountTokenProjections?

Added enforcement to the admission controller.

@mikedanese
Copy link
Copy Markdown
Member Author

/retest

@dims
Copy link
Copy Markdown
Member

dims commented Jun 4, 2018

/test pull-kubernetes-bazel-test

@dims
Copy link
Copy Markdown
Member

dims commented Jun 4, 2018

/assign @tallclair
/assign @derekwaynecarr

@k8s-github-robot
Copy link
Copy Markdown

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@CaoShuFeng @awly @derekwaynecarr @liggitt @mikedanese @saad-ali @tallclair

Pull Request Labels
  • sig/auth sig/storage: Pull Request will be escalated to these SIGs if needed.
  • priority/important-soon: Escalate to the pull request owners and SIG owner; move out of milestone after several unsuccessful escalation attempts.
  • kind/feature: New functionality.
Help

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is growing unbounded? It should grow slowly, but you need some way of clearing out old tokens.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean -1 * time.Duration(*tr.Spec.ExpirationSeconds) * time.Second * 20 / 100, which resolves to a time.Duration. But yeah, the accuracy isn't worth the time it took me to write this comment ;-)

@tallclair
Copy link
Copy Markdown
Member

/lgtm

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: awly, mikedanese, saad-ali, tallclair

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@mikedanese
Copy link
Copy Markdown
Member Author

squashed

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@mikedanese
Copy link
Copy Markdown
Member Author

fixed govet in test.

@mikedanese
Copy link
Copy Markdown
Member Author

/retest

@dims
Copy link
Copy Markdown
Member

dims commented Jun 5, 2018

@mikedanese looks like this could use a good release note. that should be the last thing this needs to merge

@k8s-github-robot
Copy link
Copy Markdown

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link
Copy Markdown

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@zparnold
Copy link
Copy Markdown

Hello there! @mikedanese I'm Zach Arnold working on Docs for the 1.11 release. This PR was identified as one needing some documentation in the https://github.com/kubernetes/website repo around your contributions (thanks by the way!) When you have some time, could you please modify/add/remove the relevant content that needs changing in our documentation repo? Thanks! Please let me or my colleague Misty know (@zparnold/@misty on K8s Slack) if you need any assistance with the documentation.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.