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

Minimize RBAC roles for controllers #6554

Open
10 tasks
killianmuldoon opened this issue May 26, 2022 · 14 comments
Open
10 tasks

Minimize RBAC roles for controllers #6554

killianmuldoon opened this issue May 26, 2022 · 14 comments
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@killianmuldoon
Copy link
Contributor

killianmuldoon commented May 26, 2022

Following on from ##6510 (comment)

In Cluster API today we create RBAC manifests which are generated using kubebuilder tools. e.g.

// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io;bootstrap.cluster.x-k8s.io;controlplane.cluster.x-k8s.io,resources=*,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusterclasses,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch

Many of our controllers seem to generate overly broad RBAC for themselves. e.g. many have the create verb when it is not used.
Removing these roles should have no impact on functitonality, minimize the capabilities of our controllers from a security perspective, and make our RBAC manifests more descriptive about what our controllers are actually doing.

We should audit the following controllers to minimize their RBAC roles:

  • MachineHealthCheck
  • Machinepool
  • KubeadmConfig
  • ClusterResourceSet
  • Cluster
  • Machine
  • MachineDeployment
  • MachineSet
  • Topology/Cluster
  • ClusterClass
@sbueringer
Copy link
Member

sbueringer commented May 27, 2022

We should be very careful. Not all verbs can be easily inferred from just reading the controller code:

  • we probably have to go transitively through a few levels of util funcs
  • controller-runtime internally creates (per default) informers when we call client.Get(), client.List(), ... (this requires get/list/watch verbs)

@sbueringer
Copy link
Member

sbueringer commented May 27, 2022

One simplification I did in the past is to categorize verbs into groups:

  • read: get list watch
  • create
  • delete
  • change: update patch

Essentially once we need one of them we just add the entire group. This simplifies it a bit. For example, once we use list is it really worth figuring out if we have a get or watch call somewhere? It comes down to pretty much the same result. Similar for update/patch.

If we are overly strict we risk missing a call somewhere, and if that call is only rarely used in edge cases we might not catch that case in e2e tests.

I think we have to balance minimal roles vs the risk of breaking something. Especially given that even with minimal roles per reconciler the whole controller will still have a lot of rights.

@killianmuldoon
Copy link
Contributor Author

That seems like a sensible approach. My impression is that we probably have create in a few places it shouldn't be. I think we have update in a lot of places where it's not used, but we're using patch so it doesn't matter.

I'm also thinking this could be something pushed to the next API rev.

@sbueringer
Copy link
Member

I think it's independent of our API version bump as it just affects the permissions of our controller and not the APIs/CRDs.

@killianmuldoon
Copy link
Contributor Author

I didn't mean to say it's dependent on a rev, more that we could do it as part of a future overall API revision as it's not urgent now IMO

@fabriziopandini
Copy link
Member

We can use also tools like https://github.com/liggitt/audit2rbac to check what is actually used

@sbueringer
Copy link
Member

sbueringer commented May 30, 2022

We can use also tools like https://github.com/liggitt/audit2rbac to check what is actually used

Good idea, but I think we should only use it as additional info not as a reference, otherwise this means we have to hit all edge cases to be safe.

@fabriziopandini fabriziopandini added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Jul 29, 2022
@k8s-triage-robot
Copy link

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

This bot triages issues and 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 issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or 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 Oct 27, 2022
@fabriziopandini
Copy link
Member

/lifecycle frozen
/triage accepted
this is still a nice issue to be addressed

/help

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 2, 2022
@k8s-ci-robot
Copy link
Contributor

@fabriziopandini:
This request has been marked as needing help from a contributor.

Guidelines

Please ensure that the issue body includes answers to the following questions:

  • Why are we solving this issue?
  • To address this issue, are there any code changes? If there are code changes, what needs to be done in the code and what places can the assignee treat as reference points?
  • Does this issue have zero to low barrier of entry?
  • How can the assignee reach out to you for help?

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/lifecycle frozen
/triage accepted
this is still a nice issue to be addressed

/help

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 triage/accepted Indicates an issue or PR is ready to be actively worked on. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Nov 2, 2022
@k8s-triage-robot
Copy link

This issue has not been updated in over 1 year, and should be re-triaged.

You can:

  • Confirm that this issue is still relevant with /triage accepted (org members only)
  • Close this issue with /close

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. and removed triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Jan 19, 2024
@fabriziopandini
Copy link
Member

/kind cleanup
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. labels Apr 11, 2024
@fabriziopandini fabriziopandini removed the lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. label Apr 16, 2024
@fabriziopandini
Copy link
Member

It is still worth to audit the code to figure out if there is something suspicious in our permissions
/help
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 24, 2024
@chrischdi
Copy link
Member

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

6 participants