Skip to content

Fix VCS stamping error in containerized builds with Podman#9008

Closed
kaovilai wants to merge 5 commits intovelero-io:mainfrom
kaovilai:fix-podman-vcs-stamping-9004
Closed

Fix VCS stamping error in containerized builds with Podman#9008
kaovilai wants to merge 5 commits intovelero-io:mainfrom
kaovilai:fix-podman-vcs-stamping-9004

Conversation

@kaovilai
Copy link
Copy Markdown
Collaborator

@kaovilai kaovilai commented Jun 6, 2025

Thank you for contributing to Velero!

Please add a summary of your change

This PR fixes VCS stamping errors that occur when using Podman as the container runtime for builds by adding git safe.directory configuration to bypass Git's "dubious ownership" security check.

Root Cause: The mounted repository directory (/github.com/vmware-tanzu/velero) is owned by root:root but files inside are owned by the mapped user, triggering Git's security feature and causing VCS stamping to fail with exit code 128.

Solution:

  • Add .gitconfig file with [safe] directory = /github.com/vmware-tanzu/velero
  • Mount .gitconfig as read-only volume in the shell target: -v "$(pwd)/.gitconfig:/root/.gitconfig:ro"

Testing: Verified that git status, VCS stamping, and make build-linux-amd64 all work correctly after the fix.

Does your change fix a particular issue?

Fixes #9004

Please indicate you've done the following:

@github-actions github-actions Bot requested review from Lyndon-Li and reasonerjt June 6, 2025 18:24
@kaovilai kaovilai force-pushed the fix-podman-vcs-stamping-9004 branch 2 times, most recently from 57e39cd to a093670 Compare June 6, 2025 18:27
@kaovilai kaovilai added the kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes label Jun 6, 2025
@kaovilai kaovilai force-pushed the fix-podman-vcs-stamping-9004 branch from 1ead63b to 584259f Compare June 6, 2025 18:31
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.81%. Comparing base (41a6922) to head (d32f63a).
⚠️ Report is 618 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9008   +/-   ##
=======================================
  Coverage   59.81%   59.81%           
=======================================
  Files         375      375           
  Lines       41056    41056           
=======================================
  Hits        24557    24557           
  Misses      15010    15010           
  Partials     1489     1489           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@reasonerjt reasonerjt requested review from blackpiglet and removed request for reasonerjt June 8, 2025 17:57
@reasonerjt
Copy link
Copy Markdown
Contributor

@blackpiglet Please double-check if the ownership issue only impacts podman. We have resolved something similar in downstream, but why we are not seeing this in upstream?

Comment thread Makefile Outdated
@blackpiglet
Copy link
Copy Markdown
Contributor

@kaovilai
I'm still confused about why this only happened on the Podman environment and only for make all-build CLI.

According to the go build help information, the -buildvsc default value should be auto.
So it seems there should be no difference between docker and podman.

	-buildvcs
		Whether to stamp binaries with version control information
		("true", "false", or "auto"). By default ("auto"), version control
		information is stamped into a binary if the main package, the main module
		containing it, and the current directory are all in the same repository.
		Use -buildvcs=false to always omit version control information, or
		-buildvcs=true to error out if version control information is available but
		cannot be included due to a missing tool or ambiguous directory structure.

@blackpiglet
Copy link
Copy Markdown
Contributor

I just found out golang may set the -buildvcs to true implicitly.
If so, do we rely on the VSC information anyway?

@blackpiglet
Copy link
Copy Markdown
Contributor

@reasonerjt
I just found a closed PR #5938 related to this.
I may not have recalled the downstream fix correctly.
It seems this error happened before, but it was not reproducible, and we didn't fix it.

@kaovilai kaovilai force-pushed the fix-podman-vcs-stamping-9004 branch from 584259f to edeb093 Compare June 9, 2025 18:04
kaovilai added 5 commits June 11, 2025 00:15
This commit addresses issue velero-io#9004 by adding git safe.directory configuration
to fix 'dubious ownership' errors that occur when using Podman as the
container runtime for builds.

The issue was caused by a directory ownership mismatch where the mounted
repository directory (/github.com/vmware-tanzu/velero) is owned by root:root
but the files inside are owned by the mapped user. This triggers Git's
security feature and causes VCS stamping to fail with exit code 128.

Changes:
- Add .gitconfig file with safe.directory configuration for the mounted path
- Mount .gitconfig as read-only volume in the shell target
- This allows Git operations to work properly inside the container

The fix is minimal, targeted, and maintains VCS stamping functionality
while being compatible with both Docker and Podman container runtimes.

Fixes velero-io#9004

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
Clarifies why this configuration is needed to fix the Git 'dubious ownership'
issue that occurs in Podman container environments where the mount point
directory has different ownership than the files inside it.

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
Added comment explaining that this file is mounted as /root/.gitconfig
by the 'shell' target in the Makefile to provide better context for
how this configuration is used in the build process.

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
Updated Makefile to use $HOME/.gitconfig instead of /root/.gitconfig
for better flexibility and to avoid hardcoded paths. Also updated
the comment in .gitconfig to reflect this change.

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
Removed separate .gitconfig mount as the file is already accessible
through the main repository mount at /github.com/vmware-tanzu/velero.
Git automatically finds the configuration file in the working directory.

This approach is simpler, more robust, and avoids any path issues.

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
@kaovilai kaovilai force-pushed the fix-podman-vcs-stamping-9004 branch from b4e10bb to d32f63a Compare June 11, 2025 04:15
@kaovilai kaovilai closed this Apr 8, 2026
@kaovilai kaovilai deleted the fix-podman-vcs-stamping-9004 branch April 8, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure: VCS stamping error in containerized builds (Podman specific)

3 participants