55 lines
1.9 KiB
Plaintext
55 lines
1.9 KiB
Plaintext
The likelihood of security incidents increases when cryptographic keys are used for a long time. Thus, to strengthen the data protection it's recommended to rotate the symmetric keys created with the Google Cloud Key Management Service (KMS) automatically and periodically. Note that it's not possible in GCP KMS to rotate asymmetric keys automatically.
|
|
|
|
|
|
== Ask Yourself Whether
|
|
|
|
* The cryptographic key is a symmetric key.
|
|
* The application requires compliance with some security standards like PCI-DSS.
|
|
|
|
|
|
== Recommended Secure Coding Practices
|
|
|
|
It's recommended to rotate keys automatically and regularly. The shorter the key period, the less data can be decrypted by an attacker if a key is compromised. So the key rotation period usually depends on the amount of data encrypted with a key or other requirements such as compliance with security standards. In general, a period of time of 90 days can be used.
|
|
|
|
|
|
== Sensitive Code Example
|
|
|
|
[source,terraform]
|
|
----
|
|
resource "google_kms_crypto_key" "noncompliant-key" { # Sensitive: no rotation period is defined
|
|
name = "example"
|
|
key_ring = google_kms_key_ring.keyring.id
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,terraform]
|
|
----
|
|
resource "google_kms_crypto_key" "compliant-key" {
|
|
name = "example"
|
|
key_ring = google_kms_key_ring.keyring.id
|
|
rotation_period = "7776000s" # 90 days
|
|
}
|
|
----
|
|
|
|
== See
|
|
|
|
* https://owasp.org/Top10/A02_2021-Cryptographic_Failures/[OWASP Top 10 2021 Category A2] - Cryptographic Failures
|
|
* https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration.html[OWASP Top 10 2017 Category A6] - Security Misconfiguration
|
|
* https://cloud.google.com/kms/docs/key-rotation[GCP Documentation] - KMS Key rotation
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Make sure creating a key without a rotation period is safe here.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|