Skip to content

Commit 42298d7

Browse files
committed
refactor ManagedControlPlane type and oidc configuration based on recent discussions
1 parent 9b03e42 commit 42298d7

15 files changed

+636
-438
lines changed

api/clusters/v1alpha1/accessrequest_types.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ type AccessRequestSpec struct {
3232
RequestRef *commonapi.ObjectReference `json:"requestRef,omitempty"`
3333

3434
// Permissions are the requested permissions.
35-
Permissions []PermissionsRequest `json:"permissions"`
35+
// If not empty, corresponding Roles and ClusterRoles will be created in the target cluster, potentially also creating namespaces for Roles.
36+
// For token-based access, the serviceaccount will be bound to the created Roles and ClusterRoles.
37+
// +optional
38+
Permissions []PermissionsRequest `json:"permissions,omitempty"`
39+
40+
// OIDCProvider is a configuration for an OIDC provider that should be used for authentication and associated role bindings.
41+
// If set, the handling ClusterProvider will create an OIDC-based access for the AccessRequest, if supported.
42+
// Otherwise, a serviceaccount with a token will be created and bound to the requested permissions.
43+
// +optional
44+
OIDCProvider *commonapi.OIDCProviderConfig `json:"oidcProvider,omitempty"`
3645
}
3746

3847
type PermissionsRequest struct {

api/clusters/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/common/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// +kubebuilder:object:generate=true
2+
package common

api/common/oidc_types.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package common
2+
3+
import (
4+
"strings"
5+
6+
rbacv1 "k8s.io/api/rbac/v1"
7+
)
8+
9+
type OIDCProviderConfig struct {
10+
// Name is the name of the OIDC provider.
11+
// May be used in k8s resources, therefore has to be a valid k8s name.
12+
// +kubebuilder:validation:MinLength=1
13+
// +kubebuilder:validation:MaxLength=253
14+
// +kubebuilder:validation:Pattern=`[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*`
15+
Name string `json:"name"`
16+
17+
// Issuer is the issuer URL of the OIDC provider.
18+
Issuer string `json:"issuer"`
19+
20+
// ClientID is the client ID to use for the OIDC provider.
21+
ClientID string `json:"clientID"`
22+
23+
// GroupsClaim is the claim in the OIDC token that contains the groups.
24+
// If empty, the default claim "groups" will be used.
25+
// +kubebuilder:default="groups"
26+
// +optional
27+
GroupsClaim string `json:"groupsClaim"`
28+
29+
// UsernameClaim is the claim in the OIDC token that contains the username.
30+
// If empty, the default claim "sub" will be used.
31+
// +kubebuilder:default="sub"
32+
// +optional
33+
UsernameClaim string `json:"usernameClaim"`
34+
35+
// UsernamePrefix is a prefix that will be added to all usernames when referenced in RBAC rules.
36+
// This is required to avoid conflicts with Kubernetes built-in users.
37+
// If the prefix does not end with a colon (:), it will be added automatically.
38+
// +kubebuilder:validation:MinLength=1
39+
UsernamePrefix string `json:"usernamePrefix"`
40+
41+
// RoleBindings is a list of subjects with (cluster) role bindings that should be created for them.
42+
// Note that the username prefix is added automatically to the subjects' names, it must not be explicitly specified here.
43+
RoleBindings []RoleBindings `json:"roleBindings"`
44+
}
45+
46+
type RoleBindings struct {
47+
// Subjects is a list of subjects that should be bound to the specified roles.
48+
// The subjects' names will be prefixed with the username prefix of the OIDC provider.
49+
Subjects []rbacv1.Subject `json:"subjects"`
50+
51+
// RoleRefs is a list of (cluster) role references that the subjects should be bound to.
52+
// Note that existence of the roles is not checked and missing (cluster) roles will result in ineffective (cluster) role bindings.
53+
RoleRefs []RoleRef `json:"roleRefs"`
54+
}
55+
56+
// +kubebuilder:validation:XValidation:rule="self.kind == 'Role' && has(self.namespace) && self.namespace != ”", message="namespace must be set if kind is 'Role'"
57+
// +kubebuilder:validation:XValidation:rule="self.kind == 'ClusterRole' && (!has(self.namespace) || self.namespace == ”)", message="namespace must not be set if kind is 'ClusterRole'"
58+
type RoleRef struct {
59+
// Name is the name of the role or cluster role to bind to the subjects.
60+
// +kubebuilder:validation:MinLength=1
61+
Name string `json:"name"`
62+
63+
// Namespace is the namespace of the role to bind to the subjects.
64+
// It must be set if the kind is 'Role' and may not be set if the kind is 'ClusterRole'.
65+
// +optional
66+
Namespace string `json:"namespace,omitempty"`
67+
68+
// Kind is the kind of the role to bind to the subjects.
69+
// It must be 'Role' or 'ClusterRole'.
70+
// +kubebuilder:validation:Enum=Role;ClusterRole
71+
Kind string `json:"kind"`
72+
}
73+
74+
// Default sets default values for the OIDCProviderConfig.
75+
// Modifies in-place and returns the receiver for chaining.
76+
func (o *OIDCProviderConfig) Default() *OIDCProviderConfig {
77+
if o == nil {
78+
return nil
79+
}
80+
if o.GroupsClaim == "" {
81+
o.GroupsClaim = "groups"
82+
}
83+
if o.UsernameClaim == "" {
84+
o.UsernameClaim = "sub"
85+
}
86+
if !strings.HasSuffix(o.UsernamePrefix, ":") {
87+
o.UsernamePrefix += ":"
88+
}
89+
return o
90+
}

api/common/status_types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ const (
1111
StatusPhaseTerminating = "Terminating"
1212
)
1313

14-
// +kubebuilder:object:generate=true
15-
1614
// Status represents the status of an openMCP resource.
1715
type Status struct {
1816
// ObservedGeneration is the generation of this resource that was last reconciled by the controller.

api/common/zz_generated.deepcopy.go

Lines changed: 127 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/core/v2alpha1/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package v2alpha1
2+
3+
const (
4+
// DefaultOIDCProviderName is the identifier for the default OIDC provider.
5+
DefaultOIDCProviderName = "default"
6+
)

api/core/v2alpha1/managedcontrolplane_auth.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)