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

[WIP] Begin KEP for fine-grained authz #3617

Closed
wants to merge 9 commits into from

Conversation

lavalamp
Copy link
Member

@lavalamp lavalamp commented Oct 12, 2022

  • One-line PR description: Initial draft of KEP
  • Other comments: This is complete enough to give the gist, but there are some missing sections still -- feel free to send PRs to my branch if you want to help.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 12, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp

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 kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory label Oct 12, 2022
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 12, 2022
* .metadata.ownerReferences (maybe)
* .status
* .status.conditions (many objects but not all; parameterized by specific type)
* .spec
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 need to add .spec.containers[].resources...


The authz system will see the verb "granular:labels".

#### Specific Labels
Copy link
Member Author

Choose a reason for hiding this comment

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

@apelisse can you look at this section and see if you can think of a better system? (you may need to read some prior sections to understand this)

keps/sig-api-machinery/3617-fine-grained-authz/README.md Outdated Show resolved Hide resolved
keps/sig-api-machinery/3617-fine-grained-authz/README.md Outdated Show resolved Hide resolved
request with a forbidden error.
3. Compute the change (patch logic, SSA logic, defaulting etc). Compute a list
of fields which changed. (SSA logic makes this easy.)
4. Pre- or post- (DECISION NEEDED) webhooks, check the list of fields:
Copy link
Member

Choose a reason for hiding this comment

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

Probably post-mutating webhooks, no? I guess you could also run it both before and after.

Copy link
Member Author

Choose a reason for hiding this comment

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

Kind of a trade off -- doing it post webhook is safer in terms of what gets committed but breaks webhooks that e.g. look at nodeName and keep a label up to date. pre-webhook is safer in terms of not exposing side-effect-having webhooks to malicious payloads.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer post-mutating webhooks as well. I'd like to check on the actual object being stored.

Co-authored-by: Han Kang <hankang@google.com>
Therefore, __modifying a single authz system can't solve the problem__.

An authz check can be thought of as sending structured data to an opaque system
which answers yes or no. Essentially we can't change things about the system
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, no, or no opinion. I think the distinction between no and no opinion is significant.

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 think that matters for individual authorizors but not really for the authz stack as a whole, which eventually either admits or rejects.

Copy link
Member Author

Choose a reason for hiding this comment

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

clarified

