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

chore: enable native user mode if devworkspace engine is enabled #1870

Merged
merged 4 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,10 @@ export class KubeHelper {
cheClusterCR.spec.devWorkspace.enable = true
}

if (cheClusterCR.spec.devWorkspace.enable) {
cheClusterCR.spec.auth.nativeUserMode = true
}

// Use self-signed TLS certificate by default (for versions before 7.14.3).
// In modern versions of Che this field is ignored.
cheClusterCR.spec.server.selfSignedCert = true
Expand Down
12 changes: 3 additions & 9 deletions src/commands/server/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { checkChectlAndCheVersionCompatibility, createNamespaceTask, downloadTem
import { InstallerTasks } from '../../tasks/installers/installer'
import { ApiTasks } from '../../tasks/platforms/api'
import { PlatformTasks } from '../../tasks/platforms/platform'
import { askForChectlUpdateIfNeeded, getCommandSuccessMessage, getEmbeddedTemplatesDirectory, getProjectName, getTlsSupport, isDevWorkspaceEnabled, isKubernetesPlatformFamily, isNativeUserModeEnabled, isOpenshiftPlatformFamily, notifyCommandCompletedSuccessfully, wrapCommandError } from '../../util'
import { askForChectlUpdateIfNeeded, getCommandSuccessMessage, getEmbeddedTemplatesDirectory, getProjectName, getTlsSupport, isDevWorkspaceEnabled, isKubernetesPlatformFamily, isOpenshiftPlatformFamily, notifyCommandCompletedSuccessfully, wrapCommandError } from '../../util'

export default class Deploy extends Command {
static description = 'Deploy Eclipse Che server'
Expand Down Expand Up @@ -339,12 +339,6 @@ export default class Deploy extends Command {
await this.setPlaformDefaults(flags, ctx)
await this.config.runHook(DEFAULT_ANALYTIC_HOOK_NAME, { command: Deploy.id, flags })

if (!flags.batch && isKubernetesPlatformFamily(flags.platform) && (isDevWorkspaceEnabled(ctx) || flags['workspace-engine'] === 'dev-workspace') && !isNativeUserModeEnabled(ctx)) {
if (!await cli.confirm('DevWorkspace is experimental feature. It requires direct access to the underlying infrastructure REST API.\nThis results in huge privilege escalation. Do you want to proceed? [y/n]')) {
cli.exit(0)
}
}

const dexTasks = new DexTasks(flags)
const cheTasks = new CheTasks(flags)
const platformTasks = new PlatformTasks(flags)
Expand All @@ -366,13 +360,13 @@ export default class Deploy extends Command {
preInstallTasks.add(downloadTemplates(flags))
preInstallTasks.add({
title: '🧪 DevWorkspace engine (experimental / technology preview) 🚨',
enabled: () => (isDevWorkspaceEnabled(ctx) || flags['workspace-engine'] === 'dev-workspace') && !ctx.isOpenShift,
enabled: () => isDevWorkspaceEnabled(ctx, flags) && !ctx.isOpenShift,
task: () => new Listr(devWorkspaceTasks.getInstallTasks()),
})

const installTasks = new Listr(undefined, ctx.listrOptions)
installTasks.add([createNamespaceTask(flags.chenamespace, this.getNamespaceLabels(flags))])
if (isKubernetesPlatformFamily(flags.platform) && isNativeUserModeEnabled(ctx)) {
if (flags.platform === 'minikube' && isDevWorkspaceEnabled(ctx, flags)) {
installTasks.add(dexTasks.getInstallTasks())
}
installTasks.add(await installerTasks.installTasks(flags, this))
Expand Down
22 changes: 12 additions & 10 deletions src/tasks/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@

import { Command } from '@oclif/command'
import * as Listr from 'listr'
import { DexContextKeys } from '../api/context'

import { CheHelper } from '../api/che'
import { CheApiClient } from '../api/che-api-client'
import { CheServerLoginManager } from '../api/che-login-manager'
import { KubeHelper } from '../api/kube'
import { OpenShiftHelper } from '../api/openshift'
import { VersionHelper } from '../api/version'
import { CHE_OPERATOR_SELECTOR, DOC_LINK, DOC_LINK_RELEASE_NOTES, OUTPUT_SEPARATOR } from '../constants'
import { addTrailingSlash, base64Decode, newError } from '../util'

import { addTrailingSlash, base64Decode, isDevWorkspaceEnabled, newError } from '../util'
import { KubeTasks } from './kube'

/**
Expand Down Expand Up @@ -743,7 +740,17 @@ export class CheTasks {
}
messages.push(OUTPUT_SEPARATOR)

if (cheConfigMap.data.CHE_KEYCLOAK_AUTH__SERVER__URL) {
if (isDevWorkspaceEnabled(ctx, flags)) {
if (flags.platform === 'minikube') {
messages.push('Dex user credentials : che@eclipse.org:admin')
messages.push('Dex user credentials : user1@che:password')
messages.push('Dex user credentials : user2@che:password')
messages.push('Dex user credentials : user3@che:password')
messages.push('Dex user credentials : user4@che:password')
messages.push('Dex user credentials : user5@che:password')
messages.push(OUTPUT_SEPARATOR)
}
} else if (cheConfigMap.data.CHE_KEYCLOAK_AUTH__SERVER__URL) {
messages.push(`Identity Provider URL : ${addTrailingSlash(cheConfigMap.data.CHE_KEYCLOAK_AUTH__SERVER__URL)}`)

if (ctx.identityProviderUsername && ctx.identityProviderPassword) {
Expand All @@ -759,11 +766,6 @@ export class CheTasks {
}
}

if (ctx[DexContextKeys.DEX_USERNAME] && ctx[DexContextKeys.DEX_PASSWORD]) {
messages.push(`Dex admin credentials : ${ctx[DexContextKeys.DEX_USERNAME]}:${ctx[DexContextKeys.DEX_PASSWORD]}`)
messages.push(OUTPUT_SEPARATOR)
}

ctx.highlightedMessages = messages.concat(ctx.highlightedMessages)
task.title = `${task.title}...done`
},
Expand Down
18 changes: 2 additions & 16 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export function getTlsSupport(ctx: any): boolean {
return true
}

export function isDevWorkspaceEnabled(ctx: any): boolean {
export function isDevWorkspaceEnabled(ctx: any, flags: any): boolean {
const crPatch = ctx[ChectlContext.CR_PATCH]
if (crPatch && crPatch.spec && crPatch.spec.devWorkspace && crPatch.spec.devWorkspace.enable) {
return true
Expand All @@ -416,21 +416,7 @@ export function isDevWorkspaceEnabled(ctx: any): boolean {
return true
}

return false
}

export function isNativeUserModeEnabled(ctx: any): boolean {
const crPatch = ctx[ChectlContext.CR_PATCH]
if (crPatch && crPatch.spec && crPatch.spec.auth && crPatch.spec.auth.nativeUserMode) {
return true
}

const customCR = ctx.customCR
if (customCR && customCR.spec && customCR.spec.auth && customCR.spec.auth.nativeUserMode) {
return true
}

return false
return flags['workspace-engine'] === 'dev-workspace'
}

export function getTlsSecretName(ctx: any): string {
Expand Down