From 81bb303312e7a6c3847511181c023585209b0d02 Mon Sep 17 00:00:00 2001 From: Robert Fairburn <8029478+rfairburn@users.noreply.github.com> Date: Mon, 28 Jul 2025 11:39:13 -0500 Subject: [PATCH] Firehose audit (#71) --- addons/logging-destination-firehose/README.md | 16 +++- addons/logging-destination-firehose/main.tf | 87 ++++++++++++++++++- .../logging-destination-firehose/outputs.tf | 5 +- .../logging-destination-firehose/variables.tf | 11 +++ 4 files changed, 114 insertions(+), 5 deletions(-) diff --git a/addons/logging-destination-firehose/README.md b/addons/logging-destination-firehose/README.md index 054cc69..7e02991 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) | 5.44.0 | +| [aws](#provider\_aws) | 6.3.0 | ## Modules @@ -19,23 +19,32 @@ No modules. | Name | Type | |------|------| +| [aws_iam_policy.firehose-audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | | [aws_iam_policy.firehose-logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | | [aws_iam_policy.firehose-results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | | [aws_iam_policy.firehose-status](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | +| [aws_iam_role.firehose-audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | | [aws_iam_role.firehose-results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | | [aws_iam_role.firehose-status](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | +| [aws_iam_role_policy_attachment.firehose-audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | | [aws_iam_role_policy_attachment.firehose-results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | | [aws_iam_role_policy_attachment.firehose-status](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | +| [aws_kinesis_firehose_delivery_stream.audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_firehose_delivery_stream) | resource | | [aws_kinesis_firehose_delivery_stream.osquery_results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_firehose_delivery_stream) | resource | | [aws_kinesis_firehose_delivery_stream.osquery_status](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_firehose_delivery_stream) | resource | +| [aws_s3_bucket.audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | | [aws_s3_bucket.osquery-results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | | [aws_s3_bucket.osquery-status](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | +| [aws_s3_bucket_lifecycle_configuration.audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource | | [aws_s3_bucket_lifecycle_configuration.osquery-results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource | | [aws_s3_bucket_lifecycle_configuration.osquery-status](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource | +| [aws_s3_bucket_public_access_block.audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource | | [aws_s3_bucket_public_access_block.osquery-results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource | | [aws_s3_bucket_public_access_block.osquery-status](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource | +| [aws_s3_bucket_server_side_encryption_configuration.audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource | | [aws_s3_bucket_server_side_encryption_configuration.osquery-results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource | | [aws_s3_bucket_server_side_encryption_configuration.osquery-status](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource | +| [aws_iam_policy_document.audit_policy_doc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | [aws_iam_policy_document.firehose-logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | [aws_iam_policy_document.osquery_firehose_assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | [aws_iam_policy_document.osquery_results_policy_doc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | @@ -46,9 +55,10 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [audit\_s3\_bucket](#input\_audit\_s3\_bucket) | n/a |
object({
name = optional(string, "fleet-audit-archive")
expires_days = optional(number, 1)
}) | {
"expires_days": 1,
"name": "fleet-audit-archive"
} | no |
| [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 |
+| [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 |
## Outputs
diff --git a/addons/logging-destination-firehose/main.tf b/addons/logging-destination-firehose/main.tf
index fcefd18..17a9ac4 100644
--- a/addons/logging-destination-firehose/main.tf
+++ b/addons/logging-destination-firehose/main.tf
@@ -14,6 +14,7 @@ resource "aws_s3_bucket" "osquery-results" { #tfsec:ignore:aws-s3-encryption-cus
resource "aws_s3_bucket_lifecycle_configuration" "osquery-results" {
bucket = aws_s3_bucket.osquery-results.bucket
rule {
+ filter {}
status = "Enabled"
id = "expire"
expiration {
@@ -52,6 +53,7 @@ resource "aws_s3_bucket" "osquery-status" { #tfsec:ignore:aws-s3-encryption-cust
resource "aws_s3_bucket_lifecycle_configuration" "osquery-status" {
bucket = aws_s3_bucket.osquery-status.bucket
rule {
+ filter {}
status = "Enabled"
id = "expire"
expiration {
@@ -77,6 +79,45 @@ resource "aws_s3_bucket_public_access_block" "osquery-status" {
restrict_public_buckets = true
}
+// Customer keys are not supported in our Fleet Terraforms at the moment. We will evaluate the
+// possibility of providing this capability in the future.
+// No versioning on this bucket is by design.
+// Bucket logging is not supported in our Fleet Terraforms at the moment. It can be enabled by the
+// organizations deploying Fleet, and we will evaluate the possibility of providing this capability
+// in the future.
+resource "aws_s3_bucket" "audit" { #tfsec:ignore:aws-s3-encryption-customer-key:exp:2022-07-01 #tfsec:ignore:aws-s3-enable-versioning #tfsec:ignore:aws-s3-enable-bucket-logging:exp:2022-06-15
+ bucket = var.audit_s3_bucket.name
+}
+
+resource "aws_s3_bucket_lifecycle_configuration" "audit" {
+ bucket = aws_s3_bucket.audit.bucket
+ rule {
+ filter {}
+ status = "Enabled"
+ id = "expire"
+ expiration {
+ days = var.audit_s3_bucket.expires_days
+ }
+ }
+}
+
+resource "aws_s3_bucket_server_side_encryption_configuration" "audit" {
+ bucket = aws_s3_bucket.audit.bucket
+ rule {
+ apply_server_side_encryption_by_default {
+ sse_algorithm = "aws:kms"
+ }
+ }
+}
+
+resource "aws_s3_bucket_public_access_block" "audit" {
+ bucket = aws_s3_bucket.audit.id
+ block_public_acls = true
+ block_public_policy = true
+ ignore_public_acls = true
+ restrict_public_buckets = true
+}
+
data "aws_iam_policy_document" "osquery_results_policy_doc" {
statement {
effect = "Allow"
@@ -107,6 +148,21 @@ data "aws_iam_policy_document" "osquery_status_policy_doc" {
}
}
+data "aws_iam_policy_document" "audit_policy_doc" {
+ statement {
+ effect = "Allow"
+ actions = [
+ "s3:AbortMultipartUpload",
+ "s3:GetBucketLocation",
+ "s3:ListBucket",
+ "s3:ListBucketMultipartUploads",
+ "s3:PutObject"
+ ]
+ // This bucket is single-purpose and using a wildcard is not problematic
+ resources = [aws_s3_bucket.audit.arn, "${aws_s3_bucket.audit.arn}/*"] #tfsec:ignore:aws-iam-no-policy-wildcards
+ }
+}
+
resource "aws_iam_policy" "firehose-results" {
name = "osquery_results_firehose_policy"
policy = data.aws_iam_policy_document.osquery_results_policy_doc.json
@@ -117,6 +173,11 @@ resource "aws_iam_policy" "firehose-status" {
policy = data.aws_iam_policy_document.osquery_status_policy_doc.json
}
+resource "aws_iam_policy" "firehose-audit" {
+ name = "audit_firehose_policy"
+ policy = data.aws_iam_policy_document.audit_policy_doc.json
+}
+
resource "aws_iam_role" "firehose-results" {
assume_role_policy = data.aws_iam_policy_document.osquery_firehose_assume_role.json
}
@@ -125,6 +186,10 @@ resource "aws_iam_role" "firehose-status" {
assume_role_policy = data.aws_iam_policy_document.osquery_firehose_assume_role.json
}
+resource "aws_iam_role" "firehose-audit" {
+ assume_role_policy = data.aws_iam_policy_document.osquery_firehose_assume_role.json
+}
+
resource "aws_iam_role_policy_attachment" "firehose-results" {
policy_arn = aws_iam_policy.firehose-results.arn
role = aws_iam_role.firehose-results.name
@@ -135,6 +200,11 @@ resource "aws_iam_role_policy_attachment" "firehose-status" {
role = aws_iam_role.firehose-status.name
}
+resource "aws_iam_role_policy_attachment" "firehose-audit" {
+ policy_arn = aws_iam_policy.firehose-audit.arn
+ role = aws_iam_role.firehose-audit.name
+}
+
data "aws_iam_policy_document" "osquery_firehose_assume_role" {
statement {
effect = "Allow"
@@ -168,6 +238,17 @@ resource "aws_kinesis_firehose_delivery_stream" "osquery_status" {
}
}
+resource "aws_kinesis_firehose_delivery_stream" "audit" {
+ name = var.audit_s3_bucket.name
+ destination = "extended_s3"
+
+ extended_s3_configuration {
+ compression_format = var.compression_format
+ role_arn = aws_iam_role.firehose-audit.arn
+ bucket_arn = aws_s3_bucket.audit.arn
+ }
+}
+
data "aws_iam_policy_document" "firehose-logging" {
statement {
actions = [
@@ -175,7 +256,11 @@ data "aws_iam_policy_document" "firehose-logging" {
"firehose:PutRecord",
"firehose:PutRecordBatch",
]
- resources = [aws_kinesis_firehose_delivery_stream.osquery_results.arn, aws_kinesis_firehose_delivery_stream.osquery_status.arn]
+ resources = [
+ aws_kinesis_firehose_delivery_stream.osquery_results.arn,
+ aws_kinesis_firehose_delivery_stream.osquery_status.arn,
+ aws_kinesis_firehose_delivery_stream.audit.arn,
+ ]
}
}
diff --git a/addons/logging-destination-firehose/outputs.tf b/addons/logging-destination-firehose/outputs.tf
index a12dbc8..ced8de6 100644
--- a/addons/logging-destination-firehose/outputs.tf
+++ b/addons/logging-destination-firehose/outputs.tf
@@ -2,9 +2,12 @@ output "fleet_extra_environment_variables" {
value = {
FLEET_FIREHOSE_STATUS_STREAM = aws_kinesis_firehose_delivery_stream.osquery_status.name
FLEET_FIREHOSE_RESULT_STREAM = aws_kinesis_firehose_delivery_stream.osquery_results.name
- FLEET_FIREHOSE_REGION = data.aws_region.current.name
+ FLEET_FIREHOSE_AUDIT_STREAM = aws_kinesis_firehose_delivery_stream.audit.name
+ FLEET_FIREHOSE_REGION = data.aws_region.current.region
FLEET_OSQUERY_STATUS_LOG_PLUGIN = "firehose"
FLEET_OSQUERY_RESULT_LOG_PLUGIN = "firehose"
+ FLEET_ACTIVITY_AUDIT_LOG_PLUGIN = "firehose"
+ FLEET_ACTIVITY_ENABLE_AUDIT_LOG = "true"
}
}
diff --git a/addons/logging-destination-firehose/variables.tf b/addons/logging-destination-firehose/variables.tf
index c97e2c3..e9187eb 100644
--- a/addons/logging-destination-firehose/variables.tf
+++ b/addons/logging-destination-firehose/variables.tf
@@ -20,6 +20,17 @@ variable "osquery_status_s3_bucket" {
}
}
+variable "audit_s3_bucket" {
+ type = object({
+ name = optional(string, "fleet-audit-archive")
+ expires_days = optional(number, 1)
+ })
+ default = {
+ name = "fleet-audit-archive"
+ expires_days = 1
+ }
+}
+
variable "compression_format" {
default = "UNCOMPRESSED"
}