## Summary
This PR extends the Fleet ECS modules to support:
- configurable Fleet server private key delivery via ecs or iam
- optional fleet_config.command overrides for Fleet task definitions
- caller-managed Fleet server private key secrets via
fleet_config.private_key_secret_arn
It also updates the external vuln scans addon to follow the same
private-key delivery and command behavior, and refreshes the generated
module documentation.
## What changed
- Added fleet_config.private_key_delivery_method with supported values:
- ecs (default): inject the private key as FLEET_SERVER_PRIVATE_KEY
- iam: inject the secret ARN as FLEET_SERVER_PRIVATE_KEY_ARN
- Added validation so only ecs or iam are accepted
- Added fleet_config.command support so callers can override the Fleet
container command when needed
- Added fleet_config.private_key_secret_arn support so callers can
supply an existing Secrets Manager secret instead of having this module
create and populate one
- Updated IAM policy wiring so private-key secret access and private-key
KMS decrypt permissions are granted to the correct role based on the
selected delivery method
- Updated module outputs so fleet_server_private_key_secret_arn returns
the effective ARN whether the secret is module-managed or caller-managed
- Updated addons/external-vuln-scans to consume the same private-key
delivery mode and optional command behavior from the passed fleet_config
- Updated byo-ecs documentation and regenerated README files
## Behavior
### Private key delivery
- ecs mode injects the secret value into the container and uses the ECS
execution role for private-key secret access
- iam mode injects the secret ARN into the container environment and
uses the Fleet task role for private-key secret access
### Command override
- When fleet_config.command is unset, the task definition omits command
- When fleet_config.command is set, the provided command is passed
through to the Fleet container
- This behavior now applies consistently to both the main ECS service
and external vuln scans
### Caller-managed private key secret
- When fleet_config.private_key_secret_arn is unset, the module creates
and populates the Fleet private key secret
- When fleet_config.private_key_secret_arn is set, the module uses the
provided secret ARN and does not create the secret, secret version, or
generated random value
## KMS note for external secrets
If a caller-managed private-key secret uses a CMK, the caller must also
provide the existing private-key KMS ARN input so the correct role
receives decrypt permissions for the selected delivery mode.
## Validation
Validated successfully with:
- terraform validate -no-color at repo root
- terraform validate -no-color in byo-vpc
- terraform validate -no-color in byo-vpc/byo-db
- terraform validate -no-color in byo-vpc/byo-db/byo-ecs
Also verified that existing module-managed private-key resources plan as
non-destructive state-address moves when transitioning to the new
counted resources:
- 0 to add
- 0 to change
- 0 to destroy
BYO ECS Module
This module deploys Fleet into an existing ECS/Fargate environment and supports optional customer-managed KMS keys (CMKs) for:
- Fleet private key secret in Secrets Manager
- Fleet application CloudWatch Logs log group encryption
- Fleet software installers S3 bucket encryption
When no KMS inputs are provided, behavior remains unchanged from prior versions.
KMS Behavior
fleet_config.private_key_secret_kms.cmk_enabled = trueenables CMK encryption for the Fleet private key secret.fleet_config.awslogs.kms.cmk_enabled = trueenables CMK encryption for the Fleet application log group whenfleet_config.awslogs.create = true.fleet_config.software_installers.create_kms_key = trueenables CMK encryption for software installers S3 objects.
For each feature:
- Set
cmk_enabled = falseor omit it to keep using the service-managed key. - For KMS options that existed in published releases before this change, legacy
enabledis deprecated but still accepted. Terraform plan/apply warns when it is used, andcmk_enabledtakes precedence if both are set. - If CMK use is enabled and no key ARN is provided, this module creates a CMK and alias.
- If a key ARN is provided, this module uses that key and does not create a CMK.
- For software installers, setting
software_installers.kms_key_arnis sufficient to use that key even ifcreate_kms_key = false.
IAM permissions for using these keys are managed in-module where possible. For module-created keys, the module prefers granting usage in the KMS key policy itself. If a caller-provided external key still needs IAM authorization and the task role ARN belongs to the same AWS account, the module attaches a separate resource-scoped KMS IAM policy to that role instead of mixing KMS access into the broader S3 or secret-access policy. extra_iam_policies attachments continue to be applied to the same-account task role when provided.
Example: Use Module-Managed Keys
module "fleet_byo_ecs" {
source = "github.com/fleetdm/fleet-terraform//byo-vpc/byo-db/byo-ecs?ref=tf-mod-byo-ecs-v1.15.0"
ecs_cluster = "fleet"
vpc_id = "vpc-1234567890abcdef0"
fleet_config = {
database = {
password_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:fleet-db"
user = "fleet"
database = "fleet"
address = "fleet.cluster-xyz.us-east-1.rds.amazonaws.com"
}
redis = {
address = "fleet-redis.example.cache.amazonaws.com:6379"
}
loadbalancer = {
arn = "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/fleet/abc123"
}
networking = {
subnets = ["subnet-aaa", "subnet-bbb"]
ingress_sources = {
cidr_blocks = []
ipv6_cidr_blocks = []
security_groups = []
prefix_list_ids = []
}
}
private_key_secret_kms = {
cmk_enabled = true
}
awslogs = {
create = true
name = "/aws/ecs/fleet"
kms = {
cmk_enabled = true
}
}
software_installers = {
create_bucket = true
create_kms_key = true
}
}
}
Example: Use Existing CMKs
fleet_config = {
private_key_secret_kms = {
cmk_enabled = true
kms_key_arn = "arn:aws:kms:us-east-1:123456789012:key/11111111-2222-3333-4444-555555555555"
}
awslogs = {
create = true
name = "/aws/ecs/fleet"
kms = {
cmk_enabled = true
kms_key_arn = "arn:aws:kms:us-east-1:123456789012:key/99999999-aaaa-bbbb-cccc-dddddddddddd"
}
}
software_installers = {
create_bucket = true
kms_key_arn = "arn:aws:kms:us-east-1:123456789012:key/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
}
}
Command Configuration
Optionally specify a custom command for the Fleet container:
fleet_config = {
# ... other config ...
command = ["/usr/bin/fleet", "agent", "--some-flag"]
}
Private Key Delivery Method
Control how the Fleet server private key is delivered to the container:
- ecs (default): The secret value is injected as
FLEET_SERVER_PRIVATE_KEYsecret. The ECS Execution Role needs Secrets Manager permissions to decrypt the secret. - iam: The secret ARN is injected as
FLEET_SERVER_PRIVATE_KEY_ARNenvironment variable. The Fleet task role needs Secrets Manager permissions to decrypt the secret.
fleet_config = {
# ... other config ...
private_key_delivery_method = "iam" # or "ecs"
}
When private_key_delivery_method = "iam", the KMS key policy for the private key secret grants decrypt permissions to the Fleet task role instead of the ECS execution role.
Caller-Provided Private Key Secret
By default, this module creates and populates the Fleet server private key secret in Secrets Manager.
To use a caller-managed existing secret instead, set fleet_config.private_key_secret_arn. When this is set:
- This module does not create the Fleet server private key secret, secret version, or generated random value.
fleet_config.private_key_secret_nameis ignored.- The provided ARN is used in both delivery modes:
ecs: injected asFLEET_SERVER_PRIVATE_KEYiam: injected asFLEET_SERVER_PRIVATE_KEY_ARN
- The output
fleet_server_private_key_secret_arnreturns the effective ARN, whether the secret is module-managed or caller-managed. - Secret value population and lifecycle are entirely caller-managed.
If the caller-provided secret uses a CMK, the caller must also provide fleet_config.private_key_secret_kms.kms_key_arn so the correct ECS execution role or Fleet task role gets decrypt permissions for the selected delivery mode. This module does not inspect external secrets to discover their KMS configuration.
fleet_config = {
private_key_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:existing-fleet-private-key"
private_key_delivery_method = "iam"
private_key_secret_kms = {
cmk_enabled = true
kms_key_arn = "arn:aws:kms:us-east-1:123456789012:key/11111111-2222-3333-4444-555555555555"
}
}
Migration Notes
- Existing deployments are unchanged unless new KMS options are enabled.
- Supplying
fleet_config.private_key_secret_arnswitches the module to use an existing caller-managed secret instead of creating one. - Enabling KMS for application logs sets
kms_key_idon the module-managed CloudWatch log group. - Enabling KMS for software installers updates S3 default encryption configuration.
- Breaking change: software installers CMK policy ownership now lives in
byo-ecs. The CloudFront addon no longer manages that key policy. - If CloudFront should access a module-managed or caller-provided software installers CMK, set
fleet_config.software_installers.cloudfront_distribution_arnto the static distribution ARN sobyo-ecscan add the requiredcloudfront.amazonaws.comkey-policy statement. - Under narrow external
kms_base_policyconfigurations, this module now adds an explicit Fleet task-role statement to the software installers CMK policy so Fleet itself can continue using the key. - If you enable software installers KMS after objects already exist in the bucket, re-encrypt existing objects by copying them onto themselves:
aws s3 cp s3://<software-installers-bucket-name> s3://<software-installers-bucket-name> --recursive - Enabling KMS for the private key secret updates the secret to use the configured CMK.
- If you enable KMS on an existing CloudWatch log group, older data remains encrypted with the previous keying context. To ensure only the new key is used, delete log streams whose last event predates the
AssociateKmsKeyevent for the currentkmsKeyId.
CloudWatch Logs KMS Migration Script
Use the helper script at ../../../scripts/cloudwatch_logs_kms_migration.sh. It is generic for any log group (for example Fleet app logs and ECS cluster exec logs), uses JSON output with jq, auto-discovers the active kmsKeyId and AssociateKmsKey cutoff, and deletes whole old streams by default.
# Dry run: list old streams only
DELETE_OLD_STREAMS=false ../../../scripts/cloudwatch_logs_kms_migration.sh <log-group-name> <region>
# Delete old streams (default behavior)
../../../scripts/cloudwatch_logs_kms_migration.sh <log-group-name> <region>
Requirements
| Name | Version |
|---|---|
| terraform | >= 1.12.0 |
| aws | >= 6.37.0 |
Providers
| Name | Version |
|---|---|
| aws | 6.38.0 |
| random | 3.8.1 |
Modules
No modules.
Resources
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| ecs_cluster | The name of the ECS cluster to use | string |
n/a | yes |
| fleet_config | The configuration object for Fleet itself. Fields that default to null will have their respective resources created if not specified. For published KMS blocks, legacy enabled is deprecated and still accepted; prefer cmk_enabled. |
object({ |
{ |
no |
| kms_base_policy | 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. |
list(object({ |
null |
no |
| migration_config | The configuration object for Fleet's migration task. | object({ |
{ |
no |
| vpc_id | n/a | string |
null |
no |
Outputs
| Name | Description |
|---|---|
| appautoscaling_target | n/a |
| execution_iam_role_arn | n/a |
| fleet_application_logs_kms_key_arn | n/a |
| fleet_config | n/a |
| fleet_s3_software_installers_config | n/a |
| fleet_server_private_key_secret_arn | n/a |
| fleet_server_private_key_secret_kms_key_arn | n/a |
| iam_role_arn | n/a |
| logging_config | n/a |
| non_circular | n/a |
| service | n/a |
| task_definition | n/a |