Skip to content

Commit efb1829

Browse files
authored
Merge pull request #20 from cloudgraphdev/feature/CG-1208
feat(services): Updated Disk and StorageAccount services needed for CIS 3.3 and 7.7 rules
2 parents 6992ec1 + deb0854 commit efb1829

File tree

8 files changed

+9803
-9517
lines changed

8 files changed

+9803
-9517
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
"@azure/arm-privatedns": "^3.0.0",
5959
"@azure/arm-recoveryservices": "^5.0.0",
6060
"@azure/arm-recoveryservices-siterecovery": "^4.0.0",
61-
"@azure/arm-rediscache": "^6.1.0",
6261
"@azure/arm-recoveryservicesbackup": "^8.1.0",
62+
"@azure/arm-rediscache": "^6.1.0",
6363
"@azure/arm-resources": "^5.0.0",
6464
"@azure/arm-security": "^4.0.0",
6565
"@azure/arm-servicebus": "^5.0.0",
@@ -72,6 +72,7 @@
7272
"@azure/core-http": "^2.2.4",
7373
"@azure/identity": "^2.0.4",
7474
"@azure/storage-blob": "^12.8.0",
75+
"@azure/storage-queue": "^12.9.0",
7576
"@cloudgraph/sdk": "0.14.2",
7677
"@graphql-tools/load-files": "^6.5.3",
7778
"@graphql-tools/merge": "^8.2.3",

src/services/disk/format.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default ({
3333
networkAccessPolicy,
3434
tier,
3535
encryption: { type: encryptionSettings = null } = {},
36+
encryptionSettingsCollection: { enabled: encryptionEnabled } = {},
3637
resourceGroupId,
3738
Tags,
3839
} = service
@@ -61,6 +62,7 @@ export default ({
6162
networkAccessPolicy,
6263
tier,
6364
encryptionSettings,
65+
azureDiskEncryptionEnabled: encryptionEnabled ?? false,
6466
resourceGroupId,
6567
tags: formatTagsFromMap(Tags),
6668
}

src/services/disk/schema.graphql

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type azureDisk implements azureResource
2020
networkAccessPolicy: String @search(by: [hash, regexp])
2121
tier: String @search(by: [hash, regexp])
2222
encryptionSettings: String @search(by: [hash, regexp])
23+
azureDiskEncryptionEnabled: Boolean @search
2324
resourceGroup: [azureResourceGroup] @hasInverse(field: disks)
2425
virtualMachine: [azureVirtualMachine] @hasInverse(field: disks)
2526
}

src/services/storageAccount/data.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import {
55
StorageAccountKey,
66
StorageManagementClient,
77
} from '@azure/arm-storage'
8+
import {
9+
QueueServiceClient,
10+
StorageSharedKeyCredential,
11+
QueueServiceProperties,
12+
} from '@azure/storage-queue'
813
import { isEmpty } from 'lodash'
914
import azureLoggerText from '../../properties/logger'
1015

@@ -21,12 +26,35 @@ export interface RawAzureStorageAccount
2126
keys: StorageAccountKey[]
2227
Tags: TagMap
2328
blobServiceProperties: BlobServiceProperties
29+
queueServiceProperties: QueueServiceProperties
2430
}
2531

2632
const { logger } = CloudGraph
2733
const lt = { ...azureLoggerText }
2834
const serviceName = 'StorageAccount'
2935

