Skip to content

Commit 6851fe9

Browse files
committed
create users on cluster init
Signed-off-by: utdrmac <matthew.boehm@percona.com>
1 parent 9a724fb commit 6851fe9

15 files changed

Lines changed: 897 additions & 6 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ lint-config: golangci-lint ## Verify golangci-lint linter configuration
105105
##@ Build
106106

107107
.PHONY: build
108-
build: manifests generate fmt vet ## Build manager binary.
108+
build: manifests generate fmt vet lint ## Build manager binary.
109109
go build -o bin/manager cmd/main.go
110110

111111
.PHONY: run

api/v1alpha1/valkeyacls_types.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
Copyright 2025 Valkey Contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
// An UserAclSpec contains user, authorization, and permissions-related configurations
20+
type UserAclSpec struct {
21+
22+
// Username
23+
// +kubebuilder:required:message=A username is required
24+
Name string `json:"name"`
25+
26+
// If the user is enabled or not
27+
// +kubebuilder:default=true
28+
Enabled bool `json:"enabled,omitempty"`
29+
30+
// Reference information to a Secret containing user passwords
31+
// +optional
32+
PasswordSecret PasswordSecretSpec `json:"passwordSecret,omitempty"`
33+
34+
// Do not apply a password to this user
35+
// +kubebuilder:default=false
36+
NoPassword bool `json:"nopass,omitempty"`
37+
38+
// Valkey command categories, commands, and subcommands restrictions for this user
39+
// +optional
40+
Commands CommandsAclSpec `json:"commands,omitempty"`
41+
42+
// Key restrictions
43+
// +optional
44+
Keys KeysAclSpec `json:"keys,omitempty"`
45+
46+
// Channel restrictions
47+
// +optional
48+
Channels ChannelsAclSpec `json:"channels,omitempty"`
49+
50+
// Raw ACL for (additional) permissions. Appended to anything generated.
51+
// +optional
52+
RawAcl string `json:"permissions,omitempty"`
53+
}
54+
55+
type PasswordSecretSpec struct {
56+
57+
// Name of the referencing Secret; Defaults to clustername-users
58+
// +optional
59+
Name string `json:"name,omitempty"`
60+
61+
// An array of keys inside the referencing Secret to find passwords; defaults to username
62+
// Valkey supports multiple passwords per user for rotation
63+
// +optional
64+
Keys []string `json:"keys,omitempty"`
65+
}
66+
67+
type CommandsAclSpec struct {
68+
69+
// Command categories (@all, @read, @write, @admin, etc.)
70+
// Individual commands (get, set, ping, etc.)
71+
// Subcommands (client|setname, config|get, etc.)
72+
73+
// Allowed commands for this user
74+
// +kubebuilder:validation:Items:Pattern=^[@a-z|]+$}
75+
Allow []string `json:"allow,omitempty"`
76+
77+
// Denied commands for this user
78+
// +kubebuilder:validation:Items:Pattern=^[@a-z|]+$}
79+
Deny []string `json:"deny,omitempty"`
80+
}
81+
82+
type KeysAclSpec struct {
83+
84+
// Keys on which this user can read, and write; maps to Valkey: ~pattern
85+
// +optional
86+
ReadWrite []string `json:"readWrite,omitempty"`
87+
88+
// Keys restricted to read-only; maps to Valkey: %R~pattern
89+
// +optional
90+
ReadOnly []string `json:"readOnly,omitempty"`
91+
92+
// Keys restricted to write-only; maps to Valkey: %W~pattern
93+
// +optional
94+
WriteOnly []string `json:"writeOnly,omitempty"`
95+
}
96+
97+
type ChannelsAclSpec struct {
98+
99+
// Pub/Sub channel patterns - maps to Valkey: &pattern
100+
// +optional
101+
Patterns []string `json:"patterns,omitempty"`
102+
}

