Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git-init for Git 2.35.2 #4756

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
if err := os.Chdir(spec.Path); err != nil {
return fmt.Errorf("failed to change directory with path %s; err: %w", spec.Path, err)
}
} else if _, err := run(logger, "", "init"); err != nil {
return err
if _, err := run(logger, "", "config", "--add", "--global", "safe.directory", spec.Path); err != nil {
return err
}
} else {
if _, err := run(logger, "", "init"); err != nil {
return err
}
if _, err := run(logger, "", "config", "--add", "--global", "safe.directory", "/"); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When spec.Path is empty, I'm not sure exactly what we should be adding as a safe.directory here instead. I'm guessing that it's the root directory, but I could very well be wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ sounds safe to me. AIUI, the CVE specifically impacts shared environments, where one user can create e.g., /.git and trick subdirectory git checkouts to using the root-level git config. Tekton doesn't have that problem (or else you're using Tekton very weirdly, and you get what you get!)

I think if this causes any problems we could just uniformly configure / as a safe directory. But being conservative sounds smart until then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I saw no reason not to just go as broad as we have to - my uncertainty is whether / is actually where we're running git init from when we don't have spec.Path.

return err
}
}
if err := configSparseCheckout(logger, spec); err != nil {
return err
Expand Down