diff --git a/core/pkg/opaprocessor/processorhandler.go b/core/pkg/opaprocessor/processorhandler.go index 8f2e32a6..397ecb3a 100644 --- a/core/pkg/opaprocessor/processorhandler.go +++ b/core/pkg/opaprocessor/processorhandler.go @@ -154,6 +154,8 @@ func (opap *OPAProcessor) processRule(rule *reporthandling.PolicyRule, fixedCont postureControlInputs := opap.regoDependenciesData.GetFilteredPostureControlInputs(rule.ConfigInputs) // get store + postureControlInputs["cloudProvider"] = []string{opap.OPASessionObj.Report.ClusterCloudProvider} + // Merge configurable control input and fixed control input for k, v := range fixedControlInputs { postureControlInputs[k] = v diff --git a/core/pkg/policyhandler/handlenotification.go b/core/pkg/policyhandler/handlenotification.go index cb86ae14..797fe881 100644 --- a/core/pkg/policyhandler/handlenotification.go +++ b/core/pkg/policyhandler/handlenotification.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/armosec/armoapi-go/armotypes" + "github.com/kubescape/k8s-interface/cloudsupport" + "github.com/kubescape/k8s-interface/k8sinterface" "github.com/kubescape/kubescape/v2/core/cautils" "github.com/kubescape/kubescape/v2/core/pkg/resourcehandler" ) @@ -49,6 +51,17 @@ func (policyHandler *PolicyHandler) CollectResources(policyIdentifier []cautils. func (policyHandler *PolicyHandler) getResources(policyIdentifier []cautils.PolicyIdentifier, opaSessionObj *cautils.OPASessionObj, scanInfo *cautils.ScanInfo) error { opaSessionObj.Report.ClusterAPIServerInfo = policyHandler.resourceHandler.GetClusterAPIServerInfo() + // attempting to get cloud provider from API server git version + if opaSessionObj.Report.ClusterAPIServerInfo != nil { + opaSessionObj.Report.ClusterCloudProvider = cloudsupport.GetCloudProvider(opaSessionObj.Report.ClusterAPIServerInfo.GitVersion) + } + + // if didn't succeed getting cloud provider from API server git version, try from context. + if opaSessionObj.Report.ClusterCloudProvider == "" { + clusterName := k8sinterface.GetContextName() + opaSessionObj.Report.ClusterCloudProvider = cloudsupport.GetCloudProvider(clusterName) + } + resourcesMap, allResources, ksResources, err := policyHandler.resourceHandler.GetResources(opaSessionObj, &policyIdentifier[0].Designators) if err != nil { return err