Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user management #1740

Merged
merged 31 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bb0910c
feat: update values-schema for users
ferruhcihan Sep 19, 2024
f06bd9e
test: versions
ferruhcihan Sep 19, 2024
b4c0de2
feat: update getUsers in the apl-keycloak-operator secret
ferruhcihan Sep 19, 2024
f00e8ef
feat: update user schema
ferruhcihan Sep 19, 2024
3b8ee12
Merge branch 'main' into APL-221
ferruhcihan Sep 24, 2024
922934f
Merge branch 'main' into APL-221
ferruhcihan Sep 24, 2024
1184e9d
feat: update user schema & write users to file
ferruhcihan Sep 26, 2024
491f8a2
feat: update users test files
ferruhcihan Sep 26, 2024
d17e7ce
feat: update env.gotmpl
ferruhcihan Sep 26, 2024
d2c6f3b
feat: update values schema
ferruhcihan Sep 27, 2024
2894be1
feat: update user test file
ferruhcihan Sep 27, 2024
084db2b
feat: update user test file
ferruhcihan Sep 27, 2024
b533a68
Merge branch 'main' into APL-221
ferruhcihan Sep 27, 2024
afd26a2
fix: revert apl chart notes.txt
ferruhcihan Sep 27, 2024
0e873b2
Merge branch 'main' into APL-221
ferruhcihan Sep 30, 2024
91024f4
fix: revert chart notes
ferruhcihan Sep 30, 2024
d9ccf8f
feat: update keycloak values-schema
ferruhcihan Sep 30, 2024
2ac7d94
test: users
ferruhcihan Oct 2, 2024
2185518
Merge branch 'main' into APL-221
srodenhuis Oct 3, 2024
bb186d6
Merge branch 'main' into APL-221
ferruhcihan Oct 4, 2024
6cda544
feat: update user in values-schema
ferruhcihan Oct 4, 2024
bfbc9dc
test: bootstrap with users
j-zimnowoda Oct 7, 2024
a6a2150
feat: update user management
ferruhcihan Oct 8, 2024
a81496b
feat: add user management values changes
ferruhcihan Oct 8, 2024
9ee90e1
feat: update users
ferruhcihan Oct 9, 2024
6af7a1a
feat: update bootstrap tests
ferruhcihan Oct 9, 2024
7f826c6
feat: update values-schema for user
ferruhcihan Oct 9, 2024
f2f6daa
Merge branch 'main' into APL-221
ferruhcihan Oct 9, 2024
2a461e6
Merge remote-tracking branch 'origin/main' into APL-221
j-zimnowoda Oct 10, 2024
ed8df93
Merge remote-tracking branch 'origin/main' into APL-221
j-zimnowoda Oct 14, 2024
5e3d4b9
chore: versions
j-zimnowoda Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"envalid": "7.3.1",
"express": "4.18.1",
"fs-extra": "9.1.0",
"generate-password": "^1.7.1",
"ignore-walk": "3.0.4",
"lodash": "4.17.21",
"node-fetch": "2.6.7",
Expand Down
16 changes: 14 additions & 2 deletions src/cmd/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Bootstrapping values', () => {
apps: { 'cert-manager': { issuer: 'custom-ca' } },
cluster: { name: 'bla', provider: 'dida' },
}
const users = [{ id: 'user1', initialPassword: 'existing-password' }, { id: 'user2' }]
const secrets = { secret: 'true', deep: { nested: 'secret' } }
const ageKeys = { publicKey: 'agePublicKey', privateKey: 'agePrivateKey' }
const kmsValues = {
Expand Down Expand Up @@ -241,6 +242,11 @@ describe('Bootstrapping values', () => {
})
describe('processing values', () => {
const generatedSecrets = { gen: 'x' }
const generatedPassword = 'generated-password'
const usersWithPasswords = [
{ id: 'user1', initialPassword: 'existing-password' },
{ id: 'user2', initialPassword: generatedPassword },
]
const ca = { a: 'cert' }
const mergedValues = merge(cloneDeep(values), cloneDeep(secrets))
const mergedSecretsWithCa = merge(cloneDeep(secrets), cloneDeep(ca))
Expand All @@ -262,6 +268,7 @@ describe('Bootstrapping values', () => {
terminal,
validateValues: jest.fn().mockReturnValue(true),
writeValues: jest.fn(),
generatePassword: jest.fn().mockReturnValue(generatedPassword),
}
})
describe('Creating CA', () => {
Expand Down Expand Up @@ -335,10 +342,15 @@ describe('Bootstrapping values', () => {
expect(res).toEqual(mergedValues)
})
it('should merge original with generated values and write them to env dir', async () => {
const writtenValues = merge(cloneDeep(values), cloneDeep(mergedSecretsWithGenAndCa))
deps.loadYaml.mockReturnValue(values)
const writtenValues = merge(
cloneDeep(values),
cloneDeep(mergedSecretsWithGenAndCa),
cloneDeep({ users: usersWithPasswords }),
)
deps.loadYaml.mockReturnValue({ ...values, users })
deps.getStoredClusterSecrets.mockReturnValue(secrets)
deps.generateSecrets.mockReturnValue(generatedSecrets)
deps.generatePassword.mockReturnValue(generatedPassword)
await processValues(deps)
expect(deps.writeValues).toHaveBeenNthCalledWith(2, writtenValues)
})
Expand Down
17 changes: 16 additions & 1 deletion src/cmd/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { copy, pathExists } from 'fs-extra'
import { copyFile, mkdir, readFile, writeFile } from 'fs/promises'
import { generate as generatePassword } from 'generate-password'
import { cloneDeep, get, merge } from 'lodash'
import { pki } from 'node-forge'
import path from 'path'
Expand Down Expand Up @@ -252,6 +253,7 @@ export const processValues = async (
generateSecrets,
createK8sSecret,
createCustomCA,
generatePassword,
},
): Promise<Record<string, any> | undefined> => {
const d = deps.terminal(`cmd:${cmdName}:processValues`)
Expand Down Expand Up @@ -287,8 +289,21 @@ export const processValues = async (
}
// merge existing secrets over newly generated ones to keep them
const allSecrets = merge(cloneDeep(caSecrets), cloneDeep(storedSecrets), cloneDeep(generatedSecrets))
// generate initial passwords for users if they don't have one
const users = get(originalInput, 'users', [])
for (const user of users) {
if (!user.initialPassword) {
user.initialPassword = deps.generatePassword({
length: 16,
numbers: true,
symbols: true,
lowercase: true,
uppercase: true,
})
}
}
// we have generated all we need, now store everything by merging the original values over all the secrets
await deps.writeValues(merge(cloneDeep(allSecrets), cloneDeep(originalInput)))
await deps.writeValues(merge(cloneDeep(allSecrets), cloneDeep(originalInput), cloneDeep({ users })))
// and do some context dependent post processing:
if (deps.isChart) {
// to support potential failing chart install we store secrets on cluster
Expand Down
7 changes: 5 additions & 2 deletions tests/fixtures/env/secrets.users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ users:
firstName: platform
lastName: admin
isPlatformAdmin: true
isTeamAdmin: false
teams: ['admin', 'demo']
isTeamAdmin: true
teams: ['demo']
initialPassword: 'platform-admin-password'
- email: [email protected]
firstName: team
lastName: admin
isPlatformAdmin: false
isTeamAdmin: true
teams: ['demo']
initialPassword: 'team-admin-password'
- email: [email protected]
firstName: team
lastName: member
isPlatformAdmin: false
isTeamAdmin: false
teams: ['demo']
initialPassword: 'team-member-password'
2 changes: 0 additions & 2 deletions values-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1464,8 +1464,6 @@ definitions:
- email
- firstName
- lastName
- isPlatformAdmin
- isTeamAdmin

properties:
alerts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
{{- $k := $c | get "keycloak" }}
{{- $doms := tpl (readFile "../../helmfile.d/snippets/domains.gotmpl") $v | fromYaml }}
{{- $joinTpl := readFile "../../helmfile.d/utils/joinListWithSep.gotmpl" }}
{{- $users := $v.users }}
{{ $users := list }}
{{- range $user := $v.users }}
j-zimnowoda marked this conversation as resolved.
Show resolved Hide resolved
{{ $groups := list }}
{{- if $user.isPlatformAdmin }}{{ $groups = append $groups "platform-admin" }}{{ end }}
{{- if $user.isTeamAdmin }}{{ $groups = append $groups "team-admin" }}{{ end }}
{{- range $team := $user.teams }}{{ $groups = append $groups (print "team-" $team) }}{{ end }}
{{- $users = append $users (dict "email" $user.email "firstName" $user.firstName "lastName" $user.lastName "initialPassword" $user.initialPassword "groups" $groups) }}
{{- end }}
{{- $users := $users | toJson }}

resources:
Expand Down