feat: warn superadmins while the default admin account is still active

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alexander Petric
2026-11-06 22:02:02 +00:00
co-authored by Claude Opus 5.5
parent 5d3f239bf2
commit f5d09365bd
9 changed files with 263 additions and 7 deletions
@@ -1293,3 +1293,65 @@ async fn test_generated_username_skips_anonymous(db: Pool<Postgres>) -> 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<Postgres>) -> 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(())
}
+24
View File
@@ -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<DB>) -> JsonResult<boo
Ok(Json(false))
}
/// Whether `admin@windmill.dev` can still sign in with `changeme`. Verified rather than
/// compared to the seeded hash: a password set back to `changeme` gets a fresh salt. Unlike
/// `is_first_time_setup`, this stays true after `base_url` is saved or other users exist.
async fn is_default_superadmin_active(
authed: ApiAuthed,
Extension(db): Extension<DB>,
Extension(argon2): Extension<Arc<Argon2<'_>>>,
) -> JsonResult<bool> {
require_super_admin(&db, &authed).await?;
let hash: Option<String> = 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,
+14
View File
@@ -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)
@@ -0,0 +1,34 @@
<script lang="ts">
import { Button } from '$lib/components/common'
import { classes as alertClasses, icons as alertIcons } from '$lib/components/common/alert/model'
import {
isDefaultSuperadminActive,
REPLACE_DEFAULT_SUPERADMIN_HREF
} from '$lib/defaultSuperadmin'
// Mount only for superadmins: the check is a superadmin endpoint. No dismiss: it stays
// for as long as anyone reaching the instance can sign in as a superadmin with the
// published credentials. Replacing the account ends the session, so the next login
// remounts the shell and re-checks.
let active = $state(false)
isDefaultSuperadminActive().then((v) => (active = v))
const palette = alertClasses.error
const Icon = alertIcons.error
</script>
{#if active}
<div
class="shrink-0 px-4 py-1.5 flex items-center justify-center gap-x-3 gap-y-1 flex-wrap {palette.bgClass}"
role="alert"
>
<Icon size={16} class="shrink-0 {palette.iconClass}" />
<span class="text-xs font-medium {palette.titleClass}">
The default superadmin account admin@windmill.dev / changeme is still active. Anyone who can
reach this instance can log in with it.
</span>
<Button variant="default" unifiedSize="xs" href={REPLACE_DEFAULT_SUPERADMIN_HREF}>
Replace account
</Button>
</div>
{/if}
@@ -0,0 +1,31 @@
<script lang="ts">
import ConfirmationModal from '$lib/components/common/confirmationModal/ConfirmationModal.svelte'
import { Button } from '$lib/components/common'
interface Props {
open: boolean
onSkip: () => void
onSetAccount: () => void
onCancel: () => void
}
let { open, onSkip, onSetAccount, onCancel }: Props = $props()
</script>
<ConfirmationModal
{open}
title="Default superadmin account still active"
confirmationText="Skip anyway"
onConfirmed={onSkip}
onCanceled={onCancel}
>
<div class="flex flex-col gap-4">
<span>
The default account <b>admin@windmill.dev</b> / <b>changeme</b> 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.
</span>
<div class="flex">
<Button variant="default" unifiedSize="sm" onClick={onSetAccount}>Set the account now</Button>
</div>
</div>
</ConfirmationModal>
+14
View File
@@ -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<boolean> {
try {
return await UserService.isDefaultSuperadminActive()
} catch (e) {
console.error('Could not check the default superadmin account', e)
return false
}
}
@@ -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. -->
<InstanceBanner />
{/if}
{#if $superadmin && !menuHidden && !devOnly}
<div
class={classNames('shrink-0', sidebarTransitionClass)}
style:padding-left="{useDrawer ? 0 : railWidth}rem"
>
<DefaultSuperadminBanner />
</div>
{/if}
{#if $userStore?.is_service_account}
<div
class="bg-yellow-100 dark:bg-yellow-900/50 border-b border-yellow-300 dark:border-yellow-700 px-4 py-2 text-sm text-yellow-800 dark:text-yellow-200 flex items-center justify-center gap-4 shrink-0"
@@ -1,12 +1,28 @@
<script lang="ts">
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')
}
}
</script>
<CenteredModal title="Welcome to Windmill">
@@ -15,7 +31,7 @@
settings or the advanced setup for full control.
</p>
<div class="flex flex-row justify-between pt-4 gap-x-1">
<Button color="light" variant="contained" unifiedSize="md" href="/user/workspaces">Skip</Button>
<Button variant="default" unifiedSize="md" onClick={skip}>Skip</Button>
<div class="flex items-center gap-2">
<Button
variant="default"
@@ -32,3 +48,17 @@
</div>
</div>
</CenteredModal>
<DefaultSuperadminSkipModal
open={showSkipWarning}
onSkip={() => {
showSkipWarning = false
goto('/user/workspaces')
}}
onSetAccount={() => {
showSkipWarning = false
selectAdminsWorkspace()
goto(REPLACE_DEFAULT_SUPERADMIN_HREF)
}}
onCancel={() => (showSkipWarning = false)}
/>
@@ -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 @@
<p class="text-secondary text-xs">
You can change these settings later in the instance settings.
</p>
<Button variant="subtle" unifiedSize="sm" onClick={finishSetup}>Skip setup</Button>
<Button variant="subtle" unifiedSize="sm" onClick={skipSetup}>Skip setup</Button>
</div>
</div>
</CenteredModal>
<DefaultSuperadminSkipModal
open={showSkipWarning}
onSkip={() => {
showSkipWarning = false
finishSetup()
}}
onSetAccount={goToAccountStep}
onCancel={() => (showSkipWarning = false)}
/>
{#if showLicenseKeyWarning}
<ConfirmationModal
open={showLicenseKeyWarning}