Skip to content

feat: authenticate RBAC calls via Clowder v2 endpoint - #2400

Open
SteveHNH wants to merge 2 commits into
RedHatInsights:masterfrom
SteveHNH:clowder-v2-auth
Open

SteveHNH wants to merge 2 commits into
RedHatInsights:masterfrom
SteveHNH:clowder-v2-auth

Conversation

@SteveHNH

@SteveHNH SteveHNH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2351, which only switched RBAC to the v2 uri.

  • resolve RBAC only from v2 (drop v1 and unused RbacURL/RBAC_URL)
  • add the SSO bearer when the endpoint is authenticated, trust ca_certificate, fail closed on missing credentials, non-https or token errors
  • redact Authorization in trace request dumps
  • local cdappconfig gets a v2 rbac endpoint

Secure Coding Practices Checklist GitHub Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Summary by Sourcery

Secure RBAC integration by using Clowder v2 endpoint metadata and enforcing authenticated HTTPS requests when configured.

New Features:

  • Authenticate RBAC requests through the Clowder v2 endpoint when required, including SSO bearer tokens and configured CA certificates.

Bug Fixes:

  • Fail closed when authenticated RBAC calls lack credentials, use non-HTTPS endpoints, or cannot obtain a token.
  • Redact Authorization headers from traced HTTP request dumps.

Enhancements:

  • Resolve RBAC exclusively from the Clowder v2 dependency configuration and remove legacy RBAC URL settings.

Deployment:

  • Update the local application configuration with the v2 RBAC endpoint.

Tests:

  • Add coverage for RBAC v2 configuration, bearer authentication, CA certificates, and authentication failure cases.

Follow-up to RedHatInsights#2351, which only switched RBAC to the v2 uri.

- resolve RBAC only from v2 (drop v1 and unused RbacURL/RBAC_URL)
- add the SSO bearer when the endpoint is authenticated, trust
  ca_certificate, fail closed on missing credentials, non-https or
  token errors
- redact Authorization in trace request dumps
- local cdappconfig gets a v2 rbac endpoint
@SteveHNH
SteveHNH requested a review from a team as a code owner November 25, 2026 20:00
@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add RBAC authentication and CA certificate fields to the shared core configuration used by the RBAC client.

  • base/utils/config.go L76-77

Implementation

Build RBAC requests from the v2 endpoint metadata, add a bearer token and trusted CA for authenticated endpoints, fail closed on authentication errors, and remove the cached RBAC URL.

  • base/utils/config.go L296-303 (+4 small edits)
  • manager/middlewares/kessel.go L27-36
  • manager/middlewares/rbac.go L10-24, L31-36, L52-118 (+1 small edits)

Redact Authorization headers from HTTP request dumps so bearer tokens are not exposed in trace logs.

  • base/utils/http.go L9, L19-20, L75-76

Configuration

Configure the local Clowder v2 RBAC endpoint and remove the obsolete test environment setting.

  • conf/cdappconfig.json L70 (removed lines), L106-115
  • conf/test.env L18 (removed lines)

Tests

Cover v2 RBAC configuration resolution, authenticated bearer and CA handling, and fail-closed behavior for missing credentials, non-HTTPS endpoints, and token errors.

  • base/utils/config_clowder_v2_test.go L10-39 (+3 small edits)
  • manager/middlewares/rbac_auth_test.go L1-134

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="manager/middlewares/rbac.go" line_range="80" />
<code_context>
+	if err := requireAuthConfig(); err != nil {
+		return "", err
+	}
+	token, err := credentials.GetToken(ctx, auth.GetTokenOptions{HttpClient: &http.Client{Timeout: tokenTimeout}})
+	if err != nil {
+		return "", errors.Wrap(err, "fetching RBAC bearer token")
</code_context>
<issue_to_address>
**HTTP SSO exposes credentials**

When the configured issuer or discovered token endpoint uses HTTP outside a trusted loopback test environment, `bearerHeader` passes the issuer to `credentials.GetToken` without requiring HTTPS for the issuer or discovered token endpoint, so OAuth client credentials travel in plaintext and are exposed to network observers.

Require HTTPS for the configured issuer and discovered token endpoint before sending OAuth credentials.
</issue_to_address>

### Comment 2
<location path="manager/middlewares/rbac.go" line_range="106" />
<code_context>
+		if err != nil {
+			return nil, err
+		}
+		headers["Authorization"] = bearer
+	}
+
</code_context>
<issue_to_address>
**Bearer token follows redirects**

