Skip to content

Commit

Permalink
wip: vulnerability scanner start, process results (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnmahanth committed Jan 13, 2023
1 parent 3170f8e commit 6c6b5d9
Show file tree
Hide file tree
Showing 22 changed files with 1,814 additions and 218 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ openapi: server

.PHONY: cli
cli:
(cd $(DEEPFENCE_CTL) && make)
(cd $(DEEPFENCE_CTL) && make clean && make all)

.PHONY: publish
publish:
Expand Down
4 changes: 2 additions & 2 deletions deepfence_agent/tools/apache/fluentbit/out_deepfence/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ require (
github.com/deepfence/ThreatMapper/deepfence_server_client v0.0.0-00010101000000-000000000000
github.com/deepfence/ThreatMapper/deepfence_utils v0.0.0-00010101000000-000000000000
github.com/fluent/fluent-bit-go v0.0.0-20221129124408-1c1d505c91a5
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/hashicorp/go-retryablehttp v0.7.2
)

require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.4 // indirect
Expand Down
8 changes: 4 additions & 4 deletions deepfence_agent/tools/apache/fluentbit/out_deepfence/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/lestrrat-go/blackmagic v1.0.1 h1:lS5Zts+5HIC/8og6cGHb0uCcNCa3OUt1ygh3Qz2Fe80=
github.com/lestrrat-go/blackmagic v1.0.1/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
Expand Down
63 changes: 38 additions & 25 deletions deepfence_agent/tools/apache/scope/probe/host/generate_sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,31 @@ func createPackageScannerClient() (pb.PackageScannerClient, error) {
return pb.NewPackageScannerClient(conn), nil
}

func GenerateSbomForVulnerabilityScan(imageName, imageId, scanId, containerId,
func GenerateSbomForVulnerabilityScan(nodeType, imageName, imageId, scanId, containerId,
kubernetesClusterName, containerName, scanType string) error {
ctx := context.Background()

hostName := scopeHostname.Get()
var nodeType string
if imageName == "host" {
nodeType = "host"
} else if containerName != "" {
nodeType = "container"
} else {
nodeType = "container_image"
}

packageScannerClient, err := createPackageScannerClient()
if err != nil {
return err
}
var source string
if imageName == "host" {
if nodeType == "host" {
source = scanPath
} else {
source = imageName
} else if nodeType == "container_image" {
if imageId != "" {
source = imageId
} else {
source = imageName
}
} else if nodeType == "container" {
if containerId != "" {
source = containerId
} else {
source = containerName
}
}
sbomRequest := &pb.SBOMRequest{
Source: source,
Expand Down Expand Up @@ -92,36 +95,46 @@ func StartVulnerabilityScan(req ctl.StartVulnerabilityScanRequest) error {
containerName = ""
containerId = ""
scanType = "all"
node_type = ""
node_id = ""
)

if imageNameArg, ok := req.BinArgs["image_name"]; ok {
imageName = imageNameArg
if node_type_Arg, ok := req.BinArgs["node_type"]; ok {
node_type = node_type_Arg
}

if node_id_Arg, ok := req.BinArgs["node_id"]; ok {
node_id = node_id_Arg
}
if containerNameArg, ok := req.BinArgs["container_name"]; ok {
containerName = containerNameArg

switch node_type {
case "container":
containerId = node_id
containerName = node_id
case "image":
imageId = node_id
imageName = node_id
node_type = "container_image"
}

if kubernetesClusterNameArg, ok := req.BinArgs["kubernetes_cluster_name"]; ok {
kubernetesClusterName = kubernetesClusterNameArg
}
if imageIdArg, ok := req.BinArgs["image_id"]; ok {
imageId = imageIdArg
}
if containerIdArg, ok := req.BinArgs["container_id"]; ok {
containerId = containerIdArg
}
if imageName != "host" && imageId == "" {
return errors.New("image_id is required for container/image vulnerability scan")
if (node_type == "container" && containerId == "") ||
(node_type == "container_image" && imageId == "") {
return errors.New("image_id/container_id is required for container/image vulnerability scan")
}
if scanTypeArg, ok := req.BinArgs["scan_type"]; ok {
scanType = scanTypeArg
}
if scanIdArg, ok := req.BinArgs["scan_id"]; ok {
scanId = scanIdArg
}
log.Infof("vulnerability scan request: %v", req)
log.Infof("uploading %s tar to console...", imageName)
// call package scanner plugin
go func() {
err := GenerateSbomForVulnerabilityScan(imageName, imageId, scanId,
err := GenerateSbomForVulnerabilityScan(node_type, imageName, imageId, scanId,
containerId, kubernetesClusterName, containerName, scanType)
if err != nil {
log.Error(err.Error())
Expand Down
9 changes: 9 additions & 0 deletions deepfence_ctl/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ var scanStartSubCmd = &cobra.Command{
ResourceType: resource_type,
})
res, _, err = http.Client().SecretScanApi.StartSecretScanExecute(req)
case "vulnerability":
req := http.Client().VulnerabilityApi.StartVulnerabilityScan(context.Background())
req = req.ModelScanTriggerReq(
deepfence_server_client.ModelScanTriggerReq{
NodeId: scan_node_id,
ResourceId: resource_id,
ResourceType: resource_type,
})
res, _, err = http.Client().VulnerabilityApi.StartVulnerabilityScanExecute(req)
default:
log.Fatal().Msg("Unsupported")
}
Expand Down
64 changes: 52 additions & 12 deletions deepfence_server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ replace github.com/weaveworks/tcptracer-bpf => ../deepfence_agent/tools/apache/d

replace github.com/deepfence/df-utils/cloud_metadata => ../deepfence_agent/tools/apache/deepfence/df-utils/cloud_metadata

replace github.com/deepfence/package-scanner => github.com/deepfence/package-scanner v1.2.4-0.20230112121648-782d22a7ebb7

require (
github.com/ThreeDotsLabs/watermill v1.1.1
github.com/ThreeDotsLabs/watermill-kafka/v2 v2.2.2
github.com/bytedance/sonic v1.7.0
github.com/casbin/casbin/v2 v2.60.0
github.com/deepfence/ThreatMapper/deepfence_ingester v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -50,56 +54,80 @@ require (
github.com/Jeffail/tunny v0.1.4 // indirect
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Microsoft/hcsshim v0.9.3 // indirect
github.com/Microsoft/hcsshim v0.9.6 // indirect
github.com/Shopify/sarama v1.32.0 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.44.178 // indirect
github.com/bluele/gcache v0.0.2 // indirect
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cenkalti/backoff/v3 v3.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/containerd/containerd v1.6.6 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/containerd/containerd v1.6.14 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/containerd/fifo v1.0.0 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/coocood/freecache v1.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/deepfence/df-utils v0.0.0-00010101000000-000000000000 // indirect
github.com/deepfence/df-utils/cloud_metadata v0.0.0-00010101000000-000000000000 // indirect
github.com/deepfence/package-scanner v0.0.0-00010101000000-000000000000 // indirect
github.com/deepfence/vessel v0.8.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.22+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/eapache/go-resiliency v1.2.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/fsouza/go-dockerclient v1.9.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-playground/form/v4 v4.2.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hibiken/asynq v0.24.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/iovisor/gobpf v0.2.0 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.0.0 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k-sone/critbitgo v1.4.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/klauspost/compress v1.15.13 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
Expand All @@ -109,23 +137,31 @@ require (
github.com/lestrrat-go/jwx/v2 v2.0.8 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/sys/mount v0.3.3 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/opencontainers/runc v1.1.2 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.4 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opencontainers/selinux v1.10.2 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
Expand All @@ -142,18 +178,22 @@ require (
github.com/weaveworks/common v0.0.0-20221201103051-7c2720a9024d // indirect
github.com/weaveworks/tcptracer-bpf v0.0.0-00010101000000-000000000000 // indirect
github.com/willdonnelly/passwd v0.0.0-20141013001024-7935dab3074c // indirect
go.opencensus.io v0.23.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama v0.31.0 // indirect
go.opentelemetry.io/otel v1.6.1 // indirect
go.opentelemetry.io/otel/trace v1.6.1 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.5.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect
google.golang.org/grpc v1.52.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
Loading

0 comments on commit 6c6b5d9

Please sign in to comment.