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

Generating permissions into permissions instead of clusterPermissions #6100

Closed
stanislavulrych opened this issue Oct 20, 2022 · 10 comments
Closed
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. triage/support Indicates an issue that is a support question.
Milestone

Comments

@stanislavulrych
Copy link

Type of question

Open question

Question

The permissions for the go based operator are generated from kubebuilder annotations in controllers code. By default, the permissions are generated into (csv).spec.install.spec.clusterPermissions

What did you expect to see?

I would like to have the permissions listed in (csv).spec.install.spec.permissions

Is there a way how to modify the kubebuilder annotations to do so?

Environment

Operator type:

Kubernetes cluster type:

OpenShift

$ operator-sdk version

operator-sdk version: "v1.23.0", commit: "1eaeb5adb56be05fe8cc6dd70517e441696846a4", kubernetes version: "1.24.2", go version: "go1.18.5", GOOS: "linux", GOARCH: "amd64"

$ go version (if language is Go)

go version go1.18.7 linux/amd64

$ kubectl version

Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.0", GitCommit:"04ad1b56880418de7bd6feb9ff37a8518fbc1a0e", GitTreeState:"clean", BuildDate:"2022-05-12T09:52:02Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"linux/amd64"}

@theishshah theishshah added the triage/support Indicates an issue that is a support question. label Oct 24, 2022
@OchiengEd
Copy link
Contributor

OchiengEd commented Oct 24, 2022

@theishshah I can look into this

@OchiengEd
Copy link
Contributor

hi @stanislavulrych You can achieve what you want by setting an arbitrary namespace in the kubebuilder rbac annotations. For example, if you want an operator to be able to create statefulsets and pods at the namespace level, it would look like shown below:

//+kubebuilder:rbac:groups=apps,resources=statefulset,namespace=placeholder,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=core,resources=pods,namespace=placeholder,verbs=get;list;watch;create;update;patch;delete

Notice I have namespace set to namespace=placeholder.

While doing this will allow the cluster roles to be made to be roles, they would not be added to .spec.install.spec.permissions in the Cluster Service Version like you would expect it to. However, the role would be added as a separate file in the bundle/manifests directory.

Full path should take the pattern, bundle/manifests/[operator-name]-manager-role.rbac.authorization.k8s.io_v1_role.yaml

@stanislavulrych
Copy link
Author

Hi @OchiengEd, thank you for the answer.

I have tried that and it really generates bundle/manifests/[operator-name]-manager-role.rbac.authorization.k8s.io_v1_role.yaml.

I just do not understand, why these permissions are not added to .spec.install.spec.permissions in the Cluster Service Version. Is there any special reason for it not being added to it?

@jmrodri jmrodri self-assigned this Oct 31, 2022
@jmrodri jmrodri added this to the v1.26.0 milestone Oct 31, 2022
@jmrodri jmrodri added the kind/bug Categorizes issue or PR as related to a bug. label Oct 31, 2022
@OchiengEd
Copy link
Contributor

OchiengEd commented Nov 1, 2022

@stanislavulrych Not sure of the reason for this behavior. At this time, the issue has been marked as a bug and I believe Jesus will be looking into why the decision was made to have it as a separate file before any action can be taken.

@jberkhahn jberkhahn modified the milestones: v1.26.0, v1.27.0 Nov 23, 2022
@tlwu2013
Copy link
Contributor

hey @stanislavulrych, are you completely blocked by this issue? If so, will it be possible for you to manually edit the .spec.install.spec.permissions in ClusterServiceVersion as a workaround for unblocking?

@stanislavulrych
Copy link
Author

@tlwu2013 so far, I am building the operators without any manual steps, which is the reason why I opened this issue - it is possible to edit the CSV manually, however, you might understand that it somehow complicates the automated pipelines for the build.

@everettraven
Copy link
Contributor

/unassign jmrodri

@varshaprasad96 varshaprasad96 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Jan 4, 2023
@varshaprasad96 varshaprasad96 removed this from the v1.27.0 milestone Jan 4, 2023
@varshaprasad96 varshaprasad96 added the lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. label Jan 9, 2023
@varshaprasad96 varshaprasad96 added this to the Backlog milestone Jan 9, 2023
@sxd
Copy link

sxd commented Sep 27, 2023

Hi Everyone!

There's any idea on continue the work on this issue?
I'm currently facing the same issue and I was having an idea that it's adding an option like --cluster-permission-to-permission (clearly not that long option) that switch the permission to the permission section.

The other idea is to add a --exclude-cluster-permission which basically exclude a set of permission resources of being moved into the permission section and being kept in the clusterPermission section, why? because some permissions like getting the nodes or namespace shouldn't be namespaced.

Any other idea on this?

@joelanford
Copy link
Member

Operator SDK should already handle this automatically if you have a RoleBinding in your manifests that binds the operator's service account to the Role.

@stanislavulrych
Copy link
Author

Hi everyone and @joelanford , in the later versions of operator-sdk, the documentation was greatly improved (thanks everyone involved for that!). By properly following the instructions in

https://sdk.operatorframework.io/docs/building-operators/golang/operator-scope/#changing-the-permissions-to-namespaced

and

https://sdk.operatorframework.io/docs/building-operators/golang/crds-scope/

I solved the problem of generating permissions instead of clusterpermissions. There is now really nothing to be added to those steps and the description is very informative. As described in the above, there is one manual step needed:

Use RoleBindings instead of ClusterRoleBindings. The config/rbac/role_binding.yaml needs to be manually updated

However, since role_binding.yaml is not regenerated during the operator build, it is not a problem even for automated build.

Thus,I am closing this.

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/bug Categorizes issue or PR as related to a bug. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

10 participants