Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #805 +/- ##
==========================================
+ Coverage 54.87% 54.97% +0.10%
==========================================
Files 55 55
Lines 5910 5910
==========================================
+ Hits 3243 3249 +6
+ Misses 2094 2088 -6
Partials 573 573 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
raharper
left a comment
There was a problem hiding this comment.
Thanks for finding this. Can we add a bats test for this one; it certainly seems like we can catch it rewriting the index today with a test case; and then with your change confirm that we no longer update the index.
3dde7fa to
0aca6a2
Compare
raharper
left a comment
There was a problem hiding this comment.
Thanks for updating the go test and adding the bats test. couple more things in the bats test to confirm.
| dest: /payload | ||
| EOF | ||
| give_user_ownership . | ||
| run_as git init -q |
There was a problem hiding this comment.
This might need to use it's own tmpdir directory so it doesn't end up getting interaction with the stacker git dir in which the test is running. see @test "git version annotation matches stackerfile repository" in basic.bats for setting up a TMPDIR separate git repo.
| run_as git -c user.name=test -c user.email=test@example.com commit -qm init | ||
|
|
||
| # Index entries cache the file owner; a refresh inside the userns rewrites it as 0/0. | ||
| owner_before=$(run_as git ls-files --debug payload | grep uid) |
There was a problem hiding this comment.
I'm not sure if on the github runner the user may be "ubuntu" or it might be "root" -- we should verify what the UID/GID of the user is first.
Then where ever we create the git repo for this test, confirm that it's owned by the correct uid/gid/user before running stacker build.
Then, after running stacker build we should print what the uid/gid/user value is, and then expect that it match the user.
If you can; disable the fix and confirm the test catches the failure. Posting a log of that failure as a comment I think is sufficient.
There was a problem hiding this comment.
Fair enough. On local machine I did run the test without the fix and it failed as expected. I missed updating the PR description with that snippet then, updated now.
And yeah, for github CI it makes sense to check the user before the test and verify it after.
During rootless builds, GitVersion runs `git status` inside the user namespace. It refreshes the index as an optional side effect, rewriting the cached uid/gid of every tracked file as 0/0. Host git then sees a stat mismatch and rereads every file. Pass --no-optional-locks so `git status` doesn't write the index. This needs git >= 2.15. test/git-index.bats fails without this change: before: uid: 1003 gid: 1002 after: uid: 0 gid: 0 Signed-off-by: Tanmay Naik <tnaik96@gmail.com>
0aca6a2 to
62a0ff9
Compare
What type of PR is this?
bug
Which issue does this PR fix?
No issue filed. Repro steps are below.
What does this PR do / Why do we need it?
During rootless builds,
GitVersionrunsgit statusinside a user namespace.git statusrefreshes the index as an optional side effect, so it writes the namespace UID/GID (0:0) into the source repo's.git/index. After that, host Git sees a stat mismatch on every tracked file and rereads them, which is slow on large repos. File contents and ownership don't change.This passes
--no-optional-lockstogit statusso it no longer writes the index.-dirtydetection works the same as before.If an issue # is not available please add repro steps and logs showing the issue:
Run as a non-root user:
Testing done on this change:
Ran the repro above with both binaries:
Same-revision rootless builds, clean and dirty:
OCI Git annotations were correct for both clean and dirty builds.
Automation added to e2e:
test/git-index.bats(unprivileged): creates a Git repo and checks that the build user owns the committed file, then runs a rootlessstacker build -f, and checks two things: the file's cached uid/gid in the index still matches the file's real owner, and the hash of.git/indexis unchanged.TestGitVersionPreservesIndex, plus a control test,TestGitStatusRefreshesStaleIndex, which shows that plaingit statusdoes rewrite a stale index.Without the fix:
With the fix:
Will this break upgrades or downgrades?
No. No image format, config, or CLI changes.
Does this PR introduce any user-facing change?
Yes, a bug fix.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.