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: [Helm] Generate password for Keycloak #686

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ ecc-jsbn@~0.1.1:

"eclipse-che@git://github.com/eclipse/che#master":
version "0.0.0"
resolved "git://github.com/eclipse/che#3a31ab8f59c02c57d225dd2ccb151d025784e0aa"
resolved "git://github.com/eclipse/che#6333d8951a949628e0c80bf61406efed6064ceca"

editorconfig@^0.15.0:
version "0.15.3"
Expand Down