Skip to content

Commit

Permalink
[Helm] Generate password for Keycloak
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <[email protected]>
  • Loading branch information
mmorhun committed May 5, 2020
1 parent 05b537b commit d782c88
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tasks/installers/common-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function createEclipeCheCluster(flags: any, kube: KubeHelper): ListrTask
}

if (cr.spec.auth && cr.spec.auth.updateAdminPassword) {
ctx.highlightedMessages.push('You will be asked to change the default Che admin password on the first login.')
ctx.highlightedMessages.push('Eclipse Che admin credentials are: "admin:admin". You will be asked to change default Che admin password on the first login.')
}

task.title = `${task.title}...done.`
Expand Down
8 changes: 8 additions & 0 deletions src/tasks/installers/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { KubeHelper } from '../../api/kube'
import { VersionHelper } from '../../api/version'
import { CHE_TLS_SECRET_NAME } from '../../constants'
import { CertManagerTasks } from '../../tasks/component-installers/cert-manager'
import { generatePassword } from '../../util'

export class HelmTasks {
protected kubeHelper: KubeHelper
Expand Down Expand Up @@ -333,6 +334,13 @@ error: E_COMMAND_FAILED`)
setOptions.push(`--set global.chePostgresPVCStorageClassName=${flags['postgres-pvc-storage-class-name']}`)
}

if (flags.multiuser) {
// Generate Keycloak admin password
const keycloakPassword = generatePassword(12)
setOptions.push(`--set che-keycloak.keycloakAdminUserPassword=${keycloakPassword}`)
ctx.highlightedMessages.push(`Autogenerated Keycloak credentials are: "admin:${keycloakPassword}"`)
}

setOptions.push(`--set global.ingressDomain=${flags.domain}`)
setOptions.push(`--set cheImage=${flags.cheimage}`)
setOptions.push(`--set che.disableProbes=${flags.debug}`)
Expand Down
29 changes: 29 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,32 @@ export function isKubernetesPlatformFamily(platform: string): boolean {
export function isOpenshiftPlatformFamily(platform: string): boolean {
return platform === 'openshift' || platform === 'minishift' || platform === 'crc'
}

export function generatePassword(passwodLength: number, charactersSet = '') {
let dictionary: string[]
if (!charactersSet) {
const ZERO_CHAR_CODE = 48
const NINE_CHAR_CODE = 57
const A_CHAR_CODE = 65
const Z_CHAR_CODE = 90
const a_CHAR_CODE = 97
const z_CHAR_CODE = 122
const ranges = [[ZERO_CHAR_CODE, NINE_CHAR_CODE], [A_CHAR_CODE, Z_CHAR_CODE], [a_CHAR_CODE, z_CHAR_CODE]]

dictionary = []
for (let range of ranges) {
for (let charCode = range[0]; charCode <= range[1]; charCode++) {
dictionary.push(String.fromCharCode(charCode))
}
}
} else {
dictionary = [...charactersSet]
}

let generatedPassword = ''
for (let i = 0; i < passwodLength; i++) {
const randomIndex = Math.floor(Math.random() * dictionary.length)
generatedPassword += dictionary[randomIndex]
}
return generatedPassword
}

0 comments on commit d782c88

Please sign in to comment.