When the RBAC endpoint responds with a redirect to an attacker-controlled subdomain of its host, `http.Client` follows redirects by default, and Go forwards sensitive headers to subdomains of the original host; a redirect from the RBAC endpoint to an attacker-controlled subdomain therefore receives the service bearer token.

Disable redirects for authenticated RBAC requests or reject redirects before forwarding the Authorization header.
</issue_to_address>

### Comment 3
<location path="manager/middlewares/rbac.go" line_range="114-116" />
<code_context>
-		DefaultHeaders: map[string]string{xRHIdentity: identity},
+		DefaultHeaders: headers,
 	}
 	if rbacURL == "" {
 		rbacURL = utils.FailIfEmpty(utils.CoreCfg.RbacAddress, "RBAC_ADDRESS") + base.RBACApiPrefix +
 			"/access/?application=patch,inventory,content-sources"
 	}
-	return &client
</code_context>
<issue_to_address>
**Concurrent RBAC checks fail**

When the first RBAC checks arrive concurrently, `makeClient` writes `rbacURL` without synchronization while `isAccessGranted` reads it for `Request`, causing a data race that can produce malformed RBAC request URLs and failed permission lookups.

Synchronize `rbacURL` initialization and reads.

Also at `manager/middlewares/rbac.go:102-105`.
</issue_to_address>

### Comment 4
<location path="manager/middlewares/rbac_auth_test.go" line_range="99-100" />
<code_context>
+	resetRbacClient(t)
+
+	// token endpoint failing
+	failing := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+		http.Error(w, "nope", http.StatusInternalServerError)
+	}))
+	defer failing.Close()
</code_context>
<issue_to_address>
**Token failure is not exercised**

When the issuer discovery request is made against the failing server, `TestRbacAuthenticatedFailsClosed` gets an error before a token request: the handler returns 500 for the issuer discovery request as well as `/token`. Its error and nil-client assertions therefore pass even if token-endpoint errors are mishandled.

Return valid issuer metadata for discovery and return 500 only from the token endpoint.
</issue_to_address>

### Comment 5
<location path="manager/middlewares/rbac_auth_test.go" line_range="111-113" />
<code_context>
+
+	// missing credentials
+	setAuthConfig("https://ewgw:443", failing.URL)
+	utils.CoreCfg.KesselAuthClientSecret = ""
+	client, err = makeClient(base.Context, "xrhid")
+	assert.Error(t, err)
+	assert.Nil(t, client)
+
</code_context>
<issue_to_address>
**Missing credentials check is masked**

When the configured client secret is empty while the SSO endpoint continues returning errors, `TestRbacAuthenticatedFailsClosed` still gets an error from the failing SSO server if `requireAuthConfig` stops rejecting the cleared client secret: `credentials` was created with valid credentials, and the token request still fails. The assertions therefore pass without verifying that missing credentials cause the failure.

Use a successful fake SSO endpoint for this subcase and verify that `makeClient` rejects the missing secret without requesting a token.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 5 findings to address first, and if the authenticated-endpoint configuration or token handling is wrong, RBAC permission checks may be made without the intended service identity or may fail closed. An overly permissive response could allow protected operations to run; reverting restores the previous calls but cannot undo actions taken while the change was live.

Blocking findings: manager/middlewares/rbac.go:80, manager/middlewares/rbac.go:106, manager/middlewares/rbac.go:116, manager/middlewares/rbac_auth_test.go:100, manager/middlewares/rbac_auth_test.go:113


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread manager/middlewares/rbac.go Resolved
Comment thread manager/middlewares/rbac.go Resolved
Comment thread manager/middlewares/rbac.go Resolved
Comment thread manager/middlewares/rbac_auth_test.go Resolved
Comment thread manager/middlewares/rbac_auth_test.go Resolved
Compute the RBAC URL per call instead of caching it in an unsynchronized global. Make the fail-closed tests reach the token endpoint and assert that missing credentials never request a token.
@MichaelMraka MichaelMraka self-assigned this Nov 26, 2026
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.

2 participants