`newfstatat` calls return changing values, resulting in git saying "detected dubious ownership in repository"

Open
#649 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Active
Tech stack
docker, git

Research direction

Start by reproducing the documented docker run command on macOS and inspect strace.log, focusing on the differing newfstatat st_uid results for /riscos-source. There is no project source file or test named in the report; done means isolating why ownership changes between processes and documenting or addressing the resulting git status failure.

Written by the indexing model from the issue text.

Description

area/kernel kind/bug platform/macos
Bug report

Bug description

Running a git status -uno command gives me an error when run inside a docker container:

On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

fatal: detected dubious ownership in repository at '/riscos-source'
To add an exception for this directory, call:

    git config --global --add safe.directory /riscos-source
fatal: detected dubious ownership in repository at '/riscos-source'
To add an exception for this directory, call:

    git config --global --add safe.directory /riscos-source
nothing to commit (use -u to show untracked files)

The container has been mounted with /riscos-source as a bind mount to the user's current working directory on macOS. The user's UID is 502 and GID is 512. There is a user 502 in the container which has been created on entry to the container.

This has worked reliably until recently. Now, we get the above failure.

Running strace -f -v -e trace=stat,newfstatat,lstat -- git status -uno 2> t to get a log of what's being done and then looking at this file we see a number of calls which return different st_uid answers.

I have attached the strace log 't' as 'strace.log'
strace.log

If we just run a grep for the st_uid calls, we see the failure case where the uid was 502... and then in the child process it suddenly starts getting returned as 0:

grep st_uid strace.log | grep '"/riscos-source"'
newfstatat(AT_FDCWD, "/riscos-source", {st_dev=makedev(0, 0x27), st_ino=19, st_mode=S_IFDIR|0775, st_nlink=19, st_uid=502, st_gid=502, st_blksize=4096, st_blocks=0, st_size=608, st_atime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_atime_nsec=175525000, st_mtime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_mtime_nsec=175525000, st_ctime=1788300992 /* 2026-09-01T23:16:32.175569713+0100 */, st_ctime_nsec=175569713}, 0) = 0
newfstatat(AT_FDCWD, "/riscos-source", {st_dev=makedev(0, 0x27), st_ino=19, st_mode=S_IFDIR|0775, st_nlink=19, st_uid=502, st_gid=502, st_blksize=4096, st_blocks=0, st_size=608, st_atime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_atime_nsec=175525000, st_mtime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_mtime_nsec=175525000, st_ctime=1788300992 /* 2026-09-01T23:16:32.175569713+0100 */, st_ctime_nsec=175569713}, 0) = 0
newfstatat(AT_FDCWD, "/riscos-source", {st_dev=makedev(0, 0x27), st_ino=19, st_mode=S_IFDIR|0775, st_nlink=19, st_uid=502, st_gid=502, st_blksize=4096, st_blocks=0, st_size=608, st_atime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_atime_nsec=175525000, st_mtime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_mtime_nsec=175525000, st_ctime=1788300992 /* 2026-09-01T23:16:32.175569713+0100 */, st_ctime_nsec=175569713}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "/riscos-source", {st_dev=makedev(0, 0x27), st_ino=19, st_mode=S_IFDIR|0775, st_nlink=19, st_uid=502, st_gid=502, st_blksize=4096, st_blocks=0, st_size=608, st_atime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_atime_nsec=175525000, st_mtime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_mtime_nsec=175525000, st_ctime=1788300992 /* 2026-09-01T23:16:32.175569713+0100 */, st_ctime_nsec=175569713}, 0) = 0
newfstatat(AT_FDCWD, "/riscos-source", {st_dev=makedev(0, 0x27), st_ino=19, st_mode=S_IFDIR|0775, st_nlink=19, st_uid=502, st_gid=502, st_blksize=4096, st_blocks=0, st_size=608, st_atime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_atime_nsec=175525000, st_mtime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_mtime_nsec=175525000, st_ctime=1788300992 /* 2026-09-01T23:16:32.175569713+0100 */, st_ctime_nsec=175569713}, AT_SYMLINK_NOFOLLOW) = 0
[pid 18206] newfstatat(AT_FDCWD, "/riscos-source", {st_dev=makedev(0, 0x27), st_ino=19, st_mode=S_IFDIR|0775, st_nlink=19, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=608, st_atime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_atime_nsec=175525000, st_mtime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_mtime_nsec=175525000, st_ctime=1788300992 /* 2026-09-01T23:16:32.175569713+0100 */, st_ctime_nsec=175569713}, 0) = 0
[pid 18206] newfstatat(AT_FDCWD, "/riscos-source", {st_dev=makedev(0, 0x27), st_ino=19, st_mode=S_IFDIR|0775, st_nlink=19, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=608, st_atime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_atime_nsec=175525000, st_mtime=1788300992 /* 2026-09-01T23:16:32.175525000+0100 */, st_mtime_nsec=175525000, st_ctime=1788300992 /* 2026-09-01T23:16:32.175569713+0100 */, st_ctime_nsec=175569713}, AT_SYMLINK_NOFOLLOW) = 0

Reproduction steps

I'm not sure that I can give you complete reproduction steps as the environment is a little odd... but I think I have a reproduction that shows it...

On macOS, with a directory (anywhere you like) which is a git repository in place of $PWD/projects/RO/tools/riscos-dumpsprites/

docker run -it --rm -v $PWD/projects/RO/tools/riscos-dumpsprites/:/riscos-source -w /riscos-source --entrypoint /bin/sh -u guest alpine/git

