Skip to content

Commit d79e4be

Browse files
Address review comments
Signed-off-by: Radek Gruchalski <[email protected]>
1 parent 0f1187d commit d79e4be

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

internal/request/http.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/client"
1717
)
1818

19-
var defaultServiceAccountGroups = []string{
20-
serviceaccount.AllServiceAccountsGroup,
21-
user.AllAuthenticated}
22-
23-
func GetDefaultServiceAccountGroups() []string {
24-
return defaultServiceAccountGroups
25-
}
26-
2719
type http struct {
2820
*h.Request
2921
authTypes []AuthType
@@ -43,7 +35,6 @@ func (h http) GetHTTPRequest() *h.Request {
4335

4436
//nolint:funlen
4537
func (h http) GetUserAndGroups() (username string, groups []string, err error) {
46-
4738
for _, fn := range h.authenticationFns() {
4839
// User authentication data is extracted according to the preferred order:
4940
// in case of first match blocking the iteration
@@ -119,7 +110,8 @@ func (h http) GetUserAndGroups() (username string, groups []string, err error) {
119110
// - system:authenticated
120111
if namespace, _, err := serviceaccount.SplitUsername(username); err == nil {
121112
groups = append(groups, fmt.Sprintf("%s%s", serviceaccount.ServiceAccountGroupPrefix, namespace))
122-
groups = append(groups, defaultServiceAccountGroups...)
113+
groups = append(groups, serviceaccount.AllServiceAccountsGroup)
114+
groups = append(groups, user.AllAuthenticated)
123115
}
124116
}()
125117
}

internal/request/http_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"sigs.k8s.io/controller-runtime/pkg/client"
1818

1919
"k8s.io/apiserver/pkg/authentication/serviceaccount"
20+
"k8s.io/apiserver/pkg/authentication/user"
2021

2122
"github.com/projectcapsule/capsule-proxy/internal/request"
2223
)
@@ -127,11 +128,12 @@ func Test_http_GetUserAndGroups(t *testing.T) {
127128
client: testClient(func(ctx context.Context, obj client.Object) error {
128129
ac := obj.(*authorizationv1.SubjectAccessReview)
129130
ac.Status.Allowed = true
131+
130132
return nil
131133
}),
132134
},
133135
wantUsername: serviceaccount.ServiceAccountUsernamePrefix + "ns:account",
134-
wantGroups: append([]string{fmt.Sprintf("%s%s", serviceaccount.ServiceAccountGroupPrefix, "ns")}, request.GetDefaultServiceAccountGroups()...),
136+
wantGroups: []string{fmt.Sprintf("%s%s", serviceaccount.ServiceAccountGroupPrefix, "ns"), serviceaccount.AllServiceAccountsGroup, user.AllAuthenticated},
135137
wantErr: false,
136138
},
137139
{

0 commit comments

Comments
 (0)