Skip to content

Add limit to the TokenRequest expiration time#63653

Merged
k8s-github-robot merged 1 commit intokubernetes:masterfrom
WanLinghao:token_expiry_limit
Jun 27, 2018
Merged

Add limit to the TokenRequest expiration time#63653
k8s-github-robot merged 1 commit intokubernetes:masterfrom
WanLinghao:token_expiry_limit

Conversation

@WanLinghao
Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
A new API TokenRequest has been implemented.It improves current serviceaccount model from many ways.
This patch adds limit to TokenRequest expiration time.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #63575

Special notes for your reviewer:

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 10, 2018
@mikedanese mikedanese self-assigned this May 10, 2018
@WanLinghao WanLinghao force-pushed the token_expiry_limit branch from f69720e to ff1e95b Compare May 11, 2018 09:05
@WanLinghao WanLinghao changed the title [WIP]Add limit to the TokenRequest expiration time Add limit to the TokenRequest expiration time May 11, 2018
@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 May 11, 2018
@WanLinghao
Copy link
Copy Markdown
Contributor Author

/test pull-kubernetes-integration

@WanLinghao
Copy link
Copy Markdown
Contributor Author

@mikedanese PTAL

Copy link
Copy Markdown
Member

@mikedanese mikedanese May 11, 2018

Choose a reason for hiding this comment

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

I'm not sure if this is useful to configure. I would suggest leaving the command line option out until people ask for it.

@WanLinghao WanLinghao force-pushed the token_expiry_limit branch from ff1e95b to 57cfbaa Compare May 12, 2018 05:55
@WanLinghao
Copy link
Copy Markdown
Contributor Author

@mikedanese WDYT this time

@WanLinghao
Copy link
Copy Markdown
Contributor Author

@mikedanese friendly ping

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.

This doesn't need to be plumbed through if the value is static.

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.

static validation should occur in pkg/apis/authentication/validation

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.

can you call this service-account-token-max-expiration and give it a type of pflag.Duration:

https://godoc.org/github.com/spf13/pflag#FlagSet.Duration

@mikedanese
Copy link
Copy Markdown
Member

I'd suggest only implementing maximum in this PR. How can we also enforce this maximum on the service account token volume projection?

@liggitt
Copy link
Copy Markdown
Member

liggitt commented May 16, 2018

if you request over the max, do you get rejected or truncated to the max? if you get rejected, that means any pod spec that specifies a max is non-portable.

@WanLinghao
Copy link
Copy Markdown
Contributor Author

WanLinghao commented May 17, 2018

From my point of view, we can simply do like other projected-volume did.
For example ,when you create a pod with following yaml file, at the same time, the secret "user" and "pass" are non-existent. The pod will stuck at ContainerCreating stage. The warning output would be like

Events:
  Type     Reason       Age               From                Message
  ----     ------       ----              ----                -------
  Normal   Scheduled    1m                default-scheduler   Successfully assigned office/test-projected-volume to 127.0.0.1
  Warning  FailedMount  44s (x8 over 1m)  kubelet, 127.0.0.1  MountVolume.SetUp failed for volume "all-in-one" : [secrets "user" not found, secrets "pass" not found]
apiVersion: v1
kind: Pod 
metadata:
  name: test-projected-volume
spec:
  containers:
  - name: alpine
    image: radial/busyboxplus:curl
    command: [ "/bin/ash", "-c", "--" ]
    args: [ "while true; do sleep 30; done;" ]
    volumeMounts:
    - name: all-in-one
      mountPath: "/projected-volume"
  volumes:
  - name: all-in-one
    projected:
      sources:
      - secret:
          name: user
      - secret:
          name: pass

In other words, we don't need special process here, the api-server would refuse the TokenRequest and the pod would be stuck at ContainerCreating stage with "expiration time out of range" warning.

I'd suggest only implementing maximum in this PR. How can we also enforce this maximum on the service account token volume projection?

@WanLinghao
Copy link
Copy Markdown
Contributor Author

WanLinghao commented May 17, 2018

