Ensure maildir ownership and permissions on user creation - #2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4f1fb5057
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fs::create_dir_all(&user_home).await?; | ||
| let hashed = hash_password(shell, password).await?; | ||
| fs::write(&password_path, hashed).await?; | ||
| ensure_maildir_permissions(shell, &user_home, &password_path).await?; |
There was a problem hiding this comment.
Clean up partial account state on permission failure
If ensure_maildir_permissions(...) fails (for example when chown/chmod lacks privileges), this ? returns immediately after the password file has already been written, leaving a partially created account on disk. On the next attempt, password_path.exists() triggers "password file already exists", so user creation can get stuck until manual cleanup. Please remove the created file/directory on this failure path, similar to the existing auth/mailbox rollback behavior.
Useful? React with 👍 / 👎.
Motivation
Permission deniederrors because newly created maildir directories and thepasswordfile were not owned or permissioned for thevmailuser.Description
ensure_maildir_permissions(...)which runschown -R vmail:vmail <user_home>,chmod 0700 <user_home>, andchmod 0600 <user_home>/passwordand returns explicit validation errors on failure.ensure_maildir_permissionsfromcreate_user_accountimmediately after writing the hashed password file to guarantee correct ownership/permissions before auth tests and mailbox initialization.AppError::Validationwith thestdout/stderrfrom the failing command.Testing
cargo fmtwhich completed successfully.cargo checkwhich finished without errors and the crate built indevprofile.Codex Task