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

git-init don't assume the image is running as root #747

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions cmd/git-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os/exec"

"github.com/knative/pkg/logging"
homedir "github.com/mitchellh/go-homedir"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -59,15 +60,24 @@ func main() {
logger, _ := logging.NewLogger("", "git-init")
defer logger.Sync()

// HACK HACK HACK
// Git seems to ignore $HOME/.ssh and look in /root/.ssh for unknown reasons.
// As a workaround, symlink /root/.ssh to where we expect the $HOME to land.
// This means SSH auth only works for our built-in git support, and not
// custom steps.
err := os.Symlink("/builder/home/.ssh", "/root/.ssh")
// HACK: This is to get git+ssh to work since ssh doesn't respect the HOME
// env variable.
homepath, err := homedir.Dir()
if err != nil {
logger.Fatalf("Unexpected error creating symlink: %v", err)
logger.Fatalf("Unexpected error: getting the user home directory: %v", err)
}
homeenv := os.Getenv("HOME")
if homeenv != "" && homeenv != homepath {
if _, err := os.Stat(homepath + "/.ssh"); os.IsNotExist(err) {
err = os.Symlink(homeenv+"/.ssh", homepath+"/.ssh")
if err != nil {
// Only do a warning, in case we don't have a real home
// directory writable in our image
logger.Warnf("Unexpected error: creating symlink: %v", err)
}
}
}

if *revision == "" {
*revision = "master"
}
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/mitchellh/go-homedir/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

167 changes: 167 additions & 0 deletions vendor/github.com/mitchellh/go-homedir/homedir.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.