Skip to content

Commit 1c9f87c

Browse files
committed
feat: add support for sync source default groups
1 parent c771478 commit 1c9f87c

File tree

4 files changed

+63
-42
lines changed

4 files changed

+63
-42
lines changed

config/crd/bases/perm8s.tobiasgrether.com_synchronisationsources.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ spec:
6262
- secretName
6363
- url
6464
type: object
65+
defaultGroups:
66+
items:
67+
type: string
68+
type: array
6569
groupMappings:
6670
additionalProperties:
6771
type: string

controller/sync.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ func (c *Controller) syncSyncHandler(ctx context.Context, objectRef cache.Object
9898
}
9999
}
100100

101+
if source.Spec.DefaultGroups != nil {
102+
groups = append(groups, *source.Spec.DefaultGroups...)
103+
}
104+
101105
desiredUser := c.GetUserFromSyncUser(identifier, user.Name, source.Namespace, groups, source)
102106

103107
currentUser, err := c.clientSet.Perm8sV1alpha1().Users(source.Namespace).Get(ctx, desiredUser.Name, v3.GetOptions{})

pkg/apis/perm8s/v1alpha1/types.go

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package v1alpha1
22

33
import (
4-
v4 "k8s.io/api/rbac/v1"
5-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4+
v4 "k8s.io/api/rbac/v1"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
66
)
77

88
type AuthenticationSource string
@@ -16,57 +16,61 @@ type AuthenticationSource string
1616
// +kubebuilder:printcolumn:JSONPath=".spec.description",name=Description,type=string
1717
// +kubebuilder:field:scope=Cluster
1818
type Group struct {
19-
metav1.TypeMeta `json:",inline"`
20-
metav1.ObjectMeta `json:"metadata,omitempty"`
19+
metav1.TypeMeta `json:",inline"`
20+
metav1.ObjectMeta `json:"metadata,omitempty"`
2121

22-
Spec GroupSpec `json:"spec"`
22+
Spec GroupSpec `json:"spec"`
2323
}
2424

2525
type GroupSpec struct {
26-
DisplayName string `json:"displayName"`
27-
Description string `json:"description"`
28-
Permissions []v4.PolicyRule `json:"permissions"ƒ`
29-
Namespaces []string `json:"namespaces"`
30-
ClusterGroup bool `json:"clusterGroup"`
26+
DisplayName string `json:"displayName"`
27+
Description string `json:"description"`
28+
Permissions []v4.PolicyRule `json:"permissions"ƒ`
29+
Namespaces []string `json:"namespaces"`
30+
ClusterGroup bool `json:"clusterGroup"`
3131
}
3232

3333
// +genclient
3434
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
3535
// +genclient:noStatus
3636
// +kubebuilder:printcolumn:JSONPath=".spec.type",name=Source Type,type=string
3737
type SynchronisationSource struct {
38-
metav1.TypeMeta `json:",inline"`
39-
metav1.ObjectMeta `json:"metadata,omitempty"`
38+
metav1.TypeMeta `json:",inline"`
39+
metav1.ObjectMeta `json:"metadata,omitempty"`
4040

41-
Spec SynchronisationSourceSpec `json:"spec"`
41+
Spec SynchronisationSourceSpec `json:"spec"`
4242
}
4343

4444
type SynchronisationSourceSpec struct {
45-
// +kubebuilder:validation:Enum=authentik;ldap
46-
Type string `json:"type"`
47-
// +kubebuilder:validation:Optional
48-
Authentik *AuthentikSynchronisationSourceSpec `json:"authentik"`
49-
// GroupMappings should be a map internal group identifier => Kubernetes Group Name
50-
// This is useful when your IdP or SyncSource returns some kind of UUID for the groups,
51-
// but you want human-readable named groups in the cluster
52-
GroupMappings map[string]string `json:"groupMappings"`
45+
// +kubebuilder:validation:Enum=authentik;ldap
46+
Type string `json:"type"`
47+
// +kubebuilder:validation:Optional
48+
Authentik *AuthentikSynchronisationSourceSpec `json:"authentik"`
49+
// GroupMappings should be a map internal group identifier => Kubernetes Group Name
50+
// This is useful when your IdP or SyncSource returns some kind of UUID for the groups,
51+
// but you want human-readable named groups in the cluster
52+
GroupMappings map[string]string `json:"groupMappings"`
53+
// +kubebuilder:validation:Optional
54+
// +kubebuilder:Optional
55+
// +kubebuilder:validation:default:=[]
56+
DefaultGroups *[]string `json:"defaultGroups"`
5357
}
5458

5559
type AuthentikSynchronisationSourceSpec struct {
56-
URL string `json:"url"`
57-
Scheme string `json:"scheme"`
58-
SecretName string `json:"secretName"`
59-
// RequiredGroups is a list where a user only gets considered for this data source once they are a member of at least one of these groups
60-
// Leaving this array empty will autopass all users
61-
RequiredGroups []string `json:"requiredGroups"`
60+
URL string `json:"url"`
61+
Scheme string `json:"scheme"`
62+
SecretName string `json:"secretName"`
63+
// RequiredGroups is a list where a user only gets considered for this data source once they are a member of at least one of these groups
64+
// Leaving this array empty will autopass all users
65+
RequiredGroups []string `json:"requiredGroups"`
6266
}
6367

6468
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
6569
type SynchronisationSourceList struct {
66-
metav1.TypeMeta `json:",inline"`
67-
metav1.ListMeta `json:"metadata"`
70+
metav1.TypeMeta `json:",inline"`
71+
metav1.ListMeta `json:"metadata"`
6872

69-
Items []SynchronisationSource `json:"items"`
73+
Items []SynchronisationSource `json:"items"`
7074
}
7175

7276
// +genclient
@@ -75,32 +79,32 @@ type SynchronisationSourceList struct {
7579
// +kubebuilder:printcolumn:JSONPath=".spec.authenticationSource",name=Authentication Source,type=string
7680
// +kubebuilder:printcolumn:JSONPath=".spec.displayName",name=Display Name,type=string
7781
type User struct {
78-
metav1.TypeMeta `json:",inline"`
79-
metav1.ObjectMeta `json:"metadata,omitempty"`
82+
metav1.TypeMeta `json:",inline"`
83+
metav1.ObjectMeta `json:"metadata,omitempty"`
8084

81-
Spec UserSpec `json:"spec"`
85+
Spec UserSpec `json:"spec"`
8286
}
8387

8488
type UserSpec struct {
85-
DisplayName string `json:"displayName"`
86-
AuthenticationSource string `json:"authenticationSource"`
87-
GroupMemberships []string `json:"groupMemberships"`
89+
DisplayName string `json:"displayName"`
90+
AuthenticationSource string `json:"authenticationSource"`
91+
GroupMemberships []string `json:"groupMemberships"`
8892
}
8993

9094
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
9195

9296
type GroupList struct {
93-
metav1.TypeMeta `json:",inline"`
94-
metav1.ListMeta `json:"metadata"`
97+
metav1.TypeMeta `json:",inline"`
98+
metav1.ListMeta `json:"metadata"`
9599

96-
Items []Group `json:"items"`
100+
Items []Group `json:"items"`
97101
}
98102

99103
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
100104

101105
type UserList struct {
102-
metav1.TypeMeta `json:",inline"`
103-
metav1.ListMeta `json:"metadata"`
106+
metav1.TypeMeta `json:",inline"`
107+
metav1.ListMeta `json:"metadata"`
104108

105-
Items []User `json:"items"`
109+
Items []User `json:"items"`
106110
}

pkg/apis/perm8s/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)