Files
fleet-terraform/addons/monitoring
Robert Fairburn e7faee93de 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`
2026-03-20 12:07:38 -05:00
..
2026-03-20 12:07:38 -05:00
2025-02-04 10:07:51 -06:00
2026-03-20 12:07:38 -05:00
2026-03-20 12:07:38 -05:00
2026-03-20 12:07:38 -05:00
2026-03-20 12:07:38 -05:00

Monitoring addon

This addon enables Cloudwatch monitoring for Fleet.

This includes:

  • 5XX Errors on ALB
  • ECS Service Monitoring
  • RDS Monitoring
  • Redis Monitoring
  • ACM Certificate Monitoring
  • A custom Lambda to check the Fleet DB for Cron runs

Preparation

Note: The documented examples and links in this README may assume use of module.fleet instead of module.main. The monitoring example configuration can be modified as documented below, if your fleet module is named fleet instead of main

  • A search and replace of module.fleet -> module.main

Some of the for_each and counts in this module cannot pre-determine the numbers until the main fleet module is applied.

You will need to terraform apply -target module.fleet prior to applying monitoring assuming the use of a configuration matching the example at https://github.com/fleetdm/fleet-terraform/blob/main/example/main.tf.

Multiple alb support was added in order to allow monitoring saml-auth-proxy. See https://github.com/fleetdm/fleet-terraform/tree/main/addons/saml-auth-proxy

Example configuration

This assumes your fleet module is main and is configured with it's default documentation.

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"
  customer_prefix        = local.customer
  fleet_ecs_service_name = module.fleet.byo-vpc.byo-db.byo-ecs.service.name
  albs = [
    {
      name                    = module.fleet.byo-vpc.byo-db.alb.lb_dns_name,
      target_group_name       = module.fleet.byo-vpc.byo-db.alb.target_group_names[0]
      target_group_arn_suffix = module.fleet.byo-vpc.byo-db.alb.target_group_arn_suffixes[0]
      arn_suffix              = module.fleet.byo-vpc.byo-db.alb.lb_arn_suffix
      ecs_service_name        = module.fleet.byo-vpc.byo-db.byo-ecs.service.name
      min_containers          = module.fleet.byo-vpc.byo-db.byo-ecs.appautoscaling_target.min_capacity
      alert_thresholds = {
        HTTPCode_ELB_5XX_Count = {
          period    = 3600
          threshold = 2
        },
        HTTPCode_Target_5XX_Count = {
          period    = 120
          threshold = 0
        }
      }
    },
  ]
  sns_topic_arns_map = {
    log_monitoring   = [var.sns_topic_arn]
    alb_httpcode_5xx = [var.sns_topic_arn]
    cron_monitoring  = [var.sns_topic_arn]
    cron_job_failure_monitoring  = [var.sns_another_topic_arn]
  }
  mysql_cluster_members = module.fleet.byo-vpc.rds.cluster_members
  # The cloudposse module seems to have a nested list here.
  redis_cluster_members = module.fleet.byo-vpc.redis.member_clusters[0]
  acm_certificate_arn   = module.acm.acm_certificate_arn
  cron_monitoring = {
    mysql_host                 = module.fleet.byo-vpc.rds.cluster_reader_endpoint
    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
    vpc_id                     = module.fleet.vpc.vpc_id
    # Format of https://pkg.go.dev/time#ParseDuration
    delay_tolerance = "4h"
    # Interval format for: https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html#rate-based
    run_interval          = "1 hour"
    log_retention_in_days = 365
    # Cron List of Names to Ignore (see below for valid values)
    ignore_list = []
  }
  log_monitoring = {
    invalid-secret = {
      log_group_name = module.fleet.byo-vpc.byo-db.byo-ecs.logging_config.awslogs-group
      pattern = "{ $.internal = \"invalid secret\" }"
      evaluation_periods = 1
      period             = 3600
      threshold          = 1
    }
    duplicate-identifier = {
      log_group_name = module.fleet.byo-vpc.byo-db.byo-ecs.logging_config.awslogs-group
      pattern = "{ $.msg = \"osquery host with duplicate identifier has enrolled in Fleet and will overwrite existing host data\" }"
      evaluation_periods = 1
      period             = 3600
      threshold          = 1
    }
    limit-exceeded = {
      log_group_name = module.fleet.byo-vpc.byo-db.byo-ecs.logging_config.awslogs-group
      pattern = "{ $.err = \"limit exceeded\" }"
      evaluation_periods = 1
      period             = 60
      threshold          = 1
    }
  }
}

SNS topic ARNs map

Valid targets for sns_topic_arns_map:

  • acm_certificate_expired
  • alb_helthyhosts
  • alb_httpcode_5xx
  • backend_response_time
  • cron_monitoring (notifications about failures in the cron scheduler)
  • cron_job_failure_monitoring (notifications about errors in individual cron jobs - defaults to value of cron_monitoring)
  • log_monitoring
  • rds_cpu_untilizaton_too_high
  • rds_db_event_subscription
  • redis_cpu_engine_utilization
  • redis_cpu_utilization
  • redis_current_connections
  • redis_database_memory_percentage
  • redis_replication_lag

If you want to publish to all, use default_sns_topic_arns instead and include your notification ARNs there.

Cron Names

  • apple_mdm_apns_pusher
  • apple_mdm_dep_profile_assigner
  • apple_mdm_iphone_ipad_refetcher
  • apple_mdm_iphone_ipad_reviver
  • automations
  • batch_activity_completion_checker
  • calendar
  • cleanups_then_aggregation
  • host_vitals_label_membership
  • integrations
  • maintained_apps
  • mdm_service_discovery
  • mdm_windows_profile_manager
  • refresh_vpp_app_versions
  • scheduled_batch_activities
  • upcoming_activities_maintenance
  • usage_statistics
  • vulnerabilities

Requirements

No requirements.

Providers

Name Version
archive 2.7.1
aws 6.20.0
null 3.2.4

Modules

No modules.

Resources

Name Type
aws_cloudwatch_event_rule.cron_monitoring_lambda resource
aws_cloudwatch_event_target.cron_monitoring_lambda resource
aws_cloudwatch_log_group.cron_monitoring_lambda resource
aws_cloudwatch_log_metric_filter.log_monitoring resource
aws_cloudwatch_metric_alarm.acm_certificate_expired resource
aws_cloudwatch_metric_alarm.alb_healthyhosts resource
aws_cloudwatch_metric_alarm.cpu_utilization_too_high resource
aws_cloudwatch_metric_alarm.lb resource
aws_cloudwatch_metric_alarm.log_monitoring resource
aws_cloudwatch_metric_alarm.redis-current-connections resource
aws_cloudwatch_metric_alarm.redis-database-memory-percentage resource
aws_cloudwatch_metric_alarm.redis-replication-lag resource
aws_cloudwatch_metric_alarm.redis_cpu resource
aws_cloudwatch_metric_alarm.redis_cpu_engine_utilization resource
aws_cloudwatch_metric_alarm.target_response_time resource
aws_db_event_subscription.default resource
aws_iam_policy.cron_monitoring_lambda resource
aws_iam_role.cron_monitoring_lambda resource
aws_iam_role_policy_attachment.cron_monitoring_lambda resource
aws_iam_role_policy_attachment.cron_monitoring_lambda_managed resource
aws_lambda_function.cron_monitoring resource
aws_lambda_permission.cron_monitoring_cloudwatch resource
aws_security_group.cron_monitoring resource
aws_security_group_rule.cron_monitoring_to_rds resource
null_resource.cron_monitoring_build resource
archive_file.cron_monitoring_lambda data source
aws_caller_identity.current data source
aws_iam_policy_document.cron_monitoring_lambda data source
aws_iam_policy_document.cron_monitoring_lambda_assume_role data source
aws_region.current data source
aws_secretsmanager_secret.mysql_database_password data source

Inputs

Name Description Type Default Required
acm_certificate_arn n/a string null no
albs n/a
list(object({
name = string
arn_suffix = string
target_group_name = string
target_group_arn_suffix = string
min_containers = optional(string, 1)
ecs_service_name = string
alert_thresholds = optional(
object({
HTTPCode_ELB_5XX_Count = object({
period = number
threshold = number
})
HTTPCode_Target_5XX_Count = object({
period = number
threshold = number
})
}),
{
HTTPCode_ELB_5XX_Count = {
period = 120
threshold = 0
},
HTTPCode_Target_5XX_Count = {
period = 120
threshold = 0
}
}
)
}))
[] no
cron_monitoring n/a
object({
mysql_host = string
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)
rds_security_group_id = string
delay_tolerance = string
run_interval = string
log_retention_in_days = optional(number, 7)
ignore_list = optional(list(string), [])
})
null no
customer_prefix n/a string "fleet" no
default_sns_topic_arns n/a list(string) [] no
fleet_ecs_service_name n/a string null no
log_monitoring Map of CloudWatch log monitors to create. Key is used as a suffix for resources and metric naming.
map(object({
log_group_name = string
pattern = string
evaluation_periods = number
period = number
threshold = number
}))
{} no
mysql_cluster_members n/a list(string) [] no
redis_cluster_members n/a list(string) [] no
sns_topic_arns_map n/a map(list(string)) {} no

Outputs

Name Description
cron_monitoring_lambda_arn n/a
cron_monitoring_lambda_role_arn n/a