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

Feat/automate postgres password auth #113

Merged
merged 1 commit into from
Dec 11, 2024
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
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-dev-audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-dev-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-int-audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-int-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-nft-audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-nft-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-prd-audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-prd-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-pre-audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
2 changes: 1 addition & 1 deletion .azuredevops/pipelines/cd-infrastructure-pre-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: fa58dc978491f04e1efab73cbf8e2228a351bf81
ref: d00eaa9a7ce04b78ff5ebf488f6d265d929a58b3
endpoint: NHSDigital

variables:
Expand Down
7 changes: 0 additions & 7 deletions infrastructure/tf-core/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ data "azurerm_key_vault_key" "private_key" {
key_vault_id = module.key_vault[each.key].key_vault_id
}

data "azurerm_key_vault_secret" "database_password" {
for_each = var.regions

name = "DATABASE-PASSWORD"
key_vault_id = module.key_vault[each.key].key_vault_id
}

data "azuread_group" "postgres_sql_admin_group" {
display_name = var.postgresql.postgres_sql_admin_group
}
7 changes: 4 additions & 3 deletions infrastructure/tf-core/function_app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ locals {
config.database_required ? {
DATABASE_NAME = "communication_management"
DATABASE_HOST = "${module.regions_config[region].names.postgres-sql-server}.postgres.database.azure.com"
DATABASE_USER = "postgresql_commgt_uks_admin"
DATABASE_PASSWORD = "@Microsoft.KeyVault(SecretUri=${data.azurerm_key_vault_secret.database_password[region].versionless_id})"
DATABASE_USER = "commgt_db_user"
DATABASE_PASSWORD = "@Microsoft.KeyVault(SecretUri=${module.postgresql_flexible_db[region].db_admin_pwd_keyvault_secret})"
# DATABASE_USER = var.postgresql.postgres_sql_admin_group
} : {}

)
Expand All @@ -125,7 +126,7 @@ locals {

# Key Vault
var.key_vault != {} ? [
for role in local.rbac_roles_key_vault : {
for role in local.rbac_roles_key_vault_user : {
role_definition_name = role
scope = module.key_vault[region].key_vault_id
}
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/tf-core/key_vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module "key_vault" {
sku_name = var.key_vault.sku_name

enable_rbac_authorization = true
rbac_roles = local.rbac_roles_key_vault
rbac_roles = local.rbac_roles_key_vault_officer

log_analytics_workspace_id = data.terraform_remote_state.audit.outputs.log_analytics_workspace_id[local.primary_region]
monitor_diagnostic_setting_keyvault_enabled_logs = local.monitor_diagnostic_setting_keyvault_enabled_logs
Expand Down
6 changes: 6 additions & 0 deletions infrastructure/tf-core/postgresql.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ module "postgresql_flexible_db" {
postgresql_admin_principal_type = "Group"
public_network_access_enabled = var.postgresql.public_network_access_enabled

# To be amended to use Managed Identity in Entra ID group after pilot
password_auth_enabled = true
administrator_login = "commgt_db_user"
key_vault_id = module.key_vault[each.key].key_vault_id
key_vault_admin_pwd_secret_name = "DATABASE-PASSWORD"

sku_name = var.postgresql.dbs.commgt.sku_name
storage_mb = var.postgresql.dbs.commgt.storage_mb
storage_tier = var.postgresql.dbs.commgt.storage_tier
Expand Down
8 changes: 7 additions & 1 deletion infrastructure/tf-core/rbac.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
locals {
rbac_roles_key_vault = [
rbac_roles_key_vault_user = [
"Key Vault Certificate User",
"Key Vault Crypto User",
"Key Vault Secrets User"
]

rbac_roles_key_vault_officer = [
"Key Vault Certificates Officer",
"Key Vault Crypto Officer",
"Key Vault Secrets Officer"
]

rbac_roles_storage = [
"Storage Account Contributor",
"Storage Blob Data Owner",
Expand Down
Loading