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 the rbac permissions for karmada-agent #5629

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

B1F030
Copy link
Contributor

@B1F030 B1F030 commented Sep 30, 2024

What type of PR is this?
/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:
Part of #5182

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 30, 2024
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 30, 2024
@B1F030
Copy link
Contributor Author

B1F030 commented Sep 30, 2024

/cc @zhzhuang-zju

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 41.85%. Comparing base (90df54a) to head (976e62f).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5629      +/-   ##
==========================================
- Coverage   41.85%   41.85%   -0.01%     
==========================================
  Files         655      655              
  Lines       55756    55756              
==========================================
- Hits        23338    23335       -3     
- Misses      30907    30910       +3     
  Partials     1511     1511              
Flag Coverage Δ
unittests 41.85% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@B1F030
Copy link
Contributor Author

B1F030 commented Sep 30, 2024

/hold

@karmada-bot karmada-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 30, 2024
@karmada-bot karmada-bot added the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Oct 13, 2024
@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from 864eb15 to 2a4567c Compare October 28, 2024 03:32
@karmada-bot karmada-bot removed the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Oct 28, 2024
@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from 2a4567c to 5abef7a Compare October 28, 2024 11:45
@karmada-bot karmada-bot added the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Oct 29, 2024
@B1F030
Copy link
Contributor Author

B1F030 commented Oct 29, 2024

/unhold

@karmada-bot karmada-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 29, 2024
@B1F030
Copy link
Contributor Author

B1F030 commented Oct 29, 2024

/cc @zhzhuang-zju

@RainbowMango
Copy link
Member

Hi @B1F030 Please quash commits and get this PR ready.

@zhzhuang-zju
Copy link
Contributor

@B1F030 The review is ongoing, and I will check whether your RBAC configuration ensures the normal operation of the agent and whether there are any redundant permissions.

@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from e6fbd93 to b3c3ad5 Compare October 29, 2024 06:56
@karmada-bot karmada-bot removed the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Oct 29, 2024
Comment on lines 193 to 289
# apiVersion: rbac.authorization.k8s.io/v1
# kind: Role
# metadata:
# name: system:karmada:agent-secret
# namespace: "{{cluster_namespace}}" # default to karmada-cluster
# rules:
# - apiGroups:
# - ""
Copy link
Contributor

Choose a reason for hiding this comment

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

@B1F030 Can you explain what these roles are and why they are commented out?

Copy link
Contributor Author

@B1F030 B1F030 Oct 29, 2024

Choose a reason for hiding this comment

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

To minimize the rbac permissions for karmada-agent, we can limit some sensitive permissions to minimum.
Sensitive permissions including:

  • clusters: [create, get]
  • clusters/status: [update]
  • secrets: [get, list, watch, create, patch]
  • works: [create, get, list, watch, update, delete]
  • works/status: [patch, delete]

Because clusters and clusters/status are not namespace-scoped, we can limit the specific resourceNames as {{clustername}}.
And because secrets and works, works/status are namespace-scoped, we can collect them into specific roles, as:
system:karmada:agent-secret(in namespace {{cluster_namespace}}, default to karmada-cluster) for secrets,
system:karmada:agent-work(in namespace karmada-es-{{clustername}}) for works, works/status.

But for now we cannot use them without codechange, for example, It will come to Error when setting up basic environment:

Error from server (NotFound):
error when creating "artifacts/deploy/bootstrap-token-configuration.yaml":
namespaces "karmada-es-{{clustername}}" not found

So we plan to comment out these roles for now, and after when we can create ns during the register.go, we can cancel the comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

The un-commented parts represent the minimal RBAC permissions that can be achieved without modifying the code and the existing karmadactl register workflow.
The commented parts represent the desired minimal RBAC permissions

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move the commented part into the documentation to demonstrate the agent's minimal permission set, and then later modify the code to align the agent's RBAC permissions with the desired minimal RBAC?

@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from b3c3ad5 to c1bef1b Compare October 29, 2024 08:39
@zhzhuang-zju
Copy link
Contributor

cc @RainbowMango

@RainbowMango
Copy link
Member

?

@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from c1bef1b to 05e04c3 Compare October 29, 2024 08:50
@B1F030 B1F030 force-pushed the karmada-agent-rbac branch 2 times, most recently from 8df1a25 to 57134ad Compare October 29, 2024 11:02
@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from 57134ad to 1720ca9 Compare October 29, 2024 11:45
@zhzhuang-zju
Copy link
Contributor

thanks~
/lgtm
cc @RainbowMango @XiShanYongYe-Chang

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 29, 2024
@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from 1720ca9 to cb11c22 Compare October 29, 2024 12:55
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Oct 29, 2024
@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from cb11c22 to 3ed107f Compare October 29, 2024 13:49
@B1F030 B1F030 force-pushed the karmada-agent-rbac branch from 3ed107f to 976e62f Compare October 29, 2024 13:50
@XiShanYongYe-Chang
Copy link
Member

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 30, 2024
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/approve

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 30, 2024
@karmada-bot karmada-bot merged commit 787f57c into karmada-io:master Oct 30, 2024
18 checks passed
@B1F030 B1F030 deleted the karmada-agent-rbac branch October 30, 2024 03:44
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. 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.

6 participants