Skip to content

fix: proper construction of SA groups for tier lookup#136

Merged
jland-redhat merged 1 commit intoopendatahub-io:mainfrom
bartoszmajsak:maas-api/fix/tier-lookup
Oct 3, 2025
Merged

fix: proper construction of SA groups for tier lookup#136
jland-redhat merged 1 commit intoopendatahub-io:mainfrom
bartoszmajsak:maas-api/fix/tier-lookup

Conversation

@bartoszmajsak
Copy link
Copy Markdown
Collaborator

@bartoszmajsak bartoszmajsak commented Oct 3, 2025

#110 brought SA group construction so that they are not explicitly required in the configmap.

This PR fixes a stupid bug that previous PR brought with better test coverage.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected handling of Kubernetes ServiceAccount group names to use the proper plural prefix, ensuring accurate tier/group mapping and expected permissions for service-account-based access.
  • Tests

    • Expanded test coverage for service account group scenarios, including premium tiers and mixed group memberships, to validate correct precedence and behavior.

opendatahub-io#110 brought SA group construction so that they are not explictly required in the configmap.

This PR fixes a stupid bug that this PR brought with better test coverage.

Signed-off-by: Bartosz Majsak <bartosz.majsak@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Updated the service account group prefix from "system:serviceaccount:" to "system:serviceaccounts:" in tier mapping logic. Adjusted and expanded tests to reflect the new group string, including scenarios for premium tier and mixed groups. No control flow or API changes.

Changes

Cohort / File(s) Summary
Tier mapping logic
maas-api/internal/tier/mapper.go
Change constructed Kubernetes service account group from singular to plural prefix: system:serviceaccounts:...
Tier mapping tests
maas-api/internal/tier/mapper_test.go
Update expected SA group strings to plural form; add premium tier SA test; add mixed groups test ensuring premium selection logic holds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my nose at plural names,
Hop from singular to broader frames.
Now serviceaccounts lead the way,
Premium carrots win the day. 🥕
Tests burrow deep, confirm the trails—
A tidy hop where nothing fails.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely describes the primary change of fixing the construction of service account groups for tier lookup, directly matching the key modification in the code and test updates.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@jland-redhat jland-redhat merged commit e315444 into opendatahub-io:main Oct 3, 2025
2 of 3 checks passed
@bartoszmajsak bartoszmajsak deleted the maas-api/fix/tier-lookup branch October 3, 2025 15:09
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eeabb25 and 1405fdf.

📒 Files selected for processing (2)
  • maas-api/internal/tier/mapper.go (1 hunks)
  • maas-api/internal/tier/mapper_test.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
maas-api/internal/tier/mapper_test.go (2)

44-44: LGTM!

The test case correctly updated to use the plural system:serviceaccounts: prefix, consistent with the fix in mapper.go.


48-53: LGTM! Good test coverage addition.

This new test case verifies that the inferred service account group for the premium tier works correctly with the updated plural prefix.

maas-api/internal/tier/mapper.go (1)

112-112: Correct service account group prefix The change to system:serviceaccounts:<namespace> aligns with Kubernetes RBAC conventions for service account groups.

Comment on lines +96 to +101
{
name: "multiple groups - service account groups",
groups: []string{"system:serviceaccounts", "system:serviceaccounts:test-tenant-tier-premium", "system:authenticated"},
expectedTier: "premium",
description: "User belongs to both premium and developer - developer has higher level (15 > 10)",
},
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.

⚠️ Potential issue | 🟡 Minor

Update the test description to match the test logic.

The test case correctly verifies that premium tier wins among mixed groups including service accounts. However, the description still mentions "developer" tier, which doesn't match the test logic.

Apply this diff to fix the description:

 		{
 			name:         "multiple groups - service account groups",
 			groups:       []string{"system:serviceaccounts", "system:serviceaccounts:test-tenant-tier-premium", "system:authenticated"},
 			expectedTier: "premium",
-			description:  "User belongs to both premium and developer - developer has higher level (15 > 10)",
+			description:  "Service account with premium namespace group should resolve to premium tier",
 		},
🤖 Prompt for AI Agents
In maas-api/internal/tier/mapper_test.go around lines 96 to 101, the test case
description incorrectly mentions "developer" even though the test data checks
that the "premium" tier wins among mixed service account groups; update the
description string to accurately state that premium wins (e.g., "User belongs to
multiple groups including premium - premium has higher level and should win") so
the description matches the test logic.

SB159 pushed a commit to SB159/maas-billing that referenced this pull request Oct 15, 2025
…#136)

opendatahub-io#110 brought SA group construction so that they are not explictly required in the configmap.

This PR fixes a stupid bug that this PR brought with better test coverage.

Signed-off-by: Bartosz Majsak <bartosz.majsak@gmail.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.

2 participants