Skip to content

RHCLOUD-51702: prefer V2 dependency endpoint for RBAC - #2351

Open
platex-rehor-bot wants to merge 2 commits into
RedHatInsights:masterfrom
platex-rehor-bot:bot/RHCLOUD-51702
Open

platex-rehor-bot wants to merge 2 commits into
RedHatInsights:masterfrom
platex-rehor-bot:bot/RHCLOUD-51702

Conversation

@platex-rehor-bot

@platex-rehor-bot platex-rehor-bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Summary

Migrates RBAC service discovery from the Clowder V1 flat endpoint list to V2 dependency endpoints. The V2 endpoint API (GetV2DependencyEndpoint("rbac", "service")) provides a complete URI including scheme and port, preferred over manual URL construction from V1 fields. V1 iteration is preserved as a fallback when V2 is not available. The RBAC_ADDRESS env var override remains as the final layer.

Jira: RHCLOUD-51702

Implemented

  • Added resolveRbacV2Address() helper that queries V2 dependency endpoints for RBAC (app=rbac, deployment=service)
  • Modified initServicesFromClowder() to try V2 first, falling back to V1 flat endpoint iteration only when V2 is unavailable
  • Added focused unit tests covering: V2 available, V2 nil/empty/wrong keys, env var override, env var preservation

Assumptions

  • app-common-go v1.7.0 (already installed) exports GetV2DependencyEndpoint — verified from module cache
  • RBAC auth mechanism (x-rh-identity forwarding) is preserved unchanged — this is a discovery-only migration
  • Dead code (CoreCfg.RbacURL set from rbac-service endpoint, never read) is intentionally left as-is per reviewer direction

Human Verification Required

  • V2 endpoint .CaCertificate is not consumed by this change. The existing RBAC HTTP client uses system trust (http.Client{}). If custom CA handling is needed in the future, it can be added as a follow-up.
  • V2 endpoint .Authenticated is not consumed. RBAC calls use x-rh-identity forwarding (in-cluster, authenticated: false). No auth mechanism change.
  • Tests could not be compiled locally due to cgo dependency on rpm/rpmlib.h (gorpm) — will validate via CI.

Considered Follow-ups

  • Dead code cleanup: CoreCfg.RbacURL / RBAC_URL env var (deferred per reviewer)
  • Content-sources-backend V2 migration (excluded from this pass per scope decision)

Validation

  • gofmt — clean
  • CGO_ENABLED=0 go build ./base/utils/ — passes
  • /clowder-v2-assess --phase after — PASS, no mechanical errors
  • Full test suite — deferred to CI (requires DB + rpm headers)

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

Update RBAC service discovery to prefer Clowder V2 dependency endpoints while preserving existing fallback and override behavior.

Bug Fixes:

  • Prefer the complete RBAC V2 dependency URI when discovering the RBAC service, while retaining V1 endpoint fallback and the existing RBAC_ADDRESS override.

Tests:

  • Add coverage for V2 endpoint resolution, unavailable or invalid V2 data, and environment override behavior.

The Clowder V2 endpoint API provides a complete URI including scheme and
port, avoiding the manual URL construction from V1 flat endpoint lists.
This change tries V2 first via GetV2DependencyEndpoint("rbac", "service")
and falls back to V1 iteration when V2 is not available. The RBAC_ADDRESS
env var override is preserved as the final layer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@platex-rehor-bot
platex-rehor-bot requested a review from a team as a code owner September 29, 2026 20:06
@sourcery-ai

sourcery-ai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Migrates RBAC service discovery to prefer the complete URI from Clowder V2 dependency endpoints, falls back to the existing V1 endpoint construction when V2 is unavailable, and preserves the final RBAC_ADDRESS environment override with focused tests covering these precedence and fallback paths.

File-Level Changes

Change Details Files
Prefer the Clowder V2 RBAC dependency URI while retaining V1 discovery as a fallback.
  • Add a helper that retrieves the rbac/service V2 endpoint and accepts only non-empty URIs.
  • Initialize RbacAddress from V2 before iterating V1 endpoints.
  • Prevent the V1 rbac endpoint from overwriting a successfully resolved V2 address.
  • Leave existing rbac-service URL handling unchanged.
base/utils/config.go
Add unit coverage for V2 resolution behavior and environment override precedence.
  • Test valid, missing, empty, and incorrectly keyed V2 endpoint data.
  • Verify endpoint metadata such as CA certificate does not alter URI resolution.
  • Verify RBAC_ADDRESS overrides V2 discovery and that V2 remains when the variable is unset.
