fix: address argus review on ensure_claude_dir — narrow to EPERM, fix doc comment
This commit is contained in:
parent
e553e40577
commit
7e229889a6
1 changed files with 20 additions and 13 deletions
|
|
@ -767,12 +767,15 @@ pub async fn setup_applied(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Create the per-agent Claude credentials dir if missing. Mode 0700 — only
|
||||
/// root inside the container reads/writes it. Idempotent: existing dirs are
|
||||
/// left untouched (an agent's OAuth tokens survive `destroy`/recreate).
|
||||
/// Create the per-agent Claude credentials dir if missing. Mode 0755 — hive-core
|
||||
/// needs read+execute to list the directory so `claude_has_session` can detect a
|
||||
/// valid session; credential files inside (`.credentials.json` etc.) are 0600 so
|
||||
/// secrets stay private regardless of the directory mode. Idempotent: existing
|
||||
/// dirs are left untouched (an agent's OAuth tokens survive `destroy`/recreate).
|
||||
/// Public for the `InitConfig` approval path in `actions.rs` which seeds
|
||||
/// dirs without calling the full `spawn`.
|
||||
pub fn ensure_claude_dir(claude_dir: &Path) -> Result<()> {
|
||||
use std::io;
|
||||
if !claude_dir.exists() {
|
||||
std::fs::create_dir_all(claude_dir)
|
||||
.with_context(|| format!("create {}", claude_dir.display()))?;
|
||||
|
|
@ -784,19 +787,23 @@ pub fn ensure_claude_dir(claude_dir: &Path) -> Result<()> {
|
|||
//
|
||||
// Best-effort: on the first container boot, `hive-agent-user-migrate`
|
||||
// chowns this dir to the agent user. After that, hive-core (a different
|
||||
// user) cannot chmod it — that's fine because the mode set during
|
||||
// initial creation (0755) is preserved through the chown.
|
||||
// user) cannot chmod it (EPERM) — that's fine because the mode set during
|
||||
// initial creation (0755) is preserved through the chown. Any other error
|
||||
// (ENOENT, I/O error) is unexpected and propagated.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
if let Err(e) =
|
||||
std::fs::set_permissions(claude_dir, std::fs::Permissions::from_mode(0o755))
|
||||
{
|
||||
tracing::debug!(
|
||||
path = %claude_dir.display(),
|
||||
error = %e,
|
||||
"ensure_claude_dir: chmod 755 skipped (dir likely owned by agent user after migration)"
|
||||
);
|
||||
match std::fs::set_permissions(claude_dir, std::fs::Permissions::from_mode(0o755)) {
|
||||
Ok(()) => {}
|
||||
Err(e) if e.kind() == io::ErrorKind::PermissionDenied => {
|
||||
tracing::debug!(
|
||||
path = %claude_dir.display(),
|
||||
"ensure_claude_dir: chmod 755 skipped (dir likely owned by agent user after migration)"
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(e).with_context(|| format!("chmod 755 {}", claude_dir.display()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue