From b6b499063a354fc6d072d78faf460462b1b2772a Mon Sep 17 00:00:00 2001 From: Robert Fairburn <8029478+rfairburn@users.noreply.github.com> Date: Thu, 10 Jul 2025 11:16:43 -0500 Subject: [PATCH] osquery-perf module to accept an enroll secret (#69) --- addons/osquery-perf/.header.md | 7 +++++-- addons/osquery-perf/README.md | 13 +++++++++---- addons/osquery-perf/main.tf | 8 +++++++- addons/osquery-perf/variables.tf | 23 ++++++++++++++--------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/addons/osquery-perf/.header.md b/addons/osquery-perf/.header.md index fe6fb1b..3df823a 100644 --- a/addons/osquery-perf/.header.md +++ b/addons/osquery-perf/.header.md @@ -2,13 +2,15 @@ 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 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. +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. + +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. Below is an example implementation of the module: ``` module "osquery_perf" { - source = "github.com/fleetdm/fleet-terraform//addons/osquery-perf?ref=main" + source = "github.com/fleetdm/fleet-terraform//addons/osquery-perf?ref=tf-mod-addon-osquery-perf-v1.1.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 @@ -19,5 +21,6 @@ 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" } ``` diff --git a/addons/osquery-perf/README.md b/addons/osquery-perf/README.md index 74b997c..7469017 100644 --- a/addons/osquery-perf/README.md +++ b/addons/osquery-perf/README.md @@ -2,13 +2,15 @@ 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 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. +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. + +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. Below is an example implementation of the module: ``` module "osquery_perf" { - source = "github.com/fleetdm/fleet-terraform//addons/osquery-perf?ref=main" + source = "github.com/fleetdm/fleet-terraform//addons/osquery-perf?ref=tf-mod-addon-osquery-perf-v1.1.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 @@ -19,6 +21,7 @@ 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" } ``` @@ -30,7 +33,7 @@ No requirements. | Name | Version | |------|---------| -| [aws](#provider\_aws) | n/a | +| [aws](#provider\_aws) | 6.2.0 | ## Modules @@ -45,6 +48,7 @@ No modules. | [aws_kms_alias.enroll_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_alias) | resource | | [aws_kms_key.enroll_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource | | [aws_secretsmanager_secret.enroll_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource | +| [aws_secretsmanager_secret_version.enroll_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource | | [aws_secretsmanager_secret_version.enroll_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/secretsmanager_secret_version) | data source | ## Inputs @@ -55,9 +59,10 @@ 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 | | [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 |
+| [logging\_options](#input\_logging\_options) | n/a | object({
awslogs-group = string
awslogs-region = string
awslogs-stream-prefix = string
}) | n/a | yes |
| [osquery\_perf\_image](#input\_osquery\_perf\_image) | n/a | `string` | n/a | yes |
| [security\_groups](#input\_security\_groups) | n/a | `list(string)` | n/a | yes |
| [server\_url](#input\_server\_url) | n/a | `string` | n/a | yes |
diff --git a/addons/osquery-perf/main.tf b/addons/osquery-perf/main.tf
index 2c2c010..b2f47ec 100644
--- a/addons/osquery-perf/main.tf
+++ b/addons/osquery-perf/main.tf
@@ -13,6 +13,12 @@ resource "aws_secretsmanager_secret" "enroll_secret" {
kms_key_id = aws_kms_key.enroll_secret.arn
}
+resource "aws_secretsmanager_secret_version" "enroll_secret" {
+ count = var.enroll_secret == null ? 0 : 1
+ secret_id = aws_secretsmanager_secret.enroll_secret.id
+ secret_string = var.enroll_secret
+}
+
data "aws_secretsmanager_secret_version" "enroll_secret" {
secret_id = aws_secretsmanager_secret.enroll_secret.id
}
@@ -45,7 +51,7 @@ resource "aws_ecs_task_definition" "osquery_perf" {
networkMode = "awsvpc"
logConfiguration = {
logDriver = "awslogs"
- options = var.logging_options
+ options = var.logging_options
}
workingDirectory = "/go",
command = concat([
diff --git a/addons/osquery-perf/variables.tf b/addons/osquery-perf/variables.tf
index 6348a33..a2fc5c3 100644
--- a/addons/osquery-perf/variables.tf
+++ b/addons/osquery-perf/variables.tf
@@ -5,25 +5,25 @@ variable "customer_prefix" {
}
variable "ecs_cluster" {
- type = string
+ type = string
}
variable "ecs_execution_iam_role_arn" {
- type = string
+ type = string
}
variable "ecs_iam_role_arn" {
- type = string
+ type = string
}
variable "extra_flags" {
- type = list(string)
- default = []
+ type = list(string)
+ default = []
}
variable "loadtest_containers" {
- type = number
- default = 1
+ type = number
+ default = 1
}
variable "logging_options" {
@@ -35,7 +35,7 @@ variable "logging_options" {
}
variable "osquery_perf_image" {
- type = string
+ type = string
}
variable "security_groups" {
@@ -44,10 +44,15 @@ variable "security_groups" {
}
variable "server_url" {
- type = string
+ type = string
}
variable "subnets" {
type = list(string)
nullable = false
}
+
+variable "enroll_secret" {
+ type = string
+ default = null
+}