base/utils/config_clowder_v2_test.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

@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 2 issues

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

## Individual Comments

### Comment 1
<location path="base/utils/config.go" line_range="289" />
<code_context>
 func initServicesFromClowder() {
+	// Try V2 dependency endpoint for RBAC (preferred over V1 flat list).
+	if addr := resolveRbacV2Address(); addr != "" {
+		CoreCfg.RbacAddress = addr
+	}
+
</code_context>
<issue_to_address>
**nitpick:** When V2 returns an HTTPS URI, `printServicesParams()` formats it as `RBAC_ADDRESS=http://https://...`, because that diagnostic function always prepends `http://` to `CoreCfg.RbacAddress`. The printed configuration is therefore invalid and misleading.

**Triggers:** When service parameters are printed after RBAC is resolved from a V2 HTTPS endpoint.

**Suggested fix:** Print `CoreCfg.RbacAddress` directly without prepending a scheme.
</issue_to_address>

### Comment 2
<location path="base/utils/config_clowder_v2_test.go" line_range="79-80" />
<code_context>
+	CoreCfg.RbacAddress = "https://rbac-service.svc:8443"
+
+	// Env var override takes precedence (initServicesFromEnv behavior)
+	os.Setenv("RBAC_ADDRESS", "http://localhost:8080")
+	defer os.Unsetenv("RBAC_ADDRESS")
+	initServicesFromEnv()
+	assert.Equal(t, "http://localhost:8080", CoreCfg.RbacAddress)
</code_context>
<issue_to_address>
**nitpick (testing):** The test overwrites any pre-existing `RBAC_ADDRESS` value and unconditionally unsets it during cleanup, so a test process or subsequent test that relies on the original environment value observes a changed environment.

**Triggers:** When the test suite is run with `RBAC_ADDRESS` already set or alongside tests that depend on that variable.

**Suggested fix:** Use `t.Setenv("RBAC_ADDRESS", "http://localhost:8080")`, which restores the original value automatically.

```suggestion
	t.Setenv("RBAC_ADDRESS", "http://localhost:8080")
```
</issue_to_address>

Sourcery assessment

Needs a human reviewer. The change redirects RBAC requests to a V2-provided URI, so a wrong or unintended endpoint could make authorization fail or accept decisions from the wrong service. Reverting stops future requests through that endpoint, but any access granted or denied while it was active cannot be undone.


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

Comment thread base/utils/config.go Outdated
func initServicesFromClowder() {
// Try V2 dependency endpoint for RBAC (preferred over V1 flat list).
if addr := resolveRbacV2Address(); addr != "" {
CoreCfg.RbacAddress = addr

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nitpick: When V2 returns an HTTPS URI, printServicesParams() formats it as RBAC_ADDRESS=http://https://..., because that diagnostic function always prepends http:// to CoreCfg.RbacAddress. The printed configuration is therefore invalid and misleading.

Triggers: When service parameters are printed after RBAC is resolved from a V2 HTTPS endpoint.

Suggested fix: Print CoreCfg.RbacAddress directly without prepending a scheme.

Comment thread base/utils/config_clowder_v2_test.go Outdated
@codecov-commenter

codecov-commenter commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.95%. Comparing base (2bd4e3f) to head (aa3b5b5).

Files with missing lines Patch % Lines
base/utils/config.go 62.50% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2351      +/-   ##
==========================================
- Coverage   58.95%   58.95%   -0.01%     
==========================================
  Files         150      150              
  Lines        9605     9612       +7     
==========================================
+ Hits         5663     5667       +4     
- Misses       3348     3349       +1     
- Partials      594      596       +2     
Flag Coverage Δ
unittests 58.95% <62.50%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

Comment thread base/utils/config_clowder_v2_test.go Outdated
Comment thread base/utils/config.go Outdated
func initServicesFromClowder() {
// Try V2 dependency endpoint for RBAC (preferred over V1 flat list).
if addr := resolveRbacV2Address(); addr != "" {
CoreCfg.RbacAddress = addr

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

move setting to rbac section; this will try to set it even if there's no rbac

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — moved the V2 resolution into the case "rbac": block so it only runs when RBAC endpoints are present. V2 is tried first; if unavailable, falls back to the V1 flat endpoint.

RHCLOUD-51702
Address review feedback: V2 endpoint resolution now scoped to the rbac
case block so it only runs when rbac endpoints exist. Tests use t.Setenv
for automatic cleanup, preventing env var side effects across test runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

3 participants