Skip to content

Commit fc32786

Browse files
authored
Merge pull request #3565 from ntnn/kcp3513-per-workspace-auth-system
Add authenticated group adder to workspace auth
2 parents dc91159 + f2e193f commit fc32786

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

docs/content/concepts/authentication/workspace.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ This feature has some small limitations that users should keep in mind:
4545
* Workspace authenticators are started asynchronously and it will take a couple of seconds for them to be ready.
4646
* The workspace authentication in the localproxy, as part of a single shard server, only knows about the data on the local shard and cannot handle cross-shard authentication. Users are advised to use the front-proxy instead.
4747
* Even when the feature is disabled on all shards and all front-proxies, the API (CRDs) are always available in kcp. Admins might uses RBAC or webhooks to prevent creating `WorkspaceAuthenticationConfiguration` objects if needed.
48+
* It is not possible to authenticate users with a username starting with with `system:` through per-workspace authentication.
49+
* It is not possible to assign groups starting with `system:` to users authenticated via per-workspace authentication, e.g. via claim mappings.
4850

4951
## Example
5052

pkg/authentication/authenticators.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ func withClusterScope(delegate authenticator.Request) authenticator.Request {
4747
if extra == nil {
4848
extra = map[string][]string{}
4949
}
50-
if true {
51-
extra["authentication.kcp.io/scopes"] = append(extra["authentication.kcp.io/scopes"], fmt.Sprintf("cluster:%s", cluster))
52-
}
50+
extra["authentication.kcp.io/scopes"] = append(extra["authentication.kcp.io/scopes"], fmt.Sprintf("cluster:%s", cluster))
5351

5452
response.User = &user.DefaultInfo{
5553
Name: response.User.GetName(),

pkg/authentication/filters.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net/http"
2222

2323
"k8s.io/apiserver/pkg/authentication/authenticator"
24+
"k8s.io/apiserver/pkg/authentication/group"
2425

2526
"github.com/kcp-dev/kcp/pkg/proxy/lookup"
2627
)
@@ -43,6 +44,8 @@ func WithWorkspaceAuthResolver(handler http.Handler, authIndex AuthenticatorInde
4344
return
4445
}
4546

47+
authn = group.NewAuthenticatedGroupAdder(authn)
48+
4649
// make the authenticator always add the target cluster to the user scopes
4750
authn = withClusterScope(authn)
4851

test/e2e/authentication/workspace_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ func TestWorkspaceOIDC(t *testing.T) {
122122

123123
for _, path := range []logicalcluster.Path{teamAPath, teamBPath, teamCPath} {
124124
t.Logf("An unauthenticated user shouldn't be able to list ConfigMaps in %s...", path)
125-
126125
_, err = randoKubeClusterClient.Cluster(path).CoreV1().ConfigMaps("default").List(ctx, metav1.ListOptions{})
127126
require.Error(t, err)
128127
}
@@ -241,7 +240,6 @@ func TestWorkspaceOIDC(t *testing.T) {
241240

242241
require.Eventually(t, func() bool {
243242
_, err := client.Cluster(workspace).CoreV1().ConfigMaps("default").List(ctx, metav1.ListOptions{})
244-
245243
return err == nil
246244
}, wait.ForeverTestTimeout, 500*time.Millisecond)
247245
} else {
@@ -282,7 +280,7 @@ func TestUserScope(t *testing.T) {
282280
userName = "peter"
283281
userEmail = "[email protected]"
284282
userGroups = []string{"developers", "admins"}
285-
expectedGroups = []string{}
283+
expectedGroups = []string{"system:authenticated"}
286284
)
287285

288286
for _, group := range userGroups {
@@ -377,7 +375,6 @@ func TestForbiddenSystemAccess(t *testing.T) {
377375
t.Log("Waiting for authenticator to be ready...")
378376
require.Eventually(t, func() bool {
379377
_, err := client.Cluster(teamPath).CoreV1().ConfigMaps("default").List(ctx, metav1.ListOptions{})
380-
381378
return err == nil
382379
}, wait.ForeverTestTimeout, 500*time.Millisecond)
383380

0 commit comments

Comments
 (0)