-
Notifications
You must be signed in to change notification settings - Fork 42
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
Implement Azure fetchers and asset provider #1310
Conversation
This pull request does not have a backport label. Could you fix it @jeniawhite? 🙏
|
📊 Allure Report - 💚 No failures were reported.
|
This pull request is now in conflicts. Could you fix it? 🙏
|
This pull request is now in conflicts. Could you fix it? 🙏
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can merge this after some tests and resolving the TODOs
// TODO: Populate from config or query (not sensitive but still don't want to commit) | ||
to.Ptr(os.Getenv("AZURE_SUBSCRIPTION_ID"))}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, this will be handled in a follow-up ticket
resources/fetching/fetcher.go
Outdated
AzureNetworkInterface = "azure-network-interface" | ||
AzureApplicationService = "azure-application-service" | ||
AzureLoggingAndMonitoring = "azure-logging-and-monitoring" | ||
AzureDatabaseService = "azure-database-service" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AzureNetworkInterface = "azure-network-interface" | |
AzureApplicationService = "azure-application-service" | |
AzureLoggingAndMonitoring = "azure-logging-and-monitoring" | |
AzureDatabaseService = "azure-database-service" |
Let's add these one by one as we implement the rules. We can merge this PR without them.
|
||
func (f *AzureAssetsFetcher) Fetch(ctx context.Context, cMetadata fetching.CycleMetadata) error { | ||
f.log.Info("Starting AzureAssetsFetcher.Fetch") | ||
// TODO: Maybe we should use a query per type instead of listing all assets in a single query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: Maybe we should use a query per type instead of listing all assets in a single query |
Is there any benefit to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that it might help us If we will need to collect multiple resource types to evaluate a single rule.
TenantId string `json:"tenant_id,omitempty"` | ||
} | ||
|
||
// TODO: Implement other types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: Implement other types |
Can we track this in a new issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically the other piece of work regarding the comment above:
Let's add these one by one as we implement the rules. We can merge this PR without them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to merge this relatively clean in main
unless if it's blocking more important work
I left comments on TODOs and we should definitely guard the casting or avoid casting alltogether
Asset AzureAssetInfo `json:"asset,omitempty"` | ||
} | ||
|
||
// TODO: Fill this struct with the required fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this done?
// TODO: Fill this struct with the required fields |
case f.resourceCh <- fetching.ResourceInfo{ | ||
CycleMetadata: cMetadata, | ||
// TODO: Safe guard this conversion | ||
Resource: getAssetFromData(asset.(map[string]any)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't ListAllAssetTypesByName
return the correct type / handle the casting instead of the caller?
return value | ||
} | ||
|
||
// TODO: Handle this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's resolve the TODOs, is this relevant?
|
||
func (r *AzureAsset) GetElasticCommonData() (map[string]any, error) { return nil, nil } | ||
|
||
// TODO: Implement this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the significance of this? Is it a blocker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a blocker because we did not decide on the subTypes yet.
As of current we only utilize the resource type and do not look at subTypes in the policies.
Future implementation of additional rules might change that, this is why it is left blank as of current.
return resourceAssets, nil | ||
} | ||
|
||
// TODO: Handle this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
s.NoError(err) | ||
s.NotNil(meta) | ||
s.NoError(err) | ||
s.NotEmpty(meta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s.NoError(err) | |
s.NotNil(meta) | |
s.NoError(err) | |
s.NotEmpty(meta) | |
require.NoError(s.T(), err) | |
s.NotEmpty(meta) |
s.Equal(mockAssets[index].Id, meta.ID) | ||
s.Equal(AzureResourceTypes[mockAssets[index].Type], meta.Type) | ||
s.Equal("", meta.SubType) | ||
s.Equal(mockAssets[index].Name, meta.Name) | ||
s.Equal(mockAssets[index].Location, meta.Region) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s.Equal(mockAssets[index].Id, meta.ID) | |
s.Equal(AzureResourceTypes[mockAssets[index].Type], meta.Type) | |
s.Equal("", meta.SubType) | |
s.Equal(mockAssets[index].Name, meta.Name) | |
s.Equal(mockAssets[index].Location, meta.Region) | |
s.Equal(mockAssets[index].Id, meta.ID) | |
s.Equal(AzureResourceTypes[mockAssets[index].Type], meta.Type) | |
s.Equal("", meta.SubType) | |
s.Equal(mockAssets[index].Name, meta.Name) | |
s.Equal(mockAssets[index].Location, meta.Region) |
I would construct an expected meta
object and compare it using the Equal
function, this produces a better diff and it is more feature-proof as we can catch cases where we forget to use new field if we combine it with exhauststruct
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but the coverails still fails
Apply suggestions from elastic#1310 - Reduce code - Protect from panics via `Require()` - Compare objects directly
Apply suggestions from #1310 - Reduce code - Protect from panics via `Require()` - Compare objects directly
Summary of your changes
Implementation of assets provider using ARG and Azure fetcher in order to fetch resources for evaluation.
Related Issues
Checklist