# 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.
274 lines
8.9 KiB
Terraform
274 lines
8.9 KiB
Terraform
// 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.
|
|
|
|
data "aws_region" "current" {}
|
|
|
|
resource "aws_s3_bucket" "osquery-results" { #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.osquery_results_s3_bucket.name
|
|
force_destroy = true
|
|
}
|
|
|
|
resource "aws_s3_bucket_lifecycle_configuration" "osquery-results" {
|
|
bucket = aws_s3_bucket.osquery-results.bucket
|
|
rule {
|
|
filter {}
|
|
status = "Enabled"
|
|
id = "expire"
|
|
expiration {
|
|
days = var.osquery_results_s3_bucket.expires_days
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "aws_s3_bucket_server_side_encryption_configuration" "osquery-results" {
|
|
bucket = aws_s3_bucket.osquery-results.bucket
|
|
rule {
|
|
apply_server_side_encryption_by_default {
|
|
sse_algorithm = "aws:kms"
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "aws_s3_bucket_public_access_block" "osquery-results" {
|
|
bucket = aws_s3_bucket.osquery-results.id
|
|
block_public_acls = true
|
|
block_public_policy = true
|
|
ignore_public_acls = true
|
|
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" "osquery-status" { #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.osquery_status_s3_bucket.name
|
|
force_destroy = true
|
|
}
|
|
|
|
resource "aws_s3_bucket_lifecycle_configuration" "osquery-status" {
|
|
bucket = aws_s3_bucket.osquery-status.bucket
|
|
rule {
|
|
filter {}
|
|
status = "Enabled"
|
|
id = "expire"
|
|
expiration {
|
|
days = var.osquery_status_s3_bucket.expires_days
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "aws_s3_bucket_server_side_encryption_configuration" "osquery-status" {
|
|
bucket = aws_s3_bucket.osquery-status.bucket
|
|
rule {
|
|
apply_server_side_encryption_by_default {
|
|
sse_algorithm = "aws:kms"
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "aws_s3_bucket_public_access_block" "osquery-status" {
|
|
bucket = aws_s3_bucket.osquery-status.id
|
|
block_public_acls = true
|
|
block_public_policy = true
|
|
ignore_public_acls = true
|
|
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
|
|
force_destroy = true
|
|
}
|
|
|
|
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"
|
|
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.osquery-results.arn, "${aws_s3_bucket.osquery-results.arn}/*"] #tfsec:ignore:aws-iam-no-policy-wildcards
|
|
}
|
|
}
|
|
|
|
data "aws_iam_policy_document" "osquery_status_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.osquery-status.arn, "${aws_s3_bucket.osquery-status.arn}/*"] #tfsec:ignore:aws-iam-no-policy-wildcards
|
|
}
|
|
}
|
|
|
|
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 = 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 = 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 = var.prefix == "" ? "audit_firehose_policy" : "${var.prefix}_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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
resource "aws_iam_role_policy_attachment" "firehose-status" {
|
|
policy_arn = aws_iam_policy.firehose-status.arn
|
|
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"
|
|
actions = ["sts:AssumeRole"]
|
|
principals {
|
|
identifiers = ["firehose.amazonaws.com"]
|
|
type = "Service"
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "aws_kinesis_firehose_delivery_stream" "osquery_results" {
|
|
name = var.osquery_results_s3_bucket.name
|
|
destination = "extended_s3"
|
|
|
|
extended_s3_configuration {
|
|
compression_format = var.compression_format
|
|
role_arn = aws_iam_role.firehose-results.arn
|
|
bucket_arn = aws_s3_bucket.osquery-results.arn
|
|
}
|
|
}
|
|
|
|
resource "aws_kinesis_firehose_delivery_stream" "osquery_status" {
|
|
name = var.osquery_status_s3_bucket.name
|
|
destination = "extended_s3"
|
|
|
|
extended_s3_configuration {
|
|
compression_format = var.compression_format
|
|
role_arn = aws_iam_role.firehose-status.arn
|
|
bucket_arn = aws_s3_bucket.osquery-status.arn
|
|
}
|
|
}
|
|
|
|
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 = [
|
|
"firehose:DescribeDeliveryStream",
|
|
"firehose:PutRecord",
|
|
"firehose:PutRecordBatch",
|
|
]
|
|
resources = [
|
|
aws_kinesis_firehose_delivery_stream.osquery_results.arn,
|
|
aws_kinesis_firehose_delivery_stream.osquery_status.arn,
|
|
aws_kinesis_firehose_delivery_stream.audit.arn,
|
|
]
|
|
}
|
|
}
|
|
|
|
resource "aws_iam_policy" "firehose-logging" {
|
|
description = "An IAM policy for fleet to log to Firehose destinations"
|
|
policy = data.aws_iam_policy_document.firehose-logging.json
|
|
}
|