Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
extend target info (#289)
Browse files Browse the repository at this point in the history
## Description

Extend target info with the following properties:
Tags 
Image
instance type (micro, large, etc.)
Platform (linux distro)
add ../vpc/security-group to the location which is only the region
currently
Launch time

## Type of Change

[* ] New Feature
  • Loading branch information
fishkerez authored May 2, 2023
1 parent 3739716 commit d2c799f
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 97 deletions.
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

0 comments on commit d2c799f

Please sign in to comment.