Skip to content

Commit c30241a

Browse files
bartoszmajsakSB159
authored andcommitted
fix: proper construction of SA groups for tier lookup (opendatahub-io#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>
1 parent 7fdfd89 commit c30241a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

maas-api/internal/tier/mapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (m *Mapper) loadTierConfig(ctx context.Context) ([]Tier, error) {
109109

110110
for i := range tiers {
111111
tier := &tiers[i]
112-
tier.Groups = append(tier.Groups, fmt.Sprintf("system:serviceaccount:%s", m.projectedNsName(tier)))
112+
tier.Groups = append(tier.Groups, fmt.Sprintf("system:serviceaccounts:%s", m.projectedNsName(tier)))
113113
}
114114

115115
return tiers, nil

maas-api/internal/tier/mapper_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ func TestMapper_GetTierForGroups(t *testing.T) {
4141
},
4242
{
4343
name: "inferred SA group - free tier",
44-
groups: []string{"system:serviceaccount:test-tenant-tier-free"},
44+
groups: []string{"system:serviceaccounts:test-tenant-tier-free"},
4545
expectedTier: "free",
4646
description: "User belongs to only free tier group",
4747
},
48+
{
49+
name: "inferred SA group - premium tier",
50+
groups: []string{"system:serviceaccounts:test-tenant-tier-premium"},
51+
expectedTier: "premium",
52+
description: "User belongs to only premium tier group",
53+
},
4854
{
4955
name: "single group - premium tier",
5056
groups: []string{"premium-users"},
@@ -87,6 +93,12 @@ func TestMapper_GetTierForGroups(t *testing.T) {
8793
expectedTier: "developer",
8894
description: "User belongs to both premium and developer - developer has higher level (15 > 10)",
8995
},
96+
{
97+
name: "multiple groups - service account groups",
98+
groups: []string{"system:serviceaccounts", "system:serviceaccounts:test-tenant-tier-premium", "system:authenticated"},
99+
expectedTier: "premium",
100+
description: "User belongs to both premium and developer - developer has higher level (15 > 10)",
101+
},
90102
{
91103
name: "three groups - enterprise wins",
92104
groups: []string{"free-users", "premium-users", "enterprise-users"},

0 commit comments

Comments
 (0)