Skip to content

fix: gate clusterview auth skip behind SKIP_HUB_PERMISSION_CHECK env var - #765

Merged
openshift-merge-bot[bot] merged 1 commit into
stolostron:mainfrom
kurwang:fix-skip-hub-permission-env
Jul 27, 2026
Merged

fix: gate clusterview auth skip behind SKIP_HUB_PERMISSION_CHECK env var#765
openshift-merge-bot[bot] merged 1 commit into
stolostron:mainfrom
kurwang:fix-skip-hub-permission-env

Conversation

@kurwang

@kurwang kurwang commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Gates the clusterview "API absent → skip auth" logic behind SKIP_HUB_PERMISSION_CHECK=true environment variable.
  • On production clusters (no env var), the proxy fails closed if the userpermissions API is missing — prevents security bypass on partial MCE installs.
  • Sets SKIP_HUB_PERMISSION_CHECK=true in the kind E2E deployment where the API is intentionally absent.

Context

Follow-up to PR #764 per reviewer feedback from @yiraeChristineKim on backplane-operator PR #3716: the unconditional skip when the clusterview API is absent could be a security issue if MCE fails to install only the userpermissions component.

Changes

  • pkg/manager/hcp_proxy.go — check os.Getenv("SKIP_HUB_PERMISSION_CHECK") == "true" before skipping
  • pkg/manager/hcp_proxy_test.go — split test into two: with env var (skip allowed) and without (fail closed)
  • test/e2e/addon-manager-deployment.yaml — add SKIP_HUB_PERMISSION_CHECK=true env var for kind E2E

Test plan

  • Test_checkHubPermission_WhenClusterviewAPIAbsent_WithEnvVar_ItShouldSkipAndAllow
  • Test_checkHubPermission_WhenClusterviewAPIAbsent_WithoutEnvVar_ItShouldFailClosed
  • All existing proxy tests pass (handleRoute, handleCreate, etc.)

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes

    • Improved hub permission validation when the required API is unavailable.
    • Production environments now fail safely with a clear message when UserPermission is not configured, rather than silently skipping authorization.
  • Configuration

    • Added an explicit opt-out for environments that do not provide the required API, such as local end-to-end testing environments.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Walkthrough

The HCP proxy now fails closed when clusterview is unavailable unless permission checks are explicitly skipped. Unit tests cover both branches, shared test setup enables skipping, and the e2e deployment sets the skip environment variable.

Changes

Hub permission enforcement

Layer / File(s) Summary
Conditional UserPermission enforcement
pkg/manager/hcp_proxy.go, pkg/manager/hcp_proxy_test.go
Missing clusterview APIs are allowed only with SKIP_HUB_PERMISSION_CHECK=true; otherwise checkHubPermission returns an error requiring production UserPermission configuration, with tests covering both outcomes.
Test and e2e skip configuration
pkg/manager/hcp_proxy_test.go, test/e2e/addon-manager-deployment.yaml
Shared proxy tests and the addon-manager e2e deployment explicitly set SKIP_HUB_PERMISSION_CHECK=true.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: yiraechristinekim

🚥 Pre-merge checks | ✅ 9 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Test Structure And Quality ⚠️ Warning The new auth tests use bare assert.NoError/assert.Error without context, which violates the assertion-message requirement. Add descriptive failure messages to the new assertions (and any helper require.NoError calls) or document an exception.
✅ Passed checks (9 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: gating the clusterview auth skip behind an env var.
Description check ✅ Passed The description covers the change, rationale, file scope, and tests, with only minor template mismatches.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed Static Go test names only; no It/Describe/Context/When calls or dynamic titles were added.
No-Weak-Crypto ✅ Passed Touched code only adds env-var gating and test/manifest updates; no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB or secret comparisons appear in the diff.
Container-Privileges ✅ Passed The only manifest change adds SKIP_HUB_PERMISSION_CHECK; existing securityContext stays non-root with allowPrivilegeEscalation:false and no privileged/host* settings.
No-Sensitive-Data-In-Logs ✅ Passed New log/error messages only mention clusterview skip state and config; no passwords, tokens, PII, session IDs, or host/customer data were added.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread pkg/manager/hcp_proxy.go Outdated
p.log.Info("clusterview API not installed, skipping hub permission check (SKIP_HUB_PERMISSION_CHECK=true)")
return nil
}
return fmt.Errorf("clusterview API not installed and SKIP_HUB_PERMISSION_CHECK is not set")

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.

Can we change to "UserPermission is required in production. Please ensure the cluster has UserPermission configured." because SKIP_HUB_PERMISSION_CHECK is for our dev and ci

Previously, when the clusterview API was absent the proxy unconditionally
skipped the hub permission check. This is a security risk on production
clusters where a partial MCE install could leave the userpermissions API
missing, bypassing authorization.

Now the skip only happens when SKIP_HUB_PERMISSION_CHECK=true is
explicitly set in the pod environment (kind E2E only). On production
clusters without the env var, the proxy fails closed.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kurwang
kurwang force-pushed the fix-skip-hub-permission-env branch from 45d3803 to 7033c4a Compare July 27, 2026 19:41

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/manager/hcp_proxy_test.go (1)

481-496: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add meaningful failure messages to the branch assertions.

  • pkg/manager/hcp_proxy_test.go#L481-L496: explain that the absent API must be allowed only when the explicit skip is enabled.
  • pkg/manager/hcp_proxy_test.go#L499-L515: explain that a missing API must deny access and report the production configuration requirement.
Proposed fix
-	assert.NoError(t, err)
+	assert.NoError(t, err, "explicit skip must allow kind environments without the clusterview API")
...
-	assert.Error(t, err)
-	assert.Contains(t, err.Error(), "UserPermission is required in production")
+	assert.Error(t, err, "missing clusterview API must fail closed when skipping is disabled")
+	assert.Contains(t, err.Error(), "UserPermission is required in production",
+		"the error must identify the required production configuration")

As per coding guidelines, “Assertions should include meaningful failure messages.” As per path instructions, assertion messages must explain what was expected and why it matters.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/manager/hcp_proxy_test.go` around lines 481 - 496, Add meaningful failure
messages to the assertions in
Test_checkHubPermission_WhenClusterviewAPIAbsent_WithEnvVar_ItShouldSkipAndAllow,
stating that an absent API is allowed only when the explicit skip setting is
enabled. Also update the assertions in pkg/manager/hcp_proxy_test.go lines
499-515 to state that a missing API must deny access and report the required
production configuration.

Sources: Coding guidelines, Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/manager/hcp_proxy_test.go`:
- Around line 481-496: Add meaningful failure messages to the assertions in
Test_checkHubPermission_WhenClusterviewAPIAbsent_WithEnvVar_ItShouldSkipAndAllow,
stating that an absent API is allowed only when the explicit skip setting is
enabled. Also update the assertions in pkg/manager/hcp_proxy_test.go lines
499-515 to state that a missing API must deny access and report the required
production configuration.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: stolostron/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ef1d8567-748f-49a2-823e-b2a8119f16f5

📥 Commits

Reviewing files that changed from the base of the PR and between ca2f5aa and 7033c4a.

📒 Files selected for processing (3)
  • pkg/manager/hcp_proxy.go
  • pkg/manager/hcp_proxy_test.go
  • test/e2e/addon-manager-deployment.yaml

@openshift-ci

openshift-ci Bot commented Jul 27, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kurwang, yiraeChristineKim

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [kurwang,yiraeChristineKim]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sonarqubecloud

Copy link
Copy Markdown

@openshift-merge-bot
openshift-merge-bot Bot merged commit 91fb96a into stolostron:main Jul 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants