Skip to content

✨ Check known required permissions for install before installing with the helm applier - #1858

Merged
joelanford merged 71 commits into
operator-framework:mainfrom
bentito:rbac-auth-k8s-replacer
Apr 15, 2025
Merged

✨ Check known required permissions for install before installing with the helm applier #1858
joelanford merged 71 commits into
operator-framework:mainfrom
bentito:rbac-auth-k8s-replacer

Conversation

@bentito

@bentitobentito commented Mar 10, 2025

Copy link
Copy Markdown
Contributor

Description

This is a successor PR to #1716 and is primarily the contributions of @trgeiger and @joelanford .

Goal and title, remain the same. Approach is a bit modified:

Pulls in RBAC authorization code from k8s.is/kubernetes, uses that code to check GET and other verb permissions as prelude to and as response from a Helm dry-run

To pull in the RBAC auth code concisely, repeatably and with warnings if the used code changes, we add a maintenance utility that adds the needed replace directives for all related staging modules (e.g., k8s.io/api, k8s.io/apimachinery, etc.) and they are automatically pinned to the corresponding published version.

All this code is initially called at

missingRules, err := h.PreAuthorizer.PreAuthorize(ctx, &ceServiceAccount, strings.NewReader(tmplRel.Manifest))

in internal/operator-controller/applier/helm.go

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@openshift-ciopenshift-ciBot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 10, 2025
@openshift-merge-robotopenshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 2025
@netlify

netlifyBot commented Mar 10, 2025

Copy link
Copy Markdown

Deploy Preview for olmv1 ready!

NameLink
🔨 Latest commit8200b97
🔍 Latest deploy loghttps://app.netlify.com/sites/olmv1/deploys/67fe95140ad6f70008b8b5b9
😎 Deploy Previewhttps://deploy-preview-1858--olmv1.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.

@bentito
bentitoforce-pushed the rbac-auth-k8s-replacer branch from 2991d5d to 65ef8a2CompareMarch 10, 2025 20:03
@openshift-merge-robotopenshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 2025
@bentito
bentito marked this pull request as ready for review March 10, 2025 20:04
@bentito
bentito requested a review from a team as a code ownerMarch 10, 2025 20:04
@openshift-ciopenshift-ciBot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 10, 2025
Comment threadgo.mod Outdated
@codecov

codecovBot commented Mar 11, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 44.06176% with 471 lines in your changes missing coverage. Please review.

Project coverage is 65.98%. Comparing base (2f22dcf) to head (8200b97).
Report is 3 commits behind head on main.

Files with missing linesPatch %Lines
hack/tools/k8smaintainer/main.go0.00%287 Missing ⚠️
internal/operator-controller/authorization/rbac.go68.45%119 Missing and 22 partials ⚠️
internal/operator-controller/applier/helm.go49.36%35 Missing and 5 partials ⚠️
cmd/operator-controller/main.go80.00%2 Missing and 1 partial ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #1858 +/- ##
==========================================
- Coverage 69.53% 65.98% -3.56% 
==========================================
Files 68 70 +2 Lines 5350 6182 +832 ==========================================
+ Hits 3720 4079 +359 - Misses 1398 1843 +445 - Partials 232 260 +28 
FlagCoverage Δ
e2e45.16% <5.58%> (-5.41%)⬇️
unit55.16% <40.97%> (-2.38%)⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

azych

This comment was marked as outdated.

Comment threadinternal/operator-controller/authorization/rbac.go
@openshift-merge-robotopenshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 14, 2025
@trgeiger

trgeiger commented Mar 15, 2025

Copy link
Copy Markdown
Contributor

I added some tests but they still need to be tweaked/finalized. I noticed while writing them up that due to the order of the logic where missing rules are checked before escalation, if bind/escalate are in play but we're missing the explicit permissions that bind/escalate would give us we end up with a result where there's no error but we do have missing rules. @joelanford is that what we would want? I would think if we can bind or escalate that we would not return that we're missing those rules since the SA can grant them.

