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

Add selfsubjectrulesreview in authorization #48051

Merged

Conversation

xilabao
Copy link
Contributor

@xilabao xilabao commented Jun 26, 2017

What this PR does / why we need it:

Which issue this PR fixes: fixes #47834 #31292

Special notes for your reviewer:

Release note:

Add selfsubjectrulesreview API for allowing users to query which permissions they have in a given namespace.

/cc @deads2k @liggitt

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 26, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @xilabao. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 26, 2017
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/new-api size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jun 26, 2017
@deads2k
Copy link
Contributor

deads2k commented Jun 26, 2017

@ericchiang you were thinking something similar.

Copy link
Contributor

@ericchiang ericchiang left a comment

Choose a reason for hiding this comment

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

Awesome!

Would like to see the kubectl code as a different PR. If it's just @kubernetes/sig-auth-pr-reviews that needs to review then we can probably get this in faster. What do you think?

)

type RESTStorageProvider struct {
Authorizer authorizer.Authorizer
Authorizer authorizer.Authorizer
AuthorizationRuleResolver rbacregistryvalidation.AuthorizationRuleResolver
Copy link
Contributor

Choose a reason for hiding this comment

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

There are other kind of authorizers. Can we ensure that this isn't actually tied to the RBAC authorizer by introducing another interface like authorizer.Authorizer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated. PTAL @ericchiang

@xilabao xilabao force-pushed the add-selfsubjectrulesreview-api branch from dedc6db to ebc53b5 Compare June 27, 2017 10:03
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2017
@xilabao xilabao force-pushed the add-selfsubjectrulesreview-api branch from ebc53b5 to 6c4e095 Compare June 27, 2017 10:05
Copy link
Contributor

@ericchiang ericchiang left a comment

Choose a reason for hiding this comment

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

You've got some generated code in your first commit.

Also can you explain a bit about what the third commit "create the methods in the generated expansion files" means? Are you creating those manually? Sorry, I'm not super familiar with the generated clientset.

// AuthorizationRulesGetter provides a function that get the list of rules that apply to a given user in a given namespace and error.
// If an error is returned, the slice of rules may not be complete, but it contains all retrievable rules. This is done because policy
// rules are purely additive and policy determinations can be made on the basis of those rules that are found.
type AuthorizationRulesGetter interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

The equivalent openshift type is called "AuthorizaitonRuleResolver"[1]. I think authorizaiton.RuleResolver would be a much more natural fit.

[1] https://github.com/openshift/origin/blob/496129f10823185674fa9d20a7e11be46ca53512/pkg/authorization/rulevalidation/find_rules.go#L27

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 think authorizaiton.RuleResolver would be a much more natural fit.

Done.

}

