Skip to content

ROX-33014: store generated internal user role in issued token#19157

Draft
rhybrillou wants to merge 9 commits intomaster-yann/ROX-33014/base_test_coveragefrom
master-yann/ROX-33014/store_ephemeral_roles_in_token
Draft

ROX-33014: store generated internal user role in issued token#19157
rhybrillou wants to merge 9 commits intomaster-yann/ROX-33014/base_test_coveragefrom
master-yann/ROX-33014/store_ephemeral_roles_in_token

Conversation

@rhybrillou
Copy link
Contributor

Description

change me!

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

change me!

@openshift-ci
Copy link

openshift-ci bot commented Feb 24, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Feb 24, 2026

Images are ready for the commit at 5a57d7f.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-139-g5a57d7f411.

@rhybrillou rhybrillou force-pushed the master-yann/ROX-33014/store_ephemeral_roles_in_token branch from 127c969 to 84762a7 Compare February 24, 2026 11:01
Copy link
Contributor

@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 - I've found 2 issues

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

## Individual Comments

### Comment 1
<location path="pkg/auth/tokens/internal_role.go" line_range="23-27" />
<code_context>
 	ClusterScopes []*ClusterScope   `json:"cluster_scopes"`
 }

 func (r *InternalRole) GetRoleName() string {
-	return internalRoleName
+	if r == nil {
+		return ""
+	}
+	return r.RoleName
 }

</code_context>
<issue_to_address>
**issue (bug_risk):** Consider defaulting to a non-empty role name for older tokens where RoleName may be unset

Previously this always returned `internalRoleName`, but now older tokens (which won’t have `RoleName` set) will deserialize with `RoleName == ""`, causing identities from those tokens to get an empty role name. That’s a behavior change that may break code or logging expecting the legacy name. Consider mapping an empty `RoleName` to the legacy default (e.g., `internalRoleName`), while still respecting non-empty values on newer tokens.
</issue_to_address>

### Comment 2
<location path="central/auth/internaltokens/service/service_impl_test.go" line_range="164" />
<code_context>
 		svc := createService(mockIssuer, mockClusterStore, mockRoleStore)
 		setClusterStoreExpectations(input, mockClusterStore)
-		setNormalRoleStoreExpectations(deploymentPS, singleNSScope, expectedRole, nil, mockRoleStore)
 		expectedClaims := tokens.RoxClaims{
-			RoleNames: []string{expectedRole.GetName()},
+			RoleNames: []string{internalRoleName},
</code_context>
<issue_to_address>
**suggestion (testing):** Extend GenerateTokenForPermissionsAndScope tests to cover additional InternalRole shapes

The new assertions cover the main case well. To strengthen coverage, please also add:
- A request with no permissions and/or no cluster scopes, confirming the token’s `InternalRole` has empty `Permissions` / `ClusterScopes` and is still accepted by the issuer.
- A request with multiple permissions and mixed full-cluster and namespace-limited scopes across multiple clusters, confirming all are correctly represented in `InternalRole.ClusterScopes` and `Permissions`.

These would replace some of the removed role/access-scope tests and validate behavior for more complex inputs.
</issue_to_address>

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.

Comment on lines 23 to +27
func (r *InternalRole) GetRoleName() string {
return internalRoleName
if r == nil {
return ""
}
return r.RoleName
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Consider defaulting to a non-empty role name for older tokens where RoleName may be unset

Previously this always returned internalRoleName, but now older tokens (which won’t have RoleName set) will deserialize with RoleName == "", causing identities from those tokens to get an empty role name. That’s a behavior change that may break code or logging expecting the legacy name. Consider mapping an empty RoleName to the legacy default (e.g., internalRoleName), while still respecting non-empty values on newer tokens.

svc := createService(mockIssuer, mockClusterStore, mockRoleStore)
setClusterStoreExpectations(input, mockClusterStore)
setNormalRoleStoreExpectations(deploymentPS, singleNSScope, expectedRole, nil, mockRoleStore)
expectedClaims := tokens.RoxClaims{
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Extend GenerateTokenForPermissionsAndScope tests to cover additional InternalRole shapes

The new assertions cover the main case well. To strengthen coverage, please also add:

  • A request with no permissions and/or no cluster scopes, confirming the token’s InternalRole has empty Permissions / ClusterScopes and is still accepted by the issuer.
  • A request with multiple permissions and mixed full-cluster and namespace-limited scopes across multiple clusters, confirming all are correctly represented in InternalRole.ClusterScopes and Permissions.

These would replace some of the removed role/access-scope tests and validate behavior for more complex inputs.

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 82.05128% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.44%. Comparing base (9faf904) to head (5a57d7f).

Files with missing lines Patch % Lines
pkg/grpc/authn/tokenbased/extractor.go 53.33% 7 Missing ⚠️
Additional details and impacted files
@@                             Coverage Diff                              @@
##           master-yann/ROX-33014/base_test_coverage   #19157      +/-   ##
============================================================================
- Coverage                                     49.49%   49.44%   -0.05%     
============================================================================
  Files                                          2683     2680       -3     
  Lines                                        202076   201813     -263     
============================================================================
- Hits                                         100013    99786     -227     
+ Misses                                        94603    94573      -30     
+ Partials                                       7460     7454       -6     
Flag Coverage Δ
go-unit-tests 49.44% <82.05%> (-0.05%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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