Skip to content

Commit

Permalink
Feat: Add continuous validation for iam key age (#4)
Browse files Browse the repository at this point in the history
* Test check 40 days old iam access key

* Fix error

* Fix iam user name

* Update age_in_days to 90 days

* Update README.md

* Test fix for unknown timestamp

* Update age_in_days to 90 days
  • Loading branch information
hazmei authored Jan 30, 2024
1 parent b09ee54 commit fd6b37c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ module "vault_secretsync" {
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.67.0 |
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.2.2 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.6.0 |
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.0 |
| <a name="requirement_vault"></a> [vault](#requirement\_vault) | >= 3.23.0 |

## Providers
Expand Down Expand Up @@ -146,7 +148,7 @@ module "vault_secretsync" {
| [null_resource.rotate_access_key](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [random_id.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
| [time_rotating.iam_user_secretsync_access_key](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/rotating) | resource |
| [time_sleep.wait_5_seconds](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
| [time_sleep.wait_for_destination_sync](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
| [vault_generic_endpoint.create_association_sync](https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/generic_endpoint) | resource |
| [vault_generic_endpoint.create_destination_sync](https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/generic_endpoint) | resource |
| [vault_generic_endpoint.remove_all_association_sync](https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/generic_endpoint) | resource |
Expand Down
9 changes: 9 additions & 0 deletions checks.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
check "check_iam_key_age_vault_secretsync" {
assert {
condition = (
timecmp(coalesce(aws_iam_access_key.vault_secretsync.create_date, local.age_in_days), local.age_in_days) > 0
)
error_message = format("The IAM key for metrics user %s is older than 90 days. Please rotate the key.",
module.iam_user_secretsync.iam_user_name)
}
}
1 change: 1 addition & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
locals {
age_in_days = timeadd(plantimestamp(), "-2160h") # 90 days (90*24 hours)
sync_base_path = "sys/sync/destinations"
destination_name = "${var.name}-${var.region}-${random_id.this.hex}"
delete_sync_destination = alltrue([var.delete_all_secret_associations, var.delete_sync_destination])
Expand Down

0 comments on commit fd6b37c

Please sign in to comment.