EDIT: This isn't a concern, I misunderstood the permissions logic here

Comment threadhack/tools/k8sMaintainer.go Outdated
Comment threadinternal/operator-controller/applier/helm.go Outdated
Comment threadinternal/operator-controller/authorization/rbac.go Outdated
Comment threadinternal/operator-controller/authorization/rbac.go Outdated
@bentito
bentitoforce-pushed the rbac-auth-k8s-replacer branch from 7a6a943 to e974006CompareMarch 18, 2025 13:44
@openshift-merge-robotopenshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 18, 2025
@trgeiger
trgeigerforce-pushed the rbac-auth-k8s-replacer branch from e974006 to 8f76fa8CompareMarch 18, 2025 14:29
Comment threadinternal/operator-controller/authorization/rbac_test.go Outdated
Comment threadinternal/operator-controller/authorization/rbac_test.go Outdated
Comment threadinternal/operator-controller/authorization/rbac.go Outdated
Comment threadinternal/operator-controller/authorization/rbac.go Outdated
Comment threadinternal/operator-controller/authorization/rbac.go Outdated
Comment threadinternal/operator-controller/authorization/rbac.go Outdated
Comment threadinternal/operator-controller/authorization/rbac.go Outdated
Comment threadinternal/operator-controller/authorization/rbac.go Outdated
Comment threadinternal/operator-controller/authorization/rbac_test.go Outdated
joelanfordand others added 2 commits April 11, 2025 21:06
…uirement
The clusterextensions/finalizer requirement comes from the desire to
support clusters where OwnerReferencesPermissionEnforcement plugin is
enabled. This plugin requires "update", but not "patch" for the
clusterextensions/finalizers permission.
See: https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#ownerreferencespermissionenforcement
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
Comment thread.golangci.yaml Outdated
Comment threadcodecov.yml Outdated
Comment threadinternal/operator-controller/applier/helm.go
Comment threadinternal/operator-controller/applier/helm_test.go
}
helmApplier := applier.Helm{
ActionClientGetter: mockAcg,
PreAuthorizer: &noOpPreAuthorizer{},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I might be missing it, but I didn't see any unit tests for what happens when PreAuthorize returns missing rules and/or an error.

That feels like a gap that should be covered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have tests for that in rbac_test.go, is that fine?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I added one for when there's an error, there are tests in rbac_test.go for returning missing rules, do we need to have an additional one in the applier tests here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know you've got the applier-level tests implemented now, so just an informational answer to your question:

We have tests for that in rbac_test.go, is that fine?

Those are good, but they don't cover how the Helm Applier handles various return values from PreAuthorize. By adding tests in the helm applier, we're not testing our specific RBAC PreAuthorizer functionality. We are testing how our helm applier handles preauthorization.

We need tests at both levels.

Comment on lines +320 to +323
desiredRel: &release.Release{
Info: &release.Info{Status: release.StatusDeployed},
Manifest: validManifest,
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there something novel about this test that isn't covered in the non-preflight variant of this test. It seems like this test case is about "how does helm applier handle a failed installation?", which is the same in both cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like this test case should be "fails because of a pre-auth failure"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I changed the test to be when there's an error returned by preauth

Comment threadinternal/operator-controller/features/features.go
Comment threadinternal/operator-controller/features/features.go Outdated
Comment threadinternal/operator-controller/applier/helm_test.go
Comment threadinternal/operator-controller/applier/helm_test.go Outdated
Comment threadMakefile
Signed-off-by: Tayler Geiger <tayler@redhat.com>
@joelanford
joelanford added this pull request to the merge queue Apr 15, 2025
Merged via the queue into operator-framework:main with commit 543f099Apr 15, 2025
@bentitobentito mentioned this pull request Apr 18, 2025
4 tasks
Sign up for freeto 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.

9 participants

@bentito@trgeiger@joelanford@perdasilva@azych@camilamacedo86@tmshort@grokspawn@openshift-merge-robot