-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkey_vault.tf
108 lines (89 loc) · 2.64 KB
/
key_vault.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#################
### Key Vault ###
#################
# Manages a Key Vault.
#
# https://gitlab.k8s.cloud.statcan.ca/cloudnative/platform/terraform/terraform-azure-key-vault.git
#
module "enc_key_vault" {
source = "git::https://gitlab.k8s.cloud.statcan.ca/cloudnative/platform/terraform/terraform-azure-key-vault.git?ref=v4.0.0"
azure_resource_attributes = {
project = var.project
environment = var.environment
location = var.location
instance = 1
}
user_defined = "pgsql"
resource_group_name = var.resource_group_name
sku_name = "premium"
purge_protection_enabled = true
soft_delete_retention_days = 90
public_network_access_enabled = var.kv_public_network_access_enabled
default_network_access_action = "Deny"
service_endpoint_subnet_ids = var.kv_subnet_ids == null ? [] : var.kv_subnet_ids
ip_rules = var.ip_rules
private_endpoints = var.kv_private_endpoints
tags = var.tags
}
# Manages a Key Vault Key.
#
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_key
#
resource "azurerm_key_vault_key" "cmk" {
name = "${var.name}-key-cmk"
key_vault_id = module.enc_key_vault.id
# Use an HSM-backed key
key_type = "RSA-HSM"
# Key size of 2048 is required for Flexible Server for PostgreSQL
# https://learn.microsoft.com/en-us/azure/postgresql/single-server/concepts-data-encryption-postgresql#limitations
key_size = "2048"
key_opts = [
"decrypt",
"encrypt",
"sign",
"unwrapKey",
"verify",
"wrapKey",
]
depends_on = [
azurerm_key_vault_access_policy.cmk,
azurerm_key_vault_access_policy.runner_manage_keys,
]
}
############################
### RBAC & Access Policy ###
############################
# Allow the disk encryption set to access to the Key Vault key
resource "azurerm_key_vault_access_policy" "cmk" {
key_vault_id = module.enc_key_vault.id
tenant_id = azurerm_user_assigned_identity.pgsql.tenant_id
object_id = azurerm_user_assigned_identity.pgsql.principal_id
key_permissions = [
"Get",
"List",
"UnwrapKey",
"WrapKey",
]
depends_on = [
module.enc_key_vault
]
}
# Allow the runner to manage the key vault keys
resource "azurerm_key_vault_access_policy" "runner_manage_keys" {
key_vault_id = module.enc_key_vault.id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.object_id
key_permissions = [
"Get",
"Create",
"Delete",
"Purge",
"Recover",
"Update",
"GetRotationPolicy",
"List"
]
depends_on = [
module.enc_key_vault
]
}