Skip to content

Commit 53740bb

Browse files
authored
Merge pull request kubernetes#85687 from dmage/decode_base64
fix: padded base64 encoded docker auth field
2 parents 050c947 + 5bec54e commit 53740bb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/credentialprovider/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ func decodeDockerConfigFieldAuth(field string) (username, password string, err e
287287

288288
// StdEncoding can only decode padded string
289289
// RawStdEncoding can only decode unpadded string
290-
// a string is correctly padded if and only if its length is a multiple of 4
291-
if (len(field) % 4) == 0 {
290+
if strings.HasSuffix(strings.TrimSpace(field), "=") {
292291
// decode padded data
293292
decoded, err = base64.StdEncoding.DecodeString(field)
294293
} else {

pkg/credentialprovider/config_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ func TestDecodeDockerConfigFieldAuth(t *testing.T) {
214214
password: "bar",
215215
},
216216

217+
// some test as before but with new line characters
218+
{
219+
input: "Zm9vOm\nJhcg==\n",
220+
username: "foo",
221+
password: "bar",
222+
},
223+
217224
// standard encoding (with padding)
218225
{
219226
input: base64.StdEncoding.EncodeToString([]byte("foo:bar")),
@@ -241,6 +248,12 @@ func TestDecodeDockerConfigFieldAuth(t *testing.T) {
241248
fail: true,
242249
},
243250

251+
// only new line characters are ignored
252+
{
253+
input: "Zm9vOmJhcg== ",
254+
fail: true,
255+
},
256+
244257
// bad base64 data
245258
{
246259
input: "pants",

0 commit comments

Comments
 (0)