# key-baseline / oci / t1 "Standard" # # A hardware-protected key with an off switch in code, and policies that keep # key managers and key users apart. Every call to the vault, including each # encrypt and decrypt, lands in the Audit service with no extra setup. locals { tags = merge({ owner = var.owner environment = var.environment data_classification = "restricted" managed_by = "terraform" }, var.extra_tags) statements = concat( var.key_admin_group == "" ? [] : [ "Allow group ${var.key_admin_group} to manage keys in compartment id ${var.compartment_ocid}", "Allow group ${var.key_admin_group} to manage vaults in compartment id ${var.compartment_ocid}", ], var.key_user_group == "" ? [] : [ "Allow group ${var.key_user_group} to use keys in compartment id ${var.compartment_ocid} where target.key.id = '${oci_kms_key.this.id}'", ], ) } resource "oci_kms_vault" "this" { compartment_id = var.compartment_ocid display_name = "${var.name}-vault" vault_type = "DEFAULT" freeform_tags = local.tags } resource "oci_kms_key" "this" { compartment_id = var.compartment_ocid display_name = var.name management_endpoint = oci_kms_vault.this.management_endpoint protection_mode = "HSM" freeform_tags = local.tags # The off switch, as code. A change here is a reviewed pull request with an # author, which is how pulling this lever should happen. desired_state = var.enabled ? "ENABLED" : "DISABLED" key_shape { algorithm = "AES" length = 32 } } # Managers use "manage", users use "use", scoped to this one key. Nobody needs # both. Created only when a group is named. resource "oci_identity_policy" "keys" { count = length(local.statements) > 0 ? 1 : 0 compartment_id = var.tenancy_ocid name = "${var.name}-keys" description = "Keeps key managers and key users apart for ${var.name}." freeform_tags = local.tags statements = local.statements }