Skip to content

Commit

Permalink
Merge pull request #5032 from nalind/abspaths
Browse files Browse the repository at this point in the history
Make sure that pathnames picked up from the environment are absolute
  • Loading branch information
openshift-merge-robot authored Sep 7, 2023
2 parents 1a001de + cc619c2 commit 25473ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/containers/storage/pkg/chrootarchive"
"github.com/containers/storage/pkg/unshare"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
)

// LookupImage returns *Image to corresponding imagename or id
Expand Down Expand Up @@ -53,7 +54,11 @@ func NormalizePlatform(platform v1.Platform) v1.Platform {
// GetTempDir returns base for a temporary directory on host.
func GetTempDir() string {
if tmpdir, ok := os.LookupEnv("TMPDIR"); ok {
return tmpdir
abs, err := filepath.Abs(tmpdir)
if err == nil {
return abs
}
logrus.Warnf("ignoring TMPDIR from environment, evaluating it: %v", err)
}
containerConfig, err := config.Default()
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
internalParse "github.com/containers/buildah/internal/parse"
internalUtil "github.com/containers/buildah/internal/util"
"github.com/containers/buildah/pkg/sshagent"
"github.com/containers/common/pkg/auth"
"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/parse"
"github.com/containers/image/v5/docker/reference"
Expand Down Expand Up @@ -449,9 +450,13 @@ func SystemContextFromFlagSet(flags *pflag.FlagSet, findFlagFunc func(name strin

func getAuthFile(authfile string) string {
if authfile != "" {
return authfile
absAuthfile, err := filepath.Abs(authfile)
if err == nil {
return absAuthfile
}
logrus.Warnf("ignoring passed-in auth file path, evaluating it: %v", err)
}
return os.Getenv("REGISTRY_AUTH_FILE")
return auth.GetDefaultAuthFile()
}

// PlatformFromOptions parses the operating system (os) and architecture (arch)
Expand Down
7 changes: 6 additions & 1 deletion pkg/sshagent/sshagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,13 @@ func NewSource(paths []string) (*Source, error) {
if len(paths) == 0 {
socket = os.Getenv("SSH_AUTH_SOCK")
if socket == "" {
return nil, errors.New("$SSH_AUTH_SOCK not set")
return nil, errors.New("SSH_AUTH_SOCK not set in environment")
}
absSocket, err := filepath.Abs(socket)
if err != nil {
return nil, fmt.Errorf("evaluating SSH_AUTH_SOCK in environment: %w", err)
}
socket = absSocket
}
for _, p := range paths {
if socket != "" {
Expand Down

0 comments on commit 25473ec

Please sign in to comment.