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

client: periodically reload InClusterConfig token #67359

Merged
merged 1 commit into from Sep 2, 2018

Conversation

mikedanese
Copy link
Member

@mikedanese mikedanese commented Aug 14, 2018

/sig auth
/sig api-machinery

NONE

@k8s-ci-robot k8s-ci-robot added 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 14, 2018
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Aug 14, 2018
@mikedanese mikedanese force-pushed the reloadtoken branch 3 times, most recently from 701b6c8 to 5623242 Compare August 14, 2018 15:27
@mikedanese
Copy link
Member Author

/retest

staging/src/k8s.io/client-go/rest/in_cluster_config.go Outdated Show resolved Hide resolved
}

if _, err := ioutil.ReadFile(tokenFile); err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Give more context to the error and check that file isn't empty.
Or create a cachingTokenSource first and do this check via ts.Token()

}

func (ts *fileTokenSource) Token() (*oauth2.Token, error) {
tokb, err := ioutil.ReadFile(ts.path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Check that token isn't empty and strings.TrimSpace it before returning to get rid of trailing newlines

Copy link
Member

@liggitt liggitt Aug 14, 2018

Choose a reason for hiding this comment

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

Disagree here. We should be consistent with how token files are handled elsewhere. We don't want to change the behavior of how we handle token files. That could lead to token files with leading/trailing spaces that work with this (common) client library and fail with others that expect the data to be good

now func() time.Time
}

var _ = oauth2.TokenSource(&cachingTokenSource{})
Copy link
Contributor

Choose a reason for hiding this comment

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

do the same for fileTokenSource

var _ = oauth2.TokenSource(&cachingTokenSource{})

func (ts *cachingTokenSource) Token() (*oauth2.Token, error) {
now := time.Now()
Copy link
Contributor

Choose a reason for hiding this comment

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

Add func newCachingTokenSource(base oauth2.TokenSource) and set ts.now and ts.leeway there


ts := &cachingTokenSource{
base: tts,
tok: c.tok,
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend leaving tok empty to make sure it works in initial state

Copy link
Member Author

Choose a reason for hiding this comment

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

I have test cases that do that.

now: func() time.Time { return start.Add(c.wait) },
}

gottok, goterr := ts.Token()
Copy link
Contributor

Choose a reason for hiding this comment

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

gotTok, gotErr

if got, want := tts.calls, c.wantTSCalls; got != want {
t.Errorf("unexpected number of Token() calls: got %d, want %d", got, want)
}
if got, want := goterr != nil, c.wantErr; got != want {
Copy link
Contributor

Choose a reason for hiding this comment

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

if gotErr != nil && !c.wantErr {
  t.Errorf(...)
}
if gotErr == nil && c.wantErr {
  t.Errorf(...)
}

for i := 0; i < 100; i++ {
go func() {
ts.Token()
wg.Done()
Copy link
Contributor

Choose a reason for hiding this comment

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

defer this before calling ts.Token

@liggitt
Copy link
Member

liggitt commented Aug 14, 2018

limiting this to InClusterConfig seems like the safest first step. Are there equivalent methods in the client libraries for other languages we need to update?

Would you expect the same updating behavior to apply to referenced token files eventually? I know of pods that run components using a kubeconfig file constructed with caFile/tokenFile references that point to the injected serviceaccount ca/token paths.

@mikedanese
Copy link
Member Author

I would expect this to work tor token-file as well. I'd like to replace the BearerToken field in rest.Config with a oauth2.TokenSource to unify all these methods. I can do that now or later.

@mikedanese mikedanese force-pushed the reloadtoken branch 2 times, most recently from 32a8559 to 8aa066d Compare August 15, 2018 01:00
@fedebongio
Copy link
Contributor

/assign @cheftako

@fedebongio
Copy link
Contributor

/assign @mbohlool

return tok, nil
}

tok, err := ts.base.Token()
Copy link
Member

Choose a reason for hiding this comment

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

if we previously successfully read a token, and failed to re-read a token, I think we should continue to use the previously read token.

leeway: 1 * time.Minute,
base: &fileTokenSource{
path: path,
period: 5 * time.Minute,
Copy link
Member

Choose a reason for hiding this comment

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

comment explaining why this period was chosen would be good

Copy link
Member Author

Choose a reason for hiding this comment

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

If only there was a reason...

@liggitt
Copy link
Member

liggitt commented Aug 23, 2018

a couple comments, looks reasonable to me otherwise.

if token reloading is desired/required in the future (at least for in-cluster configs), this should be noted in the kubernetes client guidelines, and issues should be opened to track adding it to the client libraries in other languages

@dims
Copy link
Member

dims commented Aug 24, 2018

/uncc

@k8s-github-robot
Copy link

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

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

1 similar comment
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@cblecker
Copy link
Member

cblecker commented Sep 1, 2018

/lgtm cancel
Failing tests

@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 1, 2018
@cblecker
Copy link
Member

cblecker commented Sep 2, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 2, 2018
@cblecker
Copy link
Member

cblecker commented Sep 2, 2018

The last directory is the csi-api Godeps, that was added after the fact. I'm going to submit a PR to fix, but I'm also going to manually approve to get this in

@cblecker cblecker added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 2, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

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

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

The pull request process is described here

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-github-robot
Copy link

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

@cblecker
Copy link
Member

cblecker commented Sep 2, 2018

PR to add OWNERS for that new directory: #68174

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md.

@timothysc
Copy link
Member

timothysc commented Sep 30, 2018

@kubernetes/sig-auth-bugs @kubernetes/sig-api-machinery-bugs - Folks - we're still digging into the source, but so far we believe this is the prime suspect which caused a regression in the in-cluster configuration that is used e2e test framework.

xref: #69234 (comment)

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 30, 2018
@timothysc
Copy link
Member

Submitted - #69272

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. area/custom-resources cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. 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/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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.

None yet