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

feat!: limit controller secret access only to project namespaces #2761

Merged
merged 5 commits into from
Oct 17, 2024

Conversation

krancour
Copy link
Member

@krancour krancour commented Oct 16, 2024

Fixes: #2448

Supersedes #2522

Don't be scurred... most of this is tests.

This is intended to mitigate sharded controllers (distributed to clusters other than the control plane's) having cluster-wide read on Secrets in the control plane's cluster. This will dynamically expand and contract the permissions of the Kargo controller(s) in a similar fashion to what's been done for the API server since #1486:

  • On Project create, add a RoleBinding per Kargo controller SA to grant r/o Secret access within the Project's namespace.

  • Nothing special to do on Project delete. Project delete takes the namespace with it, including any such RoleBindings.

  • On create/update of SA in Kargo's own namespace, ensure appropriate RoleBinding exists for every Project if the SA is labeled as a controller.

  • On delete of SA in Kargo's own namespace, ensure removal of appropriate RoleBinding for every Project.

  • On update of SA in Kargo's own namespace, ensure removal of appropriate RoleBinding for every Project if the SA is no-longer labeled as a controller.

Finalizers are added/removed as appropriate used to ensure necessary cleanup always occurs and that cleanup doesn't occur unnecessarily.

These changes are verified to work e2e.

Breaking change: If you have designated some namespaces as "global credential stores" using controller.globalCredentials.namespaces at install-time, you must now manually ensure controller(s) have access to Secrets in those namespaces. The chart cannot do this because the namespaces may not exist at the time Kargo is installed. This also cannot be done dynamically with the management controller because if values are removed from the list and the management controller is restarted, it will not know what namespaces have been removed from the list and require clean up.

@fykaa laid most of the groundwork for this. Thank you!

@gdsoumya requesting your 👀 on this, if you don't mind.

Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
Co-authored-by: Faeka Ansari <faeka6@gmail.com>
Copy link

netlify bot commented Oct 16, 2024

Deploy Preview for docs-kargo-io ready!

Name Link
🔨 Latest commit 7617617
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-io/deploys/6711364dc0aed8000837611b
😎 Deploy Preview https://deploy-preview-2761--docs-kargo-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

charts/kargo/README.md Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 84.23077% with 41 lines in your changes missing coverage. Please review.

Project coverage is 49.18%. Comparing base (43031a5) to head (7617617).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/controlplane/management_controller.go 0.00% 16 Missing ⚠️
...ller/management/serviceaccounts/serviceaccounts.go 90.50% 13 Missing and 2 partials ⚠️
cmd/controlplane/controller.go 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2761      +/-   ##
==========================================
- Coverage   49.54%   49.18%   -0.37%     
==========================================
  Files         271      272       +1     
  Lines       19685    24152    +4467     
==========================================
+ Hits         9753    11879    +2126     
- Misses       9301    11641    +2340     
- Partials      631      632       +1     

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

@hiddeco
Copy link
Contributor

hiddeco commented Oct 17, 2024

This is on my list to review tomorrow before you start your day.

Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
charts/kargo/README.md Outdated Show resolved Hide resolved
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
@krancour krancour force-pushed the limit-controller-access branch from 42561e7 to 7617617 Compare October 17, 2024 16:07
@krancour krancour added this pull request to the merge queue Oct 17, 2024
return errors.New("something went wrong")
},
},
assertions: func(t *testing.T, _ kargoapi.ProjectStatus, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial: we could add an assertion for projectStatus as well.

Comment on lines +53 to +57
predicate.Funcs{
DeleteFunc: func(event.DeleteEvent) bool {
// We're only interested in soft deletes
return false
},
Copy link
Contributor

Choose a reason for hiding this comment

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

oh, so are we are not filtering for update events 🤔
Were there any conditions that made the update predicate unnecessary or insufficient?

Copy link
Contributor

Choose a reason for hiding this comment

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

these do not require changes: I am just curious

Merged via the queue into akuity:main with commit 8ff3121 Oct 17, 2024
16 of 17 checks passed
@krancour krancour deleted the limit-controller-access branch October 17, 2024 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: limit controller access to control plane secrets
4 participants