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

Tests - Add AAD app for external connections #325

Closed
Closed
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
94 changes: 94 additions & 0 deletions infrastructure/transform/auth.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright (c) University College London Hospitals NHS Foundation Trust
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# AAD App + secret to set as AAD Admin of SQL Server
resource "azuread_application" "flowehr_sql_owner" {
display_name = local.sql_owner_app_name
owners = [data.azurerm_client_config.current.object_id]
}
resource "azuread_application_password" "flowehr_sql_owner" {
application_object_id = azuread_application.flowehr_sql_owner.object_id
}
resource "azuread_service_principal" "flowehr_sql_owner" {
application_id = azuread_application.flowehr_sql_owner.application_id
owners = [data.azurerm_client_config.current.object_id]
}

# AAD App + SPN for Databricks -> SQL Access
resource "azuread_application" "flowehr_databricks_sql" {
display_name = local.databricks_sql_app_name
owners = [data.azurerm_client_config.current.object_id]
}
resource "azuread_application_password" "flowehr_databricks_sql" {
application_object_id = azuread_application.flowehr_databricks_sql.object_id
}
resource "azuread_service_principal" "flowehr_databricks_sql" {
application_id = azuread_application.flowehr_databricks_sql.application_id
owners = [data.azurerm_client_config.current.object_id]
}

# AAD App + secret for connecting to external sources
resource "azuread_application" "flowehr_external_connection" {
display_name = local.external_connection_app_name
owners = [data.azurerm_client_config.current.object_id]
}
resource "azuread_application_password" "flowehr_external_connection" {
application_object_id = azuread_application.flowehr_external_connection.object_id
}
resource "azuread_service_principal" "flowehr_external_connection" {
application_id = azuread_application.flowehr_external_connection.application_id
owners = [data.azurerm_client_config.current.object_id]
}

