From 37ffe86d8b70542d8cc4e346b768aaf67a8439f2 Mon Sep 17 00:00:00 2001 From: Avinesh Tripathi Date: Wed, 21 Sep 2022 23:32:16 +0530 Subject: [PATCH] changed name and added readme --- core/cautils/getter/gcpcloudapi.go | 20 ++++++-------- core/pkg/registryadaptors/gcp/v1/Readme.md | 26 +++++++++++++++++++ .../{GCP => gcp}/v1/datastructure.go | 0 .../{GCP => gcp}/v1/gcpadaptor.go | 0 .../{GCP => gcp}/v1/gcpadaptor_test.go | 0 .../{GCP => gcp}/v1/gcpadaptormock.go | 0 .../{GCP => gcp}/v1/gcpadaptorutils.go | 0 core/pkg/resourcehandler/registrydata.go | 4 +-- 8 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 core/pkg/registryadaptors/gcp/v1/Readme.md rename core/pkg/registryadaptors/{GCP => gcp}/v1/datastructure.go (100%) rename core/pkg/registryadaptors/{GCP => gcp}/v1/gcpadaptor.go (100%) rename core/pkg/registryadaptors/{GCP => gcp}/v1/gcpadaptor_test.go (100%) rename core/pkg/registryadaptors/{GCP => gcp}/v1/gcpadaptormock.go (100%) rename core/pkg/registryadaptors/{GCP => gcp}/v1/gcpadaptorutils.go (100%) diff --git a/core/cautils/getter/gcpcloudapi.go b/core/cautils/getter/gcpcloudapi.go index f9da1f8c..8287d0cb 100644 --- a/core/cautils/getter/gcpcloudapi.go +++ b/core/cautils/getter/gcpcloudapi.go @@ -7,22 +7,19 @@ import ( ) type GCPCloudAPI struct { - credentialsPath string - context context.Context - client *containeranalysis.Client - projectID string - credentials bool - loggedIn bool + credentialsPath string + context context.Context + client *containeranalysis.Client + projectID string + credentialsCheck bool } var globalGCPCloudAPIConnector *GCPCloudAPI func GetGlobalGCPCloudAPIConnector() *GCPCloudAPI { - + // need to move this to function where creds will be added globalGCPCloudAPIConnector = &GCPCloudAPI{ - context: context.Background(), - credentials: false, - loggedIn: false, + context: context.Background(), } return globalGCPCloudAPIConnector } @@ -33,7 +30,6 @@ func (api *GCPCloudAPI) SetClient(client *containeranalysis.Client) { func (api *GCPCloudAPI) GetCrediantialsPath() string { return api.credentialsPath } func (api *GCPCloudAPI) GetClient() *containeranalysis.Client { return api.client } -func (api *GCPCloudAPI) GetLoggedIn() bool { return api.loggedIn } func (api *GCPCloudAPI) GetProjectID() string { return api.projectID } -func (api *GCPCloudAPI) GetCredentials() bool { return api.credentials } +func (api *GCPCloudAPI) GetCredentialsCheck() bool { return api.credentialsCheck } func (api *GCPCloudAPI) GetContext() context.Context { return api.context } diff --git a/core/pkg/registryadaptors/gcp/v1/Readme.md b/core/pkg/registryadaptors/gcp/v1/Readme.md new file mode 100644 index 00000000..20485c1a --- /dev/null +++ b/core/pkg/registryadaptors/gcp/v1/Readme.md @@ -0,0 +1,26 @@ +# GCP Adaptor + +### How we add gcp adaptor + +As there can be possiblities of use of multiple registries we check for each adaptor if we have required credentias. For every adaptor having credentials we append the adaptor to the adaptors slice. + +Particularly for gcp, we frstly bring the `gcpCloudAPI` from the connector. We still haven't created a proper function that initiats the gcpCloudAPI with projectId, credentialsPath, credentialsCheck fields. We check for `credentialsCheck` bool which is set true when we have credentials(to be set when initializing the gcpCloudAPI) + +### How we fetch vulnerabilities for images + +Step 1: + Get container analysis client + For this we needs credentials of the service account. Out of few approaches here we are using [JSON key file](https://cloud.google.com/container-registry/docs/advanced-authentication#json-key) for credentials and path to this file should be stored in `credentialsPath` + +Step 2: + Do ListOccurrenceRequest + For this we need the `projectID` and the `resourceUrl`. ProjectID should be provided by the users and resourceUrl is processed imageTag that we get from kubescape resources + +Step 3: + Get Occurrence iterator + We use context and the request from the ListOccurenceRequest to get the iterators + + +### How we convert the response to Vulnerabilities + +Response from the iterator has two type of kinds i.e. Discovery and Vulnerabilties and both has differnent struct \ No newline at end of file diff --git a/core/pkg/registryadaptors/GCP/v1/datastructure.go b/core/pkg/registryadaptors/gcp/v1/datastructure.go similarity index 100% rename from core/pkg/registryadaptors/GCP/v1/datastructure.go rename to core/pkg/registryadaptors/gcp/v1/datastructure.go diff --git a/core/pkg/registryadaptors/GCP/v1/gcpadaptor.go b/core/pkg/registryadaptors/gcp/v1/gcpadaptor.go similarity index 100% rename from core/pkg/registryadaptors/GCP/v1/gcpadaptor.go rename to core/pkg/registryadaptors/gcp/v1/gcpadaptor.go diff --git a/core/pkg/registryadaptors/GCP/v1/gcpadaptor_test.go b/core/pkg/registryadaptors/gcp/v1/gcpadaptor_test.go similarity index 100% rename from core/pkg/registryadaptors/GCP/v1/gcpadaptor_test.go rename to core/pkg/registryadaptors/gcp/v1/gcpadaptor_test.go diff --git a/core/pkg/registryadaptors/GCP/v1/gcpadaptormock.go b/core/pkg/registryadaptors/gcp/v1/gcpadaptormock.go similarity index 100% rename from core/pkg/registryadaptors/GCP/v1/gcpadaptormock.go rename to core/pkg/registryadaptors/gcp/v1/gcpadaptormock.go diff --git a/core/pkg/registryadaptors/GCP/v1/gcpadaptorutils.go b/core/pkg/registryadaptors/gcp/v1/gcpadaptorutils.go similarity index 100% rename from core/pkg/registryadaptors/GCP/v1/gcpadaptorutils.go rename to core/pkg/registryadaptors/gcp/v1/gcpadaptorutils.go diff --git a/core/pkg/resourcehandler/registrydata.go b/core/pkg/resourcehandler/registrydata.go index 40170f18..5620a8ea 100644 --- a/core/pkg/resourcehandler/registrydata.go +++ b/core/pkg/resourcehandler/registrydata.go @@ -8,7 +8,7 @@ import ( "github.com/kubescape/k8s-interface/workloadinterface" "github.com/kubescape/kubescape/v2/core/cautils" "github.com/kubescape/kubescape/v2/core/cautils/getter" - gcpadaptorv1 "github.com/kubescape/kubescape/v2/core/pkg/registryadaptors/GCP/v1" + gcpadaptorv1 "github.com/kubescape/kubescape/v2/core/pkg/registryadaptors/gcp/v1" armosecadaptorv1 "github.com/kubescape/kubescape/v2/core/pkg/registryadaptors/armosec/v1" "github.com/kubescape/kubescape/v2/core/pkg/registryadaptors/registryvulnerabilities" @@ -161,7 +161,7 @@ func listAdaptores() ([]registryvulnerabilities.IContainerImageVulnerabilityAdap gcpCloudAPI := getter.GetGlobalGCPCloudAPIConnector() if gcpCloudAPI != nil { - if !gcpCloudAPI.GetCredentials() { + if gcpCloudAPI.GetCredentialsCheck() { adaptors = append(adaptors, gcpadaptorv1.NewGCPAdaptor(getter.GetGlobalGCPCloudAPIConnector())) } }