Skip to content

Commit

Permalink
azure: Filter out storage accounts that deny public requests (#1698)
Browse files Browse the repository at this point in the history
* Filter out storage accounts that dney public requests

* Bump
  • Loading branch information
nturinski authored Feb 29, 2024
1 parent c840d9d commit efd6201
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
38 changes: 25 additions & 13 deletions azure/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions azure/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/vscode-azext-azureutils",
"author": "Microsoft Corporation",
"version": "3.0.0",
"version": "3.0.1",
"description": "Common Azure utils for developing Azure extensions for VS Code",
"tags": [
"azure",
Expand Down Expand Up @@ -34,7 +34,7 @@
"@azure/arm-resources": "^5.0.0",
"@azure/arm-resources-profile-2020-09-01-hybrid": "^2.0.0",
"@azure/arm-resources-subscriptions": "^2.0.0",
"@azure/arm-storage": "^18.0.0",
"@azure/arm-storage": "^18.2.0",
"@azure/arm-storage-profile-2020-09-01-hybrid": "^2.0.0",
"@azure/core-client": "^1.6.0",
"@azure/core-rest-pipeline": "^1.9.0",
Expand Down
22 changes: 20 additions & 2 deletions azure/src/wizard/StorageAccountListStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { StorageAccount, StorageManagementClient } from '@azure/arm-storage';
import type { NetworkRuleSet, StorageAccount, StorageManagementClient } from '@azure/arm-storage';
import { AzureWizardPromptStep, IAzureNamingRules, IAzureQuickPickItem, IAzureQuickPickOptions, IWizardOptions, nonNullProp, openUrl } from '@microsoft/vscode-azext-utils';
import * as vscode from 'vscode';
import * as types from '../../index';
Expand Down Expand Up @@ -121,7 +121,8 @@ export class StorageAccountListStep<T extends types.IStorageAccountWizardContext

let hasFilteredAccountsBySku: boolean = false;
let hasFilteredAccountsByLocation: boolean = false;
const storageAccounts: StorageAccount[] = (await storageAccountsTask)
let hasFilteredAccountsByNetwork = false;
const storageAccounts: (StorageAccount & { networkAcls?: NetworkRuleSet })[] = (await storageAccountsTask)
.sort((a: StorageAccount, b: StorageAccount) => nonNullProp(a, 'name').localeCompare(nonNullProp(b, 'name')));
for (const sa of storageAccounts) {
if (!sa.kind || sa.kind.match(kindRegExp) || !sa.sku || sa.sku.name.match(performanceRegExp) || sa.sku.name.match(replicationRegExp)) {
Expand All @@ -134,6 +135,14 @@ export class StorageAccountListStep<T extends types.IStorageAccountWizardContext
continue;
}

// old storage accounts (and the typings) use `networkRuleSet` but newer storage accounts have `networkAcls`
const networkDefaultAction = sa.networkRuleSet?.defaultAction ?? sa.networkAcls?.defaultAction;
if (sa.publicNetworkAccess?.toLocaleLowerCase() === 'disabled' ||
sa.publicNetworkAccess?.toLocaleLowerCase() === 'enabled' && networkDefaultAction === 'Deny') {
hasFilteredAccountsByNetwork = true;
continue;
}

picks.push({
id: sa.id,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -162,6 +171,15 @@ export class StorageAccountListStep<T extends types.IStorageAccountWizardContext
});
}

if (hasFilteredAccountsByNetwork) {
picks.push({
label: vscode.l10n.t('$(warning) Some storage accounts were filtered because of their network configurations.'),
onPicked: () => { /* do nothing */ },
data: undefined
});
}


return picks;
}
}
Expand Down

0 comments on commit efd6201

Please sign in to comment.