diff --git a/backend/windmill-api-integration-tests/tests/users.rs b/backend/windmill-api-integration-tests/tests/users.rs index 41488f34e1..0cfce5d8b4 100644 --- a/backend/windmill-api-integration-tests/tests/users.rs +++ b/backend/windmill-api-integration-tests/tests/users.rs @@ -1293,3 +1293,65 @@ async fn test_generated_username_skips_anonymous(db: Pool) -> anyhow:: assert_eq!(username, "anonymous2"); Ok(()) } + +/// The default account stays exploitable after its password is set back to `changeme`, which +/// stores a hash with a new salt and parameters, so the check must verify rather than compare. +#[sqlx::test(migrations = "../migrations", fixtures("base"))] +async fn test_is_default_superadmin_active(db: Pool) -> anyhow::Result<()> { + initialize_tracing().await; + let server = ApiServer::start(db.clone()).await?; + let url = format!( + "http://localhost:{}/api/users/is_default_superadmin_active", + server.addr.port() + ); + let active = |token: &'static str| { + let url = url.clone(); + async move { + let resp = client() + .get(url) + .header("Authorization", format!("Bearer {token}")) + .send() + .await + .unwrap(); + (resp.status(), resp.text().await.unwrap()) + } + }; + + // `changeme`, hashed with a different salt and cost than the migration's seed. + sqlx::query( + "INSERT INTO password (email, password_hash, login_type, super_admin, verified, name) + VALUES ('admin@windmill.dev', $1, 'password', true, true, 'Admin') + ON CONFLICT (email) DO UPDATE SET password_hash = $1, disabled = false", + ) + .bind("$argon2id$v=19$m=19456,t=2,p=1$TKpUDH3ZS4QevqmTfN233A$JBkCQbNobQTUlG0KlKBl1CKbPZK0iqe7BydnIqDfaVc") + .execute(&db) + .await?; + assert_eq!( + active("SECRET_TOKEN").await, + (reqwest::StatusCode::OK, "true".into()) + ); + assert_eq!( + active("SECRET_TOKEN_2").await.0, + reqwest::StatusCode::UNAUTHORIZED + ); + + sqlx::query("UPDATE password SET disabled = true WHERE email = 'admin@windmill.dev'") + .execute(&db) + .await?; + assert_eq!( + active("SECRET_TOKEN").await, + (reqwest::StatusCode::OK, "false".into()) + ); + + sqlx::query( + "UPDATE password SET disabled = false, password_hash = 'not-a-real-hash' + WHERE email = 'admin@windmill.dev'", + ) + .execute(&db) + .await?; + assert_eq!( + active("SECRET_TOKEN").await, + (reqwest::StatusCode::OK, "false".into()) + ); + Ok(()) +} diff --git a/backend/windmill-api-users/src/users.rs b/backend/windmill-api-users/src/users.rs index 57b0fe2393..49d6ffde3d 100644 --- a/backend/windmill-api-users/src/users.rs +++ b/backend/windmill-api-users/src/users.rs @@ -126,6 +126,10 @@ pub fn global_service() -> Router { .route("/decline_invite", post(decline_invite)) .route("/accept_invite", post(accept_invite)) .route("/list_as_super_admin", get(list_users_as_super_admin)) + .route( + "/is_default_superadmin_active", + get(is_default_superadmin_active), + ) .route("/set_login_type/{user}", post(set_login_type)) .route("/update/{user}", post(update_user)) .route("/delete/{user}", delete(delete_user)) @@ -382,6 +386,26 @@ pub async fn is_first_time_setup(Extension(db): Extension) -> JsonResult, + Extension(argon2): Extension>>, +) -> JsonResult { + require_super_admin(&db, &authed).await?; + let hash: Option = sqlx::query_scalar( + "SELECT password_hash FROM password WHERE email = 'admin@windmill.dev' \ + AND login_type = 'password' AND disabled = false AND password_hash IS NOT NULL", + ) + .fetch_optional(&db) + .await?; + Ok(Json(hash.is_some_and(|hash| { + argon2.verify_password(b"changeme", hash.as_str()).is_ok() + }))) +} + #[derive(Deserialize)] struct WorkspaceUsername { pub username: String, diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 970c7bedf4..ea6b7e0d92 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -4286,6 +4286,20 @@ paths: schema: type: boolean + /users/is_default_superadmin_active: + get: + summary: is the default admin@windmill.dev account still usable with its default password (superadmin only) + operationId: isDefaultSuperadminActive + tags: + - user + responses: + "200": + description: true if admin@windmill.dev can still log in with the default password + content: + application/json: + schema: + type: boolean + /users/list_as_super_admin: get: summary: list all users as super admin (require to be super amdin) diff --git a/frontend/src/lib/components/DefaultSuperadminBanner.svelte b/frontend/src/lib/components/DefaultSuperadminBanner.svelte new file mode 100644 index 0000000000..ddfca318f8 --- /dev/null +++ b/frontend/src/lib/components/DefaultSuperadminBanner.svelte @@ -0,0 +1,34 @@ + + +{#if active} + +{/if} diff --git a/frontend/src/lib/components/DefaultSuperadminSkipModal.svelte b/frontend/src/lib/components/DefaultSuperadminSkipModal.svelte new file mode 100644 index 0000000000..94a493f372 --- /dev/null +++ b/frontend/src/lib/components/DefaultSuperadminSkipModal.svelte @@ -0,0 +1,31 @@ + + + +
+ + The default account admin@windmill.dev / changeme is still active. Anyone who can + reach this instance can log in with it as superadmin. You can skip now and replace it later from + the instance settings. + +
+ +
+
+
diff --git a/frontend/src/lib/defaultSuperadmin.ts b/frontend/src/lib/defaultSuperadmin.ts new file mode 100644 index 0000000000..3f297ddbc5 --- /dev/null +++ b/frontend/src/lib/defaultSuperadmin.ts @@ -0,0 +1,14 @@ +import { UserService } from '$lib/gen' + +/** The quick setup's step that replaces the default superadmin account. */ +export const REPLACE_DEFAULT_SUPERADMIN_HREF = '/user/instance_settings?step=account' + +/** Whether admin@windmill.dev can still sign in with changeme. Superadmin-only endpoint. */ +export async function isDefaultSuperadminActive(): Promise { + try { + return await UserService.isDefaultSuperadminActive() + } catch (e) { + console.error('Could not check the default superadmin account', e) + return false + } +} diff --git a/frontend/src/routes/(root)/(logged)/+layout.svelte b/frontend/src/routes/(root)/(logged)/+layout.svelte index ba66d10c3d..9e96764223 100644 --- a/frontend/src/routes/(root)/(logged)/+layout.svelte +++ b/frontend/src/routes/(root)/(logged)/+layout.svelte @@ -124,6 +124,7 @@ import DraftMigrationErrorModal from '$lib/components/DraftMigrationErrorModal.svelte' import AppLinksModal from '$lib/components/itemSettings/AppLinksModal.svelte' import InstanceBanner from '$lib/components/InstanceBanner.svelte' + import DefaultSuperadminBanner from '$lib/components/DefaultSuperadminBanner.svelte' import InstanceUiSync from '$lib/components/InstanceUiSync.svelte' import { onDestroy, onMount, setContext, tick, untrack } from 'svelte' import { cubicOut } from 'svelte/easing' @@ -1706,6 +1707,14 @@ outside this layout, and their shortcut must reopen the URL that is their creden where the announcement would land inside someone else's page. --> {/if} + {#if $superadmin && !menuHidden && !devOnly} +
+ +
+ {/if} {#if $userStore?.is_service_account}
import CenteredModal from '$lib/components/CenteredModal.svelte' import { Button } from '$lib/components/common' + import DefaultSuperadminSkipModal from '$lib/components/DefaultSuperadminSkipModal.svelte' + import { + isDefaultSuperadminActive, + REPLACE_DEFAULT_SUPERADMIN_HREF + } from '$lib/defaultSuperadmin' + import { goto } from '$lib/navigation' import { workspaceStore } from '$lib/stores' // /user/* pages sit outside the (logged) layout, so a `?workspace=` param is not read there. function selectAdminsWorkspace(): void { $workspaceStore = 'admins' } + + let showSkipWarning = $state(false) + + async function skip() { + if (await isDefaultSuperadminActive()) { + showSkipWarning = true + } else { + goto('/user/workspaces') + } + } @@ -15,7 +31,7 @@ settings or the advanced setup for full control.

- +
+ + { + showSkipWarning = false + goto('/user/workspaces') + }} + onSetAccount={() => { + showSkipWarning = false + selectAdminsWorkspace() + goto(REPLACE_DEFAULT_SUPERADMIN_HREF) + }} + onCancel={() => (showSkipWarning = false)} +/> diff --git a/frontend/src/routes/(root)/(logged)/user/(user)/instance_settings/+page.svelte b/frontend/src/routes/(root)/(logged)/user/(user)/instance_settings/+page.svelte index a5c1a3379e..f1be16d972 100644 --- a/frontend/src/routes/(root)/(logged)/user/(user)/instance_settings/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/user/(user)/instance_settings/+page.svelte @@ -28,6 +28,8 @@ import SettingCard from '$lib/components/instanceSettings/SettingCard.svelte' import ConfirmationModal from '$lib/components/common/confirmationModal/ConfirmationModal.svelte' import InstanceAISettings from '$lib/components/instanceSettings/InstanceAISettings.svelte' + import DefaultSuperadminSkipModal from '$lib/components/DefaultSuperadminSkipModal.svelte' + import { isDefaultSuperadminActive } from '$lib/defaultSuperadmin' const settingsSteps = [ { id: 'Core', label: 'Core' }, @@ -45,16 +47,20 @@ const fullStepLabels = ['Settings', 'Root login & Resource Types'] const initialMode = page.url.searchParams.get('mode') === 'full' ? 'full' : 'wizard' - const initialStep = Math.max( - 0, - Math.min(parseInt(page.url.searchParams.get('step') ?? '0') || 0, wizardStepLabels.length - 1) - ) + const ACCOUNT_STEP_INDEX = wizardStepLabels.length - 1 + + // `step=account` lets links elsewhere reach the account step without knowing its index. + const stepParam = page.url.searchParams.get('step') + const initialStep = + stepParam === 'account' + ? ACCOUNT_STEP_INDEX + : Math.max(0, Math.min(parseInt(stepParam ?? '0') || 0, ACCOUNT_STEP_INDEX)) const initialFullStep = initialMode === 'full' ? Math.max( 0, Math.min( - parseInt(page.url.searchParams.get('step') ?? '0') || 0, + stepParam === 'account' ? fullStepLabels.length - 1 : parseInt(stepParam ?? '0') || 0, fullStepLabels.length - 1 ) ) @@ -268,6 +274,28 @@ goto('/user/workspaces') } + let showSkipWarning = $state(false) + + async function skipSetup() { + if (await isDefaultSuperadminActive()) { + showSkipWarning = true + } else { + finishSetup() + } + } + + function goToAccountStep() { + showSkipWarning = false + saveAndProceed(() => { + if (mode === 'wizard') { + wizardStep = ACCOUNT_STEP_INDEX + } else { + yamlMode = false + fullStep = fullStepLabels.length - 1 + } + }) + } + async function submitAccount() { accountError = '' accountSubmitting = true @@ -624,11 +652,21 @@

You can change these settings later in the instance settings.

- +
+ { + showSkipWarning = false + finishSetup() + }} + onSetAccount={goToAccountStep} + onCancel={() => (showSkipWarning = false)} +/> + {#if showLicenseKeyWarning}