feat(auth): admin reset, docs and image smoke test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-04 20:34:57 -03:00
1 parent 42892cb37f
commit 06b9980659
18 files changed
+267 -21

No files matched your search

+27
View File
@@ -37,6 +37,23 @@ enum Command {
json: bool,
},
Update,
/// Local account recovery. Never starts the daemon.
Auth {
#[command(subcommand)]
action: AuthAction,
},
}
#[derive(Subcommand)]
enum AuthAction {
/// Resets an administrator: removes MFA and sessions, prints a temporary
/// password once. The next login enrolls MFA again and changes the password.
Reset {
#[arg(long)]
username: String,
#[arg(long, default_value = ".acaua")]
data_dir: PathBuf,
},
}
#[tokio::main]
@@ -51,6 +68,16 @@ async fn main() {
async fn run(cli: Cli) -> acaua_core::Result<()> {
match cli.command {
Command::Serve { bind, data_dir } => web::serve(&bind, data_dir).await,
Command::Auth {
action: AuthAction::Reset { username, data_dir },
} => {
let key = web::secret_key_file(&|name| std::env::var(name).ok());
let auth = acaua_core::auth::AuthService::open(&data_dir, key.as_deref())?;
let temp = auth.reset_admin(&username, auth_http::unix_now())?;
println!("Senha temporária (exibida uma única vez): {temp}");
println!("O próximo login exige novo cadastro de MFA e troca de senha.");
Ok(())
}
Command::Analyze {
directory,
data_dir,
+12 -1
View File
@@ -406,13 +406,24 @@ async fn shutdown_signal() {
}
}
/// Path of an external secret key (a Docker secret), from `ACAUA_SECRET_KEY_FILE`.
/// An unset or empty variable means the key lives in the data directory.
pub(crate) fn secret_key_file(get: &dyn Fn(&str) -> Option<String>) -> Option<PathBuf> {
get("ACAUA_SECRET_KEY_FILE")
.filter(|value| !value.trim().is_empty())
.map(PathBuf::from)
}
pub async fn serve(bind: &str, data_dir: PathBuf) -> Result<()> {
// Decide the exposure before touching the data directory or printing a
// setup code: a refusal must leave nothing behind.
let transport = Transport::from_env(&|name| std::env::var(name).ok())?;
let _ = tracing_subscriber::fmt().try_init();
std::fs::create_dir_all(&data_dir)?;
let auth = Arc::new(AuthService::open(&data_dir, None)?);
let auth = Arc::new(AuthService::open(
&data_dir,
secret_key_file(&|name| std::env::var(name).ok()).as_deref(),
)?);
if let Some(code) = auth.ensure_bootstrap(auth_http::unix_now())? {
eprintln!("Acauã: código de configuração inicial (válido por 1 hora): {code}");
}
+16
View File
@@ -1128,3 +1128,19 @@ async fn analyze_failure_has_a_fixed_message() {
assert_eq!(r.status, StatusCode::BAD_REQUEST);
assert_eq!(r.body, r#"{"error":"analysis failed"}"#);
}
#[test]
fn secret_key_file_comes_from_the_environment() {
let with = |value: Option<&'static str>| {
secret_key_file(&move |name| {
assert_eq!(name, "ACAUA_SECRET_KEY_FILE");
value.map(String::from)
})
};
assert_eq!(with(None), None);
assert_eq!(with(Some(" ")), None);
assert_eq!(
with(Some("/run/secrets/acaua_key")),
Some(PathBuf::from("/run/secrets/acaua_key"))
);
}