fix(3-security): apply kms_protection_level to keys that set no version_template - #212
Open
scottonix wants to merge 1 commit into
Open
fix(3-security): apply kms_protection_level to keys that set no version_template#212scottonix wants to merge 1 commit into
scottonix wants to merge 1 commit into
Conversation
…on_template
core-prod.tf and core-dev.tf passed kms_protection_level to modules/kms inside
the keyring object, but that module's keyring variable is object({location,
name}); Terraform drops the extra attribute silently, so every key in kms_keys
that did not carry its own version_template was created at Cloud KMS's default
protection level (SOFTWARE) regardless of kms_protection_level.
Apply the stage-wide protection level per key instead: keys without an explicit
version_template now get GOOGLE_SYMMETRIC_ENCRYPTION at var.kms_protection_level,
keys with one keep it, and a null kms_protection_level leaves the module default
untouched.
Signed-off-by: Scott McDonald <scott.mcdonald@onixnet.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
fast/stages-aw/3-securityexposeskms_protection_level, but the value never reaches Cloud KMS.core-prod.tfandcore-dev.tfpass it tomodules/kmsinside thekeyringobject askeyring.version_template, and that module'skeyringvariable is typedobject({ location = string, name = string }). Terraform drops the extra attribute silently, so every key inkms_keysthat does not carry its ownversion_templateis created without one — i.e. at the Cloud KMS default protection level, SOFTWARE — no matter whatkms_protection_levelsays.On a FedRAMP High / IL5 deployment this is the difference between HSM-backed keys and software keys, and nothing in the plan output makes it obvious unless you read the JSON for each key's
version_template.This change applies the stage-wide protection level per key, which is the only place
modules/kmshonours it:version_templategetGOOGLE_SYMMETRIC_ENCRYPTIONatvar.kms_protection_level;version_templatekeep it (per-key override still works);kms_protection_levelleaves the module default untouched, so existing configurations that never set it plan exactly as before.The dead
version_templateinside thekeyringobject is removed, and the variable description now says what the variable does. No behaviour changes for anyone who already setsversion_templateon every key (asterraform.tfvars.sampledoes since #118).Type of Change
Deployment & Compliance Impact
Note for existing deployments: a key's protection level is immutable. A deployment that already applied stage 3 with
kms_protection_level = "HSM"and no per-keyversion_templatehas SOFTWARE keys today; after this change Terraform will plan to replace those keys (new key, new key material). That is the correct outcome, but it should be done deliberately.Checklist
Code Quality & Reusability
modules/orfast/can be leveraged for this change.documentation/naming-convention.md.Documentation
README.mdof the modified module or blueprint. (No README change needed beyond the variable description; the README variables table is tfdoc-generated.)Security
Testing
Testing Performed
Terraform 1.10.5,
hashicorp/googlefromdefault-versions.tf.terraform validateon3-securitypasses before and after (it also passes before the fix — Terraform does not warn about the discarded attribute, which is why this went unnoticed).Plan comparison with placeholder inputs (
-refresh=false, invalid credentials, so nothing is read from an API),kms_protection_level = "HSM"and two keys inus-east4:inheritswith noversion_template,explicitwithversion_template.protection_level = "SOFTWARE".terraform show -jsonof the plan,google_kms_crypto_keyvalues:main(df47667)prod-sec-kms["us-east4"].default["inherits"]version_template = null[{algorithm = GOOGLE_SYMMETRIC_ENCRYPTION, protection_level = HSM}]prod-sec-kms["us-east4"].default["explicit"]protection_level = SOFTWAREprotection_level = SOFTWARE(per-key override preserved)dev-sec-kms[...]The defect was originally found on a live FedRAMP High deployment of this stage: with
kms_protection_level = "HSM"and no per-keyversion_template, the plan JSON showed every key without aversion_template, and adding an explicit per-key template was the only way to get HSM keys.