Skip to content

Commit 268fb70

Browse files
committed
Add support for adding 'groups' (group memberships) to user entries in 'staticPasswords'
1 parent 8ab38eb commit 268fb70

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

cmd/dex/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ type password storage.Password
9595

9696
func (p *password) UnmarshalJSON(b []byte) error {
9797
var data struct {
98-
Email string `json:"email"`
99-
Username string `json:"username"`
100-
UserID string `json:"userID"`
101-
Hash string `json:"hash"`
102-
HashFromEnv string `json:"hashFromEnv"`
98+
Email string `json:"email"`
99+
Username string `json:"username"`
100+
UserID string `json:"userID"`
101+
Hash string `json:"hash"`
102+
HashFromEnv string `json:"hashFromEnv"`
103+
Groups []string `json:"groups"`
103104
}
104105
if err := json.Unmarshal(b, &data); err != nil {
105106
return err
@@ -108,6 +109,7 @@ func (p *password) UnmarshalJSON(b []byte) error {
108109
Email: data.Email,
109110
Username: data.Username,
110111
UserID: data.UserID,
112+
Groups: data.Groups,
111113
})
112114
if len(data.Hash) == 0 && len(data.HashFromEnv) > 0 {
113115
data.Hash = os.Getenv(data.HashFromEnv)

cmd/dex/config_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ staticPasswords:
116116
# bcrypt hash of the string "password"
117117
hash: "$2a$10$33EMT0cVYVlPy6WAMCLsceLYjWhuHpbz5yuZxu/GAFj03J9Lytjuy"
118118
username: "admin"
119+
groups:
120+
- "administrators"
119121
userID: "08a8684b-db88-4b73-90a9-3cd1661f5466"
120122
123+
groups:
124+
- "developers"
125+
- "testers"
121126
# base64'd value of the same bcrypt hash above. We want to be able to parse both of these
122127
hash: "JDJhJDEwJDMzRU1UMGNWWVZsUHk2V0FNQ0xzY2VMWWpXaHVIcGJ6NXl1Wnh1L0dBRmowM0o5THl0anV5"
123128
username: "foo"
@@ -134,7 +139,7 @@ logger:
134139
format: "json"
135140
136141
additionalFeatures: [
137-
"ConnectorsCRUD"
142+
"ConnectorsCRUD"
138143
]
139144
`)
140145

@@ -207,12 +212,14 @@ additionalFeatures: [
207212
StaticPasswords: []password{
208213
{
209214
215+
Groups: []string{"administrators"},
210216
Hash: []byte("$2a$10$33EMT0cVYVlPy6WAMCLsceLYjWhuHpbz5yuZxu/GAFj03J9Lytjuy"),
211217
Username: "admin",
212218
UserID: "08a8684b-db88-4b73-90a9-3cd1661f5466",
213219
},
214220
{
215221
222+
Groups: []string{"developers", "testers"},
216223
Hash: []byte("$2a$10$33EMT0cVYVlPy6WAMCLsceLYjWhuHpbz5yuZxu/GAFj03J9Lytjuy"),
217224
Username: "foo",
218225
UserID: "41331323-6f44-45e6-b3b9-2c4b60c02be5",
@@ -331,11 +338,17 @@ connectors:
331338
enablePasswordDB: true
332339
staticPasswords:
333340
341+
groups:
342+
- "administrators"
334343
# bcrypt hash of the string "password"
335344
hash: "$2a$10$33EMT0cVYVlPy6WAMCLsceLYjWhuHpbz5yuZxu/GAFj03J9Lytjuy"
336345
username: "admin"
337346
userID: "08a8684b-db88-4b73-90a9-3cd1661f5466"
338347
348+
groups:
349+
- "developers"
350+
- "testers"
351+
# hash is read from environment variable DEX_FOO_USER_PASSWORD
339352
hashFromEnv: "DEX_FOO_USER_PASSWORD"
340353
username: "foo"
341354
userID: "41331323-6f44-45e6-b3b9-2c4b60c02be5"
@@ -421,12 +434,14 @@ logger:
421434
StaticPasswords: []password{
422435
{
423436
437+
Groups: []string{"administrators"},
424438
Hash: []byte("$2a$10$33EMT0cVYVlPy6WAMCLsceLYjWhuHpbz5yuZxu/GAFj03J9Lytjuy"),
425439
Username: "admin",
426440
UserID: "08a8684b-db88-4b73-90a9-3cd1661f5466",
427441
},
428442
{
429443
444+
Groups: []string{"developers", "testers"},
430445
Hash: []byte("$2a$10$33EMT0cVYVlPy6WAMCLsceLYjWhuHpbz5yuZxu/GAFj03J9Lytjuy"),
431446
Username: "foo",
432447
UserID: "41331323-6f44-45e6-b3b9-2c4b60c02be5",

config.dev.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ enablePasswordDB: true
3030

3131
staticPasswords:
3232
- email: "[email protected]"
33+
groups:
34+
- "administrators"
35+
- "developers"
36+
- "testers"
3337
hash: "$2a$10$2b2cU8CPhOTaGrs1HRQuAueS7JTT5ZHsHSzYiFPm1leZck7Mc8T4W"
3438
username: "admin"
3539
userID: "08a8684b-db88-4b73-90a9-3cd1661f5466"

storage/storage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ type Password struct {
354354

355355
// Randomly generated user ID. This is NOT the primary ID of the Password object.
356356
UserID string `json:"userID"`
357+
358+
// Groups associated with the password entry.
359+
Groups []string `json:"groups"`
357360
}
358361

359362
// Connector is an object that contains the metadata about connectors used to login to Dex.

0 commit comments

Comments
 (0)