(TODO: I'm sure sig auth will want to correct my wording here)

* The resource type (group, version, resource)
* The object's locator (namespace if any, name, uid)
Copy link
Contributor

Choose a reason for hiding this comment

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

UID is not provided.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed


* The resource type (group, version, resource)
* The object's locator (namespace if any, name, uid)
* The actor's identity (username, group)
Copy link
Contributor

Choose a reason for hiding this comment

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

user.Extra and user.UID are provided. See user.Info.

Copy link
Member Author

Choose a reason for hiding this comment

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

added

in the order of most general to most specific. When we describe the
representation in the schema it will be clear what that means. The reason for
this is that multiple fields can be covered by a more general permission,
greatly reducing the number of checks needed in the worst case (as long as the
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we expand the authorization interface to have a slice option to pass more than one to evaluate a time? We could expand the webhook using another version and non-participating webhooks could be shimmed to answer one at a time in parallel

Copy link
Member

Choose a reason for hiding this comment

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

that's funny, I literally had that thought this morning

Copy link
Member

Choose a reason for hiding this comment

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

that would already be nice for impersonation

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 no objection to that but it sounds like an optimization that can be done whether or not the KEP goes through.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no objection to that but it sounds like an optimization that can be done whether or not the KEP goes through.

I'm not completely sure of that. There are two "obvious" ways to handle parameterization of something like label values.

  1. One way is to describe in the schema a manner in which shrink the keyspace (you've done this).
  2. Another way is to send all the label keys to the authorizer as distinct verbs and let the authorizer decide how best to let a user/cluster-admin express rules.

I think if we have a bulk authorization interface, it becomes more practical to lookup every key at once.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry it says you sent this 7 days ago but this is the first I saw it -- if you look at my comment here I think my current plan doesn't require a bulk lookup. My backup plan also doesn't require a bulk lookup.

Copy link
Member Author

Choose a reason for hiding this comment

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

The latest revision doesn't require bulk lookup, either.

@deads2k
Copy link
Contributor

deads2k commented Oct 14, 2022

Can you add a section that describes your ideal schema for describing policy rules? Is it just current RBAC with wildcard prefixes on verb?

Comment on lines +382 to +384
A risk is that it would be possible to configure permissions which result in a
large number of authz checks. Specifically CRD authors could craft a CRD with
many checks required to do anything.
Copy link
Contributor

Choose a reason for hiding this comment

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

We restrict resource use by CRDs' validation functions. Perhaps a similar restriction could apply here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, feedback is too early. Sorry about that.

(The exact permission system will be described below because we're not done with
the requirements yet, keep reading!)

#### Uncovered verbs
Copy link
Member Author

Choose a reason for hiding this comment

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

@deads2k I think moving this concept out of the schema gets you what you want.

@k8s-ci-robot
Copy link
Contributor

@lavalamp: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-enhancements-verify 63e50f1 link true /test pull-enhancements-verify

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.


"fine-grained" means giving the ability to certain actors (users, groups,
controllers, etc) to edit only particular fields, instead of entire objects.
Additionally, it involves adding the ability to restrict existing board
Copy link
Contributor

Choose a reason for hiding this comment

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

spelling? board -> broad

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.

Overall I am thrilled to see this. I am probably not close enought o find all the nitpicks needed, but I very much appreciate that you listed me. As always, your KEPs are a joy to read.

A few comments inline, one more general:

How do we default fields which are uncovered and unsatisfied? Or do we just NOT?

Ordinary users must not be able to set this to true. Only admins may set it to
true.

#### List of known fields wanting these features
Copy link
Member

Choose a reason for hiding this comment

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

We have also had CVEs in the past which would have been better solved by a field-level mechanism, I think, such as Service.spec.externalIPs

we have an alpha or beta behind us, hence we're not ready to specify that in
this KEP yet.

(The exact permission system will be described below because we're not done with
Copy link
Member

Choose a reason for hiding this comment

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

I just want to say that I am only this far in, and already I think it's a great KEP.

Example:

```
apiVersion: permissionconfig.k8s.io/v1
Copy link
Member

Choose a reason for hiding this comment

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

IMHO "config" adds no value in this string.

There's one more piece of information we need to satisfy our second goal, and it
can't go in the schema because it may vary from cluster to cluster.

This concept is whether a permission verb is "covered" by enclosing permissions,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not in love with "covered" and "unconvered" as terms - are they standard concepts in authz realm?

If not, maybe we can solicit ideas for names. e.g. Inherited vs Explicit or something


##### Everything in spec

On types:
Copy link
Member

Choose a reason for hiding this comment

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

Why both? Every type is linked from some field and we know that (sadly) we sometimes reuse types. Is there a driving case where defining it by type is the best solution?

#### Pod's nodeName

Given where this appears in Pod, this permission will only be checked for pods
if the agent doesn't have the "specification" permission.
Copy link
Member

Choose a reason for hiding this comment

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

If they have PATCH/PUT it is also satisifed, right? Because this is a convered permission?


```go
...
// +permission-verb:"nodeAssignment"
Copy link
Member

Choose a reason for hiding this comment

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

curiously, all your "verbs" are nouns - is it worth keeping the word "verb" in this? e.g +permission:"nodeAssignment" is just as clear. Or +permission-verb:"assignNode" ?

##### Everything in metadata

Configured the same as everything in spec, but the verb will be (CHOICE NEEDED)
"metadata" or "objectmeta".
Copy link
Member

Choose a reason for hiding this comment

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

FWIW "metadata" is my pref


DECISION NEEDED:

Option A: we will put a registry file in the kubernetes repository so that 3rd
Copy link
Member

Choose a reason for hiding this comment

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

#3787 ?

status: provisional
creation-date: 2022-10-07
reviewers:
- "@thockin"
Copy link
Member

Choose a reason for hiding this comment

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

thanks!

Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

I think this is how we mark pending decisions.

Comment on lines +606 to +614
DECISION NEEDED:

Option A: we will put a registry file in the kubernetes repository so that 3rd
party extension authors can register their custom permissions and dedup/reuse
rather than create new ones, if possible.

Option B: we will require 3rd party authors to prefix their custom permissions
with the string "ext" (TODO: "mycompany.example.com" if there is likely to be
space).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DECISION NEEDED:
Option A: we will put a registry file in the kubernetes repository so that 3rd
party extension authors can register their custom permissions and dedup/reuse
rather than create new ones, if possible.
Option B: we will require 3rd party authors to prefix their custom permissions
with the string "ext" (TODO: "mycompany.example.com" if there is likely to be
space).
<<[UNRESOLVED decision needed]>>
Option A: we will put a registry file in the k/kubernetes repository so that 3rd
party extension authors can register their custom permissions and dedup/reuse
rather than create new ones, if possible.
Option B: we will require 3rd party authors to prefix their custom permissions
with the string "ext" (TODO: "mycompany.example.com" if there is likely to be
space).
<<[/UNRESOLVED]>>

My option C would be to copy the idea from labels and use kubernetes.io/whatever for permissions defined by Kubernetes. Prefixes need to be valid DNS subdomains and should be associated with the party that defines them. Etc.

Comment on lines +571 to +572
DECISION NEEDED: would it be better to use a CEL expression to process the
parameter?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DECISION NEEDED: would it be better to use a CEL expression to process the
parameter?
<<[UNRESOLVED decision needed]>>
Would it be better to use a CEL expression to process the parameter?
<<[/UNRESOLVED]>>

@enj
Copy link
Member

enj commented Feb 9, 2023

/milestone v1.28

@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Feb 9, 2023

1. Check the "PUT" / "PATCH" / "CREATE" permission. If the actor has this,
place a marker=regular in the request context and proceed to step 3.
2. Otherwise, check the "granular" permission. If yes, place a
Copy link
Member

Choose a reason for hiding this comment

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

Does a granular check make sense in the context of a create? It seems reasonable to me that it would only apply to update/patch requests.

Copy link
Contributor

Choose a reason for hiding this comment

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

You might let people make a Pod, provided they don't set schedulingGates, and then have exceptions - maybe one principal can set this particular schedulingGate but not an arbitrary one.

Similar idea to setting a finalizer at create time. If we want to have fine grained control, I think it could be frustrating to have to duplicate the logic / whatever so that we restrict both creates and updates.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah the intention is that the per-field permissions are the same for both, otherwise I have to duplicate this all to handle both paths.

The result is you won't be able to create things if you lack a granular permission on a required, non-defaulted field.

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 check apply before or after static defaults?

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 think after? And probably some extra work not described in the KEP needs to be done to make it work like I just said.

I hope to make another pass on this KEP soon

Copy link
Member

@thockin thockin Feb 16, 2023

Choose a reason for hiding this comment

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

So if a field needs an uncovered permission, it cannot have a default value (or it has to be defaulted in registry, not static) - is that the right implication? That seems plausible to me.


On any mutating call,

1. Check the "PUT" / "PATCH" / "CREATE" permission. If the actor has this,
Copy link
Member

Choose a reason for hiding this comment

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

nit: permissions should be "updated" / "patch" / "create"

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 17, 2023
@enj
Copy link
Member

enj commented May 17, 2023

/close

Closing this since Daniel has stepped away from Kube and there isn't anyone to drive this currently. We can always reopen if someone steps up.

@k8s-ci-robot
Copy link
Contributor

@enj: Closed this PR.

In response to this:

/close

Closing this since Daniel has stepped away from Kube and there isn't anyone to drive this currently. We can always reopen if someone steps up.

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.

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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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