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 RBAC files for metrics authentication and authorization #2116

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kashifest
Copy link
Member

@kashifest kashifest commented Dec 11, 2024

#2102 has introduced controller-runtime's WithAuthenticationAndAuthorization filter which also requires extra RBAC roles and role bindings for metrics authentication and authorization. This PR adds those.

@metal3-io-bot metal3-io-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 11, 2024
@kashifest
Copy link
Member Author

kashifest commented Dec 11, 2024

@camilamacedo86 I could identify these RBACs. Please check if this is sufficient. Thanks for your feedback so far.

@@ -9,3 +9,12 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml

Choose a reason for hiding this comment

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

It seems accurate for me, but to ensure that the metrics is working as should be you might want use the same tests which are now scaffolded by kubebuilder, see: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4/test/e2e/e2e_test.go#L166-L235

Copy link
Member Author

Choose a reason for hiding this comment

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

it seems adapting the e2e would not only require the e2e tests but also the prometheus operator and such. Planning to do it in a followup. @lentzi90 wdyt?

Choose a reason for hiding this comment

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

You do not need prometheus operator.
You can remove this part and do not apply the ServiceMonitor

You can check in kubernetes-sigs/kubebuilder#3907 Steps to Verify Metrics with curl that is what you need. Just get the token and the steps that does

kubectl create clusterrolebinding <project-name>-metrics-binding \
  --clusterrole=<project-name>-metrics-reader \
  --serviceaccount=<project-name>-system:<project-name>-controller-manager
export TOKEN=$(kubectl create token operator-controller-controller-manager -n olmv1-system)
echo $TOKEN
kubectl run curl-metrics --rm -it --restart=Never \
  --image=curlimages/curl:7.87.0 -n <project>-system -- /bin/sh
Call the metrics enpoint using the TOKEN and check the HTTP OK 
curl -v -k -H "Authorization: Bearer $TOKEN" https://<my-project-name>-controller-manager-metrics-service.<my-project-name>-system.svc.cluster.local:8443/metrics 

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good! @kashifest can you try it?

Choose a reason for hiding this comment

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

Copy link
Member Author

@kashifest kashifest Dec 13, 2024

Choose a reason for hiding this comment

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

Honestly I have no clue now why the test is failing, heres a screenshot of my local test where everything is happy
Screenshot 2024-12-13 at 14 56 34

Copy link
Member

Choose a reason for hiding this comment

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

It is missing the command. You can test it locally with the fixture test bu doing make test-e2e. It is fast and simple, no extra config needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

command was there and it was failing even then, I removed it for testing

Copy link
Member Author

Choose a reason for hiding this comment

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

make test-e2e doesnt work as is, you need to build images also manually before it?

Copy link
Member

Choose a reason for hiding this comment

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

Right, sorry. You need to do

IMG=quay.io/metal3-io/baremetal-operator:e2e make docker
make test-e2e

@metal3-io-bot metal3-io-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 12, 2024
@kashifest kashifest force-pushed the kashif/add-missing-rbac-metrics branch 6 times, most recently from 5e84514 to c0c2f01 Compare December 12, 2024 12:36
metal3-io#2102 has introduced controller-runtime's WithAuthenticationAndAuthorization filter which also requires extra RBAC roles and role bindings for metrics authentication and authorization. This PR adds those.

Signed-off-by: Kashif Khan <[email protected]>
@kashifest kashifest force-pushed the kashif/add-missing-rbac-metrics branch 5 times, most recently from e7b25b8 to c1e6906 Compare December 13, 2024 09:37
camilamacedo86

This comment was marked as outdated.

@metal3-io-bot
Copy link
Contributor

@camilamacedo86: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

/lgtm

That is great 🥇
Thank you.

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-sigs/prow repository.

@metal3-io-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: camilamacedo86
Once this PR has been reviewed and has the lgtm label, please ask for approval from kashifest. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@kashifest kashifest force-pushed the kashif/add-missing-rbac-metrics branch from c1e6906 to c693110 Compare December 13, 2024 11:41
@kashifest kashifest force-pushed the kashif/add-missing-rbac-metrics branch 3 times, most recently from b1e40a7 to 703156f Compare December 13, 2024 15:40
Signed-off-by: Kashif Khan <[email protected]>
@kashifest kashifest force-pushed the kashif/add-missing-rbac-metrics branch from 703156f to 763acbb Compare December 13, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants