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

extend target info #289

Merged
merged 5 commits into from
May 2, 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
19 changes: 15 additions & 4 deletions api/models/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,18 @@ components:
- id
additionalProperties: false


SecurityGroup:
type: object
description: general cloud security group
properties:
id:
type: string
minLength: 1
required:
- id
additionalProperties: false

AwsSecurityGroup:
type: object
description: AWS security group
Expand Down Expand Up @@ -1448,10 +1460,33 @@ components:
$ref: '#/components/schemas/CloudProvider'
location:
type: string
tags:
type: array
items:
$ref: '#/components/schemas/Tag'
nullable: true
securityGroups:
type: array
items:
$ref: '#/components/schemas/SecurityGroup'
nullable: true
image:
type: string
instanceType:
type: string
platform:
type: string
launchTime:
type: string
format: date-time
required:
- objectType
- instanceID
- location
- instanceType
- image
- platform
- launchTime

PodInfo:
type: object
Expand Down
75 changes: 38 additions & 37 deletions api/server/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions backend/pkg/database/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,19 @@ func createVulnerabilityFindings(base models.Finding, vulnerabilities []models.V
return ret
}

func createVMInfo(instanceID, location string, instanceProvider models.CloudProvider) *models.TargetType {
func createVMInfo(instanceID, location, image, instanceType, platform string,
tags []models.Tag, launchTime time.Time, instanceProvider models.CloudProvider,
) *models.TargetType {
info := models.TargetType{}
err := info.FromVMInfo(models.VMInfo{
Image: image,
InstanceID: instanceID,
InstanceProvider: &instanceProvider,
InstanceType: instanceType,
LaunchTime: launchTime,
Location: location,
Platform: platform,
Tags: &tags,
})
if err != nil {
panic(err)
Expand Down Expand Up @@ -448,7 +455,8 @@ func createTargets() []models.Target {
TotalNegligibleVulnerabilities: utils.PointerTo(0),
},
},
TargetInfo: createVMInfo(awsInstanceEUCentral11, awsRegionEUCentral1, models.AWS),
TargetInfo: createVMInfo(awsInstanceEUCentral11, awsRegionEUCentral1+"/"+awsVPCEUCentral11+"/"+awsSGEUCentral111,
"ami-111", "t2.large", "Linux", []models.Tag{{Key: "Name", Value: "target1"}}, time.Now(), models.AWS),
},
{
ScansCount: utils.PointerTo(1),
Expand All @@ -467,7 +475,8 @@ func createTargets() []models.Target {
TotalNegligibleVulnerabilities: utils.PointerTo(0),
},
},
TargetInfo: createVMInfo(awsInstanceEUCentral12, awsRegionEUCentral1, models.AWS),
TargetInfo: createVMInfo(awsInstanceEUCentral12, awsRegionEUCentral1+"/"+awsVPCEUCentral11+"/"+awsSGEUCentral111,
"ami-111", "t2.large", "Linux", []models.Tag{{Key: "Name", Value: "target2"}}, time.Now(), models.AWS),
},
{
ScansCount: utils.PointerTo(1),
Expand All @@ -486,7 +495,8 @@ func createTargets() []models.Target {
TotalNegligibleVulnerabilities: utils.PointerTo(0),
},
},
TargetInfo: createVMInfo(awsInstanceUSEast11, awsRegionUSEast1, models.AWS),
TargetInfo: createVMInfo(awsInstanceUSEast11, awsRegionUSEast1+"/"+awsVPCUSEast11+"/"+awsSGUSEast111,
"ami-112", "t2.micro", "Linux", []models.Tag{{Key: "Name", Value: "target3"}}, time.Now(), models.AWS),
},
}
}
Expand Down
29 changes: 26 additions & 3 deletions backend/pkg/database/gorm/odata.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,35 @@ var schemaMetas = map[string]odatasql.SchemaMeta{
},
"VMInfo": {
Fields: odatasql.Schema{
"objectType": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"instanceID": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"location": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"objectType": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"instanceID": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"location": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"launchTime": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"platform": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"instanceType": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"image": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
"tags": odatasql.FieldMeta{
FieldType: odatasql.CollectionFieldType,
CollectionItemMeta: &odatasql.FieldMeta{
FieldType: odatasql.ComplexFieldType,
ComplexFieldSchemas: []string{"Tag"},
},
},
"securityGroups": odatasql.FieldMeta{
FieldType: odatasql.CollectionFieldType,
CollectionItemMeta: &odatasql.FieldMeta{
FieldType: odatasql.ComplexFieldType,
ComplexFieldSchemas: []string{"SecurityGroup"},
},
},
"instanceProvider": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
},
},
"SecurityGroup": {
Fields: odatasql.Schema{
"id": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
},
},
"ScanFindingsSummary": {
Fields: odatasql.Schema{
"totalPackages": odatasql.FieldMeta{FieldType: odatasql.PrimitiveFieldType},
Expand Down
27 changes: 27 additions & 0 deletions runtime_scan/pkg/orchestrator/configwatcher/scan_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,15 @@ func (scw *ScanConfigWatcher) createTarget(ctx context.Context, instance types.I
info := models.TargetType{}
instanceProvider := models.AWS
err := info.FromVMInfo(models.VMInfo{
Image: instance.GetImage(),
InstanceID: instance.GetID(),
InstanceProvider: &instanceProvider,
InstanceType: instance.GetType(),
LaunchTime: instance.GetLaunchTime(),
Location: instance.GetLocation(),
Platform: instance.GetPlatform(),
Tags: convertTags(instance.GetTags()),
SecurityGroups: createSecurityGroups(instance.GetSecurityGroups()),
})
if err != nil {
return "", fmt.Errorf("failed to create VMInfo: %v", err)
Expand All @@ -170,3 +176,24 @@ func (scw *ScanConfigWatcher) createTarget(ctx context.Context, instance types.I
}
return *createdTarget.Id, nil
}

func createSecurityGroups(sgs []string) *[]models.SecurityGroup {
ret := make([]models.SecurityGroup, len(sgs))
for i, sg := range sgs {
ret[i] = models.SecurityGroup{
Id: sg,
}
}
return &ret
}

func convertTags(tags []types.Tag) *[]models.Tag {
ret := make([]models.Tag, len(tags))
for i, tag := range tags {
ret[i] = models.Tag{
Key: tag.Key,
Value: tag.Val,
}
}
return &ret
}
Loading