Skip to content

feat: add KesselContentGuard to authorize content via Kessel (PULP-2707) - #1714

Draft
CryptoRodeo wants to merge 1 commit into
pulp:mainfrom
CryptoRodeo:feat/pulp-2707
Draft

CryptoRodeo wants to merge 1 commit into
pulp:mainfrom
CryptoRodeo:feat/pulp-2707

Conversation

@CryptoRodeo

@CryptoRodeo CryptoRodeo commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Why

Lightwell content needs permission-based access control. The Kessel CIAM
credentials were wired into stage in #1681, but nothing used them yet.

What

Adds a KesselContentGuard. A content request gets through only if Kessel
says the user has the guard's permission (e.g. content_sources_repository_view)
on their org's default workspace.

It follows the same flow content-sources-backend uses:

  1. Get an OAuth2 token (client credentials)
  2. Look up the org's default workspace (RBAC v2)
  3. Ask Kessel: Check (Inventory v1beta2), subject redhat/<user_id>

The official kessel-sdk does all three steps. Service accounts use their own user_id.

Fails closed:

  • No identity header: 401
  • Anything else (bad identity, denied, Kessel/RBAC/SSO down or slow): 403
  • Every external call has a tian't stall the content worker.

Before enabling in stage

  • Set KESSEL_RBAC_URL in app-interface. This PR adds the setting; it's empty by default, so nothing changes until it's set.
  • Confirm the stage KESSEL_URL is a gRPC host:port with no scheme. With credentials set, the SDK always uses TLS, so a plaintext endpoint means every guarded request gets a 403.

Testing

  • New unit tests for the allowing (user, service
    account, bad headers), fail-closed behavior, workspace caching, and the token timeout.
  • Checked in the dev containera
    /contentguards/service/kessel/, a request with no identity gets a 401,
    and one with Kessel unconfig
  • Not yet checked against real stage Kessel. That needs the stage credentials.
  • `test_authentication_error_c dev container with
    or without this change (the container's pulpcore is missing a patch).

Follow-ups (not in this PR)

  • Log a warning when the Kessel credentials are missing (right now it quietly connects
    without TLS)
  • Quieter logging while Kessel is down (currently a full traceback per denied request)
  • Cache decisions (only the wo
  • Pin the kessel-sdk version

Summary by Sourcery

Protect content access with a configurable KesselContentGuard that enforces organization-scoped permissions for authenticated principals.

New Features:

  • Add a Kessel-backed content guard that authorizes users and service accounts based on permissions on their organization’s default workspace.

Enhancements:

  • Fail closed with appropriate authentication or authorization errors when identity data is invalid, access is denied, or Kessel dependencies are unavailable.
  • Add configurable, bounded-time Kessel authentication, workspace lookup, and permission checks with per-organization workspace caching.

Build:

  • Add the Kessel SDK dependency and expose the Kessel RBAC endpoint through deployment configuration.

Deployment:

  • Add the Kessel RBAC URL setting to the clowdapp configuration, defaulting to empty until enabled per environment.

Tests:

  • Add unit coverage for Kessel permission decisions, identity parsing, caching, timeout behavior, and fail-closed access control.

Lightwell content needs permission-based access control, and the Kessel
CIAM credentials were already wired into stage (pulp#1681) but nothing used
them. This adds a KesselContentGuard that permits a content request only
when Kessel answers ALLOWED_TRUE for the guard's permission (for example
content_sources_repository_view). The check runs against the requesting
org's default workspace, with redhat/<user_id> as the subject. That is the
same flow content-sources-backend uses: look up the default workspace via
RBAC v2, then call Inventory v1beta2 Check.

The official kessel-sdk does the OAuth2 client-credentials token, the
workspace lookup and the gRPC call. The guard fails closed: a missing
identity is a 401, and anything else (a bad identity, a deny, or Kessel,
RBAC or SSO being unreachable) is a 403. Every external call has a
timeout, so a hung dependency can't stall the content worker. One new
setting, PULP_KESSEL_RBAC_URL, is wired into the clowdapp and defaults to
empty, so stage stays inert until app-interface sets it. KESSEL_URL must
be a gRPC host:port with no scheme; when the client credentials are set,
the SDK always uses TLS, so a plaintext endpoint gets a 403 on every
request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Bryan ramos <bramos@redhat.com>
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Schema and migrations

Add the KesselContentGuard database model and its permission field so guards can persist the Kessel permission they enforce.

  • pulp_service/pulp_service/app/migrations/0027_kesselcontentguard.py L1-28

API

Expose KesselContentGuard as a serialized, role-managed content-guard endpoint with its permission field.

  • pulp_service/pulp_service/app/serializers.py L39, L73-89
  • pulp_service/pulp_service/app/viewsets.py L69-75, L81, L268-338

Implementation

Parse the request identity and implement fail-closed authorization through the Kessel permission check.

  • pulp_service/pulp_service/app/models.py L18, L140-189

Build the Kessel client, resolve and cache an org's default workspace, and enforce timeouts for token, RBAC, and Inventory calls.

  • pulp_service/pulp_service/app/kessel.py L1-80

Configuration

Wire the Kessel RBAC URL into deployment parameters and application settings for environment-specific configuration.

  • deploy/clowdapp.yaml L442-443, L650-651, L1961-1963
  • pulp_service/pulp_service/app/settings.py L20-25
  • pulp_service/requirements.txt L10

Documentation

Record the new KesselContentGuard capability in the changelog.

  • CHANGES/kessel-content-guard.feature L1

Tests

Test Kessel permission decisions, workspace lookup caching and failure handling, and guard identity parsing and denial behavior.

  • pulp_service/pulp_service/tests/unit/test_kessel_client.py L1-107
  • pulp_service/pulp_service/tests/unit/test_kessel_content_guard.py L1-85

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

Sign up for free to 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.

1 participant