Skip to content

Commit 6c69383

Browse files
committed
image scp: preserve usernames containing an "@"
Signed-off-by: ROKUMATE <rohitkumawat0110@gmail.com>
1 parent d55b0a0 commit 6c69383

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

pkg/domain/utils/scp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ func ParseImageSCPArg(arg string) (*entities.ScpTransferImageOptions, []string,
361361

362362
switch {
363363
case strings.Contains(arg, "@localhost::"): // image transfer between users
364-
location.User, _, _ = strings.Cut(arg, "@")
364+
// Split on "@localhost::" rather than the first "@" so usernames
365+
// that themselves contain an "@" (e.g. Active Directory "user@domain")
366+
// are preserved. See https://github.com/containers/podman/issues/27655
367+
location.User, _, _ = strings.Cut(arg, "@localhost::")
365368
location, err = ValidateImagePortion(location, arg)
366369
if err != nil {
367370
return nil, nil, err

pkg/domain/utils/scp_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,29 @@ func TestValidateSCPArgs(t *testing.T) {
7272
})
7373
}
7474
}
75+
76+
func TestParseImageSCPArg(t *testing.T) {
77+
tests := []struct {
78+
name string
79+
arg string
80+
wantUser string
81+
}{
82+
{
83+
name: "user without domain",
84+
arg: "user@localhost::alpine",
85+
wantUser: "user",
86+
},
87+
{
88+
name: "username containing an @ (e.g. Active Directory)",
89+
arg: "user@domain@localhost::example.com/foo/bar:latest",
90+
wantUser: "user@domain",
91+
},
92+
}
93+
for _, tt := range tests {
94+
t.Run(tt.name, func(t *testing.T) {
95+
location, _, err := ParseImageSCPArg(tt.arg)
96+
assert.NoError(t, err)
97+
assert.Equal(t, tt.wantUser, location.User)
98+
})
99+
}
100+
}

0 commit comments

Comments
 (0)