Skip to content

Commit 15fd425

Browse files
update bootstrappolicy/dead addDeadClusterRole to include systemOnly annotation
Roles that have been replaced by kube controller roles should receive the systemOnly annotation to ensure they are not visible to typical end users (such as those who would use the web console). - updates bootstrappolicy/dead addDeadClusterRole - updates bootstrappolicy/web_console_role_test TestSystemOnlyRoles - still skips controller roles (maintenance simplicity), but will throw an error if the annotation is missing
1 parent 271fb1c commit 15fd425

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pkg/cmd/server/bootstrappolicy/dead.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ func addDeadClusterRole(name string) {
2121

2222
deadClusterRoles = append(deadClusterRoles,
2323
authorizationapi.ClusterRole{
24-
ObjectMeta: metav1.ObjectMeta{Name: name},
24+
ObjectMeta: metav1.ObjectMeta{
25+
Name: name,
26+
Annotations: map[string]string{
27+
// typical users should not see dead cluster roles
28+
roleSystemOnly: roleIsSystemOnly,
29+
},
30+
},
2531
},
2632
)
2733
}

pkg/cmd/server/bootstrappolicy/web_console_role_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ func TestSystemOnlyRoles(t *testing.T) {
6262

6363
for _, role := range GetBootstrapClusterRoles() {
6464
if isControllerRole(&role) {
65-
continue // assume all controller roles can be ignored
65+
if !isSystemOnlyRole(&role) {
66+
t.Errorf("Controller role %q is missing the system only annotation", role.Name)
67+
}
68+
continue // assume all controller roles can be ignored even though we require the annotation
6669
}
67-
if isSystemOnlyRole(role) {
70+
if isSystemOnlyRole(&role) {
6871
hide.Insert(role.Name)
6972
} else {
7073
show.Insert(role.Name)
@@ -86,7 +89,7 @@ func TestSystemOnlyRoles(t *testing.T) {
8689

8790
// this logic must stay in sync w/the web console for this test to be valid/valuable
8891
// it is the same logic that is run on the membership page
89-
func isSystemOnlyRole(role authorizationapi.ClusterRole) bool {
92+
func isSystemOnlyRole(role *authorizationapi.ClusterRole) bool {
9093
return role.Annotations[roleSystemOnly] == roleIsSystemOnly
9194
}
9295

0 commit comments

Comments
 (0)