Skip to content

Conversation

@osmman
Copy link
Collaborator

@osmman osmman commented Jun 3, 2025

Fixes: SECURESIGN-2157

Summary by Sourcery

Centralize and tighten RBAC permissions by replacing scattered controller-specific RBAC code with a generic RBAC action framework, define component-scoped RBAC names and rules, introduce a restricted RBAC action for TUF init jobs, refactor controllers to use the new pattern, and add unit tests for the new RBAC logic.

New Features:

  • Introduce a reusable internal/action/rbac package to centralize RBAC management across controllers
  • Add a dedicated TUF init-job RBAC action that grants only create/update on secrets

Enhancements:

  • Replace per-controller RBAC implementations with generic rbac.NewAction calls and per‐component RBAC names
  • Scope RBAC constants by component (server, UI, redis, backfill, logserver, logsigner, db) and remove redundant imports
  • Refactor Rekor, Trillian, TUF, Fulcio, CTlog, and TSA controllers to instantiate separate RBAC actions with explicit rules
  • Consolidate enablement logic in Rekor UI and backfill into helper functions

Tests:

  • Add comprehensive unit tests for the generic RBAC action covering service account creation, role and rolebinding lifecycle

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 3, 2025

Reviewer's Guide

This PR centralizes RBAC setup by extracting a generic rbacAction, removes redundant inline implementations across controllers, tightens permissions for the TUF init job, splits and renames per-component RBAC resources for Rekor and Trillian, simplifies controller code by removing unused imports and centralizing feature flags, and adds comprehensive tests for the new generic RBAC logic.

Class Diagram: Structure of Removed Inline Per-Controller RBAC Actions

classDiagram
    class Removed_Inline_rbacAction {
        <<Struct, Removed>>
        +BaseAction
        +Name() string
        +CanHandle(ctx context.Context, instance ObjectType) bool
        +Handle(ctx context.Context, instance ObjectType) *action.Result
        # // Implementation for creating ServiceAccount,
        # // Role, and RoleBinding using kubernetes.CreateOrUpdate.
        # // This structure was removed from ctlog, fulcio, tuf,
        # // rekor, and trillian controller action packages.
    }
    Removed_Inline_rbacAction : ObjectType varies (e.g., CTlog, Fulcio)
Loading

File-Level Changes

Change Details Files
Extract and consolidate RBAC logic into a reusable generic action
  • Removed per-controller inline RBAC implementations
  • Introduced internal/action/rbac with NewAction, WithRule, and WithCanHandle
  • Refactored controllers to call rbac.NewAction instead of duplicated code
internal/controller/ctlog/actions/rbac.go
internal/controller/fulcio/actions/rbac.go
internal/controller/tsa/actions/rbac.go
internal/controller/tuf/actions/rbac.go
internal/action/rbac/action.go
Introduce a dedicated RBAC action for the TUF init job with tightened permissions
  • Added NewRBACInitJobAction for TUF
  • Restricted init job role to only ‘create’ and ‘update’ secrets
  • Updated TUF constants and controller registration
internal/controller/tuf/actions/rbac.go
internal/controller/tuf/constants/constants.go
internal/controller/tuf/tuf_controller.go
test/e2e/support/tas/tuf/tuf.go
Split and rename RBAC resources per component in Rekor and Trillian
  • Expanded and renamed RBAC constants for UI, Redis, Backfill, LogServer, LogSigner, DB
  • Updated main Rekor and Trillian controllers to register separate RBAC actions
  • Added per-component NewRBACAction wrappers
internal/controller/rekor/actions/constants.go
internal/controller/rekor/rekor_controller.go
internal/controller/rekor/actions/ui/rbac.go
internal/controller/rekor/actions/redis/rbac.go
internal/controller/rekor/actions/backfillRedis/rbac.go
internal/controller/rekor/actions/server/rbac.go
internal/controller/trillian/actions/constants.go
internal/controller/trillian/trillian_controller.go
internal/controller/trillian/actions/logserver/rbac.go
internal/controller/trillian/actions/logsigner/rbac.go
internal/controller/trillian/actions/db/rbac.go
Simplify controllers by removing unused imports and centralizing feature‐enable checks
  • Deleted redundant imports (context, fmt, utils, etc.)
  • Replaced inline utils.IsEnabled calls with local enabled helper functions
  • Consolidated CanHandle logic for feature flags
internal/controller/rekor/actions/ui/deployment.go
internal/controller/rekor/actions/ui/ingress.go
internal/controller/rekor/actions/ui/initialize.go
internal/controller/rekor/actions/ui/status_url.go
internal/controller/rekor/actions/ui/svc.go
internal/controller/rekor/actions/backfillRedis/backfill_redis_cronjob.go
internal/controller/trillian/actions/db/deployment.go
internal/controller/trillian/actions/logserver/deployment.go
internal/controller/trillian/actions/logsigner/deployment.go
Add end-to-end and unit tests for generic RBAC action
  • Created comprehensive tests covering ServiceAccount, Role, and RoleBinding scenarios
  • Adapted e2e TUF test to reference the new RBACInitJob constant
internal/action/rbac/action_test.go
test/e2e/support/tas/tuf/tuf.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@osmman osmman force-pushed the tturek/cleanup-rbac branch from 650d513 to 34e7d0b Compare June 3, 2025 15:26
@osmman osmman requested a review from bouskaJ June 3, 2025 16:06
@osmman osmman marked this pull request as ready for review June 3, 2025 16:21
@osmman
Copy link
Collaborator Author

osmman commented Jun 3, 2025

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @osmman - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Include default PolicyRules when using generic RBAC action (link)

General comments:

  • Ensure each rbac.NewAction invocation includes the necessary PolicyRule(s) (e.g., configmaps and secrets) so that Roles aren’t created with empty rule sets.
  • The enabled helpers in rekor/actions/ui and rekor/actions/backfillRedis are duplicating the same logic—consider centralizing that into a shared utility.
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 4 other issues
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @osmman - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @osmman - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@osmman osmman force-pushed the tturek/cleanup-rbac branch from 34e7d0b to 458e501 Compare June 3, 2025 16:34
@osmman osmman marked this pull request as draft June 3, 2025 16:45
@osmman osmman force-pushed the tturek/cleanup-rbac branch 3 times, most recently from adeb4b3 to 417ac7f Compare June 4, 2025 11:25
@osmman osmman marked this pull request as ready for review June 4, 2025 11:26
@osmman
Copy link
Collaborator Author

osmman commented Jun 4, 2025

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @osmman - I've reviewed your changes - here's some feedback:

  • Ensure that controllers without any WithRule invocations still correctly delete their Roles and RoleBindings while preserving ServiceAccounts as before.
  • Verify that each custom WithCanHandle callback (UI, backfill, DB, etc.) reproduces the original enabled-flag and status-condition logic exactly.
  • Review the new split RBAC constants to confirm there are no naming collisions and that the generated resource names match existing deployments.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @osmman - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@osmman osmman force-pushed the tturek/cleanup-rbac branch 2 times, most recently from fef8c1e to 2acd40e Compare June 5, 2025 09:35
@osmman osmman requested a review from JasonPowr June 5, 2025 09:41
Fixes: SECURESIGN-2157

Signed-off-by: Tomas Turek <tturek@redhat.com>
@osmman osmman force-pushed the tturek/cleanup-rbac branch from 2acd40e to 98827f1 Compare June 5, 2025 09:43
@osmman osmman merged commit aaa50cd into main Jun 5, 2025
19 checks passed
@osmman osmman deleted the tturek/cleanup-rbac branch June 5, 2025 11:40
@osmman osmman added the bug Something isn't working label Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants