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
23 changes: 23 additions & 0 deletions internal/inventory/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,32 @@ type AssetResourcePolicy struct {
Condition map[string]any `json:"condition,omitempty"`
}

// EntityMetadata maps metadata required to use Entity Store
type entityMetadata struct {
Category string `json:"category"`
Type string `json:"type"`
Comment on lines +334 to +335
Copy link
Member

Choose a reason for hiding this comment

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

Are there any other fields planned? What will happen if we change the taxonomy we have now (Category, Sub-Category, Type, Sub-type) to a less granular one?

Copy link
Member Author

Choose a reason for hiding this comment

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

There might have other fields.

Once we change the taxonomy, we should follow the taxonomy.

}

// 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 +348 to +349
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]: {
Category: string(a.Asset.Category),
Type: string(a.Asset.Type),
},
}
}

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 @@ -114,6 +114,7 @@ func (a *AssetInventory) publish(assets []AssetEvent) {
"iam": e.IAM,
"resource_policies": e.ResourcePolicies,
"related.entity": e.Asset.Id,
"entities": map[string]any{"metadata": e.getEntityMetadata()},
},
}
})
Expand Down
8 changes: 8 additions & 0 deletions internal/inventory/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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