Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modules] Enable AAD authentication (#3952) #3953

Merged
merged 2 commits into from
Sep 12, 2023
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 @@ -51,6 +51,12 @@ resource keyPermissions 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
@description('The resource ID of the created Managed Identity.')
output managedIdentityResourceId string = managedIdentity.id

@description('The client ID of the created Managed Identity.')
output managedIdentityClientId string = managedIdentity.properties.clientId

@description('The name of the created Managed Identity.')
output managedIdentityName string = managedIdentity.name

@description('The resource ID of the created Key Vault.')
output keyVaultResourceId string = keyVault.id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ module testDeployment '../../main.bicep' = {
params: {
enableDefaultTelemetry: enableDefaultTelemetry
name: '${namePrefix}${serviceShort}001'
administratorLogin: 'adminUserName'
administratorLoginPassword: password
administrators: [
{
objectId: nestedDependencies.outputs.managedIdentityClientId
principalName: nestedDependencies.outputs.managedIdentityName
principalType: 'ServicePrincipal'
}
]
skuName: 'Standard_D2s_v3'
tier: 'GeneralPurpose'
availabilityZone: '1'
Expand Down
65 changes: 39 additions & 26 deletions modules/db-for-postgre-sql/flexible-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This module deploys a DBforPostgreSQL Flexible Server.
| `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) |
| `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) |
| `Microsoft.DBforPostgreSQL/flexibleServers` | [2022-12-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DBforPostgreSQL/2022-12-01/flexibleServers) |
| `Microsoft.DBforPostgreSQL/flexibleServers/administrators` | [2022-12-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DBforPostgreSQL/2022-12-01/flexibleServers/administrators) |
| `Microsoft.DBforPostgreSQL/flexibleServers/configurations` | [2022-12-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DBforPostgreSQL/2022-12-01/flexibleServers/configurations) |
| `Microsoft.DBforPostgreSQL/flexibleServers/databases` | [2022-12-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DBforPostgreSQL/2022-12-01/flexibleServers/databases) |
| `Microsoft.DBforPostgreSQL/flexibleServers/firewallRules` | [2022-12-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DBforPostgreSQL/2022-12-01/flexibleServers/firewallRules) |
Expand All @@ -28,8 +29,6 @@ This module deploys a DBforPostgreSQL Flexible Server.

| Parameter Name | Type | Allowed Values | Description |
| :-- | :-- | :-- | :-- |
| `administratorLogin` | string | | The administrator login name of a server. Can only be specified when the PostgreSQL server is being created. |
| `administratorLoginPassword` | securestring | | The administrator login password. |
| `name` | string | | The name of the PostgreSQL flexible server. |
| `skuName` | string | | The name of the sku, typically, tier + family + cores, e.g. Standard_D4s_v3. |
| `tier` | string | `[Burstable, GeneralPurpose, MemoryOptimized]` | The tier of the particular SKU. Tier must align with the "skuName" property. Example, tier cannot be "Burstable" if skuName is "Standard_D4s_v3". |
Expand All @@ -48,6 +47,10 @@ This module deploys a DBforPostgreSQL Flexible Server.

| Parameter Name | Type | Default Value | Allowed Values | Description |
| :-- | :-- | :-- | :-- | :-- |
| `activeDirectoryAuth` | string | `'Enabled'` | `[Disabled, Enabled]` | If Enabled, Azure Active Directory authentication is enabled. |
| `administratorLogin` | string | `''` | | The administrator login name of a server. Can only be specified when the PostgreSQL server is being created. |
| `administratorLoginPassword` | securestring | `''` | | The administrator login password. |
| `administrators` | array | `[]` | | The Azure AD administrators when AAD authentication enabled. |
| `availabilityZone` | string | `''` | `['', 1, 2, 3]` | Availability zone information of the server. Default will have no preference set. |
| `backupRetentionDays` | int | `7` | | Backup retention days for the server. |
| `cMKKeyName` | string | `''` | | The name of the customer managed key to use for encryption. |
Expand All @@ -70,10 +73,12 @@ This module deploys a DBforPostgreSQL Flexible Server.
| `location` | string | `[resourceGroup().location]` | | Location for all resources. |
| `lock` | string | `''` | `['', CanNotDelete, ReadOnly]` | Specify the type of lock. |
| `maintenanceWindow` | object | `{object}` | | Properties for the maintenence window. If provided, "customWindow" property must exist and set to "Enabled". |
| `passwordAuth` | string | `'Disabled'` | `[Disabled, Enabled]` | If Enabled, password authentication is enabled. |
| `privateDnsZoneArmResourceId` | string | `''` | | Private dns zone arm resource ID. Used when the desired connectivity mode is "Private Access" and required when "delegatedSubnetResourceId" is used. The Private DNS Zone must be lined to the Virtual Network referenced in "delegatedSubnetResourceId". |
| `roleAssignments` | array | `[]` | | Array of role assignment objects that contain the 'roleDefinitionIdOrName' and 'principalId' to define RBAC role assignments on this resource. In the roleDefinitionIdOrName attribute, you can provide either the display name of the role definition, or its fully qualified ID in the following format: '/providers/Microsoft.Authorization/roleDefinitions/c2f4ef07-c644-48eb-af81-4b1b4947fb11'. |
| `storageSizeGB` | int | `32` | `[32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]` | Max storage allowed for a server. |
| `tags` | object | `{object}` | | Tags of the resource. |
| `tenantId` | string | `''` | | Tenant id of the server. |
| `version` | string | `'15'` | `[11, 12, 13, 14, 15]` | PostgreSQL Server version. |


Expand Down Expand Up @@ -384,12 +389,12 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-dfpsfsmin'
params: {
// Required parameters
administratorLogin: 'adminUserName'
administratorLoginPassword: '<administratorLoginPassword>'
name: 'dfpsfsmin001'
skuName: 'Standard_B2s'
tier: 'Burstable'
// Non-required parameters
administratorLogin: 'adminUserName'
administratorLoginPassword: '<administratorLoginPassword>'
enableDefaultTelemetry: '<enableDefaultTelemetry>'
}
}
Expand All @@ -408,12 +413,6 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"administratorLogin": {
"value": "adminUserName"
},
"administratorLoginPassword": {
"value": "<administratorLoginPassword>"
},
"name": {
"value": "dfpsfsmin001"
},
Expand All @@ -424,6 +423,12 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
"value": "Burstable"
},
// Non-required parameters
"administratorLogin": {
"value": "adminUserName"
},
"administratorLoginPassword": {
"value": "<administratorLoginPassword>"
},
"enableDefaultTelemetry": {
"value": "<enableDefaultTelemetry>"
}
Expand All @@ -445,12 +450,12 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-dfpsfspvt'
params: {
// Required parameters
administratorLogin: 'adminUserName'
administratorLoginPassword: '<administratorLoginPassword>'
name: 'dfpsfspvt001'
skuName: 'Standard_D2s_v3'
tier: 'GeneralPurpose'
// Non-required parameters
administratorLogin: 'adminUserName'
administratorLoginPassword: '<administratorLoginPassword>'
configurations: [
{
name: 'log_min_messages'
Expand Down Expand Up @@ -503,12 +508,6 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"administratorLogin": {
"value": "adminUserName"
},
"administratorLoginPassword": {
"value": "<administratorLoginPassword>"
},
"name": {
"value": "dfpsfspvt001"
},
Expand All @@ -519,6 +518,12 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
"value": "GeneralPurpose"
},
// Non-required parameters
"administratorLogin": {
"value": "adminUserName"
},
"administratorLoginPassword": {
"value": "<administratorLoginPassword>"
},
"configurations": {
"value": [
{
Expand Down Expand Up @@ -594,12 +599,17 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-dfpsfsp'
params: {
// Required parameters
administratorLogin: 'adminUserName'
administratorLoginPassword: '<administratorLoginPassword>'
name: 'dfpsfsp001'
skuName: 'Standard_D2s_v3'
tier: 'GeneralPurpose'
// Non-required parameters
administrators: [
{
objectId: '<objectId>'
principalName: '<principalName>'
principalType: 'ServicePrincipal'
}
]
availabilityZone: '1'
backupRetentionDays: 20
cMKKeyName: '<cMKKeyName>'
Expand Down Expand Up @@ -674,12 +684,6 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"administratorLogin": {
"value": "adminUserName"
},
"administratorLoginPassword": {
"value": "<administratorLoginPassword>"
},
"name": {
"value": "dfpsfsp001"
},
Expand All @@ -690,6 +694,15 @@ module flexibleServer './db-for-postgre-sql/flexible-server/main.bicep' = {
"value": "GeneralPurpose"
},
// Non-required parameters
"administrators": {
"value": [
{
"objectId": "<objectId>",
"principalName": "<principalName>",
"principalType": "ServicePrincipal"
}
]
},
"availabilityZone": {
"value": "1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# DBforPostgreSQL Flexible Server Administrators `[Microsoft.DBforPostgreSQL/flexibleServers/administrators]`

This module deploys a DBforPostgreSQL Flexible Server Administrator.

## Navigation

- [Resource Types](#Resource-Types)
- [Parameters](#Parameters)
- [Outputs](#Outputs)
- [Cross-referenced modules](#Cross-referenced-modules)

## Resource Types

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.DBforPostgreSQL/flexibleServers/administrators` | [2022-12-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DBforPostgreSQL/2022-12-01/flexibleServers/administrators) |

## Parameters

**Required parameters**

| Parameter Name | Type | Allowed Values | Description |
| :-- | :-- | :-- | :-- |
| `objectId` | string | | The objectId of the Active Directory administrator. |
| `principalName` | string | | Active Directory administrator principal name. |
| `principalType` | string | `[Group, ServicePrincipal, Unknown, User]` | The principal type used to represent the type of Active Directory Administrator. |

**Conditional parameters**

| Parameter Name | Type | Description |
| :-- | :-- | :-- |
| `flexibleServerName` | string | The name of the parent PostgreSQL flexible server. Required if the template is used in a standalone deployment. |

**Optional parameters**

| Parameter Name | Type | Default Value | Description |
| :-- | :-- | :-- | :-- |
| `enableDefaultTelemetry` | bool | `True` | Enable telemetry via a Globally Unique Identifier (GUID). |
| `location` | string | `[resourceGroup().location]` | Location for all resources. |
| `tenantId` | string | `[tenant().tenantId]` | The tenantId of the Active Directory administrator. |


## Outputs

| Output Name | Type | Description |
| :-- | :-- | :-- |
| `name` | string | The name of the deployed administrator. |
| `resourceGroupName` | string | The resource group of the deployed administrator. |
| `resourceId` | string | The resource ID of the deployed administrator. |

## Cross-referenced modules

_None_
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
metadata name = 'DBforPostgreSQL Flexible Server Administrators'
metadata description = 'This module deploys a DBforPostgreSQL Flexible Server Administrator.'
metadata owner = 'Azure/module-maintainers'

@description('Conditional. The name of the parent PostgreSQL flexible server. Required if the template is used in a standalone deployment.')
param flexibleServerName string

@description('Required. The objectId of the Active Directory administrator.')
param objectId string

@description('Required. Active Directory administrator principal name.')
param principalName string

@allowed([
'Group'
'ServicePrincipal'
'Unknown'
'User'
])
@description('Required. The principal type used to represent the type of Active Directory Administrator.')
param principalType string

@description('Optional. The tenantId of the Active Directory administrator.')
param tenantId string = tenant().tenantId

@description('Optional. Location for all resources.')
param location string = resourceGroup().location

@description('Optional. Enable telemetry via a Globally Unique Identifier (GUID).')
param enableDefaultTelemetry bool = true

resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name, location)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
}
}
}

resource flexibleServer 'Microsoft.DBforPostgreSQL/flexibleServers@2022-12-01' existing = {
name: flexibleServerName
}

resource administrator 'Microsoft.DBforPostgreSQL/flexibleServers/administrators@2022-12-01' = {
name: objectId
parent: flexibleServer
properties: {
principalName: principalName
principalType: principalType
tenantId: tenantId
}
}

@description('The name of the deployed administrator.')
output name string = administrator.name

@description('The resource ID of the deployed administrator.')
output resourceId string = administrator.id

@description('The resource group of the deployed administrator.')
output resourceGroupName string = resourceGroup().name
Loading
Loading