# Push secrets to KV
resource "azurerm_key_vault_secret" "sql_server_owner_app_id" {
name = "sql-owner-app-id"
value = azuread_application.flowehr_sql_owner.application_id
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "sql_server_owner_secret" {
name = "sql-owner-secret"
value = azuread_application_password.flowehr_sql_owner.value
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "sql_server_features_admin_username" {
name = "sql-features-admin-username"
value = local.sql_server_features_admin_username
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "sql_server_features_admin_password" {
name = "sql-features-admin-password"
value = random_password.sql_admin_password.result
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "flowehr_databricks_sql_spn_app_id" {
name = "flowehr-dbks-sql-app-id"
value = azuread_service_principal.flowehr_databricks_sql.application_id
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "flowehr_databricks_sql_spn_app_secret" {
name = "flowehr-dbks-sql-app-secret"
value = azuread_application_password.flowehr_databricks_sql.value
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "flowehr_external_connection_app_id" {
name = "flowehr-external-conn-app-id"
value = azuread_service_principal.flowehr_external_connection.application_id
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "flowehr_external_connection_app_secret" {
name = "flowehr-external-conn-app-secret"
value = azuread_application_password.flowehr_external_connection.value
key_vault_id = var.core_kv_id
}
5 changes: 5 additions & 0 deletions infrastructure/transform/databricks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ resource "databricks_cluster" "cluster" {
"spark.secret.feature-store-fqdn" = "{{secrets/${databricks_secret_scope.secrets.name}/${databricks_secret.flowehr_databricks_sql_fqdn.key}}}"
"spark.secret.feature-store-database" = "{{secrets/${databricks_secret_scope.secrets.name}/${databricks_secret.flowehr_databricks_sql_database.key}}}"
}),
# Secrets for FlowEHR External app
tomap({
"spark.secret.external-connection-app-id" = "{{secrets/${databricks_secret_scope.secrets.name}/${databricks_secret.external_connection_spn_app_id.key}}}"
"spark.secret.exernal-connection-app-secret" = "{{secrets/${databricks_secret_scope.secrets.name}/${databricks_secret.external_connection_spn_app_secret.key}}}"
}),
# MSI connection to Datalake (if enabled)
var.transform.datalake != null ? tomap({
"fs.azure.account.auth.type.${module.datalake[0].adls_name}.dfs.core.windows.net" = "OAuth",
Expand Down
58 changes: 0 additions & 58 deletions infrastructure/transform/feature-data-store.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ resource "random_password" "sql_admin_password" {
min_special = 2
}

# AAD App + secret to set as AAD Admin of SQL Server
resource "azuread_application" "flowehr_sql_owner" {
display_name = local.sql_owner_app_name
owners = [data.azurerm_client_config.current.object_id]
}
resource "azuread_application_password" "flowehr_sql_owner" {
application_object_id = azuread_application.flowehr_sql_owner.object_id
}
resource "azuread_service_principal" "flowehr_sql_owner" {
application_id = azuread_application.flowehr_sql_owner.application_id
owners = [data.azurerm_client_config.current.object_id]
}

# Azure SQL logical server, public access disabled - will use private endpoints for access
resource "azurerm_mssql_server" "sql_server_features" {
name = "sql-server-features-${lower(var.naming_suffix)}"
Expand Down Expand Up @@ -145,51 +132,6 @@ resource "null_resource" "create_sql_user" {
}
}

# AAD App + SPN for Databricks -> SQL Access
resource "azuread_application" "flowehr_databricks_sql" {
display_name = local.databricks_sql_app_name
owners = [data.azurerm_client_config.current.object_id]
}
resource "azuread_application_password" "flowehr_databricks_sql" {
application_object_id = azuread_application.flowehr_databricks_sql.object_id
}
resource "azuread_service_principal" "flowehr_databricks_sql" {
application_id = azuread_application.flowehr_databricks_sql.application_id
owners = [data.azurerm_client_config.current.object_id]
}

# Push secrets to KV
resource "azurerm_key_vault_secret" "sql_server_owner_app_id" {
name = "sql-owner-app-id"
value = azuread_application.flowehr_sql_owner.application_id
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "sql_server_owner_secret" {
name = "sql-owner-secret"
value = azuread_application_password.flowehr_sql_owner.value
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "sql_server_features_admin_username" {
name = "sql-features-admin-username"
value = local.sql_server_features_admin_username
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "sql_server_features_admin_password" {
name = "sql-features-admin-password"
value = random_password.sql_admin_password.result
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "flowehr_databricks_sql_spn_app_id" {
name = "flowehr-dbks-sql-app-id"
value = azuread_service_principal.flowehr_databricks_sql.application_id
key_vault_id = var.core_kv_id
}
resource "azurerm_key_vault_secret" "flowehr_databricks_sql_spn_app_secret" {
name = "flowehr-dbks-sql-app-secret"
value = azuread_application_password.flowehr_databricks_sql.value
key_vault_id = var.core_kv_id
}

resource "azurerm_private_endpoint" "sql_server_features_pe" {
name = "pe-sql-feature-data-${var.naming_suffix}"
resource_group_name = var.core_rg_name
Expand Down
1 change: 1 addition & 0 deletions infrastructure/transform/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ locals {
sql_owner_app_name = "flowehr-sql-owner-${lower(var.naming_suffix)}"
databricks_adls_app_name = "flowehr-databricks-adls-${lower(var.naming_suffix)}"
databricks_sql_app_name = "flowehr-databricks-datawriter-${lower(var.naming_suffix)}"
external_connection_app_name = "flowehr-external-${lower(var.naming_suffix)}"
pipeline_file = "pipeline.json"
trigger_file = "trigger.json"
artifacts_dir = "artifacts"
Expand Down
12 changes: 12 additions & 0 deletions infrastructure/transform/secrets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ resource "databricks_secret" "flowehr_databricks_sql_database" {
string_value = azurerm_mssql_database.feature_database.name
scope = databricks_secret_scope.secrets.id
}
# FlowEHR external app secrets
resource "databricks_secret" "external_connection_spn_app_id" {
key = "flowehr-external-connection-app-id"
string_value = azuread_service_principal.flowehr_external_connection.application_id
scope = databricks_secret_scope.secrets.id
}

resource "databricks_secret" "external_connection_spn_app_secret" {
key = "flowehr-external-connection-app-secret"
string_value = azuread_application_password.flowehr_external_connection.value
scope = databricks_secret_scope.secrets.id
}

# Additional Databricks secrets passed in from the config
resource "databricks_secret" "databricks_config_secret" {
Expand Down
Loading