Great suggestion Jason - adding `git status` took me in a very unexpected direction, and ultimately a solution.
tl;dr if your build's base container image does not use root/uid 0, git commands won't work unless you add the `--chown=<uid>` flag to your `COPY` instruction. Go builds need this if you want `-buildvcs=auto|true` to succeed.
When I changed my build command to `RUN git status && go build` in the Dockerfile, I got the following output:
```
$ podman build -t localhost/sclorg/hello-openshift:latest .
[1/2] STEP 1/3: FROM
registry.redhat.io/ubi9/go-toolset:1.20.12 AS builder
[1/2] STEP 2/3: COPY . .
--> 10a13b463199
[1/2] STEP 3/3: RUN git status && go build -o /tmp/hello
fatal: detected dubious ownership in repository at '/opt/app-root/src'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/app-root/src
Error: building at STEP "RUN git status && go build -o /tmp/hello": while running runtime: exit status 128
```
This was a new and different error message for me - but same exit code as before. A quick Google search brought me to CVE-2022-24765 [1], whose fix introduced this "dubious ownership" message/protection.
I was finally able to piece everything together with a few more debug builds and internet searches:
1. On Fedora 39, podman runs in "rootless" mode. Files owned by me show up as owned by "root" in containers.
2. For Linux containers, `COPY` commands in Dockerfiles copy files as UID/GID 0 unless the `--chown` flag is passed. [2].
3. As part of the mitigation for CVE-2022-24765, git commands will succeed only if:
a. The `.git` directory is owned by the same user executing the `.git` command OR
b. The parent directory marked "safe" in the git configuration.
Using `COPY --chown=default . .` instead of `COPY . .` works for the UBI go-toolset image referenced previously in this thread. Your results may vary using other golang "builder" images.