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

Add entities.metadata #2769

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions internal/inventory/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,34 @@ type AssetResourcePolicy struct {
Condition map[string]any `json:"condition,omitempty"`
}

// EntityMetadata maps metadata required to use Entity Store
type entityMetadata struct {
Entity AssetClassification `json:"asset"`
Cloud *AssetCloud `json:"cloud,omitempty"`
Host *AssetHost `json:"host,omitempty"`
}

// AssetEnricher functional builder function
type AssetEnricher func(asset *AssetEvent)

func (a *AssetEvent) getEntityMetadata() map[string]entityMetadata {
ids := a.Asset.Id

if len(ids) == 0 {
return nil
}

// Picking up only first id, we need to make a decision on if we
// have a "primary" id or if we duplicate data
Comment on lines +350 to +351
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's super important. We also have to pay attention to always put "the" asset ID in the ids[0] spot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a product question I want to clear it up. I believe it was a bad decision in the end to have multiple ids.

We need to have a standardized id per resource. We need to make the decision for example is aws iam user arn or username? And one for each one of those.

The initial attempt of having a "correlation best chance" approach isn't going to help us in the asset inventory, unfortunately.

return map[string]entityMetadata{
ids[0]: {
Entity: a.Asset.AssetClassification,
Cloud: a.Cloud,
Host: a.Host,
},
}
}

func NewAssetEvent(c AssetClassification, ids []string, name string, enrichers ...AssetEnricher) AssetEvent {
a := AssetEvent{
Asset: Asset{
Expand Down
1 change: 1 addition & 0 deletions internal/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (a *AssetInventory) publish(assets []AssetEvent) {
"iam": e.IAM,
"resource_policies": e.ResourcePolicies,
"related.entity": relatedEntity,
"entities": map[string]any{"metadata": e.getEntityMetadata()},
},
}
})
Expand Down
10 changes: 9 additions & 1 deletion internal/inventory/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestAssetInventory_Run(t *testing.T) {
},
"iam": &AssetIAM{
Id: pointers.Ref("a123123"),
Arn: pointers.Ref("123123:123123:123123"),
Arn: pointers.Ref("123123:123123:123123`"),
},
"resource_policies": []AssetResourcePolicy{
{
Expand All @@ -86,6 +86,14 @@ func TestAssetInventory_Run(t *testing.T) {
},
},
"related.entity": []string{"arn:aws:ec2:us-east::ec2/234567890"},
"entities": map[string]any{
"metadata": map[string]entityMetadata{
"arn:aws:ec2:us-east::ec2/234567890": {
Category: string(CategoryInfrastructure),
Type: string(TypeVirtualMachine),
},
},
},
},
},
}
Expand Down
Loading
Loading