hashicorp/nomad · error
error setting directory permission mode: %w
Error message
error setting directory permission mode: %w
What it means
This error wraps a failure of os.Chmod after os.MkdirAll succeeded during the plugin Create operation. Because MkdirAll applies permissions through the process umask, Nomad explicitly chmods the directory to params.Mode; if that chmod fails the directory creation is aborted and this wrapped error is returned. Typical wrapped causes are permission denied (you are not the file owner) or the path being on a filesystem that does not support chmod.
Source
Thrown at client/hostvolumemanager/host_volume_plugin.go:144
params, err := decodeMkdirParams(req.Parameters)
if err != nil {
log.Error("error with parameters", "error", err)
return nil, err
}
err = os.MkdirAll(path, params.Mode)
if err != nil {
log.Error("error creating directory", "error", err)
return nil, fmt.Errorf("error creating directory: %w", err)
}
// os.MkdirAll perms are applied after umask, so the new directory may not
// have the exact permissions requested.
err = os.Chmod(path, params.Mode)
if err != nil {
log.Error("error setting directory permission mode", "error", err)
return nil, fmt.Errorf("error setting directory permission mode: %w", err)
}
if runtime.GOOS != "windows" {
// Chown note: A uid or gid of -1 means to not change that value.
if err = os.Chown(path, params.Uid, params.Gid); err != nil {
log.Error("error changing owner/group", "error", err, "uid", params.Uid, "gid", params.Gid)
// Failing to change ownership is fatal for this plugin. Since we have
// already created the directory, we should attempt to clean it.
// Otherwise, the operator must do this manually.
if err := os.RemoveAll(path); err != nil {
log.Error("failed to remove directory after create failure",
"error", err)
}
return nil, fmt.Errorf("error changing owner/group: %w", err)
}
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Inspect the wrapped OS error; if permission denied, ensure the nomad client user owns the newly created directory (check parent directory ownership and mount options).
- Check mount type: on NFS/CIFS/FAT mounts that don't honor chmod, pick a path on a local POSIX filesystem or adjust mount options.
- Check for external processes (cleanup jobs, antivirus) racing with directory creation and locking/removing the path.
- Adjust the requested Mode if it is invalid for the target filesystem.
Example fix
// before: path on CIFS mount that rejects chmod Path: "/mnt/share/vol1", Mode: 0o750 // chmod fails // after: use a local POSIX path for host volumes Path: "/opt/nomad/volumes/vol1", Mode: 0o750
Defensive patterns
Strategy: validation
Validate before calling
func modeSupported(path string) error {
// chmod support test: create and chmod a temp file on the same filesystem
f, err := os.CreateTemp(filepath.Dir(path), ".modetest*")
if err != nil {
return err
}
defer os.Remove(f.Name()); defer f.Close()
return os.Chmod(f.Name(), 0o600) // fails early on NFS/CIFS that reject chmod
} Try / catch
if err != nil && strings.Contains(err.Error(), "error setting directory permission mode") {
log.Warn("chmod unsupported or failed on target filesystem; verify mount type", "err", err)
// fall back to requesting the volume on a local path
} Prevention
- Place host volumes on local POSIX filesystems (ext4/xfs), not NFS/CIFS/FAT.
- Avoid mounts mounted with options that strip POSIX semantics.
- Ensure the nomad user creates the directory so it owns it (chmod by non-owner fails).
- Prevent external cleanup processes from racing with volume creation.
When it happens
Trigger: Plugin Create runs: os.MkdirAll succeeds but os.Chmod(path, params.Mode) returns an error — e.g. the new directory was created but its owner differs from the client process user (unusual), the underlying filesystem (some NFS configs, FAT, CIFS) rejects chmod, or the path was concurrently replaced/removed.
Common situations: Volume path on an NFS share with root_squash or a filesystem without POSIX permission support; concurrent process removing the directory between mkdir and chmod; umask-related permission surprise making the operator inspect why mode differs (this error is the chmod itself failing, rarer).
Related errors
- error creating directory: %w
- Chmod(%v) failed: %w
- error chmoding file %w
- failed to change directory permissions for the AllocDir: %v
- error changing owner/group: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/8a2019c650eca64f.
Report an issue: GitHub.