36+
const getQueueServiceProperties = async (
37+
accountName: string,
38+
accountKey: string
39+
): Promise<QueueServiceProperties> => {
40+
try {
41+
const sharedKeyCredential = new StorageSharedKeyCredential(
42+
accountName,
43+
accountKey
44+
)
45+
46+
const queueClient = new QueueServiceClient(
47+
`https://${accountName}.queue.core.windows.net`,
48+
sharedKeyCredential
49+
)
50+
51+
return await queueClient.getProperties()
52+
} catch (e) {
53+
logger.error(e)
54+
return {}
55+
}
56+
}
57+
3058
export default async ({
3159
regions,
3260
config,
@@ -88,6 +116,13 @@ export default async ({
88116
rest.name
89117
)
90118

119+
// Fetch Storage Account Queue Service Properties
120+
const [mainKey] = keys
121+
const queueServiceProperties = await getQueueServiceProperties(
122+
rest.name,
123+
mainKey.value
124+
)
125+
91126
result[region].push({
92127
id,
93128
...rest,
@@ -96,13 +131,14 @@ export default async ({
96131
keys,
97132
Tags: tags || {},
98133
blobServiceProperties,
134+
queueServiceProperties,
99135
})
100136
numOfAccounts += 1
101137
}
102138
}
103139

104140
logger.debug(lt.foundStorageAccounts(numOfAccounts))
105-
141+
106142
return result
107143
}
108144
return existingData

src/services/storageAccount/format.ts

+11
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export default ({
111111
resourceGroupId,
112112
Tags,
113113
blobServiceProperties,
114+
queueServiceProperties = {},
114115
} = service
115116

116117
return {
@@ -270,5 +271,15 @@ export default ({
270271
skuName: blobServiceProperties?.sku?.name,
271272
skuTier: blobServiceProperties?.sku?.tier,
272273
},
274+
queueServiceProperties: {
275+
logging: queueServiceProperties ? {
276+
version: queueServiceProperties.queueAnalyticsLogging?.version,
277+
read : queueServiceProperties.queueAnalyticsLogging?.read ?? false,
278+
write : queueServiceProperties.queueAnalyticsLogging?.write ?? false,
279+
delete : queueServiceProperties.queueAnalyticsLogging?.deleteProperty ?? false,
280+
retentionPolicyEnabled : queueServiceProperties.queueAnalyticsLogging?.retentionPolicy?.enabled ?? false,
281+
retentionPolicyDays: queueServiceProperties.queueAnalyticsLogging?.retentionPolicy?.days
282+
} : {},
283+
},
273284
}
274285
}

src/services/storageAccount/schema.graphql

+24
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ type azureStorageAccountServiceProperties
147147
skuTier: String @search(by: [hash, regexp])
148148
}
149149

150+
type azureStorageAccountQueueServicePropertiesLogging
151+
@generate(
152+
query: { get: false, query: true, aggregate: false }
153+
mutation: { add: false, delete: false }
154+
subscription: false
155+
) {
156+
version: String @search(by: [hash, regexp])
157+
read: Boolean @search
158+
write: Boolean @search
159+
delete: Boolean @search
160+
retentionPolicyEnabled: Boolean @search
161+
retentionPolicyDays: Int @search
162+
}
163+
164+
type azureStorageAccountQueueServiceProperties
165+
@generate(
166+
query: { get: false, query: true, aggregate: false }
167+
mutation: { add: false, delete: false }
168+
subscription: false
169+
) {
170+
logging: azureStorageAccountQueueServicePropertiesLogging
171+
}
172+
150173
type azureStorageAccount implements azureResource
151174
@generate(
152175
query: { get: true, query: true, aggregate: true }
@@ -209,6 +232,7 @@ type azureStorageAccount implements azureResource
209232
allowSharedKeyAccess: String @search(by: [hash, regexp])
210233
enableNfsV3: String @search(by: [hash, regexp])
211234
blobServiceProperties: azureStorageAccountServiceProperties
235+
queueServiceProperties: azureStorageAccountQueueServiceProperties
212236
resourceGroup: [azureResourceGroup] @hasInverse(field: storageAccounts)
213237
storageContainers: [azureStorageContainer] @hasInverse(field: storageAccount)
214238
appServiceWebApp: [azureAppServiceWebApp] @hasInverse(field: storageAccounts)

src/types/generated.ts

+15
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,7 @@ export type AzureDiagnosticSettingMetricSettings = {
23382338
};
23392339

23402340
export type AzureDisk = AzureResource & {
2341+
azureDiskEncryptionEnabled?: Maybe<Scalars['Boolean']>;
23412342
createOption?: Maybe<Scalars['String']>;
23422343
diskIopsReadWrite?: Maybe<Scalars['Int']>;
23432344
diskMbpsReadWrite?: Maybe<Scalars['Int']>;
@@ -4416,6 +4417,7 @@ export type AzureStorageAccount = AzureResource & {
44164417
primaryMicrosoftEndpoints?: Maybe<AzureStorageAccountPrimaryMicrosoftEndpoints>;
44174418
privateEndpointConnections?: Maybe<Array<Maybe<AzureStorageAccountPrivateEndpointConnection>>>;
44184419
provisioningState?: Maybe<Scalars['String']>;
4420+
queueServiceProperties?: Maybe<AzureStorageAccountQueueServiceProperties>;
44194421
resourceGroup?: Maybe<Array<Maybe<AzureResourceGroup>>>;
44204422
routingPreferenceChoice?: Maybe<Scalars['String']>;
44214423
routingPreferencePublishInternetEndpoints?: Maybe<Scalars['String']>;
@@ -4473,6 +4475,19 @@ export type AzureStorageAccountPrivateEndpointConnection = {
44734475
provisioningState?: Maybe<Scalars['String']>;
44744476
};
44754477

4478+
export type AzureStorageAccountQueueServiceProperties = {
4479+
logging?: Maybe<AzureStorageAccountQueueServicePropertiesLogging>;
4480+
};
4481+
4482+
export type AzureStorageAccountQueueServicePropertiesLogging = {
4483+
delete?: Maybe<Scalars['Boolean']>;
4484+
read?: Maybe<Scalars['Boolean']>;
4485+
retentionPolicyDays?: Maybe<Scalars['Int']>;
4486+
retentionPolicyEnabled?: Maybe<Scalars['Boolean']>;
4487+
version?: Maybe<Scalars['String']>;
4488+
write?: Maybe<Scalars['Boolean']>;
4489+
};
4490+
44764491
export type AzureStorageAccountResourceAccessRule = {
44774492
id: Scalars['String'];
44784493
resourceId?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)