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

fix(charts): Remove unnecessary sensitive permissions for DaemonSet agent and Pod init #3522

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

kaaass
Copy link
Contributor

@kaaass kaaass commented May 25, 2024

What type of PR is this?

  • release/bug

What this PR does / why we need it:

This PR removes unnecessary RBAC permissions for the DaemonSet agent and Pod init to avoid potential security risks. Technically, this PR does:

  1. Create a separate ClusterRole for each workload
  2. Remove some unnecessary permissions applied by the DaemonSet agent and Pod init

This PR minimizes the deletion of permissions to avoid affecting the normal function of the APP. However, there should still be some unnecessary RBAC permissions (such as for the Deployment controller).

Also, this PR DOES NOT include changing the kubebuilder annotation in: pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/rbac.go

Which issue(s) this PR fixes:

Fixes #3420
Fixes #3361

Special notes for your reviewer:

The removed permission from the permission rules are as follows:

I am more aggressive in deleting the permissions of DaemonSet agent, mainly because DaemonSet will be deployed to any worker node in the cluster, so attackers have more opportunities to obtain the ServiceAccount token of DaemonSet agent.

- apiGroups:
- spiderpool.spidernet.io
resources:
- spiderclaimparameters
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the work! @kaaass. Is it even better if we put resources with the same verbs into a list of the same resources? example:

- apiGroups:
  - spiderpool.spidernet.io
  resources:
  - spiderclaimparameters
  - spidercoordinators
  - spiderendpoints
  - spiderippools
  - spidermultusconfigs
  - spidersubnets
 verbs:
  - ...
  - ...
- apiGroups:
   - spiderpool.spidernet.io
   resources:
   - spidercoordinators/status
   - spiderippools/status
   - ...
   - ...

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! I've updated them.

- patch
- update
- watch
- apiGroups:
Copy link
Contributor Author

@kaaass kaaass May 28, 2024

Choose a reason for hiding this comment

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

Would it be possible to remove this rule (get/list/watch verb of *)? This rule include get/list verb of secrets at cluster-wide, which may cause some security risks. @cyclinder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also same question exists in Spiderpool controller.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, You can boldly delete them. CI will tell us if we cannot get/list/watch some resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK! Let me give it a try

@ty-dc
Copy link
Collaborator

ty-dc commented May 29, 2024

After the fix, some issues occurred, it seems that there is insufficient permissions.

  Warning  FailedCreatePodSandBox  118s                kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "91390322e1fcc5b6f8011c1f9292f3eaaba9db0b6704d79a8315413f16f05b04": plugin type="multus" name="multus-cni-network" failed (add): [default/test-pod-57c88b845c-prtfb/35ed07d0-ee08-4a64-963b-75dfeff0eb2c:macvlan-vlan0]: error adding container to network "macvlan-vlan0": failed to GetCoordinatorConfig: [GET /coordinator/config][500] getCoordinatorConfigFailure  spidercoordinator: default no ready

@kaaass
Copy link
Contributor Author

kaaass commented May 29, 2024

Thanks @ty-dc. Seems like the removal in my latest commit is too aggressive. I'll revert them.

@cyclinder
Copy link
Collaborator

Hi @kaaass, codes look good now, Could you squash the comments? now we have 6 comments on the PR. it would be nice if we can squash to one comment.

@kaaass
Copy link
Contributor Author

kaaass commented May 31, 2024

@cyclinder Sure! I've pushed them

Copy link
Collaborator

@cyclinder cyclinder left a comment

Choose a reason for hiding this comment

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

Thanks for the work! @kaaass

@cyclinder cyclinder added release/none no release note and removed release/feature-changed release note for changed feature labels May 31, 2024
@weizhoublue
Copy link
Collaborator

actually, I expect upgrading CI to test this PR @ty-dc

@ty-dc
Copy link
Collaborator

ty-dc commented Jun 6, 2024

actually, I expect upgrading CI to test this PR @ty-dc

ok

@weizhoublue weizhoublue added release/feature-new release note for new feature and removed release/none no release note labels Jun 17, 2024
@weizhoublue weizhoublue merged commit f4d26b6 into spidernet-io:main Jun 17, 2024
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/feature-new release note for new feature
Projects
None yet
4 participants