Skip to content

{workspace-path-hash} directory permission issues in multi-user environments #16170

@kornelski

Description

@kornelski

Problem

If build-dir is set globally to something like /var/tmp/cargo/{workspace-path-hash}, different users sharing the same system will run into directory permission issues, even if /var/tmp/cargo/ itself is world-writeable.

{workspace-path-hash} expands to two directory levels like ab/cdef. Cargo creates the first part with the current user's ownership. This ends up preventing other users from writing to the ab/ directory, even if the complete hash of their workspace is different, and shares only the prefix (like ab/5678). When different local users are involved, the hash is effectively just one byte and collides quickly.

Steps

rustup default nightly
export CARGO_BUILD_BUILD_DIR="/var/tmp/cargo/{workspace-path-hash}"
for n in `seq 1 30`; do
    useradd testuser$n
done
mkdir -p /var/tmp/cargo tests
chmod a+rwX /var/tmp/cargo tests
cd tests
set -e
for c in `seq 1 10`; do
    for n in `seq 1 30`; do
        runuser -u testuser$n -- bash -c 'CRATE=x$UID-$RANDOM-$RANDOM; cargo new --lib $CRATE -q; cd $CRATE; cargo b' 
    done    
done

Possible Solution(s)

  • make {workspace-path-hash} expand to a single path component
    • optionally adding {workspace-path-hash-prefix} to allow users recreate the workaround for poor filesystems
  • add a path variable with $EUID, like {os-user-id}, which would allow global directories to be sharded by user explicitly
  • make the first directory component of the hash copy access permissions from its parent directory to make the 256 dirs world-writeable too

Notes

This may be relevant in the future if Cargo switches to using system directories, and system-wide Cargo installations end up getting paths that aren't in $HOME #16147

Version

cargo 1.93.0-nightly (344c4567c 2025-10-21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cachingArea: caching of dependencies, repositories, and build artifactsC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions