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

delegated authn/z: optionally opt-out of mandatory authn/authz kubeconfig #67545

Merged

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Aug 17, 2018

This adds RemoteKubeConfigFileOptional field to the delegated authn/z option structs. If set to true, the authn/z kubeconfig file flags are optional. If no kubeconfig is given, all token requests are considered to be anonymous and no client CA is looked up in the cluster.

Prerequisite for #64149 and #67069.

@k8s-ci-robot
Copy link
Contributor

@sttts: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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 do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 17, 2018
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 17, 2018
@k8s-ci-robot k8s-ci-robot added the sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. label Aug 17, 2018
@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from fb07de6 to 9d43cb1 Compare August 17, 2018 14:57
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 17, 2018
@sttts sttts added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed approved Indicates a PR has been approved by an approver from all required OWNERS 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. labels Aug 17, 2018
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 17, 2018
@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from 9d43cb1 to c19485b Compare August 17, 2018 15:06
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 17, 2018
@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch 2 times, most recently from 2ac1d50 to 3f34458 Compare August 17, 2018 15:40
@sttts sttts added sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. labels Aug 17, 2018
@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from 3f34458 to 8a384e0 Compare August 21, 2018 14:45
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Aug 21, 2018
@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from 8a384e0 to 74f594e Compare August 21, 2018 14:51
@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2018
@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from 74f594e to c9925dc Compare August 21, 2018 14:51
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2018
@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from c9925dc to 75976d9 Compare August 21, 2018 19:50
@sttts
Copy link
Contributor Author

sttts commented Aug 27, 2018

@awly @yue9944882 after the prerequisite merged, this is pretty trivial now. ptal.

@sttts sttts added this to the v1.12 milestone Aug 27, 2018
@@ -139,9 +142,14 @@ func (s *DelegatingAuthenticationOptions) AddFlags(fs *pflag.FlagSet) {
return
}

var optionalKubeConfigSentence string
if s.RemoteKubeConfigFileOptional {
optionalKubeConfigSentence = " This is optional. If empty, all token requests are considered to be anonymous " +
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to wrap this string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -336,6 +336,15 @@ func InClusterConfig() (*Config, error) {
}, nil
}

type notInCluster struct{ error }
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a package-level var NotInClusterErr = errors.New("...") instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -41,6 +42,9 @@ type DelegatingAuthorizationOptions struct {
// RemoteKubeConfigFile is the file to use to connect to a "normal" kube API server which hosts the
// SubjectAccessReview.authorization.k8s.io endpoint for checking tokens.
RemoteKubeConfigFile string
// RemoteKubeConfigFileOptional is specifying whether not specifying the kubeconfig or
// a missing in-cluster config will be fatal.
RemoteKubeConfigFileOptional bool
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 don’t add it to the flagset,where can we set its value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the component using the option struct sets it.

Copy link
Member

Choose a reason for hiding this comment

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

i thought that every field in option struct should be added to flagset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, why? We have many which are not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

look into SecureServing as an example.

// IsNotInCluster checks whether the error means that this process is not in a in-cluster context with
// KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT set as environment variables.
func IsNotInCluster(err error) bool {
_, ok := err.(notInCluster)
Copy link
Member

Choose a reason for hiding this comment

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

what about do a type switch? and we can handle nil check here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see @awly suggestion #67545 (comment). That's even simpler.

} else {
// without the remote kubeconfig file, try to use the in-cluster config. Most addon API servers will
// use this path
clientConfig, err = rest.InClusterConfig()
if err != nil && rest.IsNotInCluster(err) && s.RemoteKubeConfigFileOptional {
Copy link
Member

Choose a reason for hiding this comment

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

ditto

if len(s.ClientCert.ClientCA) == 0 {
glog.Warningf("No authentication-kubeconfig provided in order to lookup client-ca-file in configmap/%s in %s, so client certificate authentication to extension api-server won't work.", authenticationConfigMapName, authenticationConfigMapNamespace)
}
if len(s.RequestHeader.ClientCAFile) > 0 {
Copy link
Member

@yue9944882 yue9944882 Aug 28, 2018

Choose a reason for hiding this comment

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

==0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if err != nil {
return nil, err
if client == nil {
glog.Warningf("No authorization-kubeconfig provided, so SubjectAccessReview of authorization tokens won't work.")
Copy link
Member

Choose a reason for hiding this comment

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

nit: what about straightly return the union here?a long else block looks odd to me 👀

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 prefer the if block. The authorizers slice is constructed one by one by appending new authorizers. I think it is easier to reason about the code the way it is. The pattern is clear when another authorizer is added with another if block. Then an early return wouldn't work anymore.

@yue9944882
Copy link
Member

/retest

@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from 4a752b7 to dcb9b10 Compare August 28, 2018 08:09
@sttts
Copy link
Contributor Author

sttts commented Aug 28, 2018

@yue9944882 @awly addressed all comments. Anything left?

@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from dcb9b10 to 7675587 Compare August 28, 2018 08:11
@sttts
Copy link
Contributor Author

sttts commented Aug 28, 2018

/retest

@sttts
Copy link
Contributor Author

sttts commented Aug 28, 2018

@awly lgty?

@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from 7675587 to b996971 Compare August 28, 2018 10:44
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Aug 28, 2018

@sttts: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-gke 74f594e302fc51086046ca8f45615da5a7dea76f link /test pull-kubernetes-e2e-gke
pull-kubernetes-cross 74f594e302fc51086046ca8f45615da5a7dea76f link /test pull-kubernetes-cross

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@sttts
Copy link
Contributor Author

sttts commented Aug 28, 2018

/retest

Copy link
Contributor

@awly awly left a comment

Choose a reason for hiding this comment

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

Small nits, but LGTM

@@ -313,7 +318,7 @@ func DefaultKubernetesUserAgent() string {
func InClusterConfig() (*Config, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the above comment to mention ErrNotInCluster

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -44,6 +45,10 @@ const (
DefaultBurst int = 10
)

var (
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove parens, just var ErrNotInCluster = ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@sttts sttts added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 28, 2018
@sttts sttts force-pushed the sttts-auth-optional-kubeconfig branch from b996971 to a671d65 Compare August 28, 2018 17:08
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 28, 2018
@awly
Copy link
Contributor

awly commented Aug 28, 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 Aug 28, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: awly, sttts

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

Automatic merge from submit-queue (batch tested with PRs 66960, 67545). 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/apiserver 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/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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants