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

fix: Add key vault to search service - avm/res/search/search-service #1950

Merged
merged 38 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
764b13b
aisearchservice with adminkeys in keyvault
May 16, 2024
780d080
Merge branch 'Azure:main' into Aisearch_w_keyvault
mortenvpschmidt May 16, 2024
e4e0366
AISearchService with adminkeys in keyvault
May 16, 2024
59843fa
AiSearchService with AdminKeys in Keyvault
May 16, 2024
2c71c35
AiSearchService with AdminKeys in Keyvault
May 16, 2024
72e0aaf
Typo in main.test.bicep
May 16, 2024
6f92af0
Typo in main.test.bicep
May 16, 2024
46ba068
Revert "AISearchService with adminkeys in keyvault undo recurse"
May 17, 2024
4859142
Merge branch 'Azure:main' into Aisearch_w_keyvault
mortenvpschmidt May 17, 2024
0d4bc4f
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 14, 2024
46f0179
Updated to Secrets export
Agazoth Aug 14, 2024
2bc93c3
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 16, 2024
3044eaf
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 21, 2024
e8c43fe
Key valul exists bump name
Agazoth Aug 21, 2024
8e6f4ed
Added telemetry fix
Agazoth Aug 21, 2024
af24958
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 22, 2024
588b56b
Ran Set-AVMModule
Agazoth Aug 22, 2024
968329d
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 22, 2024
386c182
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Sep 27, 2024
4475920
Short changed as agreed
Agazoth Sep 27, 2024
35f4820
Merge branch 'Aisearch_w_keyvault' of https://github.com/mortenvpschm…
Agazoth Sep 27, 2024
751c5ee
Fix readme bug
Agazoth Sep 27, 2024
157acfc
Merge branch 'main' into Aisearch_w_keyvault
eriqua Sep 29, 2024
726d5f8
Updated according to comment
Agazoth Sep 30, 2024
4b04e67
Updated according to comment
Agazoth Sep 30, 2024
bc2e35f
Readme updated
Agazoth Sep 30, 2024
9e0e703
Readme updated
Agazoth Sep 30, 2024
b78353c
fixed main.json
Agazoth Sep 30, 2024
61db651
Fixed the other readme
Agazoth Sep 30, 2024
9ebc1b0
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Oct 1, 2024
b2b9bf7
Fixed Readme manually
Agazoth Oct 1, 2024
2dbe17a
Updated readme manually
Agazoth Oct 1, 2024
efc4b8a
Casing and plural manually updated
Agazoth Oct 1, 2024
b97485a
Strange place to camelCase - fixed manually
Agazoth Oct 1, 2024
5c921d9
A linebreak seems to be missing
Agazoth Oct 1, 2024
d0a875a
Too many linebreaks ...
Agazoth Oct 1, 2024
c21bb21
Added a linebreak
Agazoth Oct 1, 2024
945c1ed
More camelCase
Agazoth Oct 1, 2024
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
134 changes: 134 additions & 0 deletions avm/res/search/search-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,85 @@ module searchService 'br/public:avm/res/search/search-service:<version>' = {
</details>
<p>

<<<<<<< HEAD
### Example 2: _Deploying with a key vault reference to save secrets_

This instance deploys the module saving admin key secrets in a key vault.


<details>

<summary>via Bicep module</summary>

```bicep
module searchService 'br/public:avm/res/search/search-service:<version>' = {
name: 'searchServiceDeployment'
params: {
// Required parameters
name: 'kv-ref'
// Non-required parameters
authOptions: {
aadOrApiKey: {
aadAuthFailureMode: 'http401WithBearerChallenge'
}
}
disableLocalAuth: false
location: '<location>'
secretsKeyVault: {
keyVaultName: '<keyVaultName>'
primaryAdminKeySecretName: 'Primary-Admin-Key'
}
}
}
```

</details>
<p>

<details>

<summary>via JSON Parameter file</summary>

```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"name": {
"value": "kv-ref"
},
// Non-required parameters
"authOptions": {
"value": {
"aadOrApiKey": {
"aadAuthFailureMode": "http401WithBearerChallenge"
}
}
},
"disableLocalAuth": {
"value": false
},
"location": {
"value": "<location>"
},
"secretsKeyVault": {
"value": {
"keyVaultName": "<keyVaultName>",
"primaryAdminKeySecretName": "Primary-Admin-Key"
}
}
}
}
```

</details>
<p>

### Example 3: _Using large parameter set_
=======
### Example 2: _Using large parameter set_
>>>>>>> parent of e4e03661 (AISearchService with adminkeys in keyvault)

This instance deploys the module with most of its features enabled.

Expand Down Expand Up @@ -620,6 +698,10 @@ module searchService 'br/public:avm/res/search/search-service:<version>' = {
| [`publicNetworkAccess`](#parameter-publicnetworkaccess) | string | This value can be set to 'enabled' to avoid breaking changes on existing customer resources and templates. If set to 'disabled', traffic over public interface is not allowed, and private endpoint connections would be the exclusive access method. |
| [`replicaCount`](#parameter-replicacount) | int | The number of replicas in the search service. If specified, it must be a value between 1 and 12 inclusive for standard SKUs or between 1 and 3 inclusive for basic SKU. |
| [`roleAssignments`](#parameter-roleassignments) | array | Array of role assignments to create. |
<<<<<<< HEAD
| [`secretsKeyVault`](#parameter-secretskeyvault) | object | Key vault reference and secret settings to add the API admin keys generated by the search-service account. |
=======
>>>>>>> parent of e4e03661 (AISearchService with adminkeys in keyvault)
| [`semanticSearch`](#parameter-semanticsearch) | string | Sets options that control the availability of semantic search. This configuration is only possible for certain search SKUs in certain locations. |
| [`sharedPrivateLinkResources`](#parameter-sharedprivatelinkresources) | array | The sharedPrivateLinkResources to create as part of the search Service. |
| [`sku`](#parameter-sku) | string | Defines the SKU of an Azure Cognitive Search Service, which determines price tier and capacity limits. |
Expand Down Expand Up @@ -1368,6 +1450,58 @@ The principal type of the assigned principal ID.
]
```

<<<<<<< HEAD
### Parameter: `secretsKeyVault`

Key vault reference and secret settings to add the API admin keys generated by the search-service account.

- Required: No
- Type: object

**Required parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`keyVaultName`](#parameter-secretskeyvaultkeyvaultname) | string | The key vault name where to store the API Admin keys generated by the modules. |

**Optional parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`primaryAdminKeySecretName`](#parameter-secretskeyvaultprimaryadminkeysecretname) | string | Default to API Primary admin key . The primary admin key secret name to create. |
| [`resourceGroupName`](#parameter-secretskeyvaultresourcegroupname) | string | Default to the resource group where this account is. The resource group name where the key vault is. |
| [`secondaryAdminKeySecretName`](#parameter-secretskeyvaultsecondaryadminkeysecretname) | string | Default to API Secondary admin key . The secondary admin key secret name to create. |

### Parameter: `secretsKeyVault.keyVaultName`

The key vault name where to store the API Admin keys generated by the modules.

- Required: Yes
- Type: string

### Parameter: `secretsKeyVault.primaryAdminKeySecretName`

Default to API Primary admin key . The primary admin key secret name to create.

- Required: No
- Type: string

### Parameter: `secretsKeyVault.resourceGroupName`

Default to the resource group where this account is. The resource group name where the key vault is.

- Required: No
- Type: string

### Parameter: `secretsKeyVault.secondaryAdminKeySecretName`

Default to API Secondary admin key . The secondary admin key secret name to create.

- Required: No
- Type: string

=======
>>>>>>> parent of e4e03661 (AISearchService with adminkeys in keyvault)
### Parameter: `semanticSearch`

Sets options that control the availability of semantic search. This configuration is only possible for certain search SKUs in certain locations.
Expand Down
82 changes: 58 additions & 24 deletions avm/res/search/search-service/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ param sharedPrivateLinkResources array = []
])
param publicNetworkAccess string = 'enabled'

@description('Optional. Key vault reference and secret settings to add the API admin keys generated by the search-service account.')
param secretsKeyVault secretsKeyVaultType?

@description('Optional. The number of replicas in the search service. If specified, it must be a value between 1 and 12 inclusive for standard SKUs or between 1 and 3 inclusive for basic SKU.')
@minValue(1)
@maxValue(12)
Expand Down Expand Up @@ -137,24 +140,23 @@ var builtInRoleNames = {
)
}

resource avmTelemetry 'Microsoft.Resources/deployments@2023-07-01' =
if (enableTelemetry) {
name: '46d3xbcp.search-searchservice.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
outputs: {
telemetry: {
type: 'String'
value: 'For more information, see https://aka.ms/avm/TelemetryInfo'
}
resource avmTelemetry 'Microsoft.Resources/deployments@2023-07-01' = if (enableTelemetry) {
name: '46d3xbcp.search-searchservice.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
outputs: {
telemetry: {
type: 'String'
value: 'For more information, see https://aka.ms/avm/TelemetryInfo'
}
}
}
}
}

resource searchService 'Microsoft.Search/searchServices@2023-11-01' = {
location: location
Expand Down Expand Up @@ -208,17 +210,16 @@ resource searchService_diagnosticSettings 'Microsoft.Insights/diagnosticSettings
}
]

resource searchService_lock 'Microsoft.Authorization/locks@2020-05-01' =
if (!empty(lock ?? {}) && lock.?kind != 'None') {
name: lock.?name ?? 'lock-${name}'
properties: {
level: lock.?kind ?? ''
notes: lock.?kind == 'CanNotDelete'
? 'Cannot delete resource or child resources.'
: 'Cannot delete or modify the resource or child resources.'
}
scope: searchService
resource searchService_lock 'Microsoft.Authorization/locks@2020-05-01' = if (!empty(lock ?? {}) && lock.?kind != 'None') {
name: lock.?name ?? 'lock-${name}'
properties: {
level: lock.?kind ?? ''
notes: lock.?kind == 'CanNotDelete'
? 'Cannot delete resource or child resources.'
: 'Cannot delete or modify the resource or child resources.'
}
scope: searchService
}

resource searchService_roleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = [
for (roleAssignment, index) in (roleAssignments ?? []): {
Expand Down Expand Up @@ -313,6 +314,25 @@ module searchService_sharedPrivateLinkResources 'shared-private-link-resource/ma
}
]

module keyVault 'modules/secrets-key-vault.bicep' = if (secretsKeyVault != null) {
name: '${uniqueString(deployment().name, location)}-secrets-kv'
scope: resourceGroup(secretsKeyVault.?resourceGroupName ?? resourceGroup().name)
params: {
keyVaultName: secretsKeyVault!.keyVaultName

keySecrets: [
{
secretName: secretsKeyVault.?primaryAdminKeySecretName ?? 'Primary-Admin-Key'
secretValue: searchService.listAdminKeys().primaryKey
}
{
secretName: secretsKeyVault.?secondaryAdminKeySecretName ?? 'Secondary-Admin-Key'
secretValue: searchService.listAdminKeys().secondaryKey
}
]
}
}

// =========== //
// Outputs //
// =========== //
Expand Down Expand Up @@ -493,3 +513,17 @@ type diagnosticSettingType = {
@description('Optional. The full ARM resource ID of the Marketplace resource to which you would like to send Diagnostic Logs.')
marketplacePartnerResourceId: string?
}[]?

type secretsKeyVaultType = {
@description('Required. The key vault name where to store the API Admin keys generated by the modules.')
keyVaultName: string

@description('Optional. Default to the resource group where this account is. The resource group name where the key vault is.')
resourceGroupName: string?

@description('Optional. Default to API Primary admin key . The primary admin key secret name to create.')
primaryAdminKeySecretName: string?

@description('Optional. Default to API Secondary admin key . The secondary admin key secret name to create.')
secondaryAdminKeySecretName: string?
}
45 changes: 42 additions & 3 deletions avm/res/search/search-service/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "13069544635575133650"
"version": "0.27.1.19265",
"templateHash": "3771642557846929937"
},
"name": "Search Services",
"description": "This module deploys a Search Service.",
Expand Down Expand Up @@ -433,6 +433,38 @@
}
},
"nullable": true
},
"secretsKeyVaultType": {
"type": "object",
"properties": {
"keyVaultName": {
"type": "string",
"metadata": {
"description": "Required. The key vault name where to store the API Admin keys generated by the modules."
}
},
"resourceGroupName": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Optional. Default to the resource group where this account is. The resource group name where the key vault is."
}
},
"primaryAdminKeySecretName": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Optional. Default to API Primary admin key . The primary admin key secret name to create."
}
},
"secondaryAdminKeySecretName": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Optional. Default to API Secondary admin key . The secondary admin key secret name to create."
}
}
}
}
},
"parameters": {
Expand Down Expand Up @@ -539,6 +571,13 @@
"description": "Optional. This value can be set to 'enabled' to avoid breaking changes on existing customer resources and templates. If set to 'disabled', traffic over public interface is not allowed, and private endpoint connections would be the exclusive access method."
}
},
"secretsKeyVault": {
"$ref": "#/definitions/secretsKeyVaultType",
"nullable": true,
"metadata": {
"description": "Optional. Key vault reference and secret settings to add the API admin keys generated by the search-service account."
}
},
"replicaCount": {
"type": "int",
"defaultValue": 3,
Expand Down Expand Up @@ -1574,4 +1613,4 @@
"value": "[reference('searchService', '2023-11-01', 'full').location]"
}
}
}
}
23 changes: 23 additions & 0 deletions avm/res/search/search-service/modules/secrets-key-vault.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param keyVaultName string
param keySecrets keySecret[]

resource kv 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
name: keyVaultName
}

resource keySecretsSecrets 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = [
for secret in keySecrets: {
name: secret.secretName
parent: kv
properties: {
value: secret.secretValue
}
}
]

type keySecret = {
secretName: string

@secure()
secretValue: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@description('Optional. The location to deploy to.')
param location string = resourceGroup().location

@description('Required. The name of the Managed Identity to create.')
param keyVaultName string

resource keyVault 'Microsoft.KeyVault/vaults@2021-06-01-preview' = {
name: keyVaultName
location: location
properties: {
sku: {
family: 'A'
name: 'standard'
}
enableRbacAuthorization: true
tenantId: subscription().tenantId
}
}

@description('The name of the Key Vault created.')
output keyVaultName string = keyVaultName
Loading