From ae8863ce649318d6f847514dbfb2b914375bff28 Mon Sep 17 00:00:00 2001 From: Jorge Falcon <22119513+BCTBB@users.noreply.github.com> Date: Fri, 19 Sep 2025 16:16:22 -0400 Subject: [PATCH] Support for internal load balancer and deletion protection, iam policy attachment processing, osquery perf fix, and cloudfront software installers (#105) # Main terraform - Modified iam `resource "aws_iam_role_policy_attachment" "extras"` from `for_each` to `count`, which allows terraform to apply even if roles are not yet created. In cases where role is not yet created, a second terraform apply is required for the resource to attach the policy. - Modified iam `resource "aws_iam_role_policy_attachment" "execution_extras"`, which allows terraform to apply even if roles are not yet created. In cases where role is not yet created, a second terraform apply is required for the resource to attach the policy. - Added support for internal load balancers to be provisioned. - Added support for toggling deletion protection on and off on the load balancer resource. # Example Module - Updated example module with changes alb changes. # Module: Cloudfront Software Installers - Added a count & tertiary to cloudfront software installer kms key policy, as it's fed in as an input. In cases where the key had not yet been created, apply would fail. - Modified `variable "s3_kms_key_id"` to allow default value `null` # Module: Logging Destination Firehose - Added prefix variable to support use-cases where multiple environments are deployed in the same account # Module: Osquery Perf - Added dependency on `data.aws_secretsmanager_secret_version.enroll_secret` to fix race condition. --- README.md | 2 +- addons/cloudfront-software-installers/main.tf | 1 + .../variables.tf | 1 + addons/logging-destination-firehose/README.md | 3 +- addons/logging-destination-firehose/main.tf | 6 +- .../logging-destination-firehose/variables.tf | 5 ++ addons/osquery-perf/.header.md | 16 +++- addons/osquery-perf/README.md | 26 ++++-- addons/osquery-perf/main.tf | 13 +-- addons/osquery-perf/outputs.tf | 7 ++ addons/osquery-perf/variables.tf | 11 ++- byo-vpc/README.md | 4 +- byo-vpc/byo-db/README.md | 4 +- byo-vpc/byo-db/byo-ecs/iam.tf | 8 +- byo-vpc/byo-db/main.tf | 2 + byo-vpc/byo-db/variables.tf | 2 + byo-vpc/variables.tf | 2 + example/.header.md | 33 ++----- example/README.md | 53 ++++------- example/main.tf | 67 ++++++-------- example/mdm-secrets.tf | 90 +++++++------------ variables.tf | 2 + 22 files changed, 167 insertions(+), 191 deletions(-) create mode 100644 addons/osquery-perf/outputs.tf diff --git a/README.md b/README.md index f95c405..fac7ccd 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ No resources. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [alb\_config](#input\_alb\_config) | n/a |
object({
name = optional(string, "fleet")
security_groups = optional(list(string), [])
access_logs = optional(map(string), {})
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
allowed_ipv6_cidrs = optional(list(string), ["::/0"])
egress_cidrs = optional(list(string), ["0.0.0.0/0"])
egress_ipv6_cidrs = optional(list(string), ["::/0"])
extra_target_groups = optional(any, [])
https_listener_rules = optional(any, [])
https_overrides = optional(any, {})
xff_header_processing_mode = optional(string, null)
tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06")
idle_timeout = optional(number, 905)
})
| `{}` | no | +| [alb\_config](#input\_alb\_config) | n/a |
object({
name = optional(string, "fleet")
security_groups = optional(list(string), [])
access_logs = optional(map(string), {})
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
allowed_ipv6_cidrs = optional(list(string), ["::/0"])
egress_cidrs = optional(list(string), ["0.0.0.0/0"])
egress_ipv6_cidrs = optional(list(string), ["::/0"])
extra_target_groups = optional(any, [])
https_listener_rules = optional(any, [])
https_overrides = optional(any, {})
xff_header_processing_mode = optional(string, null)
tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06")
idle_timeout = optional(number, 905)
internal = optional(bool, false)
enable_deletion_protection = optional(bool, true)
})
| `{}` | no | | [certificate\_arn](#input\_certificate\_arn) | n/a | `string` | n/a | yes | | [ecs\_cluster](#input\_ecs\_cluster) | The config for the terraform-aws-modules/ecs/aws module |
object({
autoscaling_capacity_providers = optional(any, {})
cluster_configuration = optional(any, {
execute_command_configuration = {
logging = "OVERRIDE"
log_configuration = {
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
}
}
})
cluster_name = optional(string, "fleet")
cluster_settings = optional(map(string), {
"name" : "containerInsights",
"value" : "enabled",
})
create = optional(bool, true)
default_capacity_provider_use_fargate = optional(bool, true)
fargate_capacity_providers = optional(any, {
FARGATE = {
default_capacity_provider_strategy = {
weight = 100
}
}
FARGATE_SPOT = {
default_capacity_provider_strategy = {
weight = 0
}
}
})
tags = optional(map(string))
})
|
{
"autoscaling_capacity_providers": {},
"cluster_configuration": {
"execute_command_configuration": {
"log_configuration": {
"cloud_watch_log_group_name": "/aws/ecs/aws-ec2"
},
"logging": "OVERRIDE"
}
},
"cluster_name": "fleet",
"cluster_settings": {
"name": "containerInsights",
"value": "enabled"
},
"create": true,
"default_capacity_provider_use_fargate": true,
"fargate_capacity_providers": {
"FARGATE": {
"default_capacity_provider_strategy": {
"weight": 100
}
},
"FARGATE_SPOT": {
"default_capacity_provider_strategy": {
"weight": 0
}
}
},
"tags": {}
}
| no | | [fleet\_config](#input\_fleet\_config) | The configuration object for Fleet itself. Fields that default to null will have their respective resources created if not specified. |
object({
task_mem = optional(number, null)
task_cpu = optional(number, null)
mem = optional(number, 4096)
cpu = optional(number, 512)
pid_mode = optional(string, null)
image = optional(string, "fleetdm/fleet:v4.72.1")
family = optional(string, "fleet")
sidecars = optional(list(any), [])
depends_on = optional(list(any), [])
mount_points = optional(list(any), [])
volumes = optional(list(any), [])
extra_environment_variables = optional(map(string), {})
extra_iam_policies = optional(list(string), [])
extra_execution_iam_policies = optional(list(string), [])
extra_secrets = optional(map(string), {})
security_group_name = optional(string, "fleet")
iam_role_arn = optional(string, null)
repository_credentials = optional(string, "")
private_key_secret_name = optional(string, "fleet-server-private-key")
service = optional(object({
name = optional(string, "fleet")
}), {
name = "fleet"
})
database = optional(object({
password_secret_arn = string
user = string
database = string
address = string
rr_address = optional(string, null)
}), {
password_secret_arn = null
user = null
database = null
address = null
rr_address = null
})
redis = optional(object({
address = string
use_tls = optional(bool, true)
}), {
address = null
use_tls = true
})
awslogs = optional(object({
name = optional(string, null)
region = optional(string, null)
create = optional(bool, true)
prefix = optional(string, "fleet")
retention = optional(number, 5)
}), {
name = null
region = null
prefix = "fleet"
retention = 5
})
loadbalancer = optional(object({
arn = string
}), {
arn = null
})
extra_load_balancers = optional(list(any), [])
networking = optional(object({
subnets = optional(list(string), null)
security_groups = optional(list(string), null)
ingress_sources = optional(object({
cidr_blocks = optional(list(string), [])
ipv6_cidr_blocks = optional(list(string), [])
security_groups = optional(list(string), [])
prefix_list_ids = optional(list(string), [])
}), {
cidr_blocks = []
ipv6_cidr_blocks = []
security_groups = []
prefix_list_ids = []
})
}), {
subnets = null
security_groups = null
ingress_sources = {
cidr_blocks = []
ipv6_cidr_blocks = []
security_groups = []
prefix_list_ids = []
}
})
autoscaling = optional(object({
max_capacity = optional(number, 5)
min_capacity = optional(number, 1)
memory_tracking_target_value = optional(number, 80)
cpu_tracking_target_value = optional(number, 80)
}), {
max_capacity = 5
min_capacity = 1
memory_tracking_target_value = 80
cpu_tracking_target_value = 80
})
iam = optional(object({
role = optional(object({
name = optional(string, "fleet-role")
policy_name = optional(string, "fleet-iam-policy")
}), {
name = "fleet-role"
policy_name = "fleet-iam-policy"
})
execution = optional(object({
name = optional(string, "fleet-execution-role")
policy_name = optional(string, "fleet-execution-role")
}), {
name = "fleet-execution-role"
policy_name = "fleet-iam-policy-execution"
})
}), {
name = "fleetdm-execution-role"
})
software_installers = optional(object({
create_bucket = optional(bool, true)
bucket_name = optional(string, null)
bucket_prefix = optional(string, "fleet-software-installers-")
s3_object_prefix = optional(string, "")
enable_bucket_versioning = optional(bool, false)
expire_noncurrent_versions = optional(bool, true)
noncurrent_version_expiration_days = optional(number, 30)
create_kms_key = optional(bool, false)
kms_alias = optional(string, "fleet-software-installers")
tags = optional(map(string), {})
}), {
create_bucket = true
bucket_name = null
bucket_prefix = "fleet-software-installers-"
s3_object_prefix = ""
enable_bucket_versioning = false
expire_noncurrent_versions = true
noncurrent_version_expiration_days = 30
create_kms_key = false
kms_alias = "fleet-software-installers"
tags = {}
})
})
|
{
"autoscaling": {
"cpu_tracking_target_value": 80,
"max_capacity": 5,
"memory_tracking_target_value": 80,
"min_capacity": 1
},
"awslogs": {
"create": true,
"name": null,
"prefix": "fleet",
"region": null,
"retention": 5
},
"cpu": 256,
"database": {
"address": null,
"database": null,
"password_secret_arn": null,
"rr_address": null,
"user": null
},
"depends_on": [],
"extra_environment_variables": {},
"extra_execution_iam_policies": [],
"extra_iam_policies": [],
"extra_load_balancers": [],
"extra_secrets": {},
"family": "fleet",
"iam": {
"execution": {
"name": "fleet-execution-role",
"policy_name": "fleet-iam-policy-execution"
},
"role": {
"name": "fleet-role",
"policy_name": "fleet-iam-policy"
}
},
"iam_role_arn": null,
"image": "fleetdm/fleet:v4.72.1",
"loadbalancer": {
"arn": null
},
"mem": 512,
"mount_points": [],
"networking": {
"ingress_sources": {
"cidr_blocks": [],
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"security_groups": []
},
"security_groups": null,
"subnets": null
},
"pid_mode": null,
"private_key_secret_name": "fleet-server-private-key",
"redis": {
"address": null,
"use_tls": true
},
"repository_credentials": "",
"security_group_name": "fleet",
"security_groups": null,
"service": {
"name": "fleet"
},
"sidecars": [],
"software_installers": {
"bucket_name": null,
"bucket_prefix": "fleet-software-installers-",
"create_bucket": true,
"s3_object_prefix": ""
},
"task_cpu": null,
"task_mem": null,
"volumes": []
}
| no | diff --git a/addons/cloudfront-software-installers/main.tf b/addons/cloudfront-software-installers/main.tf index bef796a..e66517b 100644 --- a/addons/cloudfront-software-installers/main.tf +++ b/addons/cloudfront-software-installers/main.tf @@ -53,6 +53,7 @@ data "aws_iam_policy_document" "software_installers_kms" { } 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 } diff --git a/addons/cloudfront-software-installers/variables.tf b/addons/cloudfront-software-installers/variables.tf index 23895a7..bb825ed 100644 --- a/addons/cloudfront-software-installers/variables.tf +++ b/addons/cloudfront-software-installers/variables.tf @@ -22,6 +22,7 @@ variable "s3_bucket" { variable "s3_kms_key_id" { description = "KMS key id used to encrypt the s3 bucket" type = string + default = null } variable "enable_logging" { diff --git a/addons/logging-destination-firehose/README.md b/addons/logging-destination-firehose/README.md index 7e02991..9ae97a8 100644 --- a/addons/logging-destination-firehose/README.md +++ b/addons/logging-destination-firehose/README.md @@ -9,7 +9,7 @@ No requirements. | Name | Version | |------|---------| -| [aws](#provider\_aws) | 6.3.0 | +| [aws](#provider\_aws) | 6.13.0 | ## Modules @@ -59,6 +59,7 @@ No modules. | [compression\_format](#input\_compression\_format) | n/a | `string` | `"UNCOMPRESSED"` | no | | [osquery\_results\_s3\_bucket](#input\_osquery\_results\_s3\_bucket) | n/a |
object({
name = optional(string, "fleet-osquery-results-archive")
expires_days = optional(number, 1)
})
|
{
"expires_days": 1,
"name": "fleet-osquery-results-archive"
}
| no | | [osquery\_status\_s3\_bucket](#input\_osquery\_status\_s3\_bucket) | n/a |
object({
name = optional(string, "fleet-osquery-status-archive")
expires_days = optional(number, 1)
})
|
{
"expires_days": 1,
"name": "fleet-osquery-status-archive"
}
| no | +| [prefix](#input\_prefix) | n/a | `string` | `""` | no | ## Outputs diff --git a/addons/logging-destination-firehose/main.tf b/addons/logging-destination-firehose/main.tf index 430bd71..4d84bf1 100644 --- a/addons/logging-destination-firehose/main.tf +++ b/addons/logging-destination-firehose/main.tf @@ -167,17 +167,17 @@ data "aws_iam_policy_document" "audit_policy_doc" { } resource "aws_iam_policy" "firehose-results" { - name = "osquery_results_firehose_policy" + name = var.prefix == "" ? "osquery_results_firehose_policy" : "${var.prefix}_osquery_results_firehose_policy" policy = data.aws_iam_policy_document.osquery_results_policy_doc.json } resource "aws_iam_policy" "firehose-status" { - name = "osquery_status_firehose_policy" + name = var.prefix == "" ? "osquery_status_firehose_policy" : "${var.prefix}_osquery_status_firehose_policy" policy = data.aws_iam_policy_document.osquery_status_policy_doc.json } resource "aws_iam_policy" "firehose-audit" { - name = "audit_firehose_policy" + name = var.prefix == "" ? "audit_firehose_policy" : "${var.prefix}_audit_firehose_policy" policy = data.aws_iam_policy_document.audit_policy_doc.json } diff --git a/addons/logging-destination-firehose/variables.tf b/addons/logging-destination-firehose/variables.tf index e9187eb..7371142 100644 --- a/addons/logging-destination-firehose/variables.tf +++ b/addons/logging-destination-firehose/variables.tf @@ -1,3 +1,8 @@ +variable "prefix" { + type = string + default = "" +} + variable "osquery_results_s3_bucket" { type = object({ name = optional(string, "fleet-osquery-results-archive") diff --git a/addons/osquery-perf/.header.md b/addons/osquery-perf/.header.md index 3df823a..8812542 100644 --- a/addons/osquery-perf/.header.md +++ b/addons/osquery-perf/.header.md @@ -2,15 +2,19 @@ This addon adds osquery-perf hosts to the Fleet installation. These are generally used for loadtesting or other testing purposes. See https://github.com/fleetdm/fleet/tree/main/cmd/osquery-perf to learn more about osquery-perf itself. -This addon creates an AWS Secrets Manager secret that will be used to store the enroll secret that the osquery-perf hosts use to enroll into Fleet. +This addon: +1. Creates an AWS Secrets Manager secret that will be used to store the enroll secret that the osquery-perf hosts use to enroll into Fleet. AND +2. Optionally takes a string, `enroll_secret` (string), to create an AWS Secrets Manager secret version, in the AWS Secrets Manager Secret created by the addon. If not specified directly to the module, the secret will need to have its `SecretString` populated with the enroll secret manually once everything is setup in order for the osquery-perf hosts to connect. OR +3. Optionally takes a AWS Secrets Manager secret ARN, `enroll_secret_arn` (string), for an already existing Secrets Manager secret. -The addon additionally optionally takes an enroll secret to pass into its Secrets Manager secret. If not specified directly to the module, the secret will need to have its `SecretString` populated with the enroll secret manually once everything is setup in order for the osquery-perf hosts to connect. +If both an `enroll_secret` and an `enroll_secret_arn` are defined, the module will prioritize the `enroll_secret_arn`. +If neither an `enroll_secret` or an `enroll_secret_arn` are defined, the module will create a placeholder secret, you will need to add a `secret_version` manually and `terraform apply` one more time. Below is an example implementation of the module: ``` module "osquery_perf" { - source = "github.com/fleetdm/fleet-terraform//addons/osquery-perf?ref=tf-mod-addon-osquery-perf-v1.1.0" + source = "github.com/fleetdm/fleet-terraform//addons/osquery-perf?ref=tf-mod-addon-osquery-perf-v1.2.0" customer_prefix = "fleet" ecs_cluster = module.main.byo-vpc.byo-db.byo-ecs.service.cluster subnets = module.main.byo-vpc.byo-db.byo-ecs.service.network_configuration[0].subnets @@ -21,6 +25,10 @@ module "osquery_perf" { osquery_perf_image = local.osquery_perf_image extra_flags = ["--os_templates", "mac10.14.6,ubuntu_22.04,windows_11"] logging_options = module.main.byo-vpc.byo-db.byo-ecs.logging_config - enroll_secret = "mGNJvwKhs4PIa6ZNxMiXqqBfXKO67n2Y" + # Optional - One of enroll_secret or enroll_secret_arn can be used, but neither are required. + # If neither are passed in, you will need to populate the secret version manually, + # in the secret that is created by the addon. + # enroll_secret = "mGNJvwKhs4PIa6ZNxMiXqqBfXKO67n2Y" + # enroll_secret_arn = "arn:aws:secretsmanager:::secret:" } ``` diff --git a/addons/osquery-perf/README.md b/addons/osquery-perf/README.md index 7469017..f921ecc 100644 --- a/addons/osquery-perf/README.md +++ b/addons/osquery-perf/README.md @@ -2,15 +2,19 @@ This addon adds osquery-perf hosts to the Fleet installation. These are generally used for loadtesting or other testing purposes. See https://github.com/fleetdm/fleet/tree/main/cmd/osquery-perf to learn more about osquery-perf itself. -This addon creates an AWS Secrets Manager secret that will be used to store the enroll secret that the osquery-perf hosts use to enroll into Fleet. +This addon: +1. Creates an AWS Secrets Manager secret that will be used to store the enroll secret that the osquery-perf hosts use to enroll into Fleet. AND +2. Optionally takes a string, `enroll_secret` (string), to create an AWS Secrets Manager secret version, in the AWS Secrets Manager Secret created by the addon. If not specified directly to the module, the secret will need to have its `SecretString` populated with the enroll secret manually once everything is setup in order for the osquery-perf hosts to connect. OR +3. Optionally takes a AWS Secrets Manager secret ARN, `enroll_secret_arn` (string), for an already existing Secrets Manager secret. -The addon additionally optionally takes an enroll secret to pass into its Secrets Manager secret. If not specified directly to the module, the secret will need to have its `SecretString` populated with the enroll secret manually once everything is setup in order for the osquery-perf hosts to connect. +If both an `enroll_secret` and an `enroll_secret_arn` are defined, the module will prioritize the `enroll_secret_arn`. +If neither an `enroll_secret` or an `enroll_secret_arn` are defined, the module will create a placeholder secret, you will need to add a `secret_version` manually and `terraform apply` one more time. Below is an example implementation of the module: ``` module "osquery_perf" { - source = "github.com/fleetdm/fleet-terraform//addons/osquery-perf?ref=tf-mod-addon-osquery-perf-v1.1.0" + source = "github.com/fleetdm/fleet-terraform//addons/osquery-perf?ref=tf-mod-addon-osquery-perf-v1.2.0" customer_prefix = "fleet" ecs_cluster = module.main.byo-vpc.byo-db.byo-ecs.service.cluster subnets = module.main.byo-vpc.byo-db.byo-ecs.service.network_configuration[0].subnets @@ -21,7 +25,11 @@ module "osquery_perf" { osquery_perf_image = local.osquery_perf_image extra_flags = ["--os_templates", "mac10.14.6,ubuntu_22.04,windows_11"] logging_options = module.main.byo-vpc.byo-db.byo-ecs.logging_config - enroll_secret = "mGNJvwKhs4PIa6ZNxMiXqqBfXKO67n2Y" + # Optional - One of enroll_secret or enroll_secret_arn can be used, but neither are required. + # If neither are passed in, you will need to populate the secret version manually, + # in the secret that is created by the addon. + # enroll_secret = "mGNJvwKhs4PIa6ZNxMiXqqBfXKO67n2Y" + # enroll_secret_arn = "arn:aws:secretsmanager:::secret:" } ``` @@ -33,7 +41,7 @@ No requirements. | Name | Version | |------|---------| -| [aws](#provider\_aws) | 6.2.0 | +| [aws](#provider\_aws) | 6.12.0 | ## Modules @@ -59,7 +67,8 @@ No modules. | [ecs\_cluster](#input\_ecs\_cluster) | n/a | `string` | n/a | yes | | [ecs\_execution\_iam\_role\_arn](#input\_ecs\_execution\_iam\_role\_arn) | n/a | `string` | n/a | yes | | [ecs\_iam\_role\_arn](#input\_ecs\_iam\_role\_arn) | n/a | `string` | n/a | yes | -| [enroll\_secret](#input\_enroll\_secret) | n/a | `string` | `null` | no | +| [enroll\_secret](#input\_enroll\_secret) | Value of the enroll secret to be created, if enroll\_secret\_arn is not passed in | `string` | `null` | no | +| [enroll\_secret\_arn](#input\_enroll\_secret\_arn) | ARN of the AWS Secret Version containing the enroll secret | `string` | `null` | no | | [extra\_flags](#input\_extra\_flags) | n/a | `list(string)` | `[]` | no | | [loadtest\_containers](#input\_loadtest\_containers) | n/a | `number` | `1` | no | | [logging\_options](#input\_logging\_options) | n/a |
object({
awslogs-group = string
awslogs-region = string
awslogs-stream-prefix = string
})
| n/a | yes | @@ -70,4 +79,7 @@ No modules. ## Outputs -No outputs. +| Name | Description | +|------|-------------| +| [osquery\_perf\_enroll\_secret\_id](#output\_osquery\_perf\_enroll\_secret\_id) | n/a | +| [osquery\_perf\_enroll\_secret\_name](#output\_osquery\_perf\_enroll\_secret\_name) | n/a | diff --git a/addons/osquery-perf/main.tf b/addons/osquery-perf/main.tf index b2f47ec..8b6084a 100644 --- a/addons/osquery-perf/main.tf +++ b/addons/osquery-perf/main.tf @@ -1,26 +1,29 @@ resource "aws_kms_key" "enroll_secret" { + count = var.enroll_secret_arn == null ? 1 : 0 deletion_window_in_days = 10 enable_key_rotation = true } resource "aws_kms_alias" "enroll_secret" { + count = var.enroll_secret_arn == null ? 1 : 0 name_prefix = "alias/${var.customer_prefix}-enroll-secret-key" - target_key_id = aws_kms_key.enroll_secret.key_id + target_key_id = aws_kms_key.enroll_secret[0].key_id } resource "aws_secretsmanager_secret" "enroll_secret" { + count = var.enroll_secret_arn == null ? 1 : 0 name_prefix = "${var.customer_prefix}-enroll-secret" - kms_key_id = aws_kms_key.enroll_secret.arn + kms_key_id = aws_kms_key.enroll_secret[0].arn } resource "aws_secretsmanager_secret_version" "enroll_secret" { - count = var.enroll_secret == null ? 0 : 1 - secret_id = aws_secretsmanager_secret.enroll_secret.id + count = var.enroll_secret == null || var.enroll_secret_arn != null ? 0 : 1 # Passing in ARN takes priority + secret_id = aws_secretsmanager_secret.enroll_secret[0].id secret_string = var.enroll_secret } data "aws_secretsmanager_secret_version" "enroll_secret" { - secret_id = aws_secretsmanager_secret.enroll_secret.id + secret_id = var.enroll_secret_arn == null ? aws_secretsmanager_secret.enroll_secret[0].id : var.enroll_secret_arn } resource "aws_ecs_task_definition" "osquery_perf" { diff --git a/addons/osquery-perf/outputs.tf b/addons/osquery-perf/outputs.tf new file mode 100644 index 0000000..32c630f --- /dev/null +++ b/addons/osquery-perf/outputs.tf @@ -0,0 +1,7 @@ +output "osquery_perf_enroll_secret_name" { + value = var.enroll_secret_arn != null ? null : aws_secretsmanager_secret.enroll_secret[0].name +} + +output "osquery_perf_enroll_secret_id" { + value = var.enroll_secret_arn != null ? null : aws_secretsmanager_secret.enroll_secret[0].id +} \ No newline at end of file diff --git a/addons/osquery-perf/variables.tf b/addons/osquery-perf/variables.tf index a2fc5c3..dfd9bf1 100644 --- a/addons/osquery-perf/variables.tf +++ b/addons/osquery-perf/variables.tf @@ -53,6 +53,13 @@ variable "subnets" { } variable "enroll_secret" { - type = string - default = null + type = string + description = "Value of the enroll secret to be created, if enroll_secret_arn is not passed in" + default = null +} + +variable "enroll_secret_arn" { + type = string + description = "ARN of the AWS Secret Version containing the enroll secret" + default = null } diff --git a/byo-vpc/README.md b/byo-vpc/README.md index 35eb345..45c78d3 100644 --- a/byo-vpc/README.md +++ b/byo-vpc/README.md @@ -6,7 +6,7 @@ No requirements. | Name | Version | |------|---------| -| [aws](#provider\_aws) | 6.11.0 | +| [aws](#provider\_aws) | 6.12.0 | | [random](#provider\_random) | 3.7.2 | ## Modules @@ -31,7 +31,7 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [alb\_config](#input\_alb\_config) | n/a |
object({
name = optional(string, "fleet")
subnets = list(string)
security_groups = optional(list(string), [])
access_logs = optional(map(string), {})
certificate_arn = string
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
allowed_ipv6_cidrs = optional(list(string), ["::/0"])
egress_cidrs = optional(list(string), ["0.0.0.0/0"])
egress_ipv6_cidrs = optional(list(string), ["::/0"])
extra_target_groups = optional(any, [])
https_listener_rules = optional(any, [])
https_overrides = optional(any, {})
xff_header_processing_mode = optional(string, null)
tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06")
idle_timeout = optional(number, 905)
})
| n/a | yes | +| [alb\_config](#input\_alb\_config) | n/a |
object({
name = optional(string, "fleet")
subnets = list(string)
security_groups = optional(list(string), [])
access_logs = optional(map(string), {})
certificate_arn = string
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
allowed_ipv6_cidrs = optional(list(string), ["::/0"])
egress_cidrs = optional(list(string), ["0.0.0.0/0"])
egress_ipv6_cidrs = optional(list(string), ["::/0"])
extra_target_groups = optional(any, [])
https_listener_rules = optional(any, [])
https_overrides = optional(any, {})
xff_header_processing_mode = optional(string, null)
tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06")
idle_timeout = optional(number, 905)
internal = optional(bool, false)
enable_deletion_protection = optional(bool, true)
})
| n/a | yes | | [ecs\_cluster](#input\_ecs\_cluster) | The config for the terraform-aws-modules/ecs/aws module |
object({
autoscaling_capacity_providers = optional(any, {})
cluster_configuration = optional(any, {
execute_command_configuration = {
logging = "OVERRIDE"
log_configuration = {
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
}
}
})
cluster_name = optional(string, "fleet")
cluster_settings = optional(map(string), {
"name" : "containerInsights",
"value" : "enabled",
})
create = optional(bool, true)
default_capacity_provider_use_fargate = optional(bool, true)
fargate_capacity_providers = optional(any, {
FARGATE = {
default_capacity_provider_strategy = {
weight = 100
}
}
FARGATE_SPOT = {
default_capacity_provider_strategy = {
weight = 0
}
}
})
tags = optional(map(string))
})
|
{
"autoscaling_capacity_providers": {},
"cluster_configuration": {
"execute_command_configuration": {
"log_configuration": {
"cloud_watch_log_group_name": "/aws/ecs/aws-ec2"
},
"logging": "OVERRIDE"
}
},
"cluster_name": "fleet",
"cluster_settings": {
"name": "containerInsights",
"value": "enabled"
},
"create": true,
"default_capacity_provider_use_fargate": true,
"fargate_capacity_providers": {
"FARGATE": {
"default_capacity_provider_strategy": {
"weight": 100
}
},
"FARGATE_SPOT": {
"default_capacity_provider_strategy": {
"weight": 0
}
}
},
"tags": {}
}
| no | | [fleet\_config](#input\_fleet\_config) | The configuration object for Fleet itself. Fields that default to null will have their respective resources created if not specified. |
object({
task_mem = optional(number, null)
task_cpu = optional(number, null)
mem = optional(number, 4096)
cpu = optional(number, 512)
pid_mode = optional(string, null)
image = optional(string, "fleetdm/fleet:v4.72.1")
family = optional(string, "fleet")
sidecars = optional(list(any), [])
depends_on = optional(list(any), [])
mount_points = optional(list(any), [])
volumes = optional(list(any), [])
extra_environment_variables = optional(map(string), {})
extra_iam_policies = optional(list(string), [])
extra_execution_iam_policies = optional(list(string), [])
extra_secrets = optional(map(string), {})
security_group_name = optional(string, "fleet")
iam_role_arn = optional(string, null)
repository_credentials = optional(string, "")
private_key_secret_name = optional(string, "fleet-server-private-key")
service = optional(object({
name = optional(string, "fleet")
}), {
name = "fleet"
})
database = optional(object({
password_secret_arn = string
user = string
database = string
address = string
rr_address = optional(string, null)
}), {
password_secret_arn = null
user = null
database = null
address = null
rr_address = null
})
redis = optional(object({
address = string
use_tls = optional(bool, true)
}), {
address = null
use_tls = true
})
awslogs = optional(object({
name = optional(string, null)
region = optional(string, null)
create = optional(bool, true)
prefix = optional(string, "fleet")
retention = optional(number, 5)
}), {
name = null
region = null
prefix = "fleet"
retention = 5
})
loadbalancer = optional(object({
arn = string
}), {
arn = null
})
extra_load_balancers = optional(list(any), [])
networking = optional(object({
subnets = optional(list(string), null)
security_groups = optional(list(string), null)
ingress_sources = optional(object({
cidr_blocks = optional(list(string), [])
ipv6_cidr_blocks = optional(list(string), [])
security_groups = optional(list(string), [])
prefix_list_ids = optional(list(string), [])
}), {
cidr_blocks = []
ipv6_cidr_blocks = []
security_groups = []
prefix_list_ids = []
})
}), {
subnets = null
security_groups = null
ingress_sources = {
cidr_blocks = []
ipv6_cidr_blocks = []
security_groups = []
prefix_list_ids = []
}
})
autoscaling = optional(object({
max_capacity = optional(number, 5)
min_capacity = optional(number, 1)
memory_tracking_target_value = optional(number, 80)
cpu_tracking_target_value = optional(number, 80)
}), {
max_capacity = 5
min_capacity = 1
memory_tracking_target_value = 80
cpu_tracking_target_value = 80
})
iam = optional(object({
role = optional(object({
name = optional(string, "fleet-role")
policy_name = optional(string, "fleet-iam-policy")
}), {
name = "fleet-role"
policy_name = "fleet-iam-policy"
})
execution = optional(object({
name = optional(string, "fleet-execution-role")
policy_name = optional(string, "fleet-execution-role")
}), {
name = "fleet-execution-role"
policy_name = "fleet-iam-policy-execution"
})
}), {
name = "fleetdm-execution-role"
})
software_installers = optional(object({
create_bucket = optional(bool, true)
bucket_name = optional(string, null)
bucket_prefix = optional(string, "fleet-software-installers-")
s3_object_prefix = optional(string, "")
enable_bucket_versioning = optional(bool, false)
expire_noncurrent_versions = optional(bool, true)
noncurrent_version_expiration_days = optional(number, 30)
create_kms_key = optional(bool, false)
kms_alias = optional(string, "fleet-software-installers")
tags = optional(map(string), {})
}), {
create_bucket = true
bucket_name = null
bucket_prefix = "fleet-software-installers-"
s3_object_prefix = ""
enable_bucket_versioning = false
expire_noncurrent_versions = true
noncurrent_version_expiration_days = 30
create_kms_key = false
kms_alias = "fleet-software-installers"
tags = {}
})
})
|
{
"autoscaling": {
"cpu_tracking_target_value": 80,
"max_capacity": 5,
"memory_tracking_target_value": 80,
"min_capacity": 1
},
"awslogs": {
"create": true,
"name": null,
"prefix": "fleet",
"region": null,
"retention": 5
},
"cpu": 256,
"database": {
"address": null,
"database": null,
"password_secret_arn": null,
"rr_address": null,
"user": null
},
"depends_on": [],
"extra_environment_variables": {},
"extra_execution_iam_policies": [],
"extra_iam_policies": [],
"extra_load_balancers": [],
"extra_secrets": {},
"family": "fleet",
"iam": {
"execution": {
"name": "fleet-execution-role",
"policy_name": "fleet-iam-policy-execution"
},
"role": {
"name": "fleet-role",
"policy_name": "fleet-iam-policy"
}
},
"iam_role_arn": null,
"image": "fleetdm/fleet:v4.72.1",
"loadbalancer": {
"arn": null
},
"mem": 512,
"mount_points": [],
"networking": {
"ingress_sources": {
"cidr_blocks": [],
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"security_groups": []
},
"security_groups": null,
"subnets": null
},
"pid_mode": null,
"private_key_secret_name": "fleet-server-private-key",
"redis": {
"address": null,
"use_tls": true
},
"repository_credentials": "",
"security_group_name": "fleet",
"security_groups": null,
"service": {
"name": "fleet"
},
"sidecars": [],
"software_installers": {
"bucket_name": null,
"bucket_prefix": "fleet-software-installers-",
"create_bucket": true,
"s3_object_prefix": ""
},
"task_cpu": null,
"task_mem": null,
"volumes": []
}
| no | | [migration\_config](#input\_migration\_config) | The configuration object for Fleet's migration task. |
object({
mem = number
cpu = number
})
|
{
"cpu": 1024,
"mem": 2048
}
| no | diff --git a/byo-vpc/byo-db/README.md b/byo-vpc/byo-db/README.md index 7aaa22d..ea0783d 100644 --- a/byo-vpc/byo-db/README.md +++ b/byo-vpc/byo-db/README.md @@ -6,7 +6,7 @@ No requirements. | Name | Version | |------|---------| -| [aws](#provider\_aws) | 6.11.0 | +| [aws](#provider\_aws) | 6.12.0 | ## Modules @@ -26,7 +26,7 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [alb\_config](#input\_alb\_config) | n/a |
object({
name = optional(string, "fleet")
subnets = list(string)
security_groups = optional(list(string), [])
access_logs = optional(map(string), {})
certificate_arn = string
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
allowed_ipv6_cidrs = optional(list(string), ["::/0"])
egress_cidrs = optional(list(string), ["0.0.0.0/0"])
egress_ipv6_cidrs = optional(list(string), ["::/0"])
extra_target_groups = optional(any, [])
https_listener_rules = optional(any, [])
https_overrides = optional(any, {})
xff_header_processing_mode = optional(string, null)
tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06")
idle_timeout = optional(number, 905)
})
| n/a | yes | +| [alb\_config](#input\_alb\_config) | n/a |
object({
name = optional(string, "fleet")
subnets = list(string)
security_groups = optional(list(string), [])
access_logs = optional(map(string), {})
certificate_arn = string
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
allowed_ipv6_cidrs = optional(list(string), ["::/0"])
egress_cidrs = optional(list(string), ["0.0.0.0/0"])
egress_ipv6_cidrs = optional(list(string), ["::/0"])
extra_target_groups = optional(any, [])
https_listener_rules = optional(any, [])
https_overrides = optional(any, {})
xff_header_processing_mode = optional(string, null)
tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06")
idle_timeout = optional(number, 905)
internal = optional(bool, false)
enable_deletion_protection = optional(bool, true)
})
| n/a | yes | | [ecs\_cluster](#input\_ecs\_cluster) | The config for the terraform-aws-modules/ecs/aws module |
object({
autoscaling_capacity_providers = optional(any, {})
cluster_configuration = optional(any, {
execute_command_configuration = {
logging = "OVERRIDE"
log_configuration = {
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
}
}
})
cluster_name = optional(string, "fleet")
cluster_settings = optional(map(string), {
"name" : "containerInsights",
"value" : "enabled",
})
create = optional(bool, true)
default_capacity_provider_use_fargate = optional(bool, true)
fargate_capacity_providers = optional(any, {
FARGATE = {
default_capacity_provider_strategy = {
weight = 100
}
}
FARGATE_SPOT = {
default_capacity_provider_strategy = {
weight = 0
}
}
})
tags = optional(map(string))
})
|
{
"autoscaling_capacity_providers": {},
"cluster_configuration": {
"execute_command_configuration": {
"log_configuration": {
"cloud_watch_log_group_name": "/aws/ecs/aws-ec2"
},
"logging": "OVERRIDE"
}
},
"cluster_name": "fleet",
"cluster_settings": {
"name": "containerInsights",
"value": "enabled"
},
"create": true,
"default_capacity_provider_use_fargate": true,
"fargate_capacity_providers": {
"FARGATE": {
"default_capacity_provider_strategy": {
"weight": 100
}
},
"FARGATE_SPOT": {
"default_capacity_provider_strategy": {
"weight": 0
}
}
},
"tags": {}
}
| no | | [fleet\_config](#input\_fleet\_config) | The configuration object for Fleet itself. Fields that default to null will have their respective resources created if not specified. |
object({
task_mem = optional(number, null)
task_cpu = optional(number, null)
mem = optional(number, 4096)
cpu = optional(number, 512)
pid_mode = optional(string, null)
image = optional(string, "fleetdm/fleet:v4.72.1")
family = optional(string, "fleet")
sidecars = optional(list(any), [])
depends_on = optional(list(any), [])
mount_points = optional(list(any), [])
volumes = optional(list(any), [])
extra_environment_variables = optional(map(string), {})
extra_iam_policies = optional(list(string), [])
extra_execution_iam_policies = optional(list(string), [])
extra_secrets = optional(map(string), {})
security_group_name = optional(string, "fleet")
iam_role_arn = optional(string, null)
repository_credentials = optional(string, "")
private_key_secret_name = optional(string, "fleet-server-private-key")
service = optional(object({
name = optional(string, "fleet")
}), {
name = "fleet"
})
database = optional(object({
password_secret_arn = string
user = string
database = string
address = string
rr_address = optional(string, null)
}), {
password_secret_arn = null
user = null
database = null
address = null
rr_address = null
})
redis = optional(object({
address = string
use_tls = optional(bool, true)
}), {
address = null
use_tls = true
})
awslogs = optional(object({
name = optional(string, null)
region = optional(string, null)
create = optional(bool, true)
prefix = optional(string, "fleet")
retention = optional(number, 5)
}), {
name = null
region = null
prefix = "fleet"
retention = 5
})
loadbalancer = optional(object({
arn = string
}), {
arn = null
})
extra_load_balancers = optional(list(any), [])
networking = optional(object({
subnets = optional(list(string), null)
security_groups = optional(list(string), null)
ingress_sources = optional(object({
cidr_blocks = optional(list(string), [])
ipv6_cidr_blocks = optional(list(string), [])
security_groups = optional(list(string), [])
prefix_list_ids = optional(list(string), [])
}), {
cidr_blocks = []
ipv6_cidr_blocks = []
security_groups = []
prefix_list_ids = []
})
}), {
subnets = null
security_groups = null
ingress_sources = {
cidr_blocks = []
ipv6_cidr_blocks = []
security_groups = []
prefix_list_ids = []
}
})
autoscaling = optional(object({
max_capacity = optional(number, 5)
min_capacity = optional(number, 1)
memory_tracking_target_value = optional(number, 80)
cpu_tracking_target_value = optional(number, 80)
}), {
max_capacity = 5
min_capacity = 1
memory_tracking_target_value = 80
cpu_tracking_target_value = 80
})
iam = optional(object({
role = optional(object({
name = optional(string, "fleet-role")
policy_name = optional(string, "fleet-iam-policy")
}), {
name = "fleet-role"
policy_name = "fleet-iam-policy"
})
execution = optional(object({
name = optional(string, "fleet-execution-role")
policy_name = optional(string, "fleet-execution-role")
}), {
name = "fleet-execution-role"
policy_name = "fleet-iam-policy-execution"
})
}), {
name = "fleetdm-execution-role"
})
software_installers = optional(object({
create_bucket = optional(bool, true)
bucket_name = optional(string, null)
bucket_prefix = optional(string, "fleet-software-installers-")
s3_object_prefix = optional(string, "")
enable_bucket_versioning = optional(bool, false)
expire_noncurrent_versions = optional(bool, true)
noncurrent_version_expiration_days = optional(number, 30)
create_kms_key = optional(bool, false)
kms_alias = optional(string, "fleet-software-installers")
tags = optional(map(string), {})
}), {
create_bucket = true
bucket_name = null
bucket_prefix = "fleet-software-installers-"
s3_object_prefix = ""
enable_bucket_versioning = false
expire_noncurrent_versions = true
noncurrent_version_expiration_days = 30
create_kms_key = false
kms_alias = "fleet-software-installers"
tags = {}
})
})
|
{
"autoscaling": {
"cpu_tracking_target_value": 80,
"max_capacity": 5,
"memory_tracking_target_value": 80,
"min_capacity": 1
},
"awslogs": {
"create": true,
"name": null,
"prefix": "fleet",
"region": null,
"retention": 5
},
"cpu": 256,
"database": {
"address": null,
"database": null,
"password_secret_arn": null,
"rr_address": null,
"user": null
},
"depends_on": [],
"extra_environment_variables": {},
"extra_execution_iam_policies": [],
"extra_iam_policies": [],
"extra_load_balancers": [],
"extra_secrets": {},
"family": "fleet",
"iam": {
"execution": {
"name": "fleet-execution-role",
"policy_name": "fleet-iam-policy-execution"
},
"role": {
"name": "fleet-role",
"policy_name": "fleet-iam-policy"
}
},
"iam_role_arn": null,
"image": "fleetdm/fleet:v4.72.1",
"loadbalancer": {
"arn": null
},
"mem": 512,
"mount_points": [],
"networking": {
"ingress_sources": {
"cidr_blocks": [],
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"security_groups": []
},
"security_groups": null,
"subnets": null
},
"pid_mode": null,
"private_key_secret_name": "fleet-server-private-key",
"redis": {
"address": null,
"use_tls": true
},
"repository_credentials": "",
"security_group_name": "fleet",
"security_groups": null,
"service": {
"name": "fleet"
},
"sidecars": [],
"software_installers": {
"bucket_name": null,
"bucket_prefix": "fleet-software-installers-",
"create_bucket": true,
"s3_object_prefix": ""
},
"task_cpu": null,
"task_mem": null,
"volumes": []
}
| no | | [migration\_config](#input\_migration\_config) | The configuration object for Fleet's migration task. |
object({
mem = number
cpu = number
})
|
{
"cpu": 1024,
"mem": 2048
}
| no | diff --git a/byo-vpc/byo-db/byo-ecs/iam.tf b/byo-vpc/byo-db/byo-ecs/iam.tf index c0d0d46..f3f4bc3 100644 --- a/byo-vpc/byo-db/byo-ecs/iam.tf +++ b/byo-vpc/byo-db/byo-ecs/iam.tf @@ -119,14 +119,14 @@ resource "aws_iam_role_policy_attachment" "main" { } resource "aws_iam_role_policy_attachment" "extras" { - for_each = toset(var.fleet_config.extra_iam_policies) - policy_arn = each.value + count = length(var.fleet_config.extra_iam_policies) + policy_arn = var.fleet_config.extra_iam_policies[count.index] role = aws_iam_role.main[0].name } resource "aws_iam_role_policy_attachment" "execution_extras" { - for_each = toset(var.fleet_config.extra_execution_iam_policies) - policy_arn = each.value + count = length(var.fleet_config.extra_execution_iam_policies) + policy_arn = var.fleet_config.extra_execution_iam_policies[count.index] role = aws_iam_role.execution.name } diff --git a/byo-vpc/byo-db/main.tf b/byo-vpc/byo-db/main.tf index c861774..c593cbc 100644 --- a/byo-vpc/byo-db/main.tf +++ b/byo-vpc/byo-db/main.tf @@ -73,6 +73,8 @@ module "alb" { security_groups = concat(var.alb_config.security_groups, [aws_security_group.alb.id]) access_logs = var.alb_config.access_logs idle_timeout = var.alb_config.idle_timeout + internal = var.alb_config.internal + enable_deletion_protection = var.alb_config.enable_deletion_protection target_groups = local.target_groups diff --git a/byo-vpc/byo-db/variables.tf b/byo-vpc/byo-db/variables.tf index 7249406..406df10 100644 --- a/byo-vpc/byo-db/variables.tf +++ b/byo-vpc/byo-db/variables.tf @@ -324,5 +324,7 @@ variable "alb_config" { xff_header_processing_mode = optional(string, null) tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06") idle_timeout = optional(number, 905) + internal = optional(bool, false) + enable_deletion_protection = optional(bool, true) }) } diff --git a/byo-vpc/variables.tf b/byo-vpc/variables.tf index f43497c..6426ae3 100644 --- a/byo-vpc/variables.tf +++ b/byo-vpc/variables.tf @@ -429,5 +429,7 @@ variable "alb_config" { xff_header_processing_mode = optional(string, null) tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06") idle_timeout = optional(number, 905) + internal = optional(bool, false) + enable_deletion_protection = optional(bool, true) }) } diff --git a/example/.header.md b/example/.header.md index ecd313e..cc78259 100644 --- a/example/.header.md +++ b/example/.header.md @@ -4,35 +4,12 @@ This code provides some example usage of the Fleet Terraform module, including h - domain name - route53 zone name (may match the domain name) - license key (if premium) - - uncommenting the mdm module if mdm is desired - any extra settings to be passed to Fleet via ENV var. -Due to Terraform issues, this code requires 3 applies "from scratch": -1. `terraform apply -target module.fleet.module.vpc` -2. `terraform apply -target module.osquery-carve -target module.firehose-logging` -3. If using a new route53 zone: - - `terraform apply -target aws_route53_zone.main` - - From the output, obtain the NS records created for the zone and add them to the parent DNS zone -4. If enabling mdm: `terraform apply -target module.mdm`. It will need to be uncommented as well as the KMS section below it. -5. `terraform apply -target module.fleet` -6. `terraform apply` -7. If enabling mdm do the following: - - Record the KMS key from step 5 output. - - Create the Windows MDM cert via the document at https://fleetdm.com/guides/windows-mdm-setup#step-1-generate-your-certificate-and-key, but name them as scep.key and scep.crt to follow a legacy convention of the mdm module. - - Place the certificates in the `resources` folder with the following names based upon their function: -``` -scep.crt -scep.key -``` - - Using the `encrypt.sh` script, KMS encrypt all of these secrets as follows: -``` -cd resources -for i in *; do ../scripts/encrypt.sh $i $i.encrypted; done -for i in *.encrypted; do rm ${i/.encrypted/}; done -``` -This will encrypt all of the mdm secrets and add the .encrypted extension to them. It will also remove the non-encrypted version of the secrets so that they are encrypted at rest even locally. +To deploy: - - Uncomment all of the resources and data sources in `mdm-secrets.tf`. - - Re-run `terraform apply` to populate the Secrets Manager secrets. - - Uncomment the sections in the `fleet_config` portion of `main.tf` for mdm and run a final `terraform apply`. Services will restart with mdm enabled. +1. `terraform apply` +If using a new route53 zone: + +- From the output, obtain the NS records created for the zone and add them to the parent DNS zone \ No newline at end of file diff --git a/example/README.md b/example/README.md index b88cf5a..92a392e 100644 --- a/example/README.md +++ b/example/README.md @@ -4,64 +4,49 @@ This code provides some example usage of the Fleet Terraform module, including h - domain name - route53 zone name (may match the domain name) - license key (if premium) - - uncommenting the mdm module if mdm is desired - any extra settings to be passed to Fleet via ENV var. -Due to Terraform issues, this code requires 3 applies "from scratch": -1. `terraform apply -target module.fleet.module.vpc` -2. `terraform apply -target module.osquery-carve -target module.firehose-logging` -3. If using a new route53 zone: - - `terraform apply -target aws_route53_zone.main` - - From the output, obtain the NS records created for the zone and add them to the parent DNS zone -4. If enabling mdm: `terraform apply -target module.mdm`. It will need to be uncommented as well as the KMS section below it. -5. `terraform apply -target module.fleet` -6. `terraform apply` -7. If enabling mdm do the following: - - Record the KMS key from step 5 output. - - Create the Windows MDM cert via the document at https://fleetdm.com/guides/windows-mdm-setup#step-1-generate-your-certificate-and-key, but name them as scep.key and scep.crt to follow a legacy convention of the mdm module. - - Place the certificates in the `resources` folder with the following names based upon their function: -``` -scep.crt -scep.key -``` - - Using the `encrypt.sh` script, KMS encrypt all of these secrets as follows: -``` -cd resources -for i in *; do ../scripts/encrypt.sh $i $i.encrypted; done -for i in *.encrypted; do rm ${i/.encrypted/}; done -``` -This will encrypt all of the mdm secrets and add the .encrypted extension to them. It will also remove the non-encrypted version of the secrets so that they are encrypted at rest even locally. +To deploy: - - Uncomment all of the resources and data sources in `mdm-secrets.tf`. - - Re-run `terraform apply` to populate the Secrets Manager secrets. - - Uncomment the sections in the `fleet_config` portion of `main.tf` for mdm and run a final `terraform apply`. Services will restart with mdm enabled. +1. `terraform apply` + +If using a new route53 zone: + +- From the output, obtain the NS records created for the zone and add them to the parent DNS zone ## Requirements | Name | Version | |------|---------| -| [aws](#requirement\_aws) | 5.36.0 | +| [aws](#requirement\_aws) | 6.11.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | 5.36.0 | +| [aws](#provider\_aws) | 6.11.0 | +| [random](#provider\_random) | 3.7.2 | +| [tls](#provider\_tls) | n/a | ## Modules | Name | Source | Version | |------|--------|---------| | [acm](#module\_acm) | terraform-aws-modules/acm/aws | 4.3.1 | -| [fleet](#module\_fleet) | github.com/fleetdm/fleet-terraform?depth=1&ref=tf-mod-root-v1.14.0 | n/a | -| [migrations](#module\_migrations) | github.com/fleetdm/fleet-terraform/addons/migrations?depth=1&ref=tf-mod-addon-migrations-v2.0.1 | n/a | +| [fleet](#module\_fleet) | github.com/fleetdm/fleet-terraform?depth=1&ref=tf-mod-root-v1.18.1 | n/a | +| [mdm](#module\_mdm) | github.com/fleetdm/fleet-terraform/addons/mdm?depth=1&ref=tf-mod-addon-mdm-v2.0.0 | n/a | +| [migrations](#module\_migrations) | github.com/fleetdm/fleet-terraform/addons/migrations?depth=1&ref=tf-mod-addon-migrations-v2.1.0 | n/a | ## Resources | Name | Type | |------|------| -| [aws_route53_record.main](https://registry.terraform.io/providers/hashicorp/aws/5.36.0/docs/resources/route53_record) | resource | -| [aws_route53_zone.main](https://registry.terraform.io/providers/hashicorp/aws/5.36.0/docs/resources/route53_zone) | resource | +| [aws_route53_record.main](https://registry.terraform.io/providers/hashicorp/aws/6.11.0/docs/resources/route53_record) | resource | +| [aws_route53_zone.main](https://registry.terraform.io/providers/hashicorp/aws/6.11.0/docs/resources/route53_zone) | resource | +| [aws_secretsmanager_secret_version.scep](https://registry.terraform.io/providers/hashicorp/aws/6.11.0/docs/resources/secretsmanager_secret_version) | resource | +| [random_password.challenge](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource | +| [tls_private_key.scep_key](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource | +| [tls_self_signed_cert.scep_cert](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/self_signed_cert) | resource | ## Inputs diff --git a/example/main.tf b/example/main.tf index 5317899..84e4c0a 100644 --- a/example/main.tf +++ b/example/main.tf @@ -73,7 +73,7 @@ locals { } module "fleet" { - source = "github.com/fleetdm/fleet-terraform?depth=1&ref=tf-mod-root-v1.18.0" + source = "github.com/fleetdm/fleet-terraform?depth=1&ref=tf-mod-root-v1.18.1" certificate_arn = module.acm.acm_certificate_arn vpc = { @@ -99,14 +99,17 @@ module "fleet" { cpu = 512 extra_environment_variables = merge( local.fleet_environment_variables, - # uncomment if using a3 carves + # uncomment if using s3 carves # module.osquery-carve.fleet_extra_environment_variables # uncomment if using firehose # module.firehose-logging.fleet_extra_environment_variables ) - # Uncomment if enabling mdm module below. - # extra_secrets = module.mdm.extra_secrets - # extra_execution_iam_policies = module.mdm.extra_execution_iam_policies + extra_secrets = concat( + module.mdm.extra_secrets, + ) + extra_execution_iam_policies = concat( + module.mdm.extra_execution_iam_policies, + ) # extra_iam_policies = concat( # uncomment if using a3 carves # module.osquery-carve.fleet_extra_iam_policies, @@ -142,6 +145,10 @@ module "fleet" { # Script execution can run for up to 300s plus overhead. # Ensure the load balancer does not 5XX before we have results. idle_timeout = 905 + # Optionally deploy load balancer as an internal load balancer + # internal = true + # optionally set deletion protection on (true) or off (false) + # enable_deletion_protection = true # Optionally Remove X-Forwarded-For header # xff_header_processing_mode = "remove" # See https://github.com/terraform-aws-modules/terraform-aws-alb/blob/v9.17.0/examples/complete-alb/main.tf#L383-L393. @@ -223,7 +230,6 @@ module "fleet" { # ] # }] # }], local.https_listener_rules) - } } @@ -242,6 +248,10 @@ module "migrations" { ecs_service = module.fleet.byo-vpc.byo-db.byo-ecs.service.name desired_count = module.fleet.byo-vpc.byo-db.byo-ecs.appautoscaling_target.min_capacity min_capacity = module.fleet.byo-vpc.byo-db.byo-ecs.appautoscaling_target.min_capacity + + depends_on = [ + module.fleet, + ] } # Enable if using s3 for carves @@ -254,7 +264,7 @@ module "migrations" { # Uncomment if using firehose logging destination # module "firehose-logging" { -# source = "github.com/fleetdm/fleet-terraform/addons/logging-destination-firehose?depth=1&ref=tf-mod-addon-logging-destination-firehose-v1.2.1" +# source = "github.com/fleetdm/fleet-terraform/addons/logging-destination-firehose?depth=1&ref=tf-mod-addon-logging-destination-firehose-v1.2.4" # osquery_results_s3_bucket = { # name = local.osquery_results_bucket_name # } @@ -263,13 +273,6 @@ module "migrations" { # } # } -## MDM - -# MDM Secrets must be populated with JSON data including the payload from the certs, keys, challenge, etc. -# These can be populated via terraform with a secret-version, or manually after terraform is applied. -# Note: Services will not start if the mdm module is enabled and the secrets are applied but not populated. - - ## MDM Secret payload # See https://github.com/fleetdm/fleet-terraform/blob/tf-mod-addon-mdm-v2.0.0/addons/mdm/README.md#abm @@ -277,34 +280,14 @@ module "migrations" { # the Windows MDM secrets still use this as the all Mac MDM is managed via the Fleet UI and is therefore # disabled in the module. - -# module "mdm" { -# source = "github.com/fleetdm/fleet-terraform/addons/mdm?depth=1&ref=tf-mod-addon-mdm-v2.0.0" -# apn_secret_name = null -# scep_secret_name = "fleet-scep" -# # Set abm_secret_name = null if customer is not using dep -# abm_secret_name = null -# enable_apple_mdm = false -# enable_windows_mdm = true -# } - -# If you want to supply the MDM secrets via terraform, I recommend that you do not store the secrets in the clear -# on the device that applies the terraform. For the example here, terraform will create a KMS key, which will then -# be used to encrypt the secrets. The included mdm-secrets.tf file will then use the KMS key to dercrypt the secrets -# on the filesystem to generate the - -# resource "aws_kms_key" "fleet_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.fleet_data_key.id -# } -# -# output "kms_key_id" { -# value = aws_kms_key.fleet_data_key.id -# } +module "mdm" { + source = "github.com/fleetdm/fleet-terraform/addons/mdm?depth=1&ref=tf-mod-addon-mdm-v2.0.0" + apn_secret_name = null + scep_secret_name = "fleet-scep" + abm_secret_name = null + enable_apple_mdm = false + enable_windows_mdm = true +} module "acm" { source = "terraform-aws-modules/acm/aws" diff --git a/example/mdm-secrets.tf b/example/mdm-secrets.tf index 2e76511..6c53813 100644 --- a/example/mdm-secrets.tf +++ b/example/mdm-secrets.tf @@ -1,62 +1,40 @@ -# Note: Everything is commented out here as mdm is not enabled by default. -# Uncomment to use. - -# This section expects all kms-encrypted secrets to live in the resources/ -# subdirectory. The list of expected filenames is as follows: - -locals { - mdm_resource_path = "${path.module}/resources" - scep_cert = "${local.mdm_resource_path}/scep.crt.encrypted" - scep_key = "${local.mdm_resource_path}/scep.key.encrypted" +resource "tls_private_key" "scep_key" { + algorithm = "RSA" + rsa_bits = 4096 } -# To ease the process of encrypting and decrypting secrets, see -# scripts/encrypt.sh and scripts/decrypt.sh +resource "tls_self_signed_cert" "scep_cert" { + private_key_pem = tls_private_key.scep_key.private_key_pem -# Place your non-encrypted files in the resources folder and -# run the following: -# -# cd resources -# for i in *; do ../scripts/encrypt.sh $i $i.encrypted; done -# for i in *.encrypted; do rm ${i/.encrypted/}; done + subject { + common_name = "Fleet Root CA" + organization = "Fleet." + country = "US" + } -# The SCEP challenge will be randomly generated by terraform. We do not -# need to know what it is. For troubleshooting, it can always be found -# in the SCEP secret in AWS. The SCEP cert is primarily used as the -# Windows WSTEP cert at this point as the MAC scep is generated -# automatically in the applicaton. The other MAC MDM secrets can now be -# manged via the Fleet UI + is_ca_certificate = true + validity_period_hours = 87648 -# resource "random_password" "challenge" { -# length = 12 -# special = false -# } -# -# resource "aws_secretsmanager_secret_version" "scep" { -# secret_id = module.mdm.scep.id -# secret_string = jsonencode( -# { -# FLEET_MDM_APPLE_SCEP_CERT_BYTES = data.aws_kms_secrets.scep_cert.plaintext["FLEET_MDM_APPLE_SCEP_CERT_BYTES"] -# FLEET_MDM_APPLE_SCEP_KEY_BYTES = data.aws_kms_secrets.scep_key.plaintext["FLEET_MDM_APPLE_SCEP_KEY_BYTES"] -# FLEET_MDM_APPLE_SCEP_CHALLENGE = random_password.challenge.result -# } -# ) -# } -# -# -# data "aws_kms_secrets" "scep_cert" { -# secret { -# name = "FLEET_MDM_APPLE_SCEP_CERT_BYTES" -# key_id = aws_kms_key.fleet_data_key.id -# payload = file(local.scep_cert) -# } -# } -# -# data "aws_kms_secrets" "scep_key" { -# secret { -# name = "FLEET_MDM_APPLE_SCEP_KEY_BYTES" -# key_id = aws_kms_key.fleet_data_key.id -# payload = file(local.scep_key) -# } -# } + allowed_uses = [ + "cert_signing", + "crl_signing", + "key_encipherment", + "digital_signature", + ] +} +resource "random_password" "challenge" { + length = 12 + special = false +} + +resource "aws_secretsmanager_secret_version" "scep" { + secret_id = module.mdm.scep.id + secret_string = jsonencode( + { + FLEET_MDM_APPLE_SCEP_CERT_BYTES = tls_self_signed_cert.scep_cert.cert_pem + FLEET_MDM_APPLE_SCEP_KEY_BYTES = tls_private_key.scep_key.private_key_pem + FLEET_MDM_APPLE_SCEP_CHALLENGE = random_password.challenge.result + } + ) +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index 58bd46f..f14ab34 100644 --- a/variables.tf +++ b/variables.tf @@ -475,6 +475,8 @@ variable "alb_config" { xff_header_processing_mode = optional(string, null) tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06") idle_timeout = optional(number, 905) + internal = optional(bool, false) + enable_deletion_protection = optional(bool, true) }) default = {} }