api/v1alpha1/valkeycluster_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ type ValkeyClusterSpec struct {
7373
// +kubebuilder:default:={enabled:true}
7474
// +optional
7575
Exporter ExporterSpec `json:"exporter,omitempty"`
76+
77+
// Users, and ACL-related configuration; see valkeyacls_types.go
78+
// +listType=map
79+
// +listMapKey=name
80+
Users []UserAclSpec `json:"users,omitempty"`
7681
}
7782

7883
type ExporterSpec struct {
@@ -154,6 +159,7 @@ const (
154159
ReasonSlotsUnassigned = "SlotsUnassigned"
155160
ReasonPrimaryLost = "PrimaryLost"
156161
ReasonNoSlots = "NoSlotsAvailable"
162+
ReasonUsersAclError = "UsersACLError"
157163
)
158164

159165
// +kubebuilder:object:root=true

api/v1alpha1/zz_generated.deepcopy.go

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

config/crd/bases/valkey.io_valkeyclusters.yaml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,97 @@ spec:
11641164
type: string
11651165
type: object
11661166
type: array
1167+
users:
1168+
description: Users, and ACL-related configuration; see valkeyacls_types.go
1169+
items:
1170+
description: An UserAclSpec contains user, authorization, and permissions-related
1171+
configurations
1172+
properties:
1173+
channels:
1174+
description: Channel restrictions
1175+
properties:
1176+
patterns:
1177+
description: 'Pub/Sub channel patterns - maps to Valkey:
1178+
&pattern'
1179+
items:
1180+
type: string
1181+
type: array
1182+
type: object
1183+
commands:
1184+
description: Valkey command categories, commands, and subcommands
1185+
restrictions for this user
1186+
properties:
1187+
allow:
1188+
description: Allowed commands for this user
1189+
items:
1190+
type: string
1191+
type: array
1192+
deny:
1193+
description: Denied commands for this user
1194+
items:
1195+
type: string
1196+
type: array
1197+
type: object
1198+
enabled:
1199+
default: true
1200+
description: If the user is enabled or not
1201+
type: boolean
1202+
keys:
1203+
description: Key restrictions
1204+
properties:
1205+
readOnly:
1206+
description: 'Keys restricted to read-only; maps to Valkey:
1207+
%R~pattern'
1208+
items:
1209+
type: string
1210+
type: array
1211+
readWrite:
1212+
description: 'Keys on which this user can read, and write;
1213+
maps to Valkey: ~pattern'
1214+
items:
1215+
type: string
1216+
type: array
1217+
writeOnly:
1218+
description: 'Keys restricted to write-only; maps to Valkey:
1219+
%W~pattern'
1220+
items:
1221+
type: string
1222+
type: array
1223+
type: object
1224+
name:
1225+
description: Username
1226+
type: string
1227+
nopass:
1228+
default: false
1229+
description: Do not apply a password to this user
1230+
type: boolean
1231+
passwordSecret:
1232+
description: Reference information to a Secret containing user
1233+
passwords
1234+
properties:
1235+
keys:
1236+
description: |-
1237+
An array of keys inside the referencing Secret to find passwords; defaults to username
1238+
Valkey supports multiple passwords per user for rotation
1239+
items:
1240+
type: string
1241+
type: array
1242+
name:
1243+
description: Name of the referencing Secret; Defaults to
1244+
clustername-users
1245+
type: string
1246+
type: object
1247+
permissions:
1248+
description: Raw ACL for (additional) permissions. Appended
1249+
to anything generated.
1250+
type: string
1251+
required:
1252+
- name
1253+
type: object
1254+
type: array
1255+
x-kubernetes-list-map-keys:
1256+
- name
1257+
x-kubernetes-list-type: map
11671258
type: object
11681259
status:
11691260
default:

config/rbac/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rules:
88
- ""
99
resources:
1010
- configmaps
11+
- secrets
1112
- services
1213
verbs:
1314
- create

0 commit comments

Comments
 (0)