Skip to content

Commit

Permalink
#1552 Posture Linux, Kubernetes to host, cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh2253 committed Oct 16, 2023
1 parent 700deae commit d4cac7a
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion deepfence_server/handler/cloud_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (h *Handler) ListCloudNodeAccountHandler(w http.ResponseWriter, r *http.Req
}

if utils.StringToCloudProvider(req.CloudProvider) == -1 {
if req.CloudProvider != model.PostureProviderKubernetes && req.CloudProvider != model.PostureProviderLinux {
if req.CloudProvider != model.PostureProviderCluster && req.CloudProvider != model.PostureProviderHost {
err = fmt.Errorf("unknown Provider: %s", req.CloudProvider)
log.Error().Msgf("%v", err)
h.respondError(&BadDecoding{err}, w)
Expand Down
52 changes: 26 additions & 26 deletions deepfence_server/model/cloud_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import (
)

const (
PostureProviderAWS = "aws"
PostureProviderAWSOrg = "aws_org"
PostureProviderGCP = "gcp"
PostureProviderGCPOrg = "gcp_org"
PostureProviderAzure = "azure"
PostureProviderLinux = "linux"
PostureProviderKubernetes = "kubernetes"
PostureProviderAWS = "aws"
PostureProviderAWSOrg = "aws_org"
PostureProviderGCP = "gcp"
PostureProviderGCPOrg = "gcp_org"
PostureProviderAzure = "azure"
PostureProviderHost = "host"
PostureProviderCluster = "cluster"
)

var SupportedPostureProviders = []string{PostureProviderAWS, PostureProviderGCP,
PostureProviderAzure, PostureProviderLinux, PostureProviderKubernetes}
PostureProviderAzure, PostureProviderHost, PostureProviderCluster}

type CloudNodeAccountRegisterReq struct {
NodeId string `json:"node_id" required:"true"`
Expand Down Expand Up @@ -77,9 +77,9 @@ type CloudNodeAccountInfo struct {

func (v CloudNodeAccountInfo) NodeType() string {
switch v.CloudProvider {
case PostureProviderKubernetes:
case PostureProviderCluster:
return utils.NodeTypeKubernetesCluster
case PostureProviderLinux:
case PostureProviderHost:
return utils.NodeTypeHost
}
return utils.NodeTypeCloudNode
Expand All @@ -93,7 +93,7 @@ func (v CloudNodeAccountInfo) ScanType() utils.Neo4jScanType {
switch v.CloudProvider {
case PostureProviderAWS, PostureProviderGCP, PostureProviderAzure, PostureProviderAWSOrg:
return utils.NEO4J_CLOUD_COMPLIANCE_SCAN
case PostureProviderKubernetes, PostureProviderLinux:
case PostureProviderCluster, PostureProviderHost:
return utils.NEO4J_COMPLIANCE_SCAN
default:
return utils.NEO4J_CLOUD_COMPLIANCE_SCAN
Expand All @@ -104,7 +104,7 @@ func (v CloudNodeAccountInfo) ScanResultType() string {
switch v.CloudProvider {
case PostureProviderAWS, PostureProviderGCP, PostureProviderAzure, PostureProviderAWSOrg:
return "CloudCompliance"
case PostureProviderKubernetes, PostureProviderLinux:
case PostureProviderCluster, PostureProviderHost:
return "Compliance"
default:
return "CloudCompliance"
Expand All @@ -113,9 +113,9 @@ func (v CloudNodeAccountInfo) ScanResultType() string {

func (v CloudNodeAccountInfo) GetPassStatus() []string {
switch v.CloudProvider {
case PostureProviderAWS, PostureProviderGCP, PostureProviderAzure, PostureProviderAWSOrg, PostureProviderKubernetes:
case PostureProviderAWS, PostureProviderGCP, PostureProviderAzure, PostureProviderAWSOrg, PostureProviderCluster:
return []string{"ok", "info", "skip"}
case PostureProviderLinux:
case PostureProviderHost:
return []string{"warn", "pass"}
default:
return []string{"skip", "ok", "info", "pass", "warn"}
Expand Down Expand Up @@ -158,7 +158,7 @@ type PendingCloudComplianceScan struct {

type CloudNodeControlReq struct {
NodeId string `json:"node_id"`
CloudProvider string `json:"cloud_provider" required:"true" enum:"aws,gcp,azure,linux,kubernetes"`
CloudProvider string `json:"cloud_provider" required:"true" enum:"aws,gcp,azure,host,cluster"`
ComplianceType string `json:"compliance_type" required:"true"`
}

Expand Down Expand Up @@ -270,8 +270,8 @@ func GetCloudProvidersList(ctx context.Context) ([]PostureProvider, error) {
{Name: PostureProviderGCP, NodeLabel: "Accounts"},
// {Name: PostureProviderGCPOrg, NodeLabel: "Organizations"},
{Name: PostureProviderAzure, NodeLabel: "Accounts"},
{Name: PostureProviderLinux, NodeLabel: "Hosts"},
{Name: PostureProviderKubernetes, NodeLabel: "Clusters"},
{Name: PostureProviderHost, NodeLabel: "Hosts"},
{Name: PostureProviderCluster, NodeLabel: "Clusters"},
}
providersIndex := make(map[string]int)
for i, provider := range postureProviders {
Expand All @@ -291,14 +291,14 @@ func GetCloudProvidersList(ctx context.Context) ([]PostureProvider, error) {
if err == nil {
for _, record := range records {
if record.Values[0].(bool) == true {
postureProviders[providersIndex[PostureProviderLinux]].NodeCount = record.Values[1].(int64)
postureProviders[providersIndex[PostureProviderHost]].NodeCount = record.Values[1].(int64)
} else {
postureProviders[providersIndex[PostureProviderLinux]].NodeCountInactive = record.Values[1].(int64)
postureProviders[providersIndex[PostureProviderHost]].NodeCountInactive = record.Values[1].(int64)
}
}
}
} else {
log.Warn().Msgf("GetCloudProvidersList Linux : %v", err)
log.Warn().Msgf("GetCloudProvidersList Host : %v", err)
}

// Kubernetes
Expand All @@ -311,9 +311,9 @@ func GetCloudProvidersList(ctx context.Context) ([]PostureProvider, error) {
if err == nil {
for _, record := range records {
if record.Values[0].(bool) == true {
postureProviders[providersIndex[PostureProviderKubernetes]].NodeCount = record.Values[1].(int64)
postureProviders[providersIndex[PostureProviderCluster]].NodeCount = record.Values[1].(int64)
} else {
postureProviders[providersIndex[PostureProviderKubernetes]].NodeCountInactive = record.Values[1].(int64)
postureProviders[providersIndex[PostureProviderCluster]].NodeCountInactive = record.Values[1].(int64)
}
}
}
Expand Down Expand Up @@ -373,17 +373,17 @@ func GetCloudComplianceNodesList(ctx context.Context, cloudProvider string, fw F
} else if cloudProvider == PostureProviderGCPOrg {
cloudProvider = PostureProviderGCP
isOrgListing = true
} else if cloudProvider == PostureProviderKubernetes {
} else if cloudProvider == PostureProviderCluster {
neo4jNodeType = "KubernetesCluster"
} else if cloudProvider == PostureProviderLinux {
} else if cloudProvider == PostureProviderHost {
neo4jNodeType = "Node"
passStatus = []string{"warn", "pass"}
}
var res neo4j.Result
var query string
if cloudProvider == PostureProviderKubernetes || cloudProvider == PostureProviderLinux {
if cloudProvider == PostureProviderCluster || cloudProvider == PostureProviderHost {
nonKubeFilter := ""
if cloudProvider == PostureProviderLinux {
if cloudProvider == PostureProviderHost {
nonKubeFilter = "{kubernetes_cluster_id:''}"
}
query = `
Expand Down
2 changes: 1 addition & 1 deletion deepfence_server/reporters/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func searchCloudNode(ctx context.Context, filter SearchFilter, fw model.FetchWin
return res, err
}
defer tx.Close()
if cloudProvider == model.PostureProviderLinux || cloudProvider == model.PostureProviderKubernetes {
if cloudProvider == model.PostureProviderHost || cloudProvider == model.PostureProviderCluster {
filter.Filters.ContainsFilter.FieldsValues["agent_running"] = append(make([]interface{}, 0), true)
delete(filter.Filters.ContainsFilter.FieldsValues, "cloud_provider")
}
Expand Down
2 changes: 1 addition & 1 deletion deepfence_utils/utils/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type ReportParams struct {
type ReportFilters struct {
ScanId string `json:"scan_id"`
ScanType string `json:"scan_type" validate:"required" required:"true" enum:"vulnerability,secret,malware,compliance,cloud_compliance"`
NodeType string `json:"node_type" validate:"required" required:"true" enum:"host,container,container_image,linux,cluster,aws,gcp,azure"`
NodeType string `json:"node_type" validate:"required" required:"true" enum:"host,container,container_image,cluster,aws,gcp,azure"`
SeverityOrCheckType []string `json:"severity_or_check_type" enum:"critical,high,medium,low,cis,gdpr,nist,hipaa,pci,soc_2"`
IncludeDeadNode bool `json:"include_dead_nodes"`
AdvancedReportFilters AdvancedReportFilters `json:"advanced_report_filters,omitempty"`
Expand Down
18 changes: 9 additions & 9 deletions deepfence_worker/cronjobs/cloud_compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
)

var BenchmarksAvailableMap = map[string][]string{
"aws": {"cis", "nist", "pci", "gdpr", "hipaa", "soc_2"},
"gcp": {"cis"},
"azure": {"cis", "nist", "pci", "hipaa"},
"kubernetes": {"nsa-cisa"},
"linux": {"hipaa", "nist", "pci", "gdpr"}}
"aws": {"cis", "nist", "pci", "gdpr", "hipaa", "soc_2"},
"gcp": {"cis"},
"azure": {"cis", "nist", "pci", "hipaa"},
"cluster": {"nsa-cisa"},
"host": {"hipaa", "nist", "pci", "gdpr"}}

type Benchmark struct {
BenchmarkId string `json:"benchmark_id"`
Expand Down Expand Up @@ -215,17 +215,17 @@ func CachePostureProviders(ctx context.Context, task *asynq.Task) error {
}
neo4jNodeType := "CloudNode"
nodeLabel := "Hosts"
if postureProviderName == model.PostureProviderKubernetes {
if postureProviderName == model.PostureProviderCluster {
neo4jNodeType = "KubernetesCluster"
nodeLabel = "Clusters"
} else if postureProviderName == model.PostureProviderLinux {
} else if postureProviderName == model.PostureProviderHost {
neo4jNodeType = "Node"
}
var account_count_query, resource_count_query, scan_count_query, success_count_query, global_count_query string
passStatus := []string{"ok", "info", "skip"}
if postureProviderName == model.PostureProviderLinux || postureProviderName == model.PostureProviderKubernetes {
if postureProviderName == model.PostureProviderHost || postureProviderName == model.PostureProviderCluster {
postureProvider.NodeLabel = nodeLabel
if postureProviderName == model.PostureProviderLinux {
if postureProviderName == model.PostureProviderHost {
passStatus = []string{"warn", "pass"}
}

Expand Down

0 comments on commit d4cac7a

Please sign in to comment.