Skip to content

Commit

Permalink
fix: kube-apiserver authorizers order
Browse files Browse the repository at this point in the history
Fixes handling of `kube-apiserver` authorization config authorizers.
order.

Fixes: #10110

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Jan 14, 2025
1 parent faa1490 commit 3f891f4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 11 deletions.
31 changes: 31 additions & 0 deletions hack/release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ preface = """
Talos is built with Go 1.23.4.
"""

[notes.driver-rebind]
title = "Driver Rebind"
description = """\
Expand All @@ -36,6 +37,36 @@ See the [documentation](https://www.talos.dev/v1.10/reference/configuration/hard
description = """\
Talos Linux no longer supports `cgroupsv1` when running in non-container mode.
The kernel argument `talos.unified_cgroup_hierarchy` is now ignored.
"""

[notes.kube-apiserver-authorization-config]
title = "kube-apiserver Authorization Config"
description = """\
When using `.cluster.apiServer.authorizationConfig` the user provided order for the authorizers is honoured and `Node` and `RBAC` authorizers are always added to the end if not explicitly specified.
Eg: If user provides only `Webhook` authorizer, the final order will be `Webhook`, `Node`, `RBAC`.
To provide a specific order for `Node` or `RBAC` explicitly, user can provide the authorizer in the order they want.
Eg:
```yaml
cluster:
apiServer:
authorizationConfig:
- type: Node
name: Node
- type: Webhook
name: Webhook
webhook:
connectionInfo:
type: InClusterConfig
...
- type: RBAC
name: rbac
```
Usage of `authorization-mode` CLI argument will not support this form of customization.
"""

[make_deps]
Expand Down
29 changes: 23 additions & 6 deletions internal/app/machined/pkg/controllers/k8s/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ func NewControlPlaneAuthorizationController() *ControlPlaneAuthorizationControll
var authorizers []k8s.AuthorizationAuthorizersSpec

for _, authorizer := range cfgProvider.Cluster().APIServer().AuthorizationConfig() {
// skip Node and RBAC authorizers as we add them by default later on.
if authorizer.Type() == "Node" || authorizer.Type() == "RBAC" {
continue
}

authorizers = slices.Concat(authorizers, []k8s.AuthorizationAuthorizersSpec{
{
Type: authorizer.Type(),
Expand All @@ -145,7 +140,29 @@ func NewControlPlaneAuthorizationController() *ControlPlaneAuthorizationControll
})
}

res.TypedSpec().Config = slices.Concat(v1alpha1.APIServerDefaultAuthorizationConfigAuthorizers, authorizers)
if !slices.ContainsFunc(authorizers, func(a k8s.AuthorizationAuthorizersSpec) bool {
return a.Type == "Node"
}) {
authorizers = slices.Concat(authorizers, []k8s.AuthorizationAuthorizersSpec{
{
Type: "Node",
Name: "node",
},
})
}

if !slices.ContainsFunc(authorizers, func(a k8s.AuthorizationAuthorizersSpec) bool {
return a.Type == "RBAC"
}) {
authorizers = slices.Concat(authorizers, []k8s.AuthorizationAuthorizersSpec{
{
Type: "RBAC",
Name: "rbac",
},
})
}

res.TypedSpec().Config = authorizers

return nil
},
Expand Down
18 changes: 13 additions & 5 deletions internal/app/machined/pkg/controllers/k8s/control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (suite *K8sControlPlaneSuite) TestReconcileAdditionalAuthorizationConfigAut

suite.setupMachine(cfg)

expectedAuthorizers := slices.Concat(v1alpha1.APIServerDefaultAuthorizationConfigAuthorizers, []k8s.AuthorizationAuthorizersSpec{
expectedAuthorizers := slices.Concat([]k8s.AuthorizationAuthorizersSpec{
{
Type: "Webhook",
Name: "webhook",
Expand All @@ -223,7 +223,7 @@ func (suite *K8sControlPlaneSuite) TestReconcileAdditionalAuthorizationConfigAut
},
},
},
})
}, v1alpha1.APIServerDefaultAuthorizationConfigAuthorizers)

rtestutils.AssertResources(suite.Ctx(), suite.T(), suite.State(), []resource.ID{k8s.AuthorizationConfigID},
func(authorizationConfig *k8s.AuthorizationConfig, assert *assert.Assertions) {
Expand Down Expand Up @@ -272,7 +272,7 @@ func (suite *K8sControlPlaneSuite) TestReconcileAdditionalAuthorizationConfigAut
},
{
AuthorizerType: "Node",
AuthorizerName: "foo",
AuthorizerName: "bar",
},
},
},
Expand All @@ -283,7 +283,11 @@ func (suite *K8sControlPlaneSuite) TestReconcileAdditionalAuthorizationConfigAut

suite.setupMachine(cfg)

expectedAuthorizers := slices.Concat(v1alpha1.APIServerDefaultAuthorizationConfigAuthorizers, []k8s.AuthorizationAuthorizersSpec{
expectedAuthorizers := []k8s.AuthorizationAuthorizersSpec{
{
Type: "RBAC",
Name: "foo",
},
{
Type: "Webhook",
Name: "webhook",
Expand All @@ -297,7 +301,11 @@ func (suite *K8sControlPlaneSuite) TestReconcileAdditionalAuthorizationConfigAut
},
},
},
})
{
Type: "Node",
Name: "bar",
},
}

rtestutils.AssertResources(suite.Ctx(), suite.T(), suite.State(), []resource.ID{k8s.AuthorizationConfigID},
func(authorizationConfig *k8s.AuthorizationConfig, assert *assert.Assertions) {
Expand Down

0 comments on commit 3f891f4

Please sign in to comment.