fix compose user password not working
This commit is contained in:
@@ -8,6 +8,7 @@ export interface Config {
|
|||||||
auth: {
|
auth: {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
passwordIsUserSupplied: boolean;
|
||||||
jwtSecret: string;
|
jwtSecret: string;
|
||||||
agentToken: string;
|
agentToken: string;
|
||||||
};
|
};
|
||||||
@@ -80,6 +81,7 @@ const DEFAULT_CONFIG: Config = {
|
|||||||
auth: {
|
auth: {
|
||||||
username: "admin",
|
username: "admin",
|
||||||
password: "admin",
|
password: "admin",
|
||||||
|
passwordIsUserSupplied: false,
|
||||||
jwtSecret: "",
|
jwtSecret: "",
|
||||||
agentToken: "",
|
agentToken: "",
|
||||||
},
|
},
|
||||||
@@ -296,11 +298,15 @@ export function loadConfig(): Config {
|
|||||||
|
|
||||||
const passwordFromEnv = process.env.OVERLORD_PASS;
|
const passwordFromEnv = process.env.OVERLORD_PASS;
|
||||||
const passwordFromConfig = fileConfig.auth?.password;
|
const passwordFromConfig = fileConfig.auth?.password;
|
||||||
|
const passwordFromSaved = savedSecrets.auth?.bootstrapPassword;
|
||||||
let finalBootstrapPassword =
|
let finalBootstrapPassword =
|
||||||
passwordFromEnv ||
|
passwordFromEnv ||
|
||||||
passwordFromConfig ||
|
passwordFromConfig ||
|
||||||
savedSecrets.auth?.bootstrapPassword ||
|
passwordFromSaved ||
|
||||||
DEFAULT_CONFIG.auth.password;
|
DEFAULT_CONFIG.auth.password;
|
||||||
|
const passwordIsUserSupplied =
|
||||||
|
Boolean(passwordFromEnv) ||
|
||||||
|
Boolean(passwordFromConfig);
|
||||||
|
|
||||||
const keywordsEnv = process.env.OVERLORD_NOTIFICATION_KEYWORDS;
|
const keywordsEnv = process.env.OVERLORD_NOTIFICATION_KEYWORDS;
|
||||||
const keywordsFromEnv = keywordsEnv
|
const keywordsFromEnv = keywordsEnv
|
||||||
@@ -317,6 +323,7 @@ export function loadConfig(): Config {
|
|||||||
fileConfig.auth?.username ||
|
fileConfig.auth?.username ||
|
||||||
DEFAULT_CONFIG.auth.username,
|
DEFAULT_CONFIG.auth.username,
|
||||||
password: finalBootstrapPassword,
|
password: finalBootstrapPassword,
|
||||||
|
passwordIsUserSupplied,
|
||||||
jwtSecret: finalJwtSecret,
|
jwtSecret: finalJwtSecret,
|
||||||
agentToken: finalAgentToken,
|
agentToken: finalAgentToken,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -296,6 +296,7 @@ if (userCount.count === 0) {
|
|||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
const initialUsername = (config.auth.username || "admin").trim() || "admin";
|
const initialUsername = (config.auth.username || "admin").trim() || "admin";
|
||||||
const initialPassword = config.auth.password;
|
const initialPassword = config.auth.password;
|
||||||
|
const mustChangePassword = config.auth.passwordIsUserSupplied ? 0 : 1;
|
||||||
|
|
||||||
logger.info("[users] No users found, creating default admin account");
|
logger.info("[users] No users found, creating default admin account");
|
||||||
const defaultPassword = await Bun.password.hash(initialPassword, {
|
const defaultPassword = await Bun.password.hash(initialPassword, {
|
||||||
@@ -305,7 +306,7 @@ if (userCount.count === 0) {
|
|||||||
|
|
||||||
db.prepare(
|
db.prepare(
|
||||||
"INSERT INTO users (username, password_hash, role, created_at, created_by, must_change_password, client_scope, plugin_scope, can_build, can_upload_files) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
"INSERT INTO users (username, password_hash, role, created_at, created_by, must_change_password, client_scope, plugin_scope, can_build, can_upload_files) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
).run(initialUsername, defaultPassword, "admin", Date.now(), "system", 1, "all", "all", 1, 1);
|
).run(initialUsername, defaultPassword, "admin", Date.now(), "system", mustChangePassword, "all", "all", 1, 1);
|
||||||
|
|
||||||
const createdUser = db
|
const createdUser = db
|
||||||
.prepare("SELECT * FROM users WHERE username = ?")
|
.prepare("SELECT * FROM users WHERE username = ?")
|
||||||
@@ -316,9 +317,15 @@ if (userCount.count === 0) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
logger.info(`[users] Initial admin account created (username: ${initialUsername})`);
|
logger.info(`[users] Initial admin account created (username: ${initialUsername})`);
|
||||||
logger.warn(
|
if (mustChangePassword) {
|
||||||
"[users] SECURITY WARNING: A default admin account has been created. Sign in and rotate the password immediately. Bootstrap credentials default to admin/admin unless overridden by configuration; the password is not logged.",
|
logger.warn(
|
||||||
);
|
"[users] SECURITY WARNING: A default admin account has been created with the fallback password. Sign in and rotate the password immediately. Bootstrap credentials default to admin/admin unless overridden by configuration; the password is not logged.",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
logger.info(
|
||||||
|
"[users] Initial admin account uses the operator-supplied password; first-login rotation is not required.",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUserById(id: number): User | null {
|
export function getUserById(id: number): User | null {
|
||||||
|
|||||||
Reference in New Issue
Block a user