Kms cmk root to byo db (#193)
## Highlights
- Upgrades Aurora from `terraform-aws-modules/rds-aurora/aws` `7.6.0` to
`9.16.1`
- Bumps the Terraform minimum version from `>= 1.3.8` to `>= 1.5.0`
- Adds CMK support across newly exposed RDS, Redis, VPC, ECS, and Fleet
surfaces
- Adds additive per-key `extra_kms_policies` support across the root ->
`byo-vpc` -> `byo-db` -> `byo-ecs` path
- Moves software-installers KMS policy ownership out of
`addons/cloudfront-software-installers` and back into `byo-ecs`
- Extends monitoring and ECS integration to work with CMK-encrypted DB
password secrets
- Adds migration tooling and docs for Aurora storage KMS replacement and
CloudWatch Logs KMS cutovers
## Aurora module upgrade: `7.6.0` -> `9.16.1`
This PR keeps a single Aurora module path on upstream `9.16.1` and
updates the Fleet wrapper modules to preserve compatibility where
possible while exposing the new KMS and observability capabilities.
Notable changes handled in the wrapper:
- `security_group_rules`
- upstream moved from older SG rule addressing to the newer
`security_group_rules` model
- added `moved` handling for the confirmed SG rule address rename to
avoid unnecessary destroy/create churn
- `manage_master_user_password`
- the wrapper continues to own the DB password flow
- Aurora is kept on `manage_master_user_password = false`
- Secrets Manager integration remains wrapper-managed rather than
switching to upstream-managed password behavior
- `final_snapshot_identifier`
- wrapper support was added so old behavior is preserved
- if unset, the legacy generated naming pattern is still used
- callers can now override it explicitly
- Observability / Database Insights wiring
- cluster-level Performance Insights / Database Insights configuration
was added to match Aurora's current control surface
- monitoring behavior was aligned to cluster-level management for
consistency with the Aurora module and Database Insights requirements
- `backtrack_window`
- added optional pass-through support for Aurora MySQL backtracking
- validated as `null` or `0..259200`
## Terraform version bump
This PR raises the Terraform minimum version from `>= 1.3.8` to `>=
1.5.0`.
Reason:
- deprecation warnings for legacy KMS `enabled` flags now use Terraform
`check` blocks
- `check` blocks require Terraform `1.5+`
This was done so published interfaces can remain backward-compatible for
existing `enabled` users while still warning during plan/apply and
preferring `cmk_enabled`.
## KMS surface expansion and pass-through
This PR adds or expands CMK support for:
- Aurora storage
- Aurora password secret
- Aurora observability / Performance Insights
- Aurora exported log groups
- Redis at-rest encryption
- Redis log groups
- VPC flow log CloudWatch log groups
- ECS cluster log groups
- Fleet private-key secret
- Fleet Fargate ephemeral storage
- Fleet application logs
- Fleet software installers
It also adds additive `extra_kms_policies` support across those
module-owned CMK surfaces so callers can append narrowly scoped
statements without replacing the inherited base policy.
During validation of the cron-monitoring integration, I found that the
root module schema was still dropping some nested KMS attributes before
they reached `byo-vpc`. This PR now carries those fields all the way
through to their final destinations, including:
- `rds_config.*.extra_kms_policies`
- `redis_config.*.extra_kms_policies`
- `ecs_cluster.cloudwatch_log_group.kms.extra_kms_policies`
- `fleet_config.private_key_secret_kms.extra_kms_policies`
- `fleet_config.fargate_ephemeral_storage_kms.extra_kms_policies`
- `fleet_config.awslogs.kms.extra_kms_policies`
- `fleet_config.software_installers.extra_kms_policies`
- `fleet_config.software_installers.cloudfront_distribution_arn`
- `vpc.flow_log_cloudwatch_log_group_kms.extra_kms_policies`
## DB password secret KMS handoff to monitoring
`byo-vpc` now exposes:
- `rds_password_secret_kms_key_arn`
The monitoring addon now accepts:
- `cron_monitoring.mysql_password_secret_kms_key_arn`
The monitoring addon also now exposes:
- `cron_monitoring_lambda_arn`
- `cron_monitoring_lambda_role_arn`
This is needed so the cron-monitoring Lambda can decrypt the Fleet DB
password secret when that secret is encrypted with a customer-managed
KMS key.
Expected wiring:
```hcl
module "monitoring" {
# ...
cron_monitoring = {
# ...
mysql_password_secret_name = "${local.customer}-database-password"
mysql_password_secret_kms_key_arn = module.main.byo-vpc.rds_password_secret_kms_key_arn
}
}
```
## Software installers KMS ownership change
This PR changes the software-installers KMS contract:
- `addons/cloudfront-software-installers` no longer manages the
software-installers KMS key policy
- `byo-ecs` now owns the software-installers CMK policy, including
required service / principal statements
- `fleet_config.software_installers.cloudfront_distribution_arn` is the
static input used to add the CloudFront KMS statement without
introducing a module cycle
- `byo-ecs` also adds the explicit Fleet task-role KMS statement
required under the narrower external key-policy model
- the CloudFront addon exposes `cloudfront_distribution_arn` for
visibility, but that output should not be fed back into `byo-ecs`
because that would create a dependency cycle
Important compatibility note:
- if software installers uses KMS at all, it must use a customer-managed
key
- CloudFront requires a key-policy statement on that key
- the AWS-managed default key cannot be modified to attach that policy
## Other notable items
- Added and expanded migration docs for RDS and Redis KMS adoption
- Added `byo-vpc/scripts/rds_storage_kms_migration.sh` to automate
Aurora storage-KMS migration workflows
- Added `scripts/cloudwatch_logs_kms_migration.sh` to help identify and
optionally remove pre-cutover log streams after associating a new KMS
key with a CloudWatch Logs group
- Normalized `cmk_enabled` usage while preserving deprecated `enabled`
compatibility only for previously published interfaces
- Refactored `addons/logging-alb` KMS policy handling to support
`kms_base_policy` and align it with the structured KMS statement model
used elsewhere
- Reduced repeated KMS policy boilerplate within modules where it was
materially duplicated
## Compatibility notes
- Existing published KMS interfaces that previously used `enabled` still
accept it, but now warn and prefer `cmk_enabled`
- New KMS surfaces are `cmk_enabled`-only
- Software-installers KMS policy ownership moved from
`addons/cloudfront-software-installers` to `byo-ecs`
## Validation
Validated module stacks after the refactors:
- `root`
- `byo-vpc`
- `byo-db`
- `byo-ecs`
- `addons/monitoring`
- `addons/cloudfront-software-installers`
- `addons/logging-alb`
This commit is contained in:
1 parent
b0f06cdbb8
commit
e7faee93de
38 files changed
+4128
-621
No files matched your search
@@ -26,20 +26,23 @@ Previous versions do not allow for proper interaction with both the software ins
|
||||
|
||||
### tf-mod-root/tf-mod-byo-vpc/tf-mod-byo-db/tf-mod-byo-ecs
|
||||
|
||||
For any of these modules, the software installers configuration will require a KMS key created in order to be able to set a key policy.
|
||||
For any of these modules, software installers requires a customer-managed KMS key whenever KMS encryption is used at all. CloudFront access requires a key policy statement on that key, and the AWS-managed default key cannot be modified to accept that policy.
|
||||
|
||||
Breaking change: this addon no longer manages the software installers KMS key policy. That policy now lives in `tf-mod-byo-ecs`, which means CloudFront access to the CMK must be configured there by setting `software_installers.cloudfront_distribution_arn` to the static distribution ARN.
|
||||
|
||||
This is the relevant configuration starting at the software installers configuration block:
|
||||
|
||||
```
|
||||
software_installers = {
|
||||
bucket_prefix = "fleet-software-installers-"
|
||||
create_kms_key = true
|
||||
kms_alias = "fleet-software-installers"
|
||||
bucket_prefix = "fleet-software-installers-"
|
||||
create_kms_key = true
|
||||
kms_alias = "fleet-software-installers"
|
||||
cloudfront_distribution_arn = "arn:aws:cloudfront::<account-id>:distribution/<distribution-id>"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The new configuration items are `create_kms_key` and `kms_alias`.
|
||||
The required configuration items here are `create_kms_key`, `kms_alias`, and `cloudfront_distribution_arn` when CloudFront must read from an SSE-KMS bucket.
|
||||
|
||||
### tf-mod-addon-logging-alb
|
||||
|
||||
@@ -117,7 +120,6 @@ module "cloudfront-software-installers" {
|
||||
source = "github.com/fleetdm/fleet-terraform/addons/cloudfront-software-installers?ref=tf-mod-addon-cloudfront-software-installers-v1.2.0"
|
||||
customer = "fleet"
|
||||
s3_bucket = module.main.byo-vpc.byo-db.byo-ecs.fleet_s3_software_installers_config.bucket_name
|
||||
s3_kms_key_id = module.main.byo-vpc.byo-db.byo-ecs.fleet_s3_software_installers_config.kms_key_id
|
||||
# OPTIONAL
|
||||
# If you'd like to use an existing key_group_id for your new Cloudfront distribution, uncomment key_group_id and supply the value for the key_group_id
|
||||
# If you're using an existing key_group_id, public_key_id is required. The public_key_id is the value of a public_key that is also part of the key group that you define.
|
||||
@@ -145,6 +147,8 @@ data "aws_kms_secrets" "cloudfront" {
|
||||
|
||||
Then we need to include outputs from this module once applied back into the main fleet-config under the `extra_secrets` and `extra_execution_roles`:
|
||||
|
||||
This addon also outputs `cloudfront_distribution_arn`. Do not feed that output back into `tf-mod-byo-ecs`, because that creates a Terraform cycle. Instead, set the same static ARN directly in `software_installers.cloudfront_distribution_arn`.
|
||||
|
||||
|
||||
Under the `fleet_config` section. If not using the mdm module, that could be omitted but was included to show how to include multiple extra items:
|
||||
|
||||
|
||||
@@ -25,20 +25,23 @@ Previous versions do not allow for proper interaction with both the software ins
|
||||
|
||||
### tf-mod-root/tf-mod-byo-vpc/tf-mod-byo-db/tf-mod-byo-ecs
|
||||
|
||||
For any of these modules, the software installers configuration will require a KMS key created in order to be able to set a key policy.
|
||||
For any of these modules, software installers requires a customer-managed KMS key whenever KMS encryption is used at all. CloudFront access requires a key policy statement on that key, and the AWS-managed default key cannot be modified to accept that policy.
|
||||
|
||||
Breaking change: this addon no longer manages the software installers KMS key policy. That policy now lives in `tf-mod-byo-ecs`, which means CloudFront access to the CMK must be configured there by setting `software_installers.cloudfront_distribution_arn` to the static distribution ARN.
|
||||
|
||||
This is the relevant configuration starting at the software installers configuration block:
|
||||
|
||||
```
|
||||
software_installers = {
|
||||
bucket_prefix = "fleet-software-installers-"
|
||||
create_kms_key = true
|
||||
kms_alias = "fleet-software-installers"
|
||||
bucket_prefix = "fleet-software-installers-"
|
||||
create_kms_key = true
|
||||
kms_alias = "fleet-software-installers"
|
||||
cloudfront_distribution_arn = "arn:aws:cloudfront::<account-id>:distribution/<distribution-id>"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The new configuration items are `create_kms_key` and `kms_alias`.
|
||||
The required configuration items here are `create_kms_key`, `kms_alias`, and `cloudfront_distribution_arn` when CloudFront must read from an SSE-KMS bucket.
|
||||
|
||||
### tf-mod-addon-logging-alb
|
||||
|
||||
@@ -116,7 +119,6 @@ module "cloudfront-software-installers" {
|
||||
source = "github.com/fleetdm/fleet-terraform/addons/cloudfront-software-installers?ref=tf-mod-addon-cloudfront-software-installers-v1.2.0"
|
||||
customer = "fleet"
|
||||
s3_bucket = module.main.byo-vpc.byo-db.byo-ecs.fleet_s3_software_installers_config.bucket_name
|
||||
s3_kms_key_id = module.main.byo-vpc.byo-db.byo-ecs.fleet_s3_software_installers_config.kms_key_id
|
||||
# OPTIONAL
|
||||
# If you'd like to use an existing key_group_id for your new Cloudfront distribution, uncomment key_group_id and supply the value for the key_group_id
|
||||
# If you're using an existing key_group_id, public_key_id is required. The public_key_id is the value of a public_key that is also part of the key group that you define.
|
||||
@@ -144,6 +146,8 @@ data "aws_kms_secrets" "cloudfront" {
|
||||
|
||||
Then we need to include outputs from this module once applied back into the main fleet-config under the `extra_secrets` and `extra_execution_roles`:
|
||||
|
||||
This addon also outputs `cloudfront_distribution_arn`. Do not feed that output back into `tf-mod-byo-ecs`, because that creates a Terraform cycle. Instead, set the same static ARN directly in `software_installers.cloudfront_distribution_arn`.
|
||||
|
||||
Under the `fleet_config` section. If not using the mdm module, that could be omitted but was included to show how to include multiple extra items:
|
||||
|
||||
```
|
||||
@@ -169,7 +173,7 @@ No requirements.
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.36.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
@@ -184,13 +188,10 @@ No requirements.
|
||||
| [aws_cloudfront_key_group.software_installers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_key_group) | resource |
|
||||
| [aws_cloudfront_public_key.software_installers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_public_key) | resource |
|
||||
| [aws_iam_policy.software_installers_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_kms_key_policy.software_installers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key_policy) | resource |
|
||||
| [aws_s3_bucket_policy.software_installers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
|
||||
| [aws_secretsmanager_secret.software_installers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
|
||||
| [aws_secretsmanager_secret_version.software_installers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
|
||||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
|
||||
| [aws_iam_policy_document.software_installers_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.software_installers_kms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.software_installers_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_s3_bucket.logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/s3_bucket) | data source |
|
||||
| [aws_s3_bucket.software_installers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/s3_bucket) | data source |
|
||||
@@ -208,12 +209,12 @@ No requirements.
|
||||
| <a name="input_public_key"></a> [public\_key](#input\_public\_key) | Public key used for signed URLs | `string` | n/a | yes |
|
||||
| <a name="input_public_key_id"></a> [public\_key\_id](#input\_public\_key\_id) | Cloudfront public key id. Required when passing in a key\_group\_id | `string` | `null` | no |
|
||||
| <a name="input_s3_bucket"></a> [s3\_bucket](#input\_s3\_bucket) | Name of the S3 bucket that Cloudfront will point to | `string` | n/a | yes |
|
||||
| <a name="input_s3_kms_key_id"></a> [s3\_kms\_key\_id](#input\_s3\_kms\_key\_id) | KMS key id used to encrypt the s3 bucket | `string` | `null` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_cloudfront_arn"></a> [cloudfront\_arn](#output\_cloudfront\_arn) | n/a |
|
||||
| <a name="output_cloudfront_distribution_arn"></a> [cloudfront\_distribution\_arn](#output\_cloudfront\_distribution\_arn) | n/a |
|
||||
| <a name="output_extra_execution_iam_policies"></a> [extra\_execution\_iam\_policies](#output\_extra\_execution\_iam\_policies) | n/a |
|
||||
| <a name="output_extra_secrets"></a> [extra\_secrets](#output\_extra\_secrets) | n/a |
|
||||
@@ -1,5 +1,3 @@
|
||||
data "aws_caller_identity" "current" {}
|
||||
|
||||
data "aws_iam_policy_document" "software_installers_bucket" {
|
||||
statement {
|
||||
actions = ["s3:GetObject"]
|
||||
@@ -26,38 +24,6 @@ resource "aws_s3_bucket_policy" "software_installers" {
|
||||
policy = data.aws_iam_policy_document.software_installers_bucket.json
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "software_installers_kms" {
|
||||
statement {
|
||||
actions = ["kms:*"]
|
||||
principals {
|
||||
type = "AWS"
|
||||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
|
||||
}
|
||||
resources = ["*"]
|
||||
}
|
||||
statement {
|
||||
sid = "AllowOriginAccessIdentity"
|
||||
effect = "Allow"
|
||||
principals {
|
||||
type = "Service"
|
||||
identifiers = ["cloudfront.amazonaws.com"]
|
||||
}
|
||||
actions = ["kms:Decrypt"]
|
||||
resources = ["*"]
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "AWS:SourceArn"
|
||||
values = [module.cloudfront_software_installers.cloudfront_distribution_arn]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_kms_key_policy" "software_installers" {
|
||||
count = var.s3_kms_key_id != null ? 1 : 0
|
||||
key_id = var.s3_kms_key_id
|
||||
policy = data.aws_iam_policy_document.software_installers_kms.json
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "software_installers_secret" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
|
||||
@@ -13,3 +13,7 @@ output "extra_execution_iam_policies" {
|
||||
output "cloudfront_arn" {
|
||||
value = module.cloudfront_software_installers.cloudfront_distribution_arn
|
||||
}
|
||||
|
||||
output "cloudfront_distribution_arn" {
|
||||
value = module.cloudfront_software_installers.cloudfront_distribution_arn
|
||||
}
|
||||
@@ -41,12 +41,6 @@ variable "s3_bucket" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "s3_kms_key_id" {
|
||||
description = "KMS key id used to encrypt the s3 bucket"
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "enable_logging" {
|
||||
description = "Enable optional logging to s3"
|
||||
type = bool
|
||||
|
||||
+38
-34
@@ -1,59 +1,63 @@
|
||||
data "aws_caller_identity" "current" {}
|
||||
|
||||
data "aws_partition" "current" {}
|
||||
|
||||
data "aws_region" "current" {}
|
||||
|
||||
locals {
|
||||
landing_bucket_name = "${var.prefix}-alb-logs"
|
||||
|
||||
kms_policies = concat([
|
||||
kms_base_policy_statements = var.kms_base_policy != null ? var.kms_base_policy : [
|
||||
{
|
||||
actions = ["kms:*"]
|
||||
principals = [{
|
||||
sid = "EnableRootPermissions"
|
||||
effect = "Allow"
|
||||
actions = ["kms:*"]
|
||||
resources = ["*"]
|
||||
principals = {
|
||||
type = "AWS"
|
||||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
|
||||
}]
|
||||
resources = ["*"]
|
||||
},
|
||||
identifiers = ["arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:root"]
|
||||
}
|
||||
conditions = []
|
||||
}
|
||||
]
|
||||
|
||||
kms_service_statements = [
|
||||
{
|
||||
actions = [
|
||||
"kms:Encrypt",
|
||||
"kms:Decrypt",
|
||||
"kms:GenerateDataKey*",
|
||||
"kms:DescribeKey",
|
||||
]
|
||||
sid = "AllowLambdaReencryptUseOfTheKey"
|
||||
effect = "Allow"
|
||||
actions = ["kms:Encrypt", "kms:Decrypt", "kms:GenerateDataKey*", "kms:DescribeKey"]
|
||||
resources = ["*"]
|
||||
principals = [{
|
||||
principals = {
|
||||
type = "AWS"
|
||||
identifiers = [aws_iam_role.lambda_reencrypt.arn]
|
||||
}]
|
||||
}
|
||||
conditions = []
|
||||
},
|
||||
{
|
||||
actions = [
|
||||
"kms:Encrypt",
|
||||
"kms:Decrypt",
|
||||
"kms:GenerateDataKey*",
|
||||
"kms:DescribeKey",
|
||||
]
|
||||
sid = "AllowLambdaSweepUseOfTheKey"
|
||||
effect = "Allow"
|
||||
actions = ["kms:Encrypt", "kms:Decrypt", "kms:GenerateDataKey*", "kms:DescribeKey"]
|
||||
resources = ["*"]
|
||||
principals = [{
|
||||
principals = {
|
||||
type = "AWS"
|
||||
identifiers = [aws_iam_role.lambda_sweep.arn]
|
||||
}]
|
||||
}
|
||||
conditions = []
|
||||
},
|
||||
{
|
||||
actions = [
|
||||
"kms:Encrypt",
|
||||
"kms:GenerateDataKey",
|
||||
"kms:GenerateDataKeyWithoutPlaintext",
|
||||
"kms:DescribeKey",
|
||||
]
|
||||
sid = "AllowBatchReencryptUseOfTheKey"
|
||||
effect = "Allow"
|
||||
actions = ["kms:Encrypt", "kms:GenerateDataKey", "kms:GenerateDataKeyWithoutPlaintext", "kms:DescribeKey"]
|
||||
resources = ["*"]
|
||||
principals = [{
|
||||
principals = {
|
||||
type = "AWS"
|
||||
identifiers = [aws_iam_role.batch_reencrypt.arn]
|
||||
}]
|
||||
},
|
||||
], var.extra_kms_policies)
|
||||
}
|
||||
conditions = []
|
||||
}
|
||||
]
|
||||
|
||||
kms_policies = concat(local.kms_base_policy_statements, local.kms_service_statements, var.extra_kms_policies)
|
||||
|
||||
s3_path_prefix = coalesce(var.alt_path_prefix, var.prefix)
|
||||
}
|
||||
@@ -68,7 +72,7 @@ data "aws_iam_policy_document" "kms" {
|
||||
resources = try(statement.value.resources, [])
|
||||
effect = try(statement.value.effect, null)
|
||||
dynamic "principals" {
|
||||
for_each = try(statement.value.principals, [])
|
||||
for_each = try([statement.value.principals], [])
|
||||
content {
|
||||
type = principals.value.type
|
||||
identifiers = principals.value.identifiers
|
||||
|
||||
@@ -45,6 +45,26 @@ variable "extra_kms_policies" {
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "kms_base_policy" {
|
||||
type = list(object({
|
||||
sid = string
|
||||
effect = string
|
||||
principals = object({
|
||||
type = string
|
||||
identifiers = list(string)
|
||||
})
|
||||
actions = list(string)
|
||||
resources = list(string)
|
||||
conditions = optional(list(object({
|
||||
test = string
|
||||
variable = string
|
||||
values = list(string)
|
||||
})), [])
|
||||
}))
|
||||
default = null
|
||||
description = "Optional base KMS key-policy statements to apply to module-created CMKs before module-required service access statements are merged in. If null, the module defaults to the historical root `kms:*` statement."
|
||||
}
|
||||
|
||||
variable "extra_s3_log_policies" {
|
||||
type = list(any)
|
||||
default = []
|
||||
|
||||
@@ -29,6 +29,10 @@ https://github.com/fleetdm/fleet-terraform/blob/main/example/main.tf for details
|
||||
|
||||
> Note: If you haven't specified defined `local.customer` or customized service names, the default is "fleet" for anywhere that `local.customer` is specified below.
|
||||
|
||||
If the Fleet database password secret is encrypted with a CMK, also pass `mysql_password_secret_kms_key_arn` so the cron-monitoring Lambda can decrypt it. When using the `byo-vpc` module, wire this from `module.<fleet_module>.byo-vpc.rds_password_secret_kms_key_arn`.
|
||||
|
||||
**Important:** If you supply a custom `kms_base_policy` that does not grant `kms:*` to the account root (for example, a least-privilege policy that only allows specific principals), you must also add the cron-monitoring Lambda role to `rds_config.password_secret_kms.extra_kms_policies` in the `byo-vpc` module. AWS KMS requires both the key policy and the IAM policy to allow access. The Lambda role name is predictable (`<customer_prefix>-cron-monitoring-lambda`), so you can construct the ARN before the role exists. See the `byo-vpc` module README for a full example.
|
||||
|
||||
```
|
||||
module "monitoring" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/monitoring?ref=tf-mod-addon-monitoring-v1.9.0"
|
||||
@@ -69,6 +73,7 @@ module "monitoring" {
|
||||
mysql_database = module.fleet.byo-vpc.rds.cluster_database_name
|
||||
mysql_user = module.fleet.byo-vpc.rds.cluster_master_username
|
||||
mysql_password_secret_name = "${local.customer}-database-password"
|
||||
mysql_password_secret_kms_key_arn = module.fleet.byo-vpc.rds_password_secret_kms_key_arn
|
||||
mysql_tls_config = "true"
|
||||
rds_security_group_id = module.fleet.byo-vpc.rds.security_group_id
|
||||
subnet_ids = module.fleet.vpc.private_subnets
|
||||
|
||||
@@ -29,6 +29,10 @@ https://github.com/fleetdm/fleet-terraform/blob/main/example/main.tf for details
|
||||
|
||||
> Note: If you haven't specified defined `local.customer` or customized service names, the default is "fleet" for anywhere that `local.customer` is specified below.
|
||||
|
||||
If the Fleet database password secret is encrypted with a CMK, also pass `mysql_password_secret_kms_key_arn` so the cron-monitoring Lambda can decrypt it. When using the `byo-vpc` module, wire this from `module.<fleet_module>.byo-vpc.rds_password_secret_kms_key_arn`.
|
||||
|
||||
**Important:** If you supply a custom `kms_base_policy` that does not grant `kms:*` to the account root (for example, a least-privilege policy that only allows specific principals), you must also add the cron-monitoring Lambda role to `rds_config.password_secret_kms.extra_kms_policies` in the `byo-vpc` module. AWS KMS requires both the key policy and the IAM policy to allow access. The Lambda role name is predictable (`<customer_prefix>-cron-monitoring-lambda`), so you can construct the ARN before the role exists. See the `byo-vpc` module README for a full example.
|
||||
|
||||
```
|
||||
module "monitoring" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/monitoring?ref=tf-mod-addon-monitoring-v1.9.0"
|
||||
@@ -69,6 +73,7 @@ module "monitoring" {
|
||||
mysql_database = module.fleet.byo-vpc.rds.cluster_database_name
|
||||
mysql_user = module.fleet.byo-vpc.rds.cluster_master_username
|
||||
mysql_password_secret_name = "${local.customer}-database-password"
|
||||
mysql_password_secret_kms_key_arn = module.fleet.byo-vpc.rds_password_secret_kms_key_arn
|
||||
mysql_tls_config = "true"
|
||||
rds_security_group_id = module.fleet.byo-vpc.rds.security_group_id
|
||||
subnet_ids = module.fleet.vpc.private_subnets
|
||||
@@ -158,7 +163,7 @@ No requirements.
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_archive"></a> [archive](#provider\_archive) | 2.7.1 |
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.33.0 |
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.20.0 |
|
||||
| <a name="provider_null"></a> [null](#provider\_null) | 3.2.4 |
|
||||
|
||||
## Modules
|
||||
@@ -207,7 +212,7 @@ No modules.
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_acm_certificate_arn"></a> [acm\_certificate\_arn](#input\_acm\_certificate\_arn) | n/a | `string` | `null` | no |
|
||||
| <a name="input_albs"></a> [albs](#input\_albs) | n/a | <pre>list(object({<br/> name = string<br/> arn_suffix = string<br/> target_group_name = string<br/> target_group_arn_suffix = string<br/> min_containers = optional(string, 1)<br/> ecs_service_name = string<br/> alert_thresholds = optional(<br/> object({<br/> HTTPCode_ELB_5XX_Count = object({<br/> period = number<br/> threshold = number<br/> })<br/> HTTPCode_Target_5XX_Count = object({<br/> period = number<br/> threshold = number<br/> })<br/> }),<br/> {<br/> HTTPCode_ELB_5XX_Count = {<br/> period = 120<br/> threshold = 0<br/> },<br/> HTTPCode_Target_5XX_Count = {<br/> period = 120<br/> threshold = 0<br/> }<br/> }<br/> )<br/> }))</pre> | `[]` | no |
|
||||
| <a name="input_cron_monitoring"></a> [cron\_monitoring](#input\_cron\_monitoring) | n/a | <pre>object({<br/> mysql_host = string<br/> mysql_database = string<br/> mysql_user = string<br/> mysql_password_secret_name = string<br/> mysql_tls_config = optional(string, "true")<br/> vpc_id = string<br/> subnet_ids = list(string)<br/> rds_security_group_id = string<br/> delay_tolerance = string<br/> run_interval = string<br/> log_retention_in_days = optional(number, 7)<br/> ignore_list = optional(list(string), [])<br/> })</pre> | `null` | no |
|
||||
| <a name="input_cron_monitoring"></a> [cron\_monitoring](#input\_cron\_monitoring) | n/a | <pre>object({<br/> mysql_host = string<br/> mysql_database = string<br/> mysql_user = string<br/> mysql_password_secret_name = string<br/> mysql_password_secret_kms_key_arn = optional(string, null)<br/> mysql_tls_config = optional(string, "true")<br/> vpc_id = string<br/> subnet_ids = list(string)<br/> rds_security_group_id = string<br/> delay_tolerance = string<br/> run_interval = string<br/> log_retention_in_days = optional(number, 7)<br/> ignore_list = optional(list(string), [])<br/> })</pre> | `null` | no |
|
||||
| <a name="input_customer_prefix"></a> [customer\_prefix](#input\_customer\_prefix) | n/a | `string` | `"fleet"` | no |
|
||||
| <a name="input_default_sns_topic_arns"></a> [default\_sns\_topic\_arns](#input\_default\_sns\_topic\_arns) | n/a | `list(string)` | `[]` | no |
|
||||
| <a name="input_fleet_ecs_service_name"></a> [fleet\_ecs\_service\_name](#input\_fleet\_ecs\_service\_name) | n/a | `string` | `null` | no |
|
||||
@@ -218,4 +223,7 @@ No modules.
|
||||
|
||||
## Outputs
|
||||
|
||||
No outputs.
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_cron_monitoring_lambda_arn"></a> [cron\_monitoring\_lambda\_arn](#output\_cron\_monitoring\_lambda\_arn) | n/a |
|
||||
| <a name="output_cron_monitoring_lambda_role_arn"></a> [cron\_monitoring\_lambda\_role\_arn](#output\_cron\_monitoring\_lambda\_role\_arn) | n/a |
|
||||
+27
-11
@@ -403,17 +403,17 @@ resource "aws_lambda_function" "cron_monitoring" {
|
||||
|
||||
environment {
|
||||
variables = {
|
||||
MYSQL_HOST = var.cron_monitoring.mysql_host
|
||||
MYSQL_DATABASE = var.cron_monitoring.mysql_database
|
||||
MYSQL_USER = var.cron_monitoring.mysql_user
|
||||
MYSQL_SECRETSMANAGER_SECRET = data.aws_secretsmanager_secret.mysql_database_password[0].name
|
||||
MYSQL_TLS_CONFIG = var.cron_monitoring.mysql_tls_config
|
||||
CRON_SYSTEM_MONITOR_SNS_TOPIC_ARNS = join(",", lookup(var.sns_topic_arns_map, "cron_monitoring", var.default_sns_topic_arns))
|
||||
CRON_JOB_FAILURE_MONITOR_SNS_TOPIC_ARNS = join(",", lookup(var.sns_topic_arns_map, "cron_job_failure_monitoring", var.default_sns_topic_arns))
|
||||
FLEET_ENV = var.customer_prefix
|
||||
CRON_DELAY_TOLERANCE = var.cron_monitoring.delay_tolerance
|
||||
CRON_MONITOR_RUN_INTERVAL = var.cron_monitoring.run_interval
|
||||
CRON_IGNORE_LIST = join(",", var.cron_monitoring.ignore_list)
|
||||
MYSQL_HOST = var.cron_monitoring.mysql_host
|
||||
MYSQL_DATABASE = var.cron_monitoring.mysql_database
|
||||
MYSQL_USER = var.cron_monitoring.mysql_user
|
||||
MYSQL_SECRETSMANAGER_SECRET = data.aws_secretsmanager_secret.mysql_database_password[0].name
|
||||
MYSQL_TLS_CONFIG = var.cron_monitoring.mysql_tls_config
|
||||
CRON_SYSTEM_MONITOR_SNS_TOPIC_ARNS = join(",", lookup(var.sns_topic_arns_map, "cron_monitoring", var.default_sns_topic_arns))
|
||||
CRON_JOB_FAILURE_MONITOR_SNS_TOPIC_ARNS = join(",", lookup(var.sns_topic_arns_map, "cron_job_failure_monitoring", var.default_sns_topic_arns))
|
||||
FLEET_ENV = var.customer_prefix
|
||||
CRON_DELAY_TOLERANCE = var.cron_monitoring.delay_tolerance
|
||||
CRON_MONITOR_RUN_INTERVAL = var.cron_monitoring.run_interval
|
||||
CRON_IGNORE_LIST = join(",", var.cron_monitoring.ignore_list)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,6 +474,22 @@ data "aws_iam_policy_document" "cron_monitoring_lambda" {
|
||||
|
||||
}
|
||||
|
||||
dynamic "statement" {
|
||||
for_each = var.cron_monitoring != null && try(var.cron_monitoring.mysql_password_secret_kms_key_arn, null) != null ? [var.cron_monitoring.mysql_password_secret_kms_key_arn] : []
|
||||
content {
|
||||
sid = "KMSDecryptMysqlPasswordSecret"
|
||||
|
||||
actions = [
|
||||
"kms:Decrypt",
|
||||
"kms:DescribeKey"
|
||||
]
|
||||
|
||||
resources = [statement.value]
|
||||
|
||||
effect = "Allow"
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "SNSPublish"
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
output "cron_monitoring_lambda_arn" {
|
||||
value = try(aws_lambda_function.cron_monitoring[0].arn, null)
|
||||
}
|
||||
|
||||
output "cron_monitoring_lambda_role_arn" {
|
||||
value = try(aws_iam_role.cron_monitoring_lambda[0].arn, null)
|
||||
}
|
||||
@@ -86,6 +86,7 @@ variable "cron_monitoring" {
|
||||
mysql_database = string
|
||||
mysql_user = string
|
||||
mysql_password_secret_name = string
|
||||
mysql_password_secret_kms_key_arn = optional(string, null)
|
||||
mysql_tls_config = optional(string, "true")
|
||||
vpc_id = string
|
||||
subnet_ids = list(string)
|
||||
|
||||
Reference in new issue
Block a user