charles@mooncake ~> docker run -it --rm -v $PWD/projects/RO/tools/riscos-dumpsprites/:/riscos-source -w /riscos-source --entrypoint /bin/sh -u guest alpine/git
/riscos-source $ ls
Makefile            ci-vars             res                 riscos_dumpsprites  tests
PLAN.md             project.config      riscos-dumpsprites  riscos_sprites
README.md           pyproject.toml      riscos-sprites      sprites
/riscos-source $ ls -alh
total 76K    
drwxrwxr-x   19 guest    users        608 Sep  1 22:16 .
drwxr-xr-x    1 root     root        4.0K Sep  1 23:02 ..
drwxrwxr-x   15 guest    users        480 Sep  1 22:55 .git
drwxrwxr-x    3 guest    users         96 Aug 23 02:11 .github
-rw-rw-r--    1 guest    users         71 Aug 23 02:11 .gitignore
-rw-rw-r--    1 guest    users       1.7K Aug 23 02:11 .gitlab-ci.yml
-rw-rw-r--    1 guest    users       1.9K Aug 23 02:11 Makefile
-rw-rw-r--    1 guest    users      12.8K Aug 23 02:11 PLAN.md
-rw-rw-r--    1 guest    users       6.3K Aug 23 02:11 README.md
-rwxrwxr-x    1 guest    users      16.9K Aug 23 02:11 ci-vars
-rw-rw-r--    1 guest    users         74 Aug 23 02:11 project.config
-rw-rw-r--    1 guest    users        907 Aug 23 02:11 pyproject.toml
drwxrwxr-x    7 guest    users        224 Aug 31 23:53 res
-rwxrwxr-x    1 guest    users        122 Aug 23 02:11 riscos-dumpsprites
-rwxrwxr-x    1 guest    users        118 Aug 23 02:11 riscos-sprites
drwxrwxr-x    6 guest    users        192 Sep  1 00:27 riscos_dumpsprites
drwxrwxr-x   16 guest    users        512 Sep  1 18:15 riscos_sprites
drwxrwxr-x    8 guest    users        256 Sep  1 18:15 sprites
drwxrwxr-x   12 guest    users        384 Sep  1 18:15 tests
/riscos-source $ git status
fatal: detected dubious ownership in repository at '/riscos-source'
To add an exception for this directory, call:

	git config --global --add safe.directory /riscos-source
/riscos-source $ git status
fatal: detected dubious ownership in repository at '/riscos-source'
To add an exception for this directory, call:

	git config --global --add safe.directory /riscos-source
/riscos-source $ 
Platform

macOS

Version information
charles@mooncake ~ [128]> docker version && docker info
Client:
 Version:           29.7.2
 API version:       1.55
 Go version:        go1.26.5
 Git commit:        a7dcaa6
 Built:             Wed Aug  5 18:27:50 2026
 OS/Arch:           darwin/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.88.1 (237512)
 Engine:
  Version:          29.7.2
  API version:      1.55 (minimum version 1.40)
  Go version:       go1.26.5
  Git commit:       6a43e3d
  Built:            Wed Aug  5 18:28:36 2026
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v2.3.3
  GitCommit:        aad11006b869517fcd3009450b6f82da282e1a9b
 runc:
  Version:          1.4.3
  GitCommit:        v1.4.3-0-gbb14dabe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
Client:
 Version:    29.7.2
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  agent: Docker AI Agent Runner (Docker Inc.)
    Version:  v1.124.0
    Path:     /Users/charles/.docker/cli-plugins/docker-agent
  ai: Docker AI Agent - Ask Gordon (Docker Inc.)
    Version:  v1.30.0
    Path:     /Users/charles/.docker/cli-plugins/docker-ai
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.36.1-desktop.1
    Path:     /Users/charles/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v5.4.0
    Path:     /Users/charles/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.47
    Path:     /Users/charles/.docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Docker Inc.)
    Version:  v0.4.3
    Path:     /Users/charles/.docker/cli-plugins/docker-desktop
  dhi: CLI for managing Docker Hardened Images (Docker Inc.)
    Version:  v0.0.7
    Path:     /Users/charles/.docker/cli-plugins/docker-dhi
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.31
    Path:     /Users/charles/.docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     /Users/charles/.docker/cli-plugins/docker-init
  mcp: Docker MCP Plugin (Docker Inc.)
    Version:  v0.43.3
    Path:     /Users/charles/.docker/cli-plugins/docker-mcp
  offload: Docker Offload (Docker Inc.)
    Version:  v0.6.13
    Path:     /Users/charles/.docker/cli-plugins/docker-offload
  pass: Docker Pass Secrets Manager Plugin (beta) (Docker Inc.)
    Version:  v0.2.1
    Path:     /Users/charles/.docker/cli-plugins/docker-pass
  sandbox: "docker sandbox" is deprecated, use Docker Sandboxes instead (Docker Inc.)
    Version:  v0.13.0
    Path:     /Users/charles/.docker/cli-plugins/docker-sandbox
  scout: Docker Scout (Docker Inc.)
    Version:  v1.24.0
    Path:     /Users/charles/.docker/cli-plugins/docker-scout

Server:
 Containers: 4
  Running: 4
  Paused: 0
  Stopped: 0
 Images: 71
 Server Version: 29.7.2
 Storage Driver: overlayfs
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Discovered Devices:
  cdi: docker.com/gpu=webgpu
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: aad11006b869517fcd3009450b6f82da282e1a9b
 runc version: v1.4.3-0-gbb14dabe
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 7.0.12-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 6
 Total Memory: 7.506GiB
 Name: docker-desktop
 ID: 7347611f-9b0d-41de-94b8-ea5c45d2d8fa
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/charles/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
  ::1/128
 Live Restore Enabled: false
 Firewall Backend: iptables
Diagnostics ID

No response

Dominant language
No language data
Stars
46
Forks
20
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from docker/desktop-feedback

All issues in docker/desktop-feedback

Similar issues

More DevOps issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.