changed name and added readme

This commit is contained in:
Avinesh Tripathi
2022-09-21 23:32:16 +05:30
parent 87fdbfdcc5
commit 37ffe86d8b
8 changed files with 36 additions and 14 deletions
+8 -12
View File
@@ -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 }
@@ -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
+2 -2
View File
@@ -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()))
}
}