hashicorp/nomad · error

error chowning file %w

Error message

error chowning file %w

What it means

In streamAllocDir, f.Chown(hdr.Uid, hdr.Gid) failed while restoring ownership of a migrated file. This branch only runs when euid==0 (root, non-Windows), so the failure means the tarred uid/gid could not be applied on the destination filesystem.

Source

Thrown at client/allocwatcher/alloc_watcher.go:666

					return fmt.Errorf("error removing existing file: %w", err)
				}
			}
			f, err := os.Create(fPath)
			if err != nil {
				return fmt.Errorf("error creating file: %w", err)
			}

			// Setting the permissions of the file as the origin.
			if err := f.Chmod(os.FileMode(hdr.Mode)); err != nil {
				f.Close()
				return fmt.Errorf("error chmoding file %w", err)
			}

			// Can't change owner if not root or on Windows.
			if euid == 0 {
				if err := f.Chown(hdr.Uid, hdr.Gid); err != nil {
					f.Close()
					return fmt.Errorf("error chowning file %w", err)
				}
			}

			// We write in chunks so that we can test if the client
			// is still alive
			for !canceled() {
				n, err := tr.Read(buf)
				if n > 0 && (err == nil || err == io.EOF) {
					if _, err := f.Write(buf[:n]); err != nil {
						f.Close()
						return fmt.Errorf("error writing to file %q: %w", f.Name(), err)
					}
				}

				if err != nil {
					f.Close()
					if err != io.EOF {
						return fmt.Errorf("error reading snapshot: %w", err)

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Grant CAP_CHOWN to the Nomad client container or run it on the host directly
  2. Verify the destination filesystem supports chown (avoid root-squashed NFS for the data dir)
  3. Re-snapshot the alloc dir so headers carry Uid/Gid valid on the destination host
  4. Run the client as non-root to skip the chown step if ownership preservation is not required
Defensive patterns

Strategy: validation

Validate before calling

// When running as root in a container, verify CAP_CHOWN before enabling migration:
// f, _ := os.Create(probe); err := f.Chown(1000, 1000); if err != nil { capability missing }

Try / catch

if err := watcher.Wait(ctx); err != nil {
    if strings.Contains(err.Error(), "error chowning file") {
        // fix capabilities/filesystem or run client unprivileged (skips chown)
        return err
    }
    return err
}

Prevention

When it happens

Trigger: Running as root, streamAllocDir extracts a TypeReg entry and f.Chown(hdr.Uid, hdr.Gid) returns an error (invalid uid/gid, unsupported filesystem, missing capability in container).

Common situations: Containerized root without CAP_CHOWN; root-squashed NFS or other network filesystems; tar headers with Uid/Gid that do not exist on the destination host.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/ffea91f37baf31c2. Report an issue: GitHub.