-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor(deps): Merge defsec into Trivy #6006
Closed
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package arm | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aquasecurity/trivy/internal/adapters/arm/appservice" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/authorization" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/compute" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/container" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/database" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/datafactory" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/datalake" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/keyvault" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/monitor" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/network" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/securitycenter" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/storage" | ||
"github.com/aquasecurity/trivy/internal/adapters/arm/synapse" | ||
|
||
"github.com/aquasecurity/trivy/pkg/providers/azure" | ||
scanner "github.com/aquasecurity/trivy/pkg/scanners/azure" | ||
"github.com/aquasecurity/trivy/pkg/state" | ||
) | ||
|
||
// Adapt ... | ||
func Adapt(ctx context.Context, deployment scanner.Deployment) *state.State { | ||
return &state.State{ | ||
Azure: adaptAzure(deployment), | ||
} | ||
} | ||
|
||
func adaptAzure(deployment scanner.Deployment) azure.Azure { | ||
|
||
return azure.Azure{ | ||
AppService: appservice.Adapt(deployment), | ||
Authorization: authorization.Adapt(deployment), | ||
Compute: compute.Adapt(deployment), | ||
Container: container.Adapt(deployment), | ||
Database: database.Adapt(deployment), | ||
DataFactory: datafactory.Adapt(deployment), | ||
DataLake: datalake.Adapt(deployment), | ||
KeyVault: keyvault.Adapt(deployment), | ||
Monitor: monitor.Adapt(deployment), | ||
Network: network.Adapt(deployment), | ||
SecurityCenter: securitycenter.Adapt(deployment), | ||
Storage: storage.Adapt(deployment), | ||
Synapse: synapse.Adapt(deployment), | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package appservice | ||
|
||
import ( | ||
"github.com/aquasecurity/trivy/pkg/providers/azure/appservice" | ||
"github.com/aquasecurity/trivy/pkg/scanners/azure" | ||
defsecTypes "github.com/aquasecurity/trivy/pkg/types" | ||
) | ||
|
||
func Adapt(deployment azure.Deployment) appservice.AppService { | ||
return appservice.AppService{ | ||
Services: adaptServices(deployment), | ||
FunctionApps: adaptFunctionApps(deployment), | ||
} | ||
} | ||
|
||
func adaptFunctionApps(deployment azure.Deployment) []appservice.FunctionApp { | ||
var functionApps []appservice.FunctionApp | ||
|
||
for _, resource := range deployment.GetResourcesByType("Microsoft.Web/sites") { | ||
functionApps = append(functionApps, adaptFunctionApp(resource)) | ||
} | ||
return functionApps | ||
} | ||
|
||
func adaptServices(deployment azure.Deployment) []appservice.Service { | ||
var services []appservice.Service | ||
for _, resource := range deployment.GetResourcesByType("Microsoft.Web/sites") { | ||
services = append(services, adaptService(resource)) | ||
} | ||
return services | ||
} | ||
|
||
func adaptFunctionApp(resource azure.Resource) appservice.FunctionApp { | ||
return appservice.FunctionApp{ | ||
Metadata: resource.Metadata, | ||
HTTPSOnly: resource.Properties.GetMapValue("httpsOnly").AsBoolValue(false, resource.Properties.GetMetadata()), | ||
} | ||
} | ||
|
||
func adaptService(resource azure.Resource) appservice.Service { | ||
return appservice.Service{ | ||
Metadata: resource.Metadata, | ||
EnableClientCert: resource.Properties.GetMapValue("clientCertEnabled").AsBoolValue(false, resource.Properties.GetMetadata()), | ||
Identity: struct{ Type defsecTypes.StringValue }{ | ||
Type: resource.Properties.GetMapValue("identity").GetMapValue("type").AsStringValue("", resource.Properties.GetMetadata()), | ||
}, | ||
Authentication: struct{ Enabled defsecTypes.BoolValue }{ | ||
Enabled: resource.Properties.GetMapValue("siteAuthSettings").GetMapValue("enabled").AsBoolValue(false, resource.Properties.GetMetadata()), | ||
}, | ||
Site: struct { | ||
EnableHTTP2 defsecTypes.BoolValue | ||
MinimumTLSVersion defsecTypes.StringValue | ||
}{ | ||
EnableHTTP2: resource.Properties.GetMapValue("httpsOnly").AsBoolValue(false, resource.Properties.GetMetadata()), | ||
MinimumTLSVersion: resource.Properties.GetMapValue("minTlsVersion").AsStringValue("", resource.Properties.GetMetadata()), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package authorization | ||
|
||
import ( | ||
"github.com/aquasecurity/trivy/pkg/providers/azure/authorization" | ||
"github.com/aquasecurity/trivy/pkg/scanners/azure" | ||
) | ||
|
||
func Adapt(deployment azure.Deployment) authorization.Authorization { | ||
return authorization.Authorization{ | ||
RoleDefinitions: adaptRoleDefinitions(deployment), | ||
} | ||
} | ||
|
||
func adaptRoleDefinitions(deployment azure.Deployment) (roleDefinitions []authorization.RoleDefinition) { | ||
for _, resource := range deployment.GetResourcesByType("Microsoft.Authorization/roleDefinitions") { | ||
roleDefinitions = append(roleDefinitions, adaptRoleDefinition(resource)) | ||
} | ||
return roleDefinitions | ||
} | ||
|
||
func adaptRoleDefinition(resource azure.Resource) authorization.RoleDefinition { | ||
|
||
return authorization.RoleDefinition{ | ||
Metadata: resource.Metadata, | ||
Permissions: adaptPermissions(resource), | ||
AssignableScopes: resource.Properties.GetMapValue("assignableScopes").AsStringValuesList(""), | ||
} | ||
} | ||
|
||
func adaptPermissions(resource azure.Resource) (permissions []authorization.Permission) { | ||
for _, permission := range resource.Properties.GetMapValue("permissions").AsList() { | ||
permissions = append(permissions, authorization.Permission{ | ||
Metadata: resource.Metadata, | ||
Actions: permission.GetMapValue("actions").AsStringValuesList(""), | ||
}) | ||
} | ||
return permissions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package compute | ||
|
||
import ( | ||
"github.com/aquasecurity/trivy/pkg/providers/azure/compute" | ||
"github.com/aquasecurity/trivy/pkg/scanners/azure" | ||
defsecTypes "github.com/aquasecurity/trivy/pkg/types" | ||
) | ||
|
||
func Adapt(deployment azure.Deployment) compute.Compute { | ||
return compute.Compute{ | ||
LinuxVirtualMachines: adaptLinuxVirtualMachines(deployment), | ||
WindowsVirtualMachines: adaptWindowsVirtualMachines(deployment), | ||
ManagedDisks: adaptManagedDisks(deployment), | ||
} | ||
} | ||
|
||
func adaptManagedDisks(deployment azure.Deployment) (managedDisks []compute.ManagedDisk) { | ||
|
||
for _, resource := range deployment.GetResourcesByType("Microsoft.Compute/disks") { | ||
managedDisks = append(managedDisks, adaptManagedDisk(resource)) | ||
} | ||
|
||
return managedDisks | ||
} | ||
|
||
func adaptManagedDisk(resource azure.Resource) compute.ManagedDisk { | ||
hasEncryption := resource.Properties.HasKey("encryption") | ||
|
||
return compute.ManagedDisk{ | ||
Metadata: resource.Metadata, | ||
Encryption: compute.Encryption{ | ||
Metadata: resource.Metadata, | ||
Enabled: defsecTypes.Bool(hasEncryption, resource.Metadata), | ||
}, | ||
} | ||
} | ||
|
||
func adaptWindowsVirtualMachines(deployment azure.Deployment) (windowsVirtualMachines []compute.WindowsVirtualMachine) { | ||
for _, resource := range deployment.GetResourcesByType("Microsoft.Compute/virtualMachines") { | ||
if resource.Properties.GetMapValue("osProfile").GetMapValue("windowsConfiguration").AsMap() != nil { | ||
windowsVirtualMachines = append(windowsVirtualMachines, adaptWindowsVirtualMachine(resource)) | ||
} | ||
} | ||
|
||
return windowsVirtualMachines | ||
} | ||
|
||
func adaptWindowsVirtualMachine(resource azure.Resource) compute.WindowsVirtualMachine { | ||
return compute.WindowsVirtualMachine{ | ||
Metadata: resource.Metadata, | ||
VirtualMachine: compute.VirtualMachine{ | ||
Metadata: resource.Metadata, | ||
CustomData: resource.Properties.GetMapValue("osProfile"). | ||
GetMapValue("customData").AsStringValue("", resource.Metadata), | ||
}, | ||
} | ||
} | ||
|
||
func adaptLinuxVirtualMachines(deployment azure.Deployment) (linuxVirtualMachines []compute.LinuxVirtualMachine) { | ||
for _, resource := range deployment.GetResourcesByType("Microsoft.Compute/virtualMachines") { | ||
if resource.Properties.GetMapValue("osProfile").GetMapValue("linuxConfiguration").AsMap() != nil { | ||
linuxVirtualMachines = append(linuxVirtualMachines, adaptLinuxVirtualMachine(resource)) | ||
} | ||
} | ||
|
||
return linuxVirtualMachines | ||
} | ||
|
||
func adaptLinuxVirtualMachine(resource azure.Resource) compute.LinuxVirtualMachine { | ||
return compute.LinuxVirtualMachine{ | ||
Metadata: resource.Metadata, | ||
VirtualMachine: compute.VirtualMachine{ | ||
Metadata: resource.Metadata, | ||
CustomData: resource.Properties.GetMapValue("osProfile"). | ||
GetMapValue("customData").AsStringValue("", resource.Metadata), | ||
}, | ||
OSProfileLinuxConfig: compute.OSProfileLinuxConfig{ | ||
Metadata: resource.Metadata, | ||
DisablePasswordAuthentication: resource.Properties.GetMapValue("osProfile"). | ||
GetMapValue("linuxConfiguration"). | ||
GetMapValue("disablePasswordAuthentication").AsBoolValue(false, resource.Metadata), | ||
}, | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 PR requires the changes here to be merged.