setup: trace bare repository setups
PATCH 1/1 setup: trace bare repository setups
From: Glen Choo <[email protected]>
safe.bareRepository=explicit is a safer default mode of operation, since it guards against the embedded bare repository attack [1]. Most end users don't use bare repositories directly, so they should be able to set safe.bareRepository=explicit, with the expectation that they can reenable bare repositories by specifying GIT_DIR or --git-dir.
However, the user might use a tool that invokes Git on bare repositories without setting GIT_DIR (e.g. "go mod" will clone bare repositories [2]), so even if a user wanted to use safe.bareRepository=explicit, it wouldn't be feasible until their tools learned to set GIT_DIR.
To make this transition easier, add a trace message to note when we attempt to set up a bare repository without setting GIT_DIR. This allows users and tool developers to audit which of their tools are problematic and report/fix the issue. When they are sufficiently confident, they would switch over to "safe.bareRepository=explicit".
Note that this uses trace2_data_string(), which isn't supported by the "normal" GIT_TRACE2 target, only _EVENT or _PERF.
[1] https://lore.kernel.org/git/[email protected]/
[2] https://go.dev/ref/mod
--- setup.c | 1 + t/t0035-safe-bare-repository.sh | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-)
setup.c +1 -0
@@ -1352,6 +1352,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, }if (is_git_directory (dir->buf)) { +trace2_data_string ("setup" ,NULL ,"implicit-bare-repository" , dir->buf);if (get_allowed_bare_repo () ==ALLOWED_BARE_REPO_EXPLICIT )return GIT_DIR_DISALLOWED_BARE ;if (!ensure_valid_ownership (NULL ,NULL , dir->buf, report))
t/t0035-safe-bare-repository.sh +22 -7
@@ -7,13 +7,24 @@ TEST_PASSES_SANITIZE_LEAK=true pwd="$(pwd)" -expect_accepted () { - git "$@" rev-parse --git-dir +expect_accepted_implicit () { + test_when_finished "rm \"$pwd/trace.perf\"" && + GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" +} + +expect_accepted_explicit () { + test_when_finished "rm \"$pwd/trace.perf\"" && + GIT_DIR="$@" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir && + ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" } expect_rejected () { - test_must_fail git "$@" rev-parse --git-dir 2>err && - grep -F "cannot use bare repository" err + test_when_finished "rm \"$pwd/trace.perf\"" && + test_env GIT_TRACE2_PERF="$pwd/trace.perf" \ + test_must_fail git "$@" rev-parse --git-dir 2>err && + grep -F "cannot use bare repository" err && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" } test_expect_success 'setup bare repo in worktree' '
@@ -22,12 +33,12 @@ test_expect_success 'setup bare repo in worktree' ' ' test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo ' test_expect_success 'safe.bareRepository=all' ' test_config_global safe.bareRepository all && - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo ' test_expect_success 'safe.bareRepository=explicit' '
@@ -47,7 +58,7 @@ test_expect_success 'safe.bareRepository in the repository' ' test_expect_success 'safe.bareRepository on the command line' ' test_config_global safe.bareRepository explicit && - expect_accepted -C outer-repo/bare-repo \ + expect_accepted_implicit -C outer-repo/bare-repo \ -c safe.bareRepository=all '
@@ -60,4 +71,8 @@ test_expect_success 'safe.bareRepository in included file' ' expect_rejected -C outer-repo/bare-repo ' +test_expect_success 'no trace when GIT_DIR is explicitly provided' ' + expect_accepted_explicit "$pwd/outer-repo/bare-repo" +' + test_done
base-commit: 2807bd2c10606e590886543afe4e4f208dddd489
Signature · 1 line
2.40.1.495.gc816e09b53d-goog
setup.c static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, · line 1358
Quoted 12 lines · Josh Steadmon
setup.c +1
-0@@ -1352,6 +1352,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, }if (is_git_directory (dir->buf)) { +trace2_data_string ("setup" ,NULL ,"implicit-bare-repository" , dir->buf);if (get_allowed_bare_repo () ==ALLOWED_BARE_REPO_EXPLICIT )return GIT_DIR_DISALLOWED_BARE ;if (!ensure_valid_ownership (NULL ,NULL , dir->buf, report))
That is kind of obvious.
t/t0035-safe-bare-repository.sh TEST_PASSES_SANITIZE_LEAK=true · line 11
Quoted 12 lines
t/t0035-safe-bare-repository.sh +2
-2@@ -7,13 +7,24 @@ TEST_PASSES_SANITIZE_LEAK=true pwd="$(pwd)" -expect_accepted () { - git "$@" rev-parse --git-dir +expect_accepted_implicit () { + test_when_finished "rm \"$pwd/trace.perf\"" &&
Why not
test_when_finished 'rm "$pwd/trace.perf"' &&
instead?
In your version, $pwd is expanded before test_when_finished sees it, so you'd have to worry about things like backslashes and double quotes in it. You can of course quote the '$' like so
test_when_finished "rm \"\$pwd/trace.perf\"" &&
to work it around, but it is equivalent to enclosing everything inside a pair of single quotes. Either way your $pwd will be interpolated when "eval" sees the $test_cleanup script.
And it would be much easier to read without backslash and backslashed double quotes.
t/t0035-safe-bare-repository.sh TEST_PASSES_SANITIZE_LEAK=true · line 14
Quoted 3 lines
t/t0035-safe-bare-repository.sh +3
-0+ GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" +}
We ensure that we positively have such a trace in the output. Good.
t/t0035-safe-bare-repository.sh TEST_PASSES_SANITIZE_LEAK=true · line 20
Quoted 5 lines
t/t0035-safe-bare-repository.sh +4
-0+expect_accepted_explicit () { + test_when_finished "rm \"$pwd/trace.perf\"" && + GIT_DIR="$@" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir && + ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" }
When not asking for the magic behaviour of "$@" and instead doing a "squash everything into a single string, using the first letter in $IFS as the separator in between", please write "$*" instead.
GIT_DIR="$*" GIT_TRACE2_PERF="..." git rev-parse --git-dir
But in this case, I do not think you are ever planning to send a directory name split into two or more, to be concatenated with SP, so writing it like
GIT_DIR="$1" GIT_TRACE2_PERF="..." git rev-parse --git-dir
would be much less error prone and easier to follow, I think.
t/t0035-safe-bare-repository.sh test_expect_success 'setup bare repo in worktree' ' · line 37
Quoted 7 lines
t/t0035-safe-bare-repository.sh +1
-1@@ -22,12 +33,12 @@ test_expect_success 'setup bare repo in worktree' ' ' test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo '
Perhaps futureproof this test piece by explicitly unsetting the variable before starting the test? That way, this piece will not be broken even if earlier tests gets modified to set some value to safe.bareRepository in the future.
Quoted 17 lines
t/t0035-safe-bare-repository.sh +2
-2test_expect_success 'safe.bareRepository=all' ' test_config_global safe.bareRepository all && - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo ' test_expect_success 'safe.bareRepository=explicit' '@@ -47,7 +58,7 @@ test_expect_success 'safe.bareRepository in the repository' ' test_expect_success 'safe.bareRepository on the command line' ' test_config_global safe.bareRepository explicit && - expect_accepted -C outer-repo/bare-repo \ + expect_accepted_implicit -C outer-repo/bare-repo \ -c safe.bareRepository=all '
t/t0035-safe-bare-repository.sh test_expect_success 'safe.bareRepository in included file' ' · line 78
Quoted 8 lines
t/t0035-safe-bare-repository.sh +4
-0@@ -60,4 +71,8 @@ test_expect_success 'safe.bareRepository in included file' ' expect_rejected -C outer-repo/bare-repo ' +test_expect_success 'no trace when GIT_DIR is explicitly provided' ' + expect_accepted_explicit "$pwd/outer-repo/bare-repo" +' + test_done
All the expectations look sensible. Thanks for a pleasant read.
Quoted 108 lines · Junio C Hamano
setup.c static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, · line 1358
Quoted 12 lines · Josh Steadmon
setup.c +1
-0@@ -1352,6 +1352,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, }if (is_git_directory (dir->buf)) { +trace2_data_string ("setup" ,NULL ,"implicit-bare-repository" , dir->buf);if (get_allowed_bare_repo () ==ALLOWED_BARE_REPO_EXPLICIT )return GIT_DIR_DISALLOWED_BARE ;if (!ensure_valid_ownership (NULL ,NULL , dir->buf, report))That is kind of obvious.
t/t0035-safe-bare-repository.sh TEST_PASSES_SANITIZE_LEAK=true · line 11
Quoted 12 lines
t/t0035-safe-bare-repository.sh +2
-2@@ -7,13 +7,24 @@ TEST_PASSES_SANITIZE_LEAK=true pwd="$(pwd)" -expect_accepted () { - git "$@" rev-parse --git-dir +expect_accepted_implicit () { + test_when_finished "rm \"$pwd/trace.perf\"" &&Why not
test_when_finished 'rm "$pwd/trace.perf"' &&instead?
In your version, $pwd is expanded before
test_when_finishedsees it, so you'd have to worry about things like backslashes and double quotes in it. You can of course quote the '$' like sotest_when_finished "rm \"\$pwd/trace.perf\"" &&to work it around, but it is equivalent to enclosing everything inside a pair of single quotes. Either way your $pwd will be interpolated when "eval" sees the $test_cleanup script.
And it would be much easier to read without backslash and backslashed double quotes.
t/t0035-safe-bare-repository.sh TEST_PASSES_SANITIZE_LEAK=true · line 14
Quoted 3 lines
t/t0035-safe-bare-repository.sh +3
-0+ GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" +}We ensure that we positively have such a trace in the output. Good.
t/t0035-safe-bare-repository.sh TEST_PASSES_SANITIZE_LEAK=true · line 20
Quoted 5 lines
t/t0035-safe-bare-repository.sh +4
-0+expect_accepted_explicit () { + test_when_finished "rm \"$pwd/trace.perf\"" && + GIT_DIR="$@" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir && + ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" }When not asking for the magic behaviour of "$@" and instead doing a "squash everything into a single string, using the first letter in $IFS as the separator in between", please write "$*" instead.
GIT_DIR="$*" GIT_TRACE2_PERF="..." git rev-parse --git-dirBut in this case, I do not think you are ever planning to send a directory name split into two or more, to be concatenated with SP, so writing it like
GIT_DIR="$1" GIT_TRACE2_PERF="..." git rev-parse --git-dirwould be much less error prone and easier to follow, I think.
t/t0035-safe-bare-repository.sh test_expect_success 'setup bare repo in worktree' ' · line 37
Quoted 7 lines
t/t0035-safe-bare-repository.sh +1
-1@@ -22,12 +33,12 @@ test_expect_success 'setup bare repo in worktree' ' ' test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo 'Perhaps futureproof this test piece by explicitly unsetting the variable before starting the test? That way, this piece will not be broken even if earlier tests gets modified to set some value to safe.bareRepository in the future.
Quoted 20 lines
t/t0035-safe-bare-repository.sh +2
-2test_expect_success 'safe.bareRepository=all' ' test_config_global safe.bareRepository all && - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo ' test_expect_success 'safe.bareRepository=explicit' '@@ -47,7 +58,7 @@ test_expect_success 'safe.bareRepository in the repository' ' test_expect_success 'safe.bareRepository on the command line' ' test_config_global safe.bareRepository explicit && - expect_accepted -C outer-repo/bare-repo \ + expect_accepted_implicit -C outer-repo/bare-repo \ -c safe.bareRepository=all '@@ -60,4 +71,8 @@ test_expect_success 'safe.bareRepository in included file' ' expect_rejected -C outer-repo/bare-repo '
Quoted 7 lines
t/t0035-safe-bare-repository.sh test_expect_success 'safe.bareRepository in included file' ' · line 78
Quoted 5 lines
t/t0035-safe-bare-repository.sh +4
-0+test_expect_success 'no trace when GIT_DIR is explicitly provided' ' + expect_accepted_explicit "$pwd/outer-repo/bare-repo" +' + test_doneAll the expectations look sensible. Thanks for a pleasant read.
Agreed with all the feedback points, will fix in V2. Thanks!
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Josh Steadmon
(quoted diff) +0
-0@@ -22,12 +33,12 @@ test_expect_success 'setup bare repo in worktree' ' '
Quoted 9 lines
t/t0035-safe-bare-repository.sh test_expect_success 'setup bare repo in worktree' ' · line 37
Quoted 4 lines
t/t0035-safe-bare-repository.sh +1
-1test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo 'Perhaps futureproof this test piece by explicitly unsetting the variable before starting the test? That way, this piece will not be broken even if earlier tests gets modified to set some value to safe.bareRepository in the future.
Actually, explicitly setting the variable here is equivalent to the following test case, so I'll just remove this one.
Quoted 16 lines · Josh Steadmon
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Josh Steadmon
(quoted diff) +0
-0@@ -22,12 +33,12 @@ test_expect_success 'setup bare repo in worktree' ' 'Quoted 9 lines
t/t0035-safe-bare-repository.sh test_expect_success 'setup bare repo in worktree' ' · line 37
Quoted 4 lines
t/t0035-safe-bare-repository.sh +1
-1test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo 'Perhaps futureproof this test piece by explicitly unsetting the variable before starting the test? That way, this piece will not be broken even if earlier tests gets modified to set some value to safe.bareRepository in the future.
Quoted 2 lines
Actually, explicitly setting the variable here is equivalent to the following test case, so I'll just remove this one.
I meant explicitly UNsetting, though?
Quoted 18 lines · Junio C Hamano
Quoted 16 lines · Josh Steadmon
Quoted 14 lines · Junio C Hamano
t/t0035-safe-bare-repository.sh test_expect_success 'setup bare repo in worktree' ' · line 37
Quoted 7 lines · Josh Steadmon
t/t0035-safe-bare-repository.sh +1
-1@@ -22,12 +33,12 @@ test_expect_success 'setup bare repo in worktree' ' ' test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo 'Perhaps futureproof this test piece by explicitly unsetting the variable before starting the test? That way, this piece will not be broken even if earlier tests gets modified to set some value to safe.bareRepository in the future.
Quoted 4 lines
Quoted 2 lines
Actually, explicitly setting the variable here is equivalent to the following test case, so I'll just remove this one.
I meant explicitly UNsetting, though?
Ah, sorry for misunderstanding. I've restored the test along with a test_unconfig line for V3; however, doesn't this just turn into a "change detector" test whose only purpose will be to fail if/when we change the default value for this config option?
Quoted 4 lines · Josh Steadmon
Ah, sorry for misunderstanding. I've restored the test along with a
test_unconfigline for V3; however, doesn't this just turn into a "change detector" test whose only purpose will be to fail if/when we change the default value for this config option?
Maybe a difference in opinion: "change detection" sounds like non-essential changes to program behavior can cause a test to fail, but default value handling seems quite essential to me. Not to mention that default value handling is easy to break, so IMO guarding against accidental regressions is pretty useful.
As for practical churn, I don't expect that we'll intentionally change this default often.
Quoted 1 line · Josh Steadmon
From: Glen Choo <[email protected]>
I can confirm that I did write an initial version of this, which Josh cleaned up for the mailing list (thanks!). Most, if not all, of the mistakes are originally mine.
Quoted 5 lines
To make this transition easier, add a trace message to note when we attempt to set up a bare repository without setting
GIT_DIR. This allows users and tool developers to audit which of their tools are problematic and report/fix the issue. When they are sufficiently confident, they would switch over to "safe.bareRepository=explicit".
One alternative to this is to trace all of the repository setup process. E.g. if we traced the data points in t/t1510-repo-setup.sh, like GIT_DIR and whether the repository is bare, you could reverse-engineer whether we've hit the "set up a bare repository without GIT_DIR" case, but that's significantly more complicated. If the goal of this patch is to make it easy for users, tool developers and sysadmins to see if "safe.bareRepository=explicit" might be tripped, giving a single, meaningful event is much easier way to get there.
It would be nice to trace all of the repo setup eventually, anyway, and I don't think this change precludes that.
Quoted 1 line
Change-Id: I8e8b5e70ce8c6c81ec4716187c27c44da38b35db
Leftover from Gerrit, perhaps?
Unsurprisingly, I don't have comments on the diff, at least not anything that Junio hasn't already spotted.
Quoted 26 lines · Glen Choo
Quoted 1 line · Josh Steadmon
From: Glen Choo <[email protected]>
I can confirm that I did write an initial version of this, which Josh cleaned up for the mailing list (thanks!). Most, if not all, of the mistakes are originally mine.
Quoted 5 lines
To make this transition easier, add a trace message to note when we attempt to set up a bare repository without setting
GIT_DIR. This allows users and tool developers to audit which of their tools are problematic and report/fix the issue. When they are sufficiently confident, they would switch over to "safe.bareRepository=explicit".One alternative to this is to trace all of the repository setup process. E.g. if we traced the data points in
t/t1510-repo-setup.sh, likeGIT_DIRand whether the repository is bare, you could reverse-engineer whether we've hit the "set up a bare repository withoutGIT_DIR" case, but that's significantly more complicated. If the goal of this patch is to make it easy for users, tool developers and sysadmins to see if "safe.bareRepository=explicit" might be tripped, giving a single, meaningful event is much easier way to get there.It would be nice to trace all of the repo setup eventually, anyway, and I don't think this change precludes that.
Quoted 6 lines
Quoted 1 line
Change-Id: I8e8b5e70ce8c6c81ec4716187c27c44da38b35db
Leftover from Gerrit, perhaps?
Unsurprisingly, I don't have comments on the diff, at least not anything that Junio hasn't already spotted.
Whoops, thanks for the catch. It would seem my send-email workflow broke somehow while I was away from work. I also had a comment explaining why I was sending this out for you, which somehow got dropped.
PATCH v2 1/1 setup: trace bare repository setups
In reply to Josh SteadmonFrom: Glen Choo <[email protected]>
safe.bareRepository=explicit is a safer default mode of operation, since it guards against the embedded bare repository attack [1]. Most end users don't use bare repositories directly, so they should be able to set safe.bareRepository=explicit, with the expectation that they can reenable bare repositories by specifying GIT_DIR or --git-dir.
However, the user might use a tool that invokes Git on bare repositories without setting GIT_DIR (e.g. "go mod" will clone bare repositories [2]), so even if a user wanted to use safe.bareRepository=explicit, it wouldn't be feasible until their tools learned to set GIT_DIR.
To make this transition easier, add a trace message to note when we attempt to set up a bare repository without setting GIT_DIR. This allows users and tool developers to audit which of their tools are problematic and report/fix the issue. When they are sufficiently confident, they would switch over to "safe.bareRepository=explicit".
Note that this uses trace2_data_string(), which isn't supported by the "normal" GIT_TRACE2 target, only _EVENT or _PERF.
[1] https://lore.kernel.org/git/[email protected]/
[2] https://go.dev/ref/mod
---
I'm sending a lightly-adapted version of Glen's tracing patch because Glen will be on vacation next week and we'd like to get this upstream ASAP.
Cleaned up some test-style issues since V1.
Range-diff against v1:
1: cb72bca46c ! 1: b548d96db7 setup: trace bare repository setups
@@ t/t0035-safe-bare-repository.sh: TEST_PASSES_SANITIZE_LEAK=true
-expect_accepted () {
- git "$@" rev-parse --git-dir
+expect_accepted_implicit () {
-+ test_when_finished "rm \"$pwd/trace.perf\"" &&
++ test_when_finished 'rm "$pwd/trace.perf"' &&
+ GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir &&
+ grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf"
+}
+
+expect_accepted_explicit () {
-+ test_when_finished "rm \"$pwd/trace.perf\"" &&
-+ GIT_DIR="$@" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir &&
++ test_when_finished 'rm "$pwd/trace.perf"' &&
++ GIT_DIR="$1" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir &&
+ ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf"
}
expect_rejected () {
- test_must_fail git "$@" rev-parse --git-dir 2>err &&
- grep -F "cannot use bare repository" err
-+ test_when_finished "rm \"$pwd/trace.perf\"" &&
++ test_when_finished 'rm "$pwd/trace.perf"' &&
+ test_env GIT_TRACE2_PERF="$pwd/trace.perf" \
+ test_must_fail git "$@" rev-parse --git-dir 2>err &&
+ grep -F "cannot use bare repository" err &&
@@ t/t0035-safe-bare-repository.sh: TEST_PASSES_SANITIZE_LEAK=true
test_expect_success 'setup bare repo in worktree' '
@@ t/t0035-safe-bare-repository.sh: test_expect_success 'setup bare repo in worktree' '
+ git init --bare outer-repo/bare-repo
'
- test_expect_success 'safe.bareRepository unset' '
+-test_expect_success 'safe.bareRepository unset' '
- expect_accepted -C outer-repo/bare-repo
-+ expect_accepted_implicit -C outer-repo/bare-repo
- '
-
+-'
+-
test_expect_success 'safe.bareRepository=all' '
test_config_global safe.bareRepository all &&
- expect_accepted -C outer-repo/bare-reposetup.c | 1 + t/t0035-safe-bare-repository.sh | 31 +++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-)
setup.c +1 -0
@@ -1352,6 +1352,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, }if (is_git_directory (dir->buf)) { +trace2_data_string ("setup" ,NULL ,"implicit-bare-repository" , dir->buf);if (get_allowed_bare_repo () ==ALLOWED_BARE_REPO_EXPLICIT )return GIT_DIR_DISALLOWED_BARE ;if (!ensure_valid_ownership (NULL ,NULL , dir->buf, report))
t/t0035-safe-bare-repository.sh +21 -10
@@ -7,13 +7,24 @@ TEST_PASSES_SANITIZE_LEAK=true pwd="$(pwd)" -expect_accepted () { - git "$@" rev-parse --git-dir +expect_accepted_implicit () { + test_when_finished 'rm "$pwd/trace.perf"' && + GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" +} + +expect_accepted_explicit () { + test_when_finished 'rm "$pwd/trace.perf"' && + GIT_DIR="$1" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir && + ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" } expect_rejected () { - test_must_fail git "$@" rev-parse --git-dir 2>err && - grep -F "cannot use bare repository" err + test_when_finished 'rm "$pwd/trace.perf"' && + test_env GIT_TRACE2_PERF="$pwd/trace.perf" \ + test_must_fail git "$@" rev-parse --git-dir 2>err && + grep -F "cannot use bare repository" err && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" } test_expect_success 'setup bare repo in worktree' '
@@ -21,13 +32,9 @@ test_expect_success 'setup bare repo in worktree' ' git init --bare outer-repo/bare-repo ' -test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo -' - test_expect_success 'safe.bareRepository=all' ' test_config_global safe.bareRepository all && - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo ' test_expect_success 'safe.bareRepository=explicit' '
@@ -47,7 +54,7 @@ test_expect_success 'safe.bareRepository in the repository' ' test_expect_success 'safe.bareRepository on the command line' ' test_config_global safe.bareRepository explicit && - expect_accepted -C outer-repo/bare-repo \ + expect_accepted_implicit -C outer-repo/bare-repo \ -c safe.bareRepository=all '
@@ -60,4 +67,8 @@ test_expect_success 'safe.bareRepository in included file' ' expect_rejected -C outer-repo/bare-repo ' +test_expect_success 'no trace when GIT_DIR is explicitly provided' ' + expect_accepted_explicit "$pwd/outer-repo/bare-repo" +' + test_done
base-commit: 2807bd2c10606e590886543afe4e4f208dddd489
Signature · 1 line
2.40.1.495.gc816e09b53d-goog
Quoted 11 lines · Josh Steadmon
t/t0035-safe-bare-repository.sh +1
-2@@ -7,13 +7,24 @@ TEST_PASSES_SANITIZE_LEAK=true pwd="$(pwd)" -expect_accepted () { - git "$@" rev-parse --git-dir +expect_accepted_implicit () {
t/t0035-safe-bare-repository.sh TEST_PASSES_SANITIZE_LEAK=true · line 20
Quoted 10 lines
t/t0035-safe-bare-repository.sh +9
-0+ test_when_finished 'rm "$pwd/trace.perf"' && + GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" +} + +expect_accepted_explicit () { + test_when_finished 'rm "$pwd/trace.perf"' && + GIT_DIR="$1" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir && + ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" }
(Not new in v2) This wasn't obvious to me at first, but
grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf"
looks like it's asserting that we trace that the bare repository is $pwd, but it's actually only asserting that is starts with $pwd. If it might trip up other reasers, a comment here would be helpful.
t/t0035-safe-bare-repository.sh test_expect_success 'setup bare repo in worktree' ' · line 27
Quoted 8 lines
t/t0035-safe-bare-repository.sh +0
-4@@ -21,13 +32,9 @@ test_expect_success 'setup bare repo in worktree' ' git init --bare outer-repo/bare-repo ' -test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo -' -
I found this surprising; I thought it was quite valuable to test the default behavior. I'd prefer to keep this test.
Perhaps there was a miscommunication? You mentioned:
Actually, explicitly setting the variable here is equivalent to the following test case, so I'll just remove this one.
which is true, but I think Junio meant _un_setting the variable, something like:
test_expect_success 'safe.bareRepository unset' '
+ test_unconfig --global safe.bareRepository &&
expect_accepted -C outer-repo/bare-repo
'
Quoted 26 lines · Glen Choo
Quoted 11 lines · Josh Steadmon
t/t0035-safe-bare-repository.sh +1
-2@@ -7,13 +7,24 @@ TEST_PASSES_SANITIZE_LEAK=true pwd="$(pwd)" -expect_accepted () { - git "$@" rev-parse --git-dir +expect_accepted_implicit () {t/t0035-safe-bare-repository.sh TEST_PASSES_SANITIZE_LEAK=true · line 20
Quoted 10 lines
t/t0035-safe-bare-repository.sh +9
-0+ test_when_finished 'rm "$pwd/trace.perf"' && + GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" +} + +expect_accepted_explicit () { + test_when_finished 'rm "$pwd/trace.perf"' && + GIT_DIR="$1" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir && + ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" }(Not new in v2) This wasn't obvious to me at first, but
Quoted 5 lines
grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf"
looks like it's asserting that we trace that the bare repository is $pwd, but it's actually only asserting that is starts with $pwd. If it might trip up other reasers, a comment here would be helpful.
Added a note in V3.
Quoted 17 lines
t/t0035-safe-bare-repository.sh test_expect_success 'setup bare repo in worktree' ' · line 27
Quoted 8 lines
t/t0035-safe-bare-repository.sh +0
-4@@ -21,13 +32,9 @@ test_expect_success 'setup bare repo in worktree' ' git init --bare outer-repo/bare-repo ' -test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo -' -I found this surprising; I thought it was quite valuable to test the default behavior. I'd prefer to keep this test.
Perhaps there was a miscommunication? You mentioned:
Actually, explicitly setting the variable here is equivalent to the following test case, so I'll just remove this one.
Quoted 7 lines
which is true, but I think Junio meant
_un_settingthe variable, something like:
test_expect_success'safe.bareRepository unset' '
+test_unconfig--global safe.bareRepository &&
expect_accepted-C outer-repo/bare-repo
'
Yeah, misunderstood. However, see my reply to Junio about this being a "change detector" test.
PATCH v3 1/1 setup: trace bare repository setups
In reply to Josh SteadmonFrom: Glen Choo <[email protected]>
safe.bareRepository=explicit is a safer default mode of operation, since it guards against the embedded bare repository attack [1]. Most end users don't use bare repositories directly, so they should be able to set safe.bareRepository=explicit, with the expectation that they can reenable bare repositories by specifying GIT_DIR or --git-dir.
However, the user might use a tool that invokes Git on bare repositories without setting GIT_DIR (e.g. "go mod" will clone bare repositories [2]), so even if a user wanted to use safe.bareRepository=explicit, it wouldn't be feasible until their tools learned to set GIT_DIR.
To make this transition easier, add a trace message to note when we attempt to set up a bare repository without setting GIT_DIR. This allows users and tool developers to audit which of their tools are problematic and report/fix the issue. When they are sufficiently confident, they would switch over to "safe.bareRepository=explicit".
Note that this uses trace2_data_string(), which isn't supported by the "normal" GIT_TRACE2 target, only _EVENT or _PERF.
[1] https://lore.kernel.org/git/[email protected]/
[2] https://go.dev/ref/mod
---
I'm sending a lightly-adapted version of Glen's tracing patch because Glen will be on vacation next week and we'd like to get this upstream ASAP.
Changes in V3: added a test_unconfig test case for safe.bareRepository Changes in V2: cleaned up test-style issues.
Range-diff against v2:
1: b548d96db7 ! 1: e98be8e7f7 setup: trace bare repository setups
@@ t/t0035-safe-bare-repository.sh: TEST_PASSES_SANITIZE_LEAK=true
+expect_accepted_implicit () {
+ test_when_finished 'rm "$pwd/trace.perf"' &&
+ GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir &&
++ # Note: we're intentionally only checking that the bare repo has a
++ # directory *prefix* of $pwd
+ grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf"
+}
+
@@ t/t0035-safe-bare-repository.sh: TEST_PASSES_SANITIZE_LEAK=true
test_expect_success 'setup bare repo in worktree' '
@@ t/t0035-safe-bare-repository.sh: test_expect_success 'setup bare repo in worktree' '
- git init --bare outer-repo/bare-repo
'
--test_expect_success 'safe.bareRepository unset' '
+ test_expect_success 'safe.bareRepository unset' '
- expect_accepted -C outer-repo/bare-repo
--'
--
++ test_unconfig --global safe.bareRepository &&
++ expect_accepted_implicit -C outer-repo/bare-repo
+ '
+
test_expect_success 'safe.bareRepository=all' '
test_config_global safe.bareRepository all &&
- expect_accepted -C outer-repo/bare-repo
setup.c | 1 + t/t0035-safe-bare-repository.sh | 32 +++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-)
setup.c +1 -0
@@ -1352,6 +1352,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, }if (is_git_directory (dir->buf)) { +trace2_data_string ("setup" ,NULL ,"implicit-bare-repository" , dir->buf);if (get_allowed_bare_repo () ==ALLOWED_BARE_REPO_EXPLICIT )return GIT_DIR_DISALLOWED_BARE ;if (!ensure_valid_ownership (NULL ,NULL , dir->buf, report))
t/t0035-safe-bare-repository.sh +25 -7
@@ -7,13 +7,26 @@ TEST_PASSES_SANITIZE_LEAK=true pwd="$(pwd)" -expect_accepted () { - git "$@" rev-parse --git-dir +expect_accepted_implicit () { + test_when_finished 'rm "$pwd/trace.perf"' && + GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir && + # Note: we're intentionally only checking that the bare repo has a + # directory *prefix* of $pwd + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" +} + +expect_accepted_explicit () { + test_when_finished 'rm "$pwd/trace.perf"' && + GIT_DIR="$1" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir && + ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" } expect_rejected () { - test_must_fail git "$@" rev-parse --git-dir 2>err && - grep -F "cannot use bare repository" err + test_when_finished 'rm "$pwd/trace.perf"' && + test_env GIT_TRACE2_PERF="$pwd/trace.perf" \ + test_must_fail git "$@" rev-parse --git-dir 2>err && + grep -F "cannot use bare repository" err && + grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf" } test_expect_success 'setup bare repo in worktree' '
@@ -22,12 +35,13 @@ test_expect_success 'setup bare repo in worktree' ' ' test_expect_success 'safe.bareRepository unset' ' - expect_accepted -C outer-repo/bare-repo + test_unconfig --global safe.bareRepository && + expect_accepted_implicit -C outer-repo/bare-repo ' test_expect_success 'safe.bareRepository=all' ' test_config_global safe.bareRepository all && - expect_accepted -C outer-repo/bare-repo + expect_accepted_implicit -C outer-repo/bare-repo ' test_expect_success 'safe.bareRepository=explicit' '
@@ -47,7 +61,7 @@ test_expect_success 'safe.bareRepository in the repository' ' test_expect_success 'safe.bareRepository on the command line' ' test_config_global safe.bareRepository explicit && - expect_accepted -C outer-repo/bare-repo \ + expect_accepted_implicit -C outer-repo/bare-repo \ -c safe.bareRepository=all '
@@ -60,4 +74,8 @@ test_expect_success 'safe.bareRepository in included file' ' expect_rejected -C outer-repo/bare-repo ' +test_expect_success 'no trace when GIT_DIR is explicitly provided' ' + expect_accepted_explicit "$pwd/outer-repo/bare-repo" +' + test_done
base-commit: 2807bd2c10606e590886543afe4e4f208dddd489
Signature · 1 line
2.40.1.495.gc816e09b53d-goog
Quoted 27 lines · Josh Steadmon
From: Glen Choo <[email protected]>
safe.bareRepository=explicit is a safer default mode of operation, since it guards against the embedded bare repository attack [1]. Most end users don't use bare repositories directly, so they should be able to set safe.bareRepository=explicit, with the expectation that they can reenable bare repositories by specifying
GIT_DIRor --git-dir.However, the user might use a tool that invokes Git on bare repositories without setting
GIT_DIR(e.g. "go mod" will clone bare repositories [2]), so even if a user wanted to use safe.bareRepository=explicit, it wouldn't be feasible until their tools learned to setGIT_DIR.To make this transition easier, add a trace message to note when we attempt to set up a bare repository without setting
GIT_DIR. This allows users and tool developers to audit which of their tools are problematic and report/fix the issue. When they are sufficiently confident, they would switch over to "safe.bareRepository=explicit".Note that this uses
trace2_data_string(), which isn't supported by the "normal"GIT_TRACE2target, only_EVENTor_PERF.[1] https://lore.kernel.org/git/[email protected]/
[2] https://go.dev/ref/modSigned-off-by Glen Choo <[email protected]>Signed-off-by Josh Steadmon <[email protected]>
Quoted 7 lines
---
I'm sending a lightly-adapted version of Glen's tracing patch because Glen will be on vacation next week and we'd like to get this upstream ASAP.Changes in V3: added a
test_unconfigtest case for safe.bareRepository Changes in V2: cleaned up test-style issues.
Thanks. We saw no interest on the list in reviewing this patch further, it seems, but I didn't see anything glaringly wrong, see no reason not to merge it, and this should help noticing potential issues by $corp folks, I would presume, so let's merge it as-is.
Quoted 4 lines · Junio C Hamano
Thanks. We saw no interest on the list in reviewing this patch further, it seems, but I didn't see anything glaringly wrong, see no reason not to merge it, and this should help noticing potential issues by $corp folks, I would presume, so let's merge it as-is.
I took a look through this thread and would be fine to see this one picked up, though I did have a couple of questions:
- Is the plan to eventually disable $GIT_DIR discovery in bare repositories by default in a future version? I am still uncertain of the assumption that most end-users don't interact with bare repositories directly.
Certainly forges touch bare repositories without always setting $GIT_DIR in their environment. But I would imagine that other tools indirectly touch bare repositories on behalf of the user. You mentioned "go" as one such tool that doesn't set $GIT_DIR, I imagine there are many more.
- If it is the plan to disable $GIT_DIR discovery in bare repositories in the future, I'm not sure how visible the extra trace line would be. Perhaps that is desirable, since having an advise() call on every Git invocation in a bare repository would be noisy.
Thanks,
Taylor
Quoted 6 lines · Taylor Blau
Quoted 4 lines · Junio C Hamano
Thanks. We saw no interest on the list in reviewing this patch further, it seems, but I didn't see anything glaringly wrong, see no reason not to merge it, and this should help noticing potential issues by $corp folks, I would presume, so let's merge it as-is.
Quoted 7 lines
I took a look through this thread and would be fine to see this one picked up, though I did have a couple of questions:
- Is the plan to eventually disable $GIT_DIR discovery in bare repositories by default in a future version? I am still uncertain of the assumption that most end-users don't interact with bare repositories directly.
I think at some point in the future, we'd like for safe.bareRepository=explicit to be the default. To get to a state where we're comfortable making that change, we plan in the near-ish future to flip the default when feature.experimental is enabled.
Quoted 10 lines
Certainly forges touch bare repositories without always setting $GIT_DIR in their environment. But I would imagine that other tools indirectly touch bare repositories on behalf of the user. You mentioned "go" as one such tool that doesn't set $GIT_DIR, I imagine there are many more.
- If it is the plan to disable $GIT_DIR discovery in bare repositories in the future, I'm not sure how visible the extra trace line would be. Perhaps that is desirable, since having an
advise()call on every Git invocation in a bare repository would be noisy.
Yeah, this is mainly to help us plan for our internal rollout of safe.bareRepository=explicit at $DAYJOB, but we assume it would be helpful for others who might also be considering this, or for developers of affected tooling when they receive a bug report that bareRepository breaks their users.
We also want to add some more detailed tracing in general around repo/worktree initialization, but that part is not so urgent.