@liggitt I think we can add support of percent expiration-time.
For example, a cluster starts with max-expiration time of 10 days could accept "50%" max expiration-time, which equals 5 days.
WDYT

if you request over the max, do you get rejected or truncated to the max? if you get rejected, that means any pod spec that specifies a max is non-portable.

@liggitt
Copy link
Copy Markdown
Member

liggitt commented May 17, 2018

@liggitt I think we can add support of percent expiration-time.
For example, a cluster starts with max-expiration time of 10 days could accept "50%" max expiration-time, which equals 5 days.
WDYT

what are the reasons someone would request a specific validity period? requesting a percentage of an unknown period doesn't make sense to me.

@mikedanese
Copy link
Copy Markdown
Member

I suggest we do none configurable hard validation as in #63999 and do a configurable soft validation. i.e. we should add a flag --service-account-token-max-expiration that configures the registry to truncate larger requested durations to an upper bound. I think this will be a useful flag when people start rotating these keys on a schedule. @WanLinghao @liggitt does that seem reasonable?

@WanLinghao
Copy link
Copy Markdown
Contributor Author

@mikedanese I think for lower bound, none configurable hard validation is reasonable.
But for upper bound, configurable soft validation alone is enough. Since if we set the hard validation too low, it would restrict users. If we set it too high, it makes no difference from permanent one.

Maybe we can do like this, user can't request a token with expiration time lower than 10minutes, its hard validation and non-configurable. For upper bound, if it is configured, any larger request would be truncated into max value. If it is not configured, there's no upper bound on expiration time.

@WanLinghao WanLinghao force-pushed the token_expiry_limit branch from 57cfbaa to 94b4a87 Compare May 18, 2018 06:32
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 11, 2018
@WanLinghao WanLinghao force-pushed the token_expiry_limit branch from c7f9618 to eb05913 Compare June 11, 2018 09:25
@WanLinghao
Copy link
Copy Markdown
Contributor Author

@liggitt @mikedanese test added, PTAL

Copy link
Copy Markdown
Member

@liggitt liggitt Jun 11, 2018

Choose a reason for hiding this comment

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

if non-zero, should verify this is:

  • >= the default value (1 hour)
  • <= the max value (2^32 seconds)

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.

lgtm otherwise

@WanLinghao WanLinghao force-pushed the token_expiry_limit branch 2 times, most recently from 12c943e to 30b99bd Compare June 12, 2018 04:05
@WanLinghao
Copy link
Copy Markdown
Contributor Author

/test pull-kubernetes-e2e-gce

@WanLinghao
Copy link
Copy Markdown
Contributor Author

@liggitt done PTAL

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.

typo: hour

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.

lowBound := time.Hour would be simpler

Copy link
Copy Markdown
Member

@liggitt liggitt Jun 12, 2018

Choose a reason for hiding this comment

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

upBound := time.Duration(1<<32) * time.Second would be simpler

@WanLinghao
Copy link
Copy Markdown
Contributor Author

@liggitt Done PTAL

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.

name this maxExpirationSeconds so it's clear what the unit is

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.

..., must be between ...

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Jun 13, 2018

/approve
a couple nits, then go ahead and squash
@mikedanese has lgtm

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 13, 2018
…ins a TokenRequest's expiration time to avoid extreme value which could harm the cluster.
@WanLinghao WanLinghao force-pushed the token_expiry_limit branch from 7b8b02c to f16470c Compare June 14, 2018 01:33
@WanLinghao
Copy link
Copy Markdown
Contributor Author

@mikedanese PTAL

@WanLinghao
Copy link
Copy Markdown
Contributor Author

@mikedanese friendly ping

@mikedanese
Copy link
Copy Markdown
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 26, 2018
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, mikedanese, WanLinghao

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

@WanLinghao
Copy link
Copy Markdown
Contributor Author

/retest

2 similar comments
@WanLinghao
Copy link
Copy Markdown
Contributor Author

/retest

@WanLinghao
Copy link
Copy Markdown
Contributor Author

/retest

@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.

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/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Limit the range of token expiration

5 participants