-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
600 additions
and
248 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package azqr | ||
|
||
import ( | ||
"github.com/Azure/azqr/internal/scanners" | ||
"github.com/Azure/azqr/internal/scanners/dbw" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
scanCmd.AddCommand(dbwCmd) | ||
} | ||
|
||
var dbwCmd = &cobra.Command{ | ||
Use: "dbw", | ||
Short: "Scan Azure Databricks", | ||
Long: "Scan Azure Databricks", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
serviceScanners := []scanners.IAzureScanner{ | ||
&dbw.DatabricksScanner{}, | ||
} | ||
|
||
scan(cmd, serviceScanners) | ||
}, | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,66 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package dbw | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
|
||
"github.com/Azure/azqr/internal/scanners" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/databricks/armdatabricks" | ||
) | ||
|
||
// DatabricksScanner - Scanner for Azure Databricks | ||
type DatabricksScanner struct { | ||
config *scanners.ScannerConfig | ||
client *armdatabricks.WorkspacesClient | ||
} | ||
|
||
// Init - Initializes the DatabricksScanner | ||
func (c *DatabricksScanner) Init(config *scanners.ScannerConfig) error { | ||
c.config = config | ||
var err error | ||
c.client, err = armdatabricks.NewWorkspacesClient(config.SubscriptionID, config.Cred, config.ClientOptions) | ||
return err | ||
} | ||
|
||
// Scan - Scans all Azure Databricks in a Resource Group | ||
func (c *DatabricksScanner) Scan(resourceGroupName string, scanContext *scanners.ScanContext) ([]scanners.AzureServiceResult, error) { | ||
log.Info().Stack().Msgf("Scanning Azure Databricks in Resource Group %s", resourceGroupName) | ||
|
||
workspaces, err := c.listWorkspaces(resourceGroupName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
engine := scanners.RuleEngine{} | ||
rules := c.GetRules() | ||
results := []scanners.AzureServiceResult{} | ||
|
||
for _, ws := range workspaces { | ||
rr := engine.EvaluateRules(rules, ws, scanContext) | ||
|
||
results = append(results, scanners.AzureServiceResult{ | ||
SubscriptionID: c.config.SubscriptionID, | ||
ResourceGroup: resourceGroupName, | ||
ServiceName: *ws.Name, | ||
Type: *ws.Type, | ||
Location: *ws.Location, | ||
Rules: rr, | ||
}) | ||
} | ||
return results, nil | ||
} | ||
|
||
func (c *DatabricksScanner) listWorkspaces(resourceGroupName string) ([]*armdatabricks.Workspace, error) { | ||
pager := c.client.NewListByResourceGroupPager(resourceGroupName, nil) | ||
|
||
registries := make([]*armdatabricks.Workspace, 0) | ||
for pager.More() { | ||
resp, err := pager.NextPage(c.config.Ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
registries = append(registries, resp.Value...) | ||
} | ||
return registries, nil | ||
} |
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,98 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package dbw | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/Azure/azqr/internal/ref" | ||
"github.com/Azure/azqr/internal/scanners" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/databricks/armdatabricks" | ||
) | ||
|
||
// GetRules - Returns the rules for the DatabricksScanner | ||
func (a *DatabricksScanner) GetRules() map[string]scanners.AzureRule { | ||
return map[string]scanners.AzureRule{ | ||
"dbw-001": { | ||
Id: "dbw-001", | ||
Category: scanners.RulesCategoryReliability, | ||
Subcategory: scanners.RulesSubcategoryReliabilityDiagnosticLogs, | ||
Description: "Azure Databricks should have diagnostic settings enabled", | ||
Severity: scanners.SeverityMedium, | ||
Eval: func(target interface{}, scanContext *scanners.ScanContext) (bool, string) { | ||
service := target.(*armdatabricks.Workspace) | ||
_, ok := scanContext.DiagnosticsSettings[strings.ToLower(*service.ID)] | ||
return !ok, "" | ||
}, | ||
Url: "https://learn.microsoft.com/en-us/azure/databricks/administration-guide/account-settings/audit-log-delivery", | ||
Field: scanners.OverviewFieldDiagnostics, | ||
}, | ||
"dbw-003": { | ||
Id: "dbw-003", | ||
Category: scanners.RulesCategoryReliability, | ||
Subcategory: scanners.RulesSubcategoryReliabilitySLA, | ||
Description: "Azure Databricks should have a SLA", | ||
Severity: scanners.SeverityHigh, | ||
Eval: func(target interface{}, scanContext *scanners.ScanContext) (bool, string) { | ||
return false, "99.95%" | ||
}, | ||
Url: "https://www.microsoft.com/licensing/docs/view/Service-Level-Agreements-SLA-for-Online-Services", | ||
Field: scanners.OverviewFieldSLA, | ||
}, | ||
"dbw-004": { | ||
Id: "dbw-004", | ||
Category: scanners.RulesCategorySecurity, | ||
Subcategory: scanners.RulesSubcategorySecurityPrivateEndpoint, | ||
Description: "Azure Databricks should have private endpoints enabled", | ||
Severity: scanners.SeverityHigh, | ||
Eval: func(target interface{}, scanContext *scanners.ScanContext) (bool, string) { | ||
i := target.(*armdatabricks.Workspace) | ||
pe := len(i.Properties.PrivateEndpointConnections) > 0 | ||
return !pe, "" | ||
}, | ||
Url: "https://learn.microsoft.com/en-us/azure/databricks/administration-guide/cloud-configurations/azure/private-link", | ||
Field: scanners.OverviewFieldPrivate, | ||
}, | ||
"dbw-005": { | ||
Id: "dbw-005", | ||
Category: scanners.RulesCategoryReliability, | ||
Subcategory: scanners.RulesSubcategoryReliabilitySKU, | ||
Description: "Azure Databricks SKU", | ||
Severity: scanners.SeverityHigh, | ||
Eval: func(target interface{}, scanContext *scanners.ScanContext) (bool, string) { | ||
i := target.(*armdatabricks.Workspace) | ||
return false, string(*i.SKU.Name) | ||
}, | ||
Url: "https://azure.microsoft.com/en-us/pricing/details/databricks/", | ||
Field: scanners.OverviewFieldSKU, | ||
}, | ||
"dbw-006": { | ||
Id: "dbw-006", | ||
Category: scanners.RulesCategoryOperationalExcellence, | ||
Subcategory: scanners.RulesSubcategoryOperationalExcellenceCAF, | ||
Description: "Azure Databricks Name should comply with naming conventions", | ||
Severity: scanners.SeverityLow, | ||
Eval: func(target interface{}, scanContext *scanners.ScanContext) (bool, string) { | ||
c := target.(*armdatabricks.Workspace) | ||
caf := strings.HasPrefix(*c.Name, "dbw") | ||
return !caf, "" | ||
}, | ||
Url: "https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-abbreviations", | ||
Field: scanners.OverviewFieldCAF, | ||
}, | ||
"dbw-007": { | ||
Id: "dbw-007", | ||
Category: scanners.RulesCategorySecurity, | ||
Subcategory: scanners.RulesSubcategorySecurityIdentity, | ||
Description: "Azure Databricks should have the Public IP disabled", | ||
Severity: scanners.SeverityMedium, | ||
Eval: func(target interface{}, scanContext *scanners.ScanContext) (bool, string) { | ||
c := target.(*armdatabricks.Workspace) | ||
broken := c.Properties.Parameters.EnableNoPublicIP != nil && c.Properties.Parameters.EnableNoPublicIP.Value == ref.Of(true) | ||
return broken, "" | ||
}, | ||
Url: "https://learn.microsoft.com/en-us/azure/databricks/security/network/secure-cluster-connectivity", | ||
}, | ||
} | ||
} |
Oops, something went wrong.