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.
This commit is contained in:
1 parent
1d8bd3007d
commit
ae8863ce64
22 files changed
+167
-191
No files matched your search
+5
-28
@@ -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 <kms-key-id-from-terraform-output> $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
|
||||
+19
-34
@@ -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 <kms-key-id-from-terraform-output> $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 |
|
||||
|------|---------|
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | 5.36.0 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | 6.11.0 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.36.0 |
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.11.0 |
|
||||
| <a name="provider_random"></a> [random](#provider\_random) | 3.7.2 |
|
||||
| <a name="provider_tls"></a> [tls](#provider\_tls) | n/a |
|
||||
|
||||
## Modules
|
||||
|
||||
| Name | Source | Version |
|
||||
|------|--------|---------|
|
||||
| <a name="module_acm"></a> [acm](#module\_acm) | terraform-aws-modules/acm/aws | 4.3.1 |
|
||||
| <a name="module_fleet"></a> [fleet](#module\_fleet) | github.com/fleetdm/fleet-terraform?depth=1&ref=tf-mod-root-v1.14.0 | n/a |
|
||||
| <a name="module_migrations"></a> [migrations](#module\_migrations) | github.com/fleetdm/fleet-terraform/addons/migrations?depth=1&ref=tf-mod-addon-migrations-v2.0.1 | n/a |
|
||||
| <a name="module_fleet"></a> [fleet](#module\_fleet) | github.com/fleetdm/fleet-terraform?depth=1&ref=tf-mod-root-v1.18.1 | n/a |
|
||||
| <a name="module_mdm"></a> [mdm](#module\_mdm) | github.com/fleetdm/fleet-terraform/addons/mdm?depth=1&ref=tf-mod-addon-mdm-v2.0.0 | n/a |
|
||||
| <a name="module_migrations"></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
|
||||
|
||||
|
||||
+25
-42
@@ -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"
|
||||
|
||||
+34
-56
@@ -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 <kms-key-id-from-terraform-output> $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
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user