Skip to content

Commit f808b30

Browse files
authored
feat: support token auth for ManagedControlPlaneV2 (#168)
1 parent de9cd02 commit f808b30

File tree

8 files changed

+807
-330
lines changed

8 files changed

+807
-330
lines changed

api/core/v2alpha1/constants.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
MCPNameLabel = GroupName + "/mcp-name"
1212
MCPNamespaceLabel = GroupName + "/mcp-namespace"
1313
OIDCProviderLabel = GroupName + "/oidc-provider"
14+
TokenProviderLabel = GroupName + "/token-provider"
1415
MCPPurposeOverrideLabel = GroupName + "/purpose"
1516

1617
// ManagedPurposeMCPPurposeOverride is used as value for the managed purpose label. It must not be modified.
@@ -32,8 +33,13 @@ const (
3233
ConditionClusterRequestReady = "ClusterRequestReady"
3334
ConditionClusterConditionsSynced = "ClusterConditionsSynced"
3435
ConditionPrefixClusterCondition = "Cluster."
35-
ConditionPrefixOIDCAccessReady = "OIDCAccessReady."
36+
ConditionPrefixAccessReady = "AccessReady."
3637
ConditionAllAccessReady = "AllAccessReady"
3738
ConditionAllServicesDeleted = "AllServicesDeleted"
3839
ConditionAllClusterRequestsDeleted = "AllClusterRequestsDeleted"
3940
)
41+
42+
const (
43+
OIDCNamePrefix = "oidc:"
44+
TokenNamePrefix = "token:"
45+
)

api/core/v2alpha1/managedcontrolplane_types.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package v2alpha1
33
import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
55

6+
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
7+
68
commonapi "github.com/openmcp-project/openmcp-operator/api/common"
79
)
810

@@ -11,28 +13,48 @@ type ManagedControlPlaneV2Spec struct {
1113
IAM IAMConfig `json:"iam"`
1214
}
1315

14-
type ManagedControlPlaneV2Status struct {
15-
commonapi.Status `json:",inline"`
16+
type IAMConfig struct {
17+
// Tokens is a list of token-based access configurations.
18+
// +optional
19+
Tokens []TokenConfig `json:"tokens,omitempty"`
20+
// OIDC is the OIDC-based access configuration.
21+
OIDC *OIDCConfig `json:"oidc,omitempty"`
22+
}
1623

17-
// Access is a mapping from OIDC provider names to secret references.
18-
// Each referenced secret is expected to contain a 'kubeconfig' key with the kubeconfig that was generated for the respective OIDC provider for the ManagedControlPlaneV2.
19-
// The default OIDC provider, if configured, uses the name "default" in this mapping.
20-
// The "default" key is also used if the ClusterProvider does not support OIDC-based access and created a serviceaccount with a token instead.
24+
type OIDCConfig struct {
25+
// DefaultProvider is the standard OIDC provider that is enabled for all ManagedControlPlaneV2 resources.
26+
DefaultProvider DefaultProviderConfig `json:"defaultProvider,omitempty"`
27+
// ExtraProviders is a list of OIDC providers that should be configured for the ManagedControlPlaneV2.
28+
// They are independent of the standard OIDC provider and in addition to it, unless it has been disabled by not specifying any role bindings.
2129
// +optional
22-
Access map[string]commonapi.LocalObjectReference `json:"access,omitempty"`
30+
ExtraProviders []commonapi.OIDCProviderConfig `json:"extraProviders,omitempty"`
2331
}
2432

25-
type IAMConfig struct {
33+
type DefaultProviderConfig struct {
2634
// RoleBindings is a list of subjects with (cluster) role bindings that should be created for them.
2735
// These bindings refer to the standard OIDC provider. If empty, the standard OIDC provider is disabled.
2836
// Note that the username prefix is added automatically to the subjects' names, it must not be explicitly specified here.
2937
// +optional
3038
RoleBindings []commonapi.RoleBindings `json:"roleBindings,omitempty"`
39+
}
3140

32-
// OIDCProviders is a list of OIDC providers that should be configured for the ManagedControlPlaneV2.
33-
// They are independent of the standard OIDC provider and in addition to it, unless it has been disabled by not specifying any role bindings.
41+
type TokenConfig struct {
42+
// Name is the name of this token configuration.
43+
// It is used to generate a secret name and must be unique among all token configurations in the same ManagedControlPlaneV2.
44+
// +kubebuilder:validation:minLength=1
45+
Name string `json:"name"`
46+
clustersv1alpha1.TokenConfig `json:",inline"`
47+
}
48+
49+
type ManagedControlPlaneV2Status struct {
50+
commonapi.Status `json:",inline"`
51+
52+
// Access is a mapping from OIDC provider names to secret references.
53+
// Each referenced secret is expected to contain a 'kubeconfig' key with the kubeconfig that was generated for the respective OIDC provider for the ManagedControlPlaneV2.
54+
// The default OIDC provider, if configured, uses the name "default" in this mapping.
55+
// The "default" key is also used if the ClusterProvider does not support OIDC-based access and created a serviceaccount with a token instead.
3456
// +optional
35-
OIDCProviders []*commonapi.OIDCProviderConfig `json:"oidcProviders,omitempty"`
57+
Access map[string]commonapi.LocalObjectReference `json:"access,omitempty"`
3658
}
3759

3860
// +kubebuilder:object:root=true

api/core/v2alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)