// Authorizes against a chain of authorizer.AuthorizationRulesGetter objects and returns nil if successful and returns error if unsuccessful
func (authzHandler unionAuthzRulesHandler) RulesFor(user user.Info, namespace string) ([]authorizationapi.ResourceRule, []authorizationapi.NonResourceRule, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have expected some sort of logic to de-dup identical rules from different authorizers or when one returns a wildcard rule that encompasses the other rules.

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 would have expected some sort of logic to de-dup identical rules from different authorizers or when one returns a wildcard rule that encompasses the other rules.

could we sort in kubectl code?


func NewREST(authorizationRulesGetter authorizer.AuthorizationRulesGetter) *REST {
return &REST{authorizationRulesGetter}
//return &REST{ruleResolver: ruleResolver}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove commented out return.

if !ok {
return nil, apierrors.NewBadRequest("no user present on request")
}
namespace, _ := genericapirequest.NamespaceFrom(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we grabbing a namespace? Isn't the SelfSubjectRulesReview non-namespaced?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why are we grabbing a namespace? Isn't the SelfSubjectRulesReview non-namespaced?

I think that SelfSubjectRulesReview can get the cluster wide rules and the rules in the specified namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

Which specified namespace? The resource isn't namespaced, so I don't see a way for this to ever hold a 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.

@ericchiang you are right. SelfSubjectRulesReview should be namespaced. fixed. ptal

Copy link
Contributor

Choose a reason for hiding this comment

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

SelfSubjectRulesReview should be namespaced.

No, it definitely should definitely be cluster wide or you'd never be able to get information about cluster level resources. e.g. we need this to help determine what namespaces users have access too.

Copy link
Member

Choose a reason for hiding this comment

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

This still doesn't look right... I'd expect the types to be cluster-scoped, and there to be a spec that allows indicating the namespace to evaluate at (see SelfSubjectAccessReview.Spec.ResourceAttributes.Namespace as a parallel)

Copy link
Contributor

Choose a reason for hiding this comment

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

This still doesn't look right... I'd expect the types to be cluster-scoped, a

It seems weird to have a cluster scoped resource that is only valid in the context of a namespace. We can't reasonably evaluate permissions across all namespaces because of fanout. We could give strictly cluster-scoped powers, but that's of limited utility. You're just trying for parity with SAR?

// If an error is returned, the slice of rules may not be complete, but it contains all retrievable rules. This is done because policy
// rules are purely additive and policy determinations can be made on the basis of those rules that are found.
type AuthorizationRulesGetter interface {
RulesFor(user user.Info, namespace string) ([]authorizationapi.ResourceRule, []authorizationapi.NonResourceRule, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to articulate how this method works for cluster wide (non-namespaced) rule evaluation. Particularly since this is only being used to fill out a non-namespaced resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to articulate how this method works for cluster wide (non-namespaced) rule evaluation. Particularly since this is only being used to fill out a non-namespaced resource.

comments added

@@ -20,6 +20,7 @@ import (
"net/http"

"k8s.io/apiserver/pkg/authentication/user"
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't know the implications of having this start to import an API package since before it was nicely self contained. cc @deads2k any thoughts 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.

Don't know the implications of having this start to import an API package since before it was nicely self contained.

Done. use "k8s.io/api/authorization/v1" instead of "k8s.io/kubernetes/pkg/apis/authorization"

@xilabao xilabao force-pushed the add-selfsubjectrulesreview-api branch 2 times, most recently from cfcc972 to 7fb4c2f Compare June 28, 2017 08:12
@xilabao
Copy link
Contributor Author

xilabao commented Jun 28, 2017

Also can you explain a bit about what the third commit "create the methods in the generated expansion files" means? Are you creating those manually?

I create those methods manually. I ref to the discussion at #31271 (comment)

@ericchiang
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 28, 2017
@xilabao xilabao force-pushed the add-selfsubjectrulesreview-api branch 7 times, most recently from 9eaaa68 to 5f4deda Compare June 29, 2017 08:42
@ericchiang
Copy link
Contributor

This is working and I don't see any other outstanding concerns about the API

$ curl -k -X POST \
>     --key /var/run/kubernetes/client-admin.key \
>     --cert /var/run/kubernetes/client-admin.crt \
>     -H 'Content-Type: application/json;stream=watch' \
>     --data '{"spec":{"namespace":"kube-system"}}' \
>     https://localhost:6443/apis/authorization.k8s.io/v1/selfsubjectrulesreviews
{
  "kind": "SelfSubjectRulesReview",
  "apiVersion": "authorization.k8s.io/v1",
  "metadata": {
    "creationTimestamp": null
  },
  "spec": {},
  "status": {
    "resourceRules": [
      {
        "verbs": [
          "*"
        ],
        "apiGroups": [
          "*"
        ],
        "resources": [
          "*"
        ]
      },
      {
        "verbs": [
          "create"
        ],
        "apiGroups": [
          "authorization.k8s.io"
        ],
        "resources": [
          "selfsubjectaccessreviews"
        ]
      }
    ],
    "nonResourceRules": [
      {
        "verbs": [
          "*"
        ],
        "nonResourceURLs": [
          "*"
        ]
      },
      {
        "verbs": [
          "get"
        ],
        "nonResourceURLs": [
          "/api",
          "/api/*",
          "/apis",
          "/apis/*",
          "/healthz",
          "/swaggerapi",
          "/swaggerapi/*",
          "/version"
        ]
      }
    ],
    "incomplete": false
  }
}

/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 31, 2017
@calebamiles
Copy link
Contributor

/test pull-kubernetes-e2e-kops-aws
/test pull-kubernetes-bazel

@xilabao xilabao force-pushed the add-selfsubjectrulesreview-api branch from ae322d7 to 790374d Compare September 1, 2017 11:16
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 1, 2017
@xilabao
Copy link
Contributor Author

xilabao commented Sep 1, 2017

/test pull-kubernetes-bazel
/test pull-kubernetes-kubemark-e2e-gce
/test pull-kubernetes-e2e-gce-etcd3

@xilabao
Copy link
Contributor Author

xilabao commented Sep 1, 2017

/test pull-kubernetes-kubemark-e2e-gce

@deads2k
Copy link
Contributor

deads2k commented Sep 1, 2017

/approve

@xilabao
Copy link
Contributor Author

xilabao commented Sep 1, 2017

/test pull-kubernetes-kubemark-e2e-gce

@ericchiang
Copy link
Contributor

/lgtm

/assign @smarterclayton

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 1, 2017
@smarterclayton
Copy link
Contributor

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, ericchiang, smarterclayton, xilabao

Associated issue: 47834

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 1, 2017
@ericchiang
Copy link
Contributor

/retest

@ericchiang
Copy link
Contributor

/test pull-kubernetes-kubemark-e2e-gce

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

@CaoShuFeng
Copy link
Contributor

/test pull-kubernetes-verify

@liggitt
Copy link
Member

liggitt commented Sep 2, 2017

/retest

1 similar comment
@ericchiang
Copy link
Contributor

/retest

@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 (batch tested with PRs 45724, 48051, 46444, 51056, 51605)

@k8s-github-robot k8s-github-robot merged commit c84b313 into kubernetes:master Sep 2, 2017
@k8s-ci-robot
Copy link
Contributor

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

Test name Commit Details Rerun command
pull-kubernetes-bazel 921a0566f15b961131e6001966b655535ae64aca link /test pull-kubernetes-bazel
pull-kubernetes-e2e-gce-etcd3 790374d link /test pull-kubernetes-e2e-gce-etcd3
pull-kubernetes-e2e-kops-aws 790374d link /test pull-kubernetes-e2e-kops-aws

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.

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

support what-can-i-do in kubernetes