Repository: aquasecurity/starboard
Pull request #859 (2021-12-17 14:07:02)

fix: parse registry credentials when auth is blank
Resolves: #855
Resolves: #857

Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>

codecov[bot]: # [Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/859?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) Report
> Merging [#859](https://codecov.io/gh/aquasecurity/starboard/pull/859?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) (64955e1) into [main](https://codecov.io/gh/aquasecurity/starboard/commit/85723da5523759e240fa08b886bb4137fede82d1?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) (85723da) will **decrease** coverage by `19.50%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/aquasecurity/starboard/pull/859/graphs/tree.svg?width=650&height=150&src=pr&token=qqTGKAJ0Wb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity)](https://codecov.io/gh/aquasecurity/starboard/pull/859?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity)

```diff
@@             Coverage Diff             @@
##             main     #859       +/-   ##
===========================================
- Coverage   65.52%   46.02%   -19.51%     
===========================================
  Files          58       41       -17     
  Lines        6454     5278     -1176     
===========================================
- Hits         4229     2429     -1800     
- Misses       1798     2702      +904     
+ Partials      427      147      -280     
```


| [Impacted Files](https://codecov.io/gh/aquasecurity/starboard/pull/859?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) | Coverage Δ | |
|---|---|---|
| [pkg/docker/config.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2RvY2tlci9jb25maWcuZ28=) | `73.61% <100.00%> (+2.39%)` | :arrow_up: |
| [pkg/plugin/factory.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL3BsdWdpbi9mYWN0b3J5Lmdv) | `0.00% <0.00%> (-81.14%)` | :arrow_down: |
| [pkg/kubehunter/scanner.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2t1YmVodW50ZXIvc2Nhbm5lci5nbw==) | `0.00% <0.00%> (-75.72%)` | :arrow_down: |
| [pkg/operator/controller/vulnerabilityreport.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL29wZXJhdG9yL2NvbnRyb2xsZXIvdnVsbmVyYWJpbGl0eXJlcG9ydC5nbw==) | `0.00% <0.00%> (-64.69%)` | :arrow_down: |
| [pkg/kube/runnable\_job.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2t1YmUvcnVubmFibGVfam9iLmdv) | `0.00% <0.00%> (-63.73%)` | :arrow_down: |
| [pkg/operator/controller/configauditreport.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL29wZXJhdG9yL2NvbnRyb2xsZXIvY29uZmlnYXVkaXRyZXBvcnQuZ28=) | `0.00% <0.00%> (-62.95%)` | :arrow_down: |
| [pkg/kubehunter/model.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2t1YmVodW50ZXIvbW9kZWwuZ28=) | `0.00% <0.00%> (-62.86%)` | :arrow_down: |
| [pkg/vulnerabilityreport/scanner.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL3Z1bG5lcmFiaWxpdHlyZXBvcnQvc2Nhbm5lci5nbw==) | `0.00% <0.00%> (-60.40%)` | :arrow_down: |
| [pkg/operator/controller/ciskubebenchreport.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL29wZXJhdG9yL2NvbnRyb2xsZXIvY2lza3ViZWJlbmNocmVwb3J0Lmdv) | `0.00% <0.00%> (-56.77%)` | :arrow_down: |
| [pkg/configauditreport/scanner.go](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2NvbmZpZ2F1ZGl0cmVwb3J0L3NjYW5uZXIuZ28=) | `0.00% <0.00%> (-56.39%)` | :arrow_down: |
| ... and [31 more](https://codecov.io/gh/aquasecurity/starboard/pull/859/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/859?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/859?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity). Last update [85723da...64955e1](https://codecov.io/gh/aquasecurity/starboard/pull/859?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity).


Patch:
diff --git a/pkg/docker/config.go b/pkg/docker/config.go
index 94e24ee..11de7c9 100644
--- a/pkg/docker/config.go
+++ b/pkg/docker/config.go
@@ -67,7 +67,15 @@ func (c *Config) Read(contents []byte) error {
 func decodeAuths(auths map[string]Auth) (map[string]Auth, error) {
 	decodedAuths := make(map[string]Auth)
 	for server, entry := range auths {
-		if (Auth{}) == entry {
+		if entry == (Auth{}) {
+			continue
+		}
+
+		if strings.TrimSpace(string(entry.Auth)) == "" {
+			decodedAuths[server] = Auth{
+				Username: entry.Username,
+				Password: entry.Password,
+			}
 			continue
 		}
 


Test patch:
diff --git a/pkg/docker/config_test.go b/pkg/docker/config_test.go
index 1a7dfbf..328ef31 100644
--- a/pkg/docker/config_test.go
+++ b/pkg/docker/config_test.go
@@ -38,28 +38,53 @@ func TestConfig_Read(t *testing.T) {
 			expectedError: errors.New("unexpected end of JSON input"),
 		},
 		{
-			name: "Should return server credentials with encoded username and password",
+			name: "Should return server credentials stored as username and password encoded in the auth property",
 			givenJSON: `{
-						"auths": {
-							"https://index.docker.io/v1/": {
-							"auth": "ZG9ja2VyOmh1Yg=="
-							},
-							"harbor.domain": {
-							"auth": "YWRtaW46SGFyYm9yMTIzNDU="
+							"auths": {
+								"https://index.docker.io/v1/": {
+									"auth": "ZG9ja2VyOmh1Yg=="
+								},
+								"harbor.domain": {
+									"auth": "YWRtaW46SGFyYm9yMTIzNDU="
+								}
 							}
-						}
 						}`,
 			expectedAuth: map[string]docker.Auth{
+				"https://index.docker.io/v1/": {
+					Auth:     "ZG9ja2VyOmh1Yg==",
+					Username: "docker",
+					Password: "hub",
+				},
 				"harbor.domain": {
 					Auth:     "YWRtaW46SGFyYm9yMTIzNDU=",
 					Username: "admin",
 					Password: "Harbor12345",
 				},
+			},
+		},
+		{
+			name: "Should return server credentials stored in username and password properties",
+			givenJSON: `{
+							"auths": {
+								"https://index.docker.io/v1/": {
+									"auth": "ZG9ja2VyOmh1Yg=="
+								},
+								"harbor.domain": {
+									"username": "admin",
+									"password": "Harbor12345"
+								}
+							}
+						}`,
+			expectedAuth: map[string]docker.Auth{
 				"https://index.docker.io/v1/": {
 					Auth:     "ZG9ja2VyOmh1Yg==",
 					Username: "docker",
 					Password: "hub",
 				},
+				"harbor.domain": {
+					Username: "admin",
+					Password: "Harbor12345",
+				},
 			},
 		},
 		{