Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,48 @@ priority: 11015

## ID: BCPNFR21 - User-defined types - Decorators

Similar to [BCPNFR9]({{% siteparam base %}}/spec/BCPNFR9), User-defined types (UDTs) MUST implement [decorators](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/parameters#use-decorators) such as `description` & `secure` (if sensitive). This is true for every property of the UDT, as well as the UDT itself.
User-defined types (UDTs) and each of their properties MUST have a `@description()` [decorator](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/user-defined-data-types#decorators).

Further, User-defined types SHOULD implement decorators like `allowed`, `minValue`, `maxValue`, `minLength` & `maxLength` (and others if available) as they have a big positive impact on the module's usability.
Apply the secure input requirements in [BCPNFR9]({{% siteparam base %}}/spec/BCPNFR9) to UDT properties as well as parameters. If a UDT has both sensitive and non-sensitive properties, mark each sensitive `string` property with `@secure()`. You can mark an `object` property `@secure()` only if all of its properties are sensitive. Do not mark an object, property, or parameter `@secure()` if it contains any non-sensitive properties, because this marks everything inside it as secure too.

`@secure()` works only on strings and objects, not arrays. For an array of objects, mark the secure properties on the item type, not on the array.

UDTs SHOULD also use constraints such as `minValue`, `maxValue`, `minLength`, and `maxLength` to improve usability.

In this example, the parent marks the `password` property as secure and passes it to the child's secure `accountPassword` parameter. The `name` property and `accountName` parameter both stay non-secure.

Parent module:

```bicep
@description('My type''s description.')
type myType = {
@description('Optional. The threshold of your resource.')
@minValue(1)
@maxValue(10)
threshold: int?

@description('Required. The SKU of your resource.')
sku: ('Basic' | 'Premium' | 'Standard')
@description('The settings for an account.')
type account = {
@description('The account name.')
@minLength(1)
name: string

@description('The account password.')
@secure()
password: string
}

@description('Required. The accounts to configure.')
param accounts account[]

module accountDeployments 'account.bicep' = [for account in accounts: {
params: {
accountName: account.name
accountPassword: account.password
}
}]
```

Child module inputs (`account.bicep`):

```bicep
@description('Required. The account name.')
param accountName string

@description('Required. The account password.')
@secure()
param accountPassword string
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ priority: 11011

## ID: BCPNFR9 - Inputs - Decorators

Similar to [BCPNFR21]({{% siteparam base %}}/spec/BCPNFR21), input parameters MUST implement [decorators](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/parameters#use-decorators) such as `description` & `secure` (if sensitive).
Input parameters MUST have a `@description()` [decorator](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/parameters#use-decorators). Mark sensitive `string` parameters, and parameters whose entire object value is sensitive, with `@secure()`. For objects that mix sensitive and non-sensitive properties, or arrays of objects with sensitive properties, follow [BCPNFR21]({{% siteparam base %}}/spec/BCPNFR21).

When a module passes an input to a secure child module parameter, a secure property of a child module input, or a secure resource property, you MUST also mark the source parameter or property `@secure()`. Do this at every step of the deployment: if you secure only the last input, the value stays unprotected at the earlier steps. Do not pass a `@secure()` value to a non-secure module or resource input. Leave non-sensitive values unmarked so you can pass them to non-secure inputs.

The Bicep linter rules [`use-secure-value-for-secure-inputs`](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/linter-rule-use-secure-value-for-secure-inputs) and `no-secure-values-in-insecure-inputs` report these mismatches as warnings in Bicep versions that support the checks. Follow this requirement even if the Bicep version used by AVM CI does not yet report the mismatch.

Further, input parameters SHOULD implement decorators like `allowed`, `minValue`, `maxValue`, `minLength` & `maxLength` (and others if available) as they have a big positive impact on the module's usability.

Expand Down