Skip to content

Commit c4831a4

Browse files
Merge pull request #212062 from mumian/0921-linter-secure-params
New Bicep linter rule: secure-params-in-nested-deploy
2 parents 194fbcd + 1c60a4d commit c4831a4

File tree

4 files changed

+140
-6
lines changed

4 files changed

+140
-6
lines changed

articles/azure-resource-manager/bicep/bicep-config-linter.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Linter settings for Bicep config
33
description: Describes how to customize configuration values for the Bicep linter
44
ms.topic: conceptual
5-
ms.date: 08/01/2022
5+
ms.date: 09/21/2022
66
---
77

88
# Add linter settings in the Bicep config file
@@ -29,9 +29,27 @@ The following example shows the rules that are available for configuration.
2929
"artifacts-parameters": {
3030
"level": "warning"
3131
},
32+
"max-outputs": {
33+
"level": "warning"
34+
},
35+
"max-params": {
36+
"level": "warning"
37+
},
38+
"max-resources": {
39+
"level": "warning"
40+
},
41+
"max-variables": {
42+
"level": "warning"
43+
},
3244
"no-hardcoded-env-urls": {
3345
"level": "warning"
3446
},
47+
"no-hardcoded-location": {
48+
"level": "warning"
49+
},
50+
"no-loc-expr-outside-params": {
51+
"level": "warning"
52+
},
3553
"no-unnecessary-dependson": {
3654
"level": "warning"
3755
},
@@ -59,12 +77,18 @@ The following example shows the rules that are available for configuration.
5977
"secure-parameter-default": {
6078
"level": "warning"
6179
},
62-
"simplify-interpolation": {
80+
"secure-params-in-nested-deploy": {
6381
"level": "warning"
6482
},
6583
"secure-secrets-in-params": {
6684
"level": "warning"
6785
},
86+
"simplify-interpolation": {
87+
"level": "warning"
88+
},
89+
"use-protectedsettings-for-commandtoexecute-secrets": {
90+
"level": "warning"
91+
},
6892
"use-stable-resource-identifiers": {
6993
"level": "warning"
7094
},
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: Linter rule - secure params in nested deploy
3+
description: Linter rule - secure params in nested deploy
4+
ms.topic: conceptual
5+
ms.date: 09/22/2022
6+
---
7+
8+
# Linter rule - secure params in nested deploy
9+
10+
Outer-scoped nested deployment resources shouldn't use for secure parameters or list* functions. You could expose the secure values in the deployment history.
11+
12+
## Linter rule code
13+
14+
Use the following value in the [Bicep configuration file](bicep-config-linter.md) to customize rule settings:
15+
16+
`secure-params-in-nested-deploy`
17+
18+
## Solution
19+
20+
Either set the [deployment's properties.expressionEvaluationOptions.scope](/azure/templates/microsoft.resources/deployments?pivots=deployment-language-bicep) to `inner` or use a Bicep module instead.
21+
22+
The following example fails this test because a secure parameter is referenced in an outer-scoped nested deployment resource.
23+
24+
```bicep
25+
@secure()
26+
param secureValue string
27+
28+
resource nested 'Microsoft.Resources/deployments@2021-04-01' = {
29+
name: 'nested'
30+
properties: {
31+
mode: 'Incremental'
32+
template: {
33+
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
34+
contentVersion: '1.0.0.0'
35+
variables: {}
36+
resources: [
37+
{
38+
name: 'outerImplicit'
39+
type: 'Microsoft.Network/networkSecurityGroups'
40+
apiVersion: '2019-11-01'
41+
location: '[resourceGroup().location]'
42+
properties: {
43+
securityRules: [
44+
{
45+
name: 'outerImplicit'
46+
properties: {
47+
description: format('{0}', secureValue)
48+
protocol: 'Tcp'
49+
}
50+
}
51+
]
52+
}
53+
}
54+
]
55+
}
56+
}
57+
}
58+
```
59+
60+
You can fix it by setting the deployment's properties.expressionEvaluationOptions.scope to 'inner':
61+
62+
```bicep
63+
@secure()
64+
param secureValue string
65+
66+
resource nested 'Microsoft.Resources/deployments@2021-04-01' = {
67+
name: 'nested'
68+
properties: {
69+
mode: 'Incremental'
70+
expressionEvaluationOptions: {
71+
scope: 'Inner' // Set to inner scope
72+
}
73+
template: {
74+
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
75+
contentVersion: '1.0.0.0'
76+
variables: {}
77+
resources: [
78+
{
79+
name: 'outerImplicit'
80+
type: 'Microsoft.Network/networkSecurityGroups'
81+
apiVersion: '2019-11-01'
82+
location: '[resourceGroup().location]'
83+
properties: {
84+
securityRules: [
85+
{
86+
name: 'outerImplicit'
87+
properties: {
88+
description: format('{0}', secureValue)
89+
protocol: 'Tcp'
90+
}
91+
}
92+
]
93+
}
94+
}
95+
]
96+
}
97+
}
98+
}
99+
100+
```
101+
102+
## Next steps
103+
104+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Use Bicep linter
33
description: Learn how to use Bicep linter.
44
ms.topic: conceptual
5-
ms.date: 07/29/2022
5+
ms.date: 09/21/2022
66
---
77

88
# Use Bicep linter
@@ -24,14 +24,18 @@ The default set of linter rules is minimal and taken from [arm-ttk test cases](.
2424
- [max-resources](./linter-rule-max-resources.md)
2525
- [max-variables](./linter-rule-max-variables.md)
2626
- [no-hardcoded-env-urls](./linter-rule-no-hardcoded-environment-urls.md)
27+
- [no-hardcoded-location](./linter-rule-no-hardcoded-location.md)
28+
- [no-loc-expr-outside-params](./linter-rule-no-loc-expr-outside-params.md)
2729
- [no-unnecessary-dependson](./linter-rule-no-unnecessary-dependson.md)
2830
- [no-unused-existing-resources](./linter-rule-no-unused-existing-resources.md)
2931
- [no-unused-params](./linter-rule-no-unused-parameters.md)
3032
- [no-unused-vars](./linter-rule-no-unused-variables.md)
3133
- [outputs-should-not-contain-secrets](./linter-rule-outputs-should-not-contain-secrets.md)
3234
- [prefer-interpolation](./linter-rule-prefer-interpolation.md)
3335
- [prefer-unquoted-property-names](./linter-rule-prefer-unquoted-property-names.md)
36+
- [protect-commandtoexecute-secrets](./linter-rule-protect-commandtoexecute-secrets.md)
3437
- [secure-parameter-default](./linter-rule-secure-parameter-default.md)
38+
- [secure-params-in-nested-deploy](./linter-rule-secure-params-in-nested-deploy.md)
3539
- [secure-secrets-in-params](./linter-rule-secure-secrets-in-parameters.md)
3640
- [simplify-interpolation](./linter-rule-simplify-interpolation.md)
3741
- [use-protectedsettings-for-commandtoexecute-secrets](./linter-rule-use-protectedsettings-for-commandtoexecute-secrets.md)
@@ -68,15 +72,15 @@ You can integrate these checks as a part of your CI/CD pipelines. You can use a
6872

6973
## Silencing false positives
7074

71-
Sometimes a rule can have false positives. For example you may need to include a link to a blob storage directly without using the [environment()](./bicep-functions-deployment.md#environment) function.
75+
Sometimes a rule can have false positives. For example, you may need to include a link to a blob storage directly without using the [environment()](./bicep-functions-deployment.md#environment) function.
7276
In this case you can disable the warning for one line only, not the entire document, by adding `#disable-next-line <rule name>` before the line with the warning.
7377

7478
```bicep
7579
#disable-next-line no-hardcoded-env-urls //Direct download link to my toolset
7680
scriptDownloadUrl: 'https://mytools.blob.core.windows.net/...'
7781
```
7882

79-
It is good practice to add a comment explaining why the rule does not apply to this line.
83+
It's good practice to add a comment explaining why the rule doesn't apply to this line.
8084

8185
## Next steps
8286

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@
402402
href: linter-rule-max-variables.md
403403
- name: No hardcoded environment URLs
404404
href: linter-rule-no-hardcoded-environment-urls.md
405-
- name: No hard-coded locations
405+
- name: No hardcoded locations
406406
href: linter-rule-no-hardcoded-location.md
407407
- name: No location expressions outside of parameter default values
408408
href: linter-rule-no-loc-expr-outside-params.md
@@ -424,6 +424,8 @@
424424
href: linter-rule-protect-commandtoexecute-secrets.md
425425
- name: Secure parameter default
426426
href: linter-rule-secure-parameter-default.md
427+
- name: Secure parameters in nested deployments
428+
href: linter-rule-secure-params-in-nested-deploy.md
427429
- name: Secure secrets in parameters
428430
href: linter-rule-secure-secrets-in-parameters.md
429431
- name: Simplify interpolation

0 commit comments

Comments
 (0)