Skip to content

Commit b8ba9a0

Browse files
authored
Disable Batch Account and storage keys (#348)
* user subscription mode * Deploy staging PCTasks again
1 parent 705b7da commit b8ba9a0

4 files changed

Lines changed: 34 additions & 16 deletions

File tree

deployment/helm/deploy-values.template.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,16 @@ pctasks:
4545
run:
4646
task_runner_type: "batch"
4747
streaming_task_namespace: "pc"
48-
streaming_task_node_group: {{ tf.aks_streaming_task_node_group_name }}
4948
task_poll_seconds: 30
5049

5150
notifications:
5251
queue_name: "notifications"
53-
connection_string: {{ tf.sa_connection_string }}
52+
connection_string: "NOT_USED"
5453

5554
tables:
5655
account_url: {{ tf.sa_tables_account_url }}
5756
account_name: {{ tf.sa_account_name }}
58-
connection_string: {{ tf.sa_connection_string }}
57+
connection_string: "NOT_USED"
5958
image_key_table_name: "imagekeys"
6059

6160
blob:
@@ -82,7 +81,7 @@ pctasks:
8281
batch:
8382
enabled: true
8483
url: "{{ tf.batch_url }}"
85-
key: "{{ tf.batch_key }}"
84+
key: "NOT_USED"
8685
default_pool_id: "{{ tf.batch_default_pool_id }}"
8786
submit_threads: 0
8887

deployment/terraform/resources/batch.tf

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ resource "azurerm_batch_account" "pctasks" {
1212
name = local.nodash_prefix
1313
resource_group_name = azurerm_resource_group.pctasks.name
1414
location = azurerm_resource_group.pctasks.location
15-
pool_allocation_mode = "BatchService"
15+
pool_allocation_mode = "UserSubscription"
1616
storage_account_id = azurerm_storage_account.pctasks-batch.id
17-
storage_account_authentication_mode = "StorageKeys"
17+
storage_account_authentication_mode = "BatchAccountManagedIdentity"
18+
allowed_authentication_modes = ["AAD"]
19+
key_vault_reference {
20+
id = data.azurerm_key_vault.pctasks.id
21+
url = data.azurerm_key_vault.pctasks.vault_uri
22+
}
23+
24+
identity {
25+
type = "SystemAssigned"
26+
}
1827

1928
tags = {
2029
ManagedBy = "AI4E"
@@ -53,3 +62,10 @@ resource "azurerm_role_assignment" "batch-tasks-blob-storage-contributor" {
5362
"/subscriptions/1b045d0d-e560-456a-952d-7514f87f1b1f", # NOAA Data Project
5463
])
5564
}
65+
66+
# Allow workflow identity to submit and manage Batch jobs
67+
resource "azurerm_role_assignment" "workflows-batch-contributor" {
68+
role_definition_name = "Azure Batch Job Submitter"
69+
principal_id = azurerm_user_assigned_identity.workflows.principal_id
70+
scope = azurerm_batch_account.pctasks.id
71+
}

deployment/terraform/resources/keyvault.tf

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ resource "azurerm_role_assignment" "functions-secrets-user" {
99
scope = data.azurerm_key_vault.pctasks.id
1010
}
1111

12+
# Required for Batch UserSubscription mode
13+
data "azuread_service_principal" "batch" {
14+
display_name = "Microsoft Azure Batch"
15+
}
16+
17+
resource "azurerm_role_assignment" "batch-keyvault-secrets-officer" {
18+
role_definition_name = "Key Vault Secrets Officer"
19+
principal_id = data.azuread_service_principal.batch.object_id
20+
scope = data.azurerm_key_vault.pctasks.id
21+
}
22+
1223
# Store database information as a secret
1324

1425
resource "azurerm_key_vault_secret" "pgstac-connection-string" {
@@ -18,8 +29,8 @@ resource "azurerm_key_vault_secret" "pgstac-connection-string" {
1829
}
1930

2031
resource "azurerm_key_vault_secret" "task-application-insights-connection-string" {
21-
name = "task-application-insights-connection-string"
22-
value = azurerm_application_insights.pctasks.connection_string
32+
name = "task-application-insights-connection-string"
33+
value = azurerm_application_insights.pctasks.connection_string
2334
key_vault_id = data.azurerm_key_vault.pctasks.id
2435
}
2536

deployment/terraform/resources/output.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ output "batch_url" {
8686
value = "https://${azurerm_batch_account.pctasks.account_endpoint}"
8787
}
8888

89-
output "batch_key" {
90-
value = azurerm_batch_account.pctasks.primary_access_key
91-
}
92-
9389
output "batch_default_pool_id" {
9490
value = var.batch_default_pool_id
9591
}
@@ -134,10 +130,6 @@ output "sa_account_name" {
134130
value = azurerm_storage_account.pctasks.name
135131
}
136132

137-
output "sa_connection_string" {
138-
value = azurerm_storage_account.pctasks.primary_connection_string
139-
}
140-
141133
## Keyvault
142134

143135
output "keyvault_url" {

0 commit comments

Comments
 (0)