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 non-resource-request support to ABAC, fix kubectl for namespaced users #16148

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented Oct 23, 2015

Rebased and built on #13667

  • authorizer.Attributes
    • Added attribute indicating whether the request was for a resource (IsResourceRequest)
    • Added attribute containing the request path (can be used in combination with IsResourceRequest to authorize non-resource requests to paths like /swaggerapi, or /apis or /healthz, etc)
  • ABAC policy
    • Added support for matching on API groups attribute
    • Added support for matching non-resource requests (fixes kubectl does not work with namespace authorization. #13097)
    • Added line number and context to load errors
    • Ignore empty and comment lines
    • Converted to versioned resources (similar to scheduler policy objects) (fixes All policy config should be versioned, like APIs or other configuration #15117)
    • In "abac.authorization.kubernetes.io/v1beta1", explicitly require "user":"*","namespace":"*","resource":"*","apiGroup":"*","nonResourcePath":"*" to match all (deny by default, rather than grant by default)
    • Defined a "abac.authorization.kubernetes.io/v0" version for ABAC policy rule objects with conversions to "abac.authorization.kubernetes.io/v1beta1" preserving current behavior (preserved all ABAC tests as well)

@liggitt liggitt force-pushed the mkulke-fix_kubectl_for_namespaced_users branch from c89926d to e162b71 Compare October 23, 2015 06:40
@liggitt
Copy link
Member Author

liggitt commented Oct 23, 2015

@deads2k @mkulke PTAL
@mkulke can you comment to appease the cla bot?

@liggitt
Copy link
Member Author

liggitt commented Oct 23, 2015

@kubernetes/kube-iam this should give us sufficient authz power to allow API discovery and version negotiation while still constraining users to namespaces. I'd like to update the ABAC file format to a versioned format (falling back to the current JSONL format on deserialize errors for backwards compatibility), but will do that in another PR

@k8s-github-robot k8s-github-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 23, 2015
@k8s-github-robot
Copy link

Labelling this PR as size/L

@deads2k
Copy link
Contributor

deads2k commented Oct 23, 2015

@liggitt the sticking point last time was whether non-resource access was default allow or default deny. Which did you choose?

@mkulke
Copy link
Contributor

mkulke commented Oct 23, 2015

@liggitt LGTM

i built and tested the branch, seems to work fine:

$ ../../tmp/kubernetes/_output/dockerized/bin/linux/amd64/kubectl version
Client Version: version.Info{Major:"1", Minor:"2+", GitVersion:"v1.2.0-alpha.1.1513+e162b71ae80901", GitCommit:"e162b71ae809019a631c0704f18c3a1de631fb86", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"2+", GitVersion:"v1.2.0-alpha.1.1513+e162b71ae80901", GitCommit:"e162b71ae809019a631c0704f18c3a1de631fb86", GitTreeState:"clean"}

$ ../../tmp/kubernetes/_output/dockerized/bin/linux/amd64/kubectl --context=orange run nginx --image=nginx
replicationcontroller "nginx" created

$ ../../tmp/kubernetes/_output/dockerized/bin/linux/amd64/kubectl --context=black run nginx --image=nginx
replicationcontroller "nginx" created

$ ../../tmp/kubernetes/_output/dockerized/bin/linux/amd64/kubectl --context=black get po
NAME          READY     STATUS    RESTARTS   AGE
nginx-b80ks   1/1       Running   0          5m

$ ../../tmp/kubernetes/_output/dockerized/bin/linux/amd64/kubectl --context=liggitt --all-namespaces=true get po
NAMESPACE   NAME          READY     STATUS    RESTARTS   AGE
black       nginx-b80ks   1/1       Running   0          6m
orange      nginx-ayprx   1/1       Running   0          6m

@liggitt
Copy link
Member Author

liggitt commented Oct 23, 2015

flakes, only one that looked like it could be relevant (kubectl test) passed locally:

[Fail] Kubectl client Kubectl describe [It] should check if kubectl describe prints relevant information for rc and pods [Conformance] 
/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/test/e2e/kubectl.go:936

[Fail] Probing container [It] with readiness probe should not be ready before initial delay and never restart [Conformance] 
/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/test/e2e/container_probe.go:59

[Fail] Pods [It] should have their container restart back-off timer increase exponentially 
/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/test/e2e/pods.go:859

@k8s-bot test this

@liggitt
Copy link
Member Author

liggitt commented Oct 23, 2015

maybe... do you care if I squash to a single commit?

@liggitt
Copy link
Member Author

liggitt commented Oct 23, 2015

@deads2k the sticking point last time was whether non-resource access was default allow or default deny. Which did you choose?

I chose default deny, because default allow seems crazy when a field name typo in the policy file means the rule would be empty, allowing all. Granted, that's how namespace and resource behave now... but I was hoping to avoid propagating that.

Thinking further, though, {"user":"admin"} has to grant access to everything (resource and non-resource) to preserve compatibility. I'll add tests to make sure that doesn't break.

To get this looking the way I want internally, I may bite the bullet and add a versioned schema for ABACPolicy, and start requiring "*" for namespace and resource to match. Something like this:

{
  "apiVersion":"v1",
  "kind":"ABACPolicyList",
  "items":[
    {"user":"admin","nonResourcePath":"*","namespace":"*",resource:"*"},
  ]
}

Deserialize failures on old ABAC files could attempt to read the JSONL format and convert to the versioned form like this:

{"user":"u"}                  -> {"user":"u","nonResourcePath":"*","namespace":"*","resource":"*"}

{"user":"u","namespace":"ns"} -> {"user":"u","namespace":"ns","resource":"*"}

{"user":"u","resource":"r"}   -> {"user":"u","namespace":"*","resource":"r"}

Before I start on that, any objections from @kubernetes/kube-iam on the approach?

@liggitt
Copy link
Member Author

liggitt commented Oct 23, 2015

or, while bullets are being bitten, this:

{
  "apiVersion":"v1",
  "kind":"ABACPolicyList",
  "items":[
    {
      "user":"u",
      "groups":["g1","g2"],
      "verbs":["get","list","watch"], // or ["*"]
      "namespaces":["ns1","ns2"], // or ["*"]
      "resources":["pods","replicationcontrollers"], // or ["*"]
      "nonResourcePaths":["/api","/api/*","/apis","/apis/*"] // or ["*"]
    },
    ...
  ]
}

Being able to grant a user or group permission across namespaces, verbs, and resources in a single rule improves readability quite a bit. Depends on how real we envision this being, and whether we see this as a progression toward dynamic authz.

@deads2k
Copy link
Contributor

deads2k commented Oct 23, 2015

or, while bullets are being bitten, this:

No. That makes verbs for nonResourcePaths weird. What would a watch on a nonResourcePath mean?

@mkulke
Copy link
Contributor

mkulke commented Oct 23, 2015

@liggitt: sure, go ahead.

@liggitt liggitt force-pushed the mkulke-fix_kubectl_for_namespaced_users branch from e162b71 to e0afd87 Compare October 25, 2015 00:28
@deads2k
Copy link
Contributor

deads2k commented Oct 26, 2015

I like default denies and other than allowing both non-resource and resource rules in a single statement, I like the format of #16148 (comment).

If you want a new format, would it be easier to simply have a second authorizer to implement it?

@yuvipanda
Copy link
Contributor

/cc @erictune (This is the kubectl namespacing patch I was talking about)

@liggitt liggitt changed the title Fix kubectl for namespaced users WIP - Fix kubectl for namespaced users Nov 12, 2015
@liggitt liggitt force-pushed the mkulke-fix_kubectl_for_namespaced_users branch 2 times, most recently from 28b47c7 to d393378 Compare November 20, 2015 06:21
@liggitt liggitt changed the title WIP - Fix kubectl for namespaced users Add non-resource-requests support to ABAC, fix kubectl for namespaced users Nov 20, 2015
@liggitt liggitt changed the title Add non-resource-requests support to ABAC, fix kubectl for namespaced users Add non-resource-request support to ABAC, fix kubectl for namespaced users Nov 20, 2015
@k8s-github-robot
Copy link

Labelling this PR as size/XXL

@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 20, 2015
@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/new-api labels Dec 1, 2015
@k8s-bot
Copy link

k8s-bot commented Dec 1, 2015

GCE e2e test build/test passed for commit 0ad102799d267992f65df5505a50eea44aa90a56.

@k8s-bot
Copy link

k8s-bot commented Dec 1, 2015

GCE e2e test build/test passed for commit bb20bead6cf93cf3f5faf5adff6ca0c1d6591a97.

@lavalamp
Copy link
Member

lavalamp commented Dec 2, 2015

Thank you for humoring me, no more objections here!

@deads2k
Copy link
Contributor

deads2k commented Dec 2, 2015

lgtm.

Squash and tag at will.

@liggitt liggitt force-pushed the mkulke-fix_kubectl_for_namespaced_users branch from bb20bea to dc4506e Compare December 2, 2015 18:25
@liggitt liggitt added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 2, 2015
@liggitt
Copy link
Member Author

liggitt commented Dec 2, 2015

@lavalamp thinking further, was there a specific reason for making the version v1beta1 rather than v1? It's a very granular api group, so bumping versions wouldn't be hard, I just wondered

@lavalamp
Copy link
Member

lavalamp commented Dec 2, 2015

Yeah-- if we call it v1beta1 then I don't have to be picky about the
contents of the API types :) :)

On Wed, Dec 2, 2015 at 10:37 AM, Jordan Liggitt notifications@github.com
wrote:

@lavalamp https://github.com/lavalamp thinking further, was there a
specific reason for making the version v1beta1 rather than v1? It's a
very granular api group, so bumping versions wouldn't be hard, I just
wondered


Reply to this email directly or view it on GitHub
#16148 (comment)
.

@k8s-bot
Copy link

k8s-bot commented Dec 2, 2015

GCE e2e test build/test passed for commit dc4506ecd57e2f53a4ec7fad31f9a99914a71e77.

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Dec 2, 2015

GCE e2e test build/test passed for commit dc4506ecd57e2f53a4ec7fad31f9a99914a71e77.

@liggitt liggitt force-pushed the mkulke-fix_kubectl_for_namespaced_users branch from dc4506e to 2321651 Compare December 3, 2015 17:43
@liggitt
Copy link
Member Author

liggitt commented Dec 3, 2015

rebased

@liggitt liggitt added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Dec 3, 2015
@k8s-github-robot
Copy link

@k8s-bot ok to test
@k8s-bot test this

pr builder appears to be missing, activating due to 'lgtm' label.

@k8s-github-robot
Copy link

Travis continuous integration appears to have missed, closing and re-opening to trigger it

@k8s-bot
Copy link

k8s-bot commented Dec 3, 2015

GCE e2e test build/test passed for commit 2321651.

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Dec 3, 2015

GCE e2e test build/test passed for commit 2321651.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

k8s-github-robot pushed a commit that referenced this pull request Dec 3, 2015
@k8s-github-robot k8s-github-robot merged commit 6117707 into kubernetes:master Dec 3, 2015
@liggitt liggitt deleted the mkulke-fix_kubectl_for_namespaced_users branch December 3, 2015 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
10 participants