Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organisation Scan Start on children #1611

Merged
merged 6 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deepfence_server/handler/scan_reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (h *Handler) StartComplianceScanHandler(w http.ResponseWriter, r *http.Requ
return
}
} else {
nodes = reqs.NodeIds
nodes = cloudNodeIds
}

var scanTrigger model.NodeIdentifier
Expand Down
31 changes: 28 additions & 3 deletions deepfence_server/reporters/scan/scan_reporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ func GetCloudAccountIDs(ctx context.Context, cloudProviderIds []model.NodeIdenti

nres, err := tx.Run(`
MATCH (n:CloudNode)
WHERE n.cloud_provider IN $node_ids
RETURN n.node_id`,
WHERE n.node_id IN $node_ids
RETURN n.node_id, n.cloud_provider`,
map[string]interface{}{"node_ids": NodeIdentifierToIdList(cloudProviderIds)})
if err != nil {
return res, err
Expand All @@ -427,13 +427,38 @@ func GetCloudAccountIDs(ctx context.Context, cloudProviderIds []model.NodeIdenti
if err != nil {
return res, err
}

orgNodeIds := []string{}
for _, rec := range recs {
cloudProvider := rec.Values[1].(string)
if cloudProvider == model.PostureProviderAWSOrg || cloudProvider == model.PostureProviderGCPOrg {
orgNodeIds = append(orgNodeIds, rec.Values[0].(string))
continue
}
res = append(res, model.NodeIdentifier{
NodeId: rec.Values[0].(string),
NodeType: controls.ResourceTypeToString(controls.CloudAccount),
})
}
if len(orgNodeIds) > 0 {
nres, err = tx.Run(`
MATCH (n:CloudNode) -[:IS_CHILD] -> (m)
WHERE n.node_id IN $node_ids
RETURN m.node_id`,
map[string]interface{}{"node_ids": orgNodeIds})
if err != nil {
return res, err
}
recs, err = nres.Collect()
if err != nil {
return res, err
}
for _, rec := range recs {
res = append(res, model.NodeIdentifier{
NodeId: rec.Values[0].(string),
NodeType: controls.ResourceTypeToString(controls.CloudAccount),
})
}
}

return res, nil
}
Expand Down