@@ -12,9 +12,18 @@ import (
12
12
authenticationv1 "k8s.io/api/authentication/v1"
13
13
authorizationv1 "k8s.io/api/authorization/v1"
14
14
"k8s.io/apiserver/pkg/authentication/serviceaccount"
15
+ "k8s.io/apiserver/pkg/authentication/user"
15
16
"sigs.k8s.io/controller-runtime/pkg/client"
16
17
)
17
18
19
+ var defaultServiceAccountGroups = []string {
20
+ serviceaccount .AllServiceAccountsGroup ,
21
+ user .AllAuthenticated }
22
+
23
+ func GetDefaultServiceAccountGroups () []string {
24
+ return defaultServiceAccountGroups
25
+ }
26
+
18
27
type http struct {
19
28
* h.Request
20
29
authTypes []AuthType
@@ -34,6 +43,7 @@ func (h http) GetHTTPRequest() *h.Request {
34
43
35
44
//nolint:funlen
36
45
func (h http ) GetUserAndGroups () (username string , groups []string , err error ) {
46
+
37
47
for _ , fn := range h .authenticationFns () {
38
48
// User authentication data is extracted according to the preferred order:
39
49
// in case of first match blocking the iteration
@@ -106,9 +116,10 @@ func (h http) GetUserAndGroups() (username string, groups []string, err error) {
106
116
// by appending the expected service account groups:
107
117
// - system:serviceaccounts:<namespace>
108
118
// - system:serviceaccounts
119
+ // - system:authenticated
109
120
if namespace , _ , err := serviceaccount .SplitUsername (username ); err == nil {
110
- groups = append (groups , serviceaccount .AllServiceAccountsGroup )
111
121
groups = append (groups , fmt .Sprintf ("%s%s" , serviceaccount .ServiceAccountGroupPrefix , namespace ))
122
+ groups = append (groups , defaultServiceAccountGroups ... )
112
123
}
113
124
}()
114
125
}
0 commit comments