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

rbac: narrow permissions #613

Merged
merged 3 commits into from
Mar 2, 2023
Merged

Conversation

t0rr3sp3dr0
Copy link
Contributor

Create new Roles and ServiceAccounts for the Interceptor and for the Scaler with granular permissions given to them. The Operator Role was changed to narrow its scope and remove write access to resources not owned by it.

Checklist

Fixes #612

@t0rr3sp3dr0 t0rr3sp3dr0 requested a review from a team as a code owner February 24, 2023 02:52
@t0rr3sp3dr0
Copy link
Contributor Author

@JorTurFer @tomkerkhove, could you take a look at this PR and allow the workflows to run?

Changelog.md Outdated Show resolved Hide resolved
@@ -90,6 +90,7 @@ func main() {
lggr,
cl,
servingCfg.ConfigMapCacheRsyncPeriod,
servingCfg.CurrentNamespace,
Copy link
Member

Choose a reason for hiding this comment

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

Can you elaborate on this please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! When I changed the permissions so the add-on components only had access to ConfigMaps on the keda namespace, it started to fail with the following error:

W0224 02:33:59.494889       1 reflector.go:424] pkg/mod/k8s.io/client-go@v0.26.1/tools/cache/reflector.go:169: failed to list *v1.ConfigMap: configmaps is forbidden: User "system:serviceaccount:keda:keda-http-add-on-interceptor" cannot list resource "configmaps" in API group "" at the cluster scope

After investigating, I found that the ConfigMap Informer was watching all ConfigMaps of the cluster, not just the ones on the keda namespace. Then I changed it to only look at ConfigMaps from the keda namespace (https://github.com/kedacore/http-add-on/pull/613/files#diff-a2bfc341efdd78af356e3724892bfd7ef8c5cfb3cc9cf14b209df74db39249b8L129-L132). But a user may want to install KEDA on another namespace and this is parameterised, so I need to tell the informer which namespace the add-on is installed for it to watch at ConfigMaps there. That's why I had to add this extra parameter.

Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

Nice improvement!
More fine permission management is always worth :)
How did you generate the RBAC files? We have this command in make file for generating current RBAC file based on the RBAC annotations. I like the idea of a better permission segmentation, but we should maintain a way to automatically generate manifests (including RBAC files).
I guess that we can adapt it for the new scenario

@t0rr3sp3dr0 t0rr3sp3dr0 force-pushed the pedrotorres/issue-612 branch 2 times, most recently from 569dbc0 to 6d4c3d8 Compare February 25, 2023 03:53
@t0rr3sp3dr0
Copy link
Contributor Author

@JorTurFer, I changed the // +kubebuilder: comments so the RBAC manifests are automatically generated by controller-gen for the operator when we run make manifests. The YAMLs for the interceptor and the scaler are completely unmanaged in the current implementation, so I created the new manifests manually.

@JorTurFer
Copy link
Member

JorTurFer commented Feb 25, 2023

I created the new manifests manually

I think that we should generate them automatically. It's more complicated but it's doable and we can rely on kubebuilder for generating the RBAC manifests, there are several good reasons for that like in case of RBAC API changes, we don't need to deal with them or the automatically update of every required RBAC just adding kubebuilder comments. I can help you with that if you want, I did it in KEDA (but finally it wasn't necessary so I removed it).

Let me know if you want to do that part or you prefer that I do it

Signed-off-by: Pedro Tôrres <pedrotorres@microsoft.com>
Signed-off-by: Pedro Tôrres <pedrotorres@microsoft.com>
@t0rr3sp3dr0
Copy link
Contributor Author

@JorTurFer, done! I've configured manifest generation for interceptor and scaler with kubebuilder.

Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

LGTM from code pov, but I' m not totally sure about having 3 different service accounts, I see the improvement of role segmentation, but I'm not sure if having 1 sa per component is overkill.
Apart from that, should we update the helm chart now or maybe as the changes include the RBAC files we can do it for the release?
WDYT about these questions @tomkerkhove ?

@t0rr3sp3dr0
Copy link
Contributor Author

I created three different ServiceAccounts to reduce the blast radius in case some component gets compromised. The interceptor receives arbitrary requests, parses their them, and then forwards to the appropriate services, so I don't like the idea of giving this component any kind of write access.

Signed-off-by: Pedro Tôrres <t0rr3sp3dr0@gmail.com>
@JorTurFer
Copy link
Member

I created three different ServiceAccounts to reduce the blast radius in case some component gets compromised. The interceptor receives arbitrary requests, parses their them, and then forwards to the appropriate services, so I don't like the idea of giving this component any kind of write access.

This makes sense totally. Thanks for the clarification ❤️ !
The only question left is about when we should update the helm chart @tomkerkhove

@tomkerkhove
Copy link
Member

We can update it now already, but ship once we ship newer version

@JorTurFer
Copy link
Member

JorTurFer commented Feb 28, 2023

@t0rr3sp3dr0 , do you know how to do it?
You need to open a PR reflecting this RBAC changes in this repo https://github.com/kedacore/charts/tree/main/http-add-on

I can help if you have any trouble

@t0rr3sp3dr0
Copy link
Contributor Author

@JorTurFer, here is the PR with the changes to the Helm Chart: kedacore/charts#398

@JorTurFer JorTurFer merged commit 653ddb6 into kedacore:main Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permissions given to the add-on components are too broad
3 participants