-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
send skipTLSVerify and Insecure in image scanning command (#212)
* send skipTLSVerify and Insecure in image scanning command Signed-off-by: Amir Malka <[email protected]> * update go.mod Signed-off-by: Amir Malka <[email protected]> * fix test Signed-off-by: Amir Malka <[email protected]> * make map Signed-off-by: Amir Malka <[email protected]> --------- Signed-off-by: Amir Malka <[email protected]>
Showing
5 changed files
with
151 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"apiVersion": "v1", | ||
"kind": "Secret", | ||
"type": "Opaque", | ||
"data": { | ||
"registriesAuth": "WyAgICAgCiAgewogICAgInJlZ2lzdHJ5IjogImRvY2tlci5pbyIsCiAgICAidXNlcm5hbWUiOiAidGVzdC11c2VyIiwKICAgICJwYXNzd29yZCI6ICJ0ZXN0LXBhc3MiLAogICAgImF1dGhfbWV0aG9kIjogImNyZWRlbnRpYWxzIiwKICAgICJodHRwIjogdHJ1ZQogIH0sCiAgewogICAgInJlZ2lzdHJ5IjogInF1YXkuaW8iLAogICAgInVzZXJuYW1lIjogInRlc3QtdXNlci1xdWF5IiwKICAgICJwYXNzd29yZCI6ICJ0ZXN0LXBhc3MtcXVheSIsCiAgICAiYXV0aF9tZXRob2QiOiAiY3JlZGVudGlhbHMiLAogICAgInNraXBUbHNWZXJpZnkiOiB0cnVlCiAgfQpdCg==" | ||
}, | ||
"metadata": { | ||
"creationTimestamp": "2024-03-03T13:45:44Z", | ||
"name": "kubescape-registry-scan-test-secret", | ||
"namespace": "kubescape", | ||
"resourceVersion": "80227", | ||
"uid": "0617be65-cf6c-4cac-8bcf-d26592b34156" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,58 @@ | ||
package mainhandler | ||
|
||
import ( | ||
"testing" | ||
|
||
_ "embed" | ||
|
||
dockerregistry "github.com/docker/docker/api/types/registry" | ||
"github.com/kubescape/k8s-interface/k8sinterface" | ||
"github.com/kubescape/k8s-interface/workloadinterface" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
//go:embed testdata/vulnscan/registry-secret.json | ||
var registrySecret []byte | ||
|
||
type WorkloadsGetterMock struct{} | ||
|
||
func (mock *WorkloadsGetterMock) GetWorkload(namespace, kind, name string) (k8sinterface.IWorkload, error) { | ||
wl, err := workloadinterface.NewWorkload(registrySecret) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return wl, nil | ||
} | ||
func (mock *WorkloadsGetterMock) ListWorkloads2(namespace, kind string) ([]k8sinterface.IWorkload, error) { | ||
wl, _ := mock.GetWorkload(namespace, kind, "") | ||
return []k8sinterface.IWorkload{wl}, nil | ||
} | ||
|
||
func Test_ActionHandler_getImageScanConfig(t *testing.T) { | ||
expectedAuthConfigs := []dockerregistry.AuthConfig{ | ||
{ | ||
Username: "test-user", | ||
Password: "test-pass", | ||
ServerAddress: "docker.io", | ||
}, | ||
{ | ||
Username: "test-user-quay", | ||
Password: "test-pass-quay", | ||
ServerAddress: "quay.io", | ||
}, | ||
} | ||
|
||
k8sApiMock := &WorkloadsGetterMock{} | ||
|
||
res, err := getImageScanConfig(k8sApiMock, "", nil, "nginx:latest") // no registry treated as docker.io | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedAuthConfigs, res.authConfigs) | ||
assert.True(t, *res.insecure) | ||
assert.Nil(t, res.skipTLSVerify) | ||
|
||
res, err = getImageScanConfig(k8sApiMock, "", nil, "quay.IO/kubescape/nginx:latest") | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedAuthConfigs, res.authConfigs) | ||
assert.Nil(t, res.insecure) | ||
assert.True(t, *res.skipTLSVerify) | ||
} |