## 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`
169 lines
6.2 KiB
Markdown
169 lines
6.2 KiB
Markdown
# Cloudfront Software Installers
|
|
|
|
This module allows for Fleet software installers to be served via AWS Cloudfront instead of directly from Fleet.
|
|
|
|
This should improve the performance of software installer delivery. For general information about Fleet and Cloudfront see the following:
|
|
|
|
https://fleetdm.com/guides/cdn-signed-urls
|
|
https://victoronsoftware.com/posts/cloudfront-signed-urls/
|
|
|
|
The second link includes a script that can be used to test and see if signed URLs are working outside of Fleet for troubleshooting purposes.
|
|
|
|
|
|
## Other module requirements
|
|
|
|
These are the minimum versions of modules required if used:
|
|
|
|
- tf-mod-root-v1.13.0
|
|
- tf-mod-byo-vpc-v1.14.0
|
|
- tf-mod-byo-db-v1.10.0
|
|
- tf-mod-byo-ecs-v1.9.0
|
|
- tf-mod-addon-logging-alb-v1.3.0
|
|
|
|
Previous versions do not allow for proper interaction with both the software installers and logging s3 buckets.
|
|
|
|
## Configuration considerations for other modules
|
|
|
|
### tf-mod-root/tf-mod-byo-vpc/tf-mod-byo-db/tf-mod-byo-ecs
|
|
|
|
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"
|
|
cloudfront_distribution_arn = "arn:aws:cloudfront::<account-id>:distribution/<distribution-id>"
|
|
}
|
|
|
|
```
|
|
|
|
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
|
|
|
|
No changes required if using at least version `tf-mod-addon-logging-alb-v1.3.0`. Bucket ACLs are changed to allow for the alb logging bucket to accept Cloudfront logs via ACLs.
|
|
|
|
## Configuration Example
|
|
|
|
This example assumes that you used the following commands to create your public and private key for consumption by the module:
|
|
|
|
```
|
|
openssl genrsa -out cloudfront.key 2048
|
|
openssl rsa -pubout -in cloudfront.key -out cloudfront.pem
|
|
```
|
|
|
|
To be able to store these in source control in a sane manner, the objects will be KMS encrypted for storage at rest. This can happen by having a KMS key as follows:
|
|
|
|
```
|
|
|
|
resource "aws_kms_key" "customer_data_key" {
|
|
description = "key used to encrypt sensitive data stored in terraform"
|
|
}
|
|
|
|
resource "aws_kms_alias" "alias" {
|
|
name = "alias/fleet-terraform-encrypted"
|
|
target_key_id = aws_kms_key.customer_data_key.id
|
|
}
|
|
|
|
output "kms_key_id" {
|
|
value = aws_kms_key.customer_data_key.id
|
|
}
|
|
```
|
|
|
|
Then with the key, the following `encrypt.sh` script encrypt the objects:
|
|
|
|
```
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
function usage() {
|
|
cat <<-EOUSAGE
|
|
|
|
Usage: $(basename ${0}) <KMS_KEY_ID> <SOURCE> <DESTINATION> [AWS_PROFILE]
|
|
|
|
This script encrypts an plaintext file from SOURCE into an
|
|
AWS KMS encrypted DESTINATION file. Optionally you
|
|
may provide the AWS_PROFILE you wish to use to run the aws kms
|
|
commands.
|
|
|
|
EOUSAGE
|
|
exit 1
|
|
}
|
|
|
|
[ $# -lt 3 ] && usage
|
|
|
|
if [ -n "${4}" ]; then
|
|
export AWS_PROFILE=${4}
|
|
fi
|
|
|
|
aws kms encrypt --key-id "${1:?}" --plaintext fileb://<(cat "${2:?}") --output text --query CiphertextBlob > "${3:?}"
|
|
```
|
|
|
|
We can do the following with that script to encrypt the objects:
|
|
|
|
```
|
|
./encrypt.sh <KMS_KEY_ID> cloudfront.key cloudfront.key.encrypted
|
|
./encrypt.sh <KMS_KEY_ID> cloudfront.pem cloudfront.pem.encrypted
|
|
|
|
```
|
|
|
|
Now with those encrypted we could setup the module with something like the following to populate the module (assuming we add the files to a /resources folder):
|
|
|
|
```
|
|
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
|
|
# 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.
|
|
# key_group_id = ""
|
|
# public_key_id = ""
|
|
public_key = data.aws_kms_secrets.cloudfront.plaintext["public_key"]
|
|
private_key = data.aws_kms_secrets.cloudfront.plaintext["private_key"]
|
|
enable_logging = true
|
|
logging_s3_bucket = module.logging_alb.log_s3_bucket_id
|
|
}
|
|
|
|
data "aws_kms_secrets" "cloudfront" {
|
|
secret {
|
|
name = "public_key"
|
|
key_id = aws_kms_key.customer_data_key.id
|
|
payload = file("${path.module}/resources/cloudfront.pem.encrypted")
|
|
}
|
|
secret {
|
|
name = "private_key"
|
|
key_id = aws_kms_key.customer_data_key.id
|
|
payload = file("${path.module}/resources/cloudfront.key.encrypted")
|
|
}
|
|
}
|
|
```
|
|
|
|
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:
|
|
|
|
```
|
|
fleet_config = {
|
|
...
|
|
extra_execution_iam_policies = concat(
|
|
module.mdm.extra_execution_iam_policies,
|
|
module.cloudfront-software-installers.extra_execution_iam_policies,
|
|
)
|
|
extra_secrets = merge(
|
|
module.mdm.extra_secrets,
|
|
module.cloudfront-software-installers.extra_secrets
|
|
)
|
|
}
|
|
|
|
```
|