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

oidc authentication: switch to v2 of coreos/go-oidc #58544

Merged
merged 3 commits into from
Feb 21, 2018

Conversation

ericchiang
Copy link
Contributor

@ericchiang ericchiang commented Jan 19, 2018

Switch to v2 of coreos/go-oidc, which uses square/go-jose to verify tokens and supports more signing algorithms.

Most of this PR removes dependencies used by the older version of github.com/coreos/go-oidc, and updates vendor files.

This PR has been tested against tokens issued by Okta, Google, and CoreOS's dex.

Closes #57806

kube-apiserver: the OpenID Connect authenticator can now verify ID Tokens signed with JOSE algorithms other than RS256 through the --oidc-signing-algs flag.
kube-apiserver: the OpenID Connect authenticator no longer accepts tokens from the Google v3 token APIs, users must switch to the "https://www.googleapis.com/oauth2/v4/token" endpoint.

cc @rithujohn191 @liggitt
cc @kubernetes/sig-auth-pr-reviews

@k8s-ci-robot k8s-ci-robot added 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 19, 2018
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Godep parts look OK. ping me when LGTM'ed and I can approve.

@ericchiang ericchiang force-pushed the oidc-v2 branch 2 times, most recently from 3e0afec to 8eeefd2 Compare January 19, 2018 22:55
Copy link
Contributor

@rithujohn191 rithujohn191 left a comment

Choose a reason for hiding this comment

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

the lint check and staging-godeps check seems to have failed

var groups []string
if err := c.unmarshalClaim(a.groupsClaim, &groups); err != nil {
var group string
if err := c.unmarshalClaim(a.groupsClaim, &group); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment about why you are trying to decode it as string again as opposed to an array of strings would be helpful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a link to #33290

Copy link
Member

Choose a reason for hiding this comment

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

alternatively create a:

type stringOrArray []string

with a UnmarshalJSON func that does the right thing.

@ericchiang
Copy link
Contributor Author

https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/pr-logs/pull/58544/pull-kubernetes-unit/76002/

Failure on

k8s.io/kubernetes/vendor/k8s.io/apiextensions-apiserver/test/integration TestPatch 0.82s

/test pull-kubernetes-unit

@@ -0,0 +1,27 @@
#!/bin/bash -e
Copy link
Member

Choose a reason for hiding this comment

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

can we move this under testdata? makes it clearer it is only for test

}

// whilelist of signing algorithms to ensure users don't mistakenly pass something
// goofy.
Copy link
Member

Choose a reason for hiding this comment

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

don't want to enable none? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I swear I remember someone accidentally using tokens with HS256.

if client := a.oidcClient.Load(); client != nil {
return client.(*oidc.Client), nil
}
client := &http.Client{Transport: tr, Timeout: 15 * time.Second}
Copy link
Member

@liggitt liggitt Jan 20, 2018

Choose a reason for hiding this comment

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

this is the client used in the background to fetch discovery docs and public keys? what was the timeout before?

edit: found it. there was no timeout previously. 15 seconds sounds a little aggressive, especially for a background process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bumped to 30 seconds

@ericchiang
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

@ericchiang
Copy link
Contributor Author

ericchiang commented Jan 22, 2018

/test pull-kubernetes-e2e-kops-aws

edit: flaking on #58578

@ericchiang
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

1 similar comment
@ericchiang
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

@ericchiang
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

@ericchiang
Copy link
Contributor Author

@kubernetes/sig-auth-pr-reviews tests are green

@liggitt
Copy link
Member

liggitt commented Jan 26, 2018

+	// Check issuer.
+	if t.Issuer != v.issuer {
+		// Google sometimes returns "accounts.google.com" as the issuer claim instead of
+		// the required "https://accounts.google.com". Detect this case and allow it only
+		// for Google.
+		//
+		// We will not add hooks to let other providers go off spec like this.
+		if !(v.issuer == issuerGoogleAccounts && t.Issuer == issuerGoogleAccountsNoScheme) {
+			return nil, fmt.Errorf("oidc: id token issued by a different provider, expected %q got %q", v.issuer, t.Issuer)
+		}
+	}

really?

if !ok {
return fmt.Errorf("claim not present")
}
return json.Unmarshal([]byte(val), v)
Copy link
Member

Choose a reason for hiding this comment

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

does this echo the value in errors? we weren't returning claim values in error messages before, just type info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's doesn't appear to return the value: https://play.golang.org/p/Ed2vi-1gDEK

I can add a test to make sure that behavior doesn't change in future releases of Go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test added.

return nil, false, err
}
claims, err := jwt.Claims()
idToken, err := verifier.Verify(ctx, token)
Copy link
Member

Choose a reason for hiding this comment

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

can be a follow-up, but might be good to consider doing something similar to #58791 to avoid noise in logs when this is combined with other token auth methods

@liggitt
Copy link
Member

liggitt commented Jan 26, 2018

a couple questions, LGTM overall. would like a second review on the authorize path. @tallclair can you review or pick a delegate?

@k8s-ci-robot k8s-ci-robot assigned deads2k and unassigned liggitt Jan 27, 2018
@ericchiang ericchiang force-pushed the oidc-v2 branch 2 times, most recently from ba0d4e2 to 4f13d09 Compare January 31, 2018 19:34
@thockin
Copy link
Member

thockin commented Feb 6, 2018

I have no context on this - please assign to me if you need some approval.

@liggitt
Copy link
Member

liggitt commented Feb 10, 2018

/lgtm

would like a second from another @kubernetes/sig-auth-pr-reviews reviewer, then can get top-level approval for godep change

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

@mikedanese mikedanese left a comment

Choose a reason for hiding this comment

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

/lgtm

})
}

// whilelist of signing algorithms to ensure users don't mistakenly pass something
Copy link
Member

Choose a reason for hiding this comment

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

typo: whitelist

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 16, 2018
@mikedanese
Copy link
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 Feb 16, 2018
@ericchiang
Copy link
Contributor Author

/assign @thockin

For final approval

@smarterclayton
Copy link
Contributor

/approve

for godep

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 21, 2018
@k8s-github-robot
Copy link

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

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

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/security cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet