Initial migration (#1)
This will be needed to make the initial tags. Once merged to main, I will tag with the same module revisions as what exists in the Fleet repo. We can then test the example module using the new settings. Once validated, we'll then update the main fleet repo to redirect here for /terraform and remove everything there. Anything referring to old tags will still work in-place. Additionally any website references will be updated as well to reflect these changes.
This commit is contained in:
1 parent
ab9ac9862e
commit
f378f62db2
186 files changed
+9900
-3
No files matched your search
@@ -0,0 +1,2 @@
|
||||
This directory contains addons to the core Fleet module that add additional features such as logging destinations, or other features that some customers might not want.
|
||||
These can be included and used as desired.
|
||||
@@ -0,0 +1,16 @@
|
||||
# S3 File Carving backend
|
||||
|
||||
This module creates the necessary IAM role for Fleet to attach when it's running in server mode.
|
||||
|
||||
It also exports the `fleet_extra_environment_variables` to configure Fleet server to use S3 as the backing carve results store.
|
||||
|
||||
Usage typically looks like:
|
||||
|
||||
```terraform
|
||||
fleet_config = {
|
||||
extra_environment_variables = merge(
|
||||
local.extra_environment_variables,
|
||||
module.carving.fleet_extra_environment_variables
|
||||
)
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,54 @@
|
||||
# S3 File Carving backend
|
||||
|
||||
This module creates the necessary IAM role for Fleet to attach when it's running in server mode.
|
||||
|
||||
It also exports the `fleet_extra_environment_variables` to configure Fleet server to use S3 as the backing carve results store.
|
||||
|
||||
Usage typically looks like:
|
||||
|
||||
```terraform
|
||||
fleet_config = {
|
||||
extra_environment_variables = merge(
|
||||
local.extra_environment_variables,
|
||||
module.carving.fleet_extra_environment_variables
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
No requirements.
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_iam_policy.fleet-assume-role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_iam_policy_document.fleet-assume-role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_iam_role_arn"></a> [iam\_role\_arn](#input\_iam\_role\_arn) | IAM Role ARN to assume into for file carving uploads to S3 | `string` | n/a | yes |
|
||||
| <a name="input_s3_bucket_name"></a> [s3\_bucket\_name](#input\_s3\_bucket\_name) | The S3 bucket for carve results to be written to | `string` | n/a | yes |
|
||||
| <a name="input_s3_bucket_region"></a> [s3\_bucket\_region](#input\_s3\_bucket\_region) | The S3 bucket region | `string` | n/a | yes |
|
||||
| <a name="input_s3_carve_prefix"></a> [s3\_carve\_prefix](#input\_s3\_carve\_prefix) | The S3 object prefix to use when storing carve results | `string` | `""` | no |
|
||||
| <a name="input_sts_external_id"></a> [sts\_external\_id](#input\_sts\_external\_id) | Optional unique identifier that can be used by the principal assuming the role to assert its identity. | `string` | `""` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_fleet_extra_environment_variables"></a> [fleet\_extra\_environment\_variables](#output\_fleet\_extra\_environment\_variables) | n/a |
|
||||
| <a name="output_fleet_extra_iam_policies"></a> [fleet\_extra\_iam\_policies](#output\_fleet\_extra\_iam\_policies) | n/a |
|
||||
@@ -0,0 +1,11 @@
|
||||
data "aws_iam_policy_document" "fleet-assume-role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
resources = [var.iam_role_arn]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "fleet-assume-role" {
|
||||
policy = data.aws_iam_policy_document.fleet-assume-role.json
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
output "fleet_extra_environment_variables" {
|
||||
value = {
|
||||
FLEET_S3_CARVES_STS_ASSUME_ROLE_ARN = var.iam_role_arn
|
||||
FLEET_S3_CARVES_STS_EXTERNAL_ID = var.sts_external_id
|
||||
FLEET_S3_CARVES_BUCKET = var.s3_bucket_name
|
||||
FLEET_S3_CARVES_REGION = var.s3_bucket_region
|
||||
FLEET_S3_CARVES_PREFIX = var.s3_carve_prefix
|
||||
}
|
||||
}
|
||||
|
||||
output "fleet_extra_iam_policies" {
|
||||
value = [
|
||||
aws_iam_policy.fleet-assume-role.arn
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
variable "iam_role_arn" {
|
||||
type = string
|
||||
description = "IAM Role ARN to assume into for file carving uploads to S3"
|
||||
}
|
||||
|
||||
variable "sts_external_id" {
|
||||
type = string
|
||||
description = "Optional unique identifier that can be used by the principal assuming the role to assert its identity."
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "s3_bucket_name" {
|
||||
type = string
|
||||
description = "The S3 bucket for carve results to be written to"
|
||||
}
|
||||
|
||||
variable "s3_bucket_region" {
|
||||
type = string
|
||||
description = "The S3 bucket region"
|
||||
}
|
||||
|
||||
variable "s3_carve_prefix" {
|
||||
type = string
|
||||
description = "The S3 object prefix to use when storing carve results"
|
||||
default = ""
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
# AWS S3 File Carving Infrastructure
|
||||
|
||||
This Terraform configuration sets up the necessary resources for a secure file carving infrastructure in AWS. File carving is a significant capability for security and forensic analysis, enabling organizations to extract and analyze the content of files from their endpoints.
|
||||
|
||||
## Overview of Resources
|
||||
|
||||
The resources configured in this Terraform script include:
|
||||
|
||||
- **AWS Key Management Service (KMS) Key**: A customer-managed KMS key is created to provide server-side encryption for the S3 bucket where carved files will be stored. The policy attached to this key grants full KMS permissions to the AWS account's root user.
|
||||
|
||||
- **Amazon S3 Bucket**: An S3 bucket is provisioned to act as the central repository for storing the results of the file carving process. The bucket is named according to the provided variable `var.bucket_name`.
|
||||
|
||||
- **S3 Bucket Server-Side Encryption Configuration**: This resource configures server-side encryption for the S3 bucket, specifying the custom-created KMS key as the master key for encrypting objects stored in the bucket.
|
||||
|
||||
- **IAM Policy**: An IAM policy is created to enable specific access to the S3 bucket. This policy is defined via a detailed policy document which grants permissions to perform various actions essential for managing the file carving process. Actions include object retrieval (`GetObject*`), object creation (`PutObject*`), listing the bucket (`ListBucket*`), and managing multipart uploads. It also allows for certain KMS actions necessary for encrypting and decrypting the stored data.
|
||||
|
||||
- **IAM Role**: An IAM role (`aws_iam_role`) is provisioned with a trust relationship policy that permits an external entity, specified by `var.fleet_iam_role_arn`, to assume the role. This allows secure access to the S3 bucket and KMS key based on assuming roles across AWS accounts or services.
|
||||
|
||||
- **IAM Role Policy Attachment**: This attachment links the previously created IAM policy to the IAM role, ensuring that the permissions are in effect when the role is assumed by the external entity.
|
||||
|
||||
## Usage
|
||||
|
||||
To use this Terraform configuration, ensure that you have Terraform installed and configured with the necessary AWS credentials. You should define the `bucket_name` and `fleet_iam_role_arn` variables according to your organization's requirements before applying the Terraform plan.
|
||||
|
||||
This infrastructure enables secure storage and access for file carving results, facilitating forensic analysis and the capability to respond to security incidents effectively.
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,71 @@
|
||||
# AWS S3 File Carving Infrastructure
|
||||
|
||||
This Terraform configuration sets up the necessary resources for a secure file carving infrastructure in AWS. File carving is a significant capability for security and forensic analysis, enabling organizations to extract and analyze the content of files from their endpoints.
|
||||
|
||||
## Overview of Resources
|
||||
|
||||
The resources configured in this Terraform script include:
|
||||
|
||||
- **AWS Key Management Service (KMS) Key**: A customer-managed KMS key is created to provide server-side encryption for the S3 bucket where carved files will be stored. The policy attached to this key grants full KMS permissions to the AWS account's root user.
|
||||
|
||||
- **Amazon S3 Bucket**: An S3 bucket is provisioned to act as the central repository for storing the results of the file carving process. The bucket is named according to the provided variable `var.bucket_name`.
|
||||
|
||||
- **S3 Bucket Server-Side Encryption Configuration**: This resource configures server-side encryption for the S3 bucket, specifying the custom-created KMS key as the master key for encrypting objects stored in the bucket.
|
||||
|
||||
- **IAM Policy**: An IAM policy is created to enable specific access to the S3 bucket. This policy is defined via a detailed policy document which grants permissions to perform various actions essential for managing the file carving process. Actions include object retrieval (`GetObject*`), object creation (`PutObject*`), listing the bucket (`ListBucket*`), and managing multipart uploads. It also allows for certain KMS actions necessary for encrypting and decrypting the stored data.
|
||||
|
||||
- **IAM Role**: An IAM role (`aws_iam_role`) is provisioned with a trust relationship policy that permits an external entity, specified by `var.fleet_iam_role_arn`, to assume the role. This allows secure access to the S3 bucket and KMS key based on assuming roles across AWS accounts or services.
|
||||
|
||||
- **IAM Role Policy Attachment**: This attachment links the previously created IAM policy to the IAM role, ensuring that the permissions are in effect when the role is assumed by the external entity.
|
||||
|
||||
## Usage
|
||||
|
||||
To use this Terraform configuration, ensure that you have Terraform installed and configured with the necessary AWS credentials. You should define the `bucket_name` and `fleet_iam_role_arn` variables according to your organization's requirements before applying the Terraform plan.
|
||||
|
||||
This infrastructure enables secure storage and access for file carving results, facilitating forensic analysis and the capability to respond to security incidents effectively.
|
||||
|
||||
## Requirements
|
||||
|
||||
No requirements.
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_iam_policy.s3_access_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_iam_role.carve_s3_delegation_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
|
||||
| [aws_iam_role_policy_attachment.s3_access_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
|
||||
| [aws_kms_key.s3_encryption_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
|
||||
| [aws_s3_bucket.carve_results_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
|
||||
| [aws_s3_bucket_public_access_block.carve_results](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
|
||||
| [aws_s3_bucket_server_side_encryption_configuration.sse](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
|
||||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
|
||||
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.kms_key_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.s3_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_bucket_name"></a> [bucket\_name](#input\_bucket\_name) | The name of the osquery carve results bucket | `string` | n/a | yes |
|
||||
| <a name="input_fleet_iam_role_arn"></a> [fleet\_iam\_role\_arn](#input\_fleet\_iam\_role\_arn) | The IAM role ARN of the Fleet service | `string` | n/a | yes |
|
||||
| <a name="input_sts_external_id"></a> [sts\_external\_id](#input\_sts\_external\_id) | Optional unique identifier that can be used by the principal assuming the role to assert its identity. | `string` | `""` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_iam_role_arn"></a> [iam\_role\_arn](#output\_iam\_role\_arn) | n/a |
|
||||
| <a name="output_s3_bucket_name"></a> [s3\_bucket\_name](#output\_s3\_bucket\_name) | n/a |
|
||||
| <a name="output_s3_bucket_region"></a> [s3\_bucket\_region](#output\_s3\_bucket\_region) | n/a |
|
||||
@@ -0,0 +1,11 @@
|
||||
output "iam_role_arn" {
|
||||
value = aws_iam_role.carve_s3_delegation_role.arn
|
||||
}
|
||||
|
||||
output "s3_bucket_name" {
|
||||
value = aws_s3_bucket.carve_results_bucket.id
|
||||
}
|
||||
|
||||
output "s3_bucket_region" {
|
||||
value = aws_s3_bucket.carve_results_bucket.region
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
data "aws_caller_identity" "current" {}
|
||||
|
||||
# IAM policy document for the KMS key
|
||||
data "aws_iam_policy_document" "kms_key_policy" {
|
||||
statement {
|
||||
sid = "Enable IAM User Permissions"
|
||||
actions = ["kms:*"]
|
||||
resources = ["*"]
|
||||
principals {
|
||||
type = "AWS"
|
||||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Create a KMS key for encrypting the S3 bucket
|
||||
resource "aws_kms_key" "s3_encryption_key" {
|
||||
description = "KMS key for S3 bucket encryption"
|
||||
is_enabled = true
|
||||
policy = data.aws_iam_policy_document.kms_key_policy.json
|
||||
}
|
||||
|
||||
# Create an S3 bucket with server-side encryption using the customer-managed key
|
||||
resource "aws_s3_bucket" "carve_results_bucket" {
|
||||
bucket = var.bucket_name
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_public_access_block" "carve_results" {
|
||||
bucket = aws_s3_bucket.carve_results_bucket.id
|
||||
|
||||
block_public_acls = true
|
||||
block_public_policy = true
|
||||
ignore_public_acls = true
|
||||
restrict_public_buckets = true
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_server_side_encryption_configuration" "sse" {
|
||||
bucket = aws_s3_bucket.carve_results_bucket.id
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "aws:kms"
|
||||
kms_master_key_id = aws_kms_key.s3_encryption_key.key_id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Create an IAM policy which allows the necessary S3 actions
|
||||
resource "aws_iam_policy" "s3_access_policy" {
|
||||
name = "s3_access_policy"
|
||||
policy = data.aws_iam_policy_document.s3_policy.json
|
||||
}
|
||||
|
||||
# IAM policy document
|
||||
data "aws_iam_policy_document" "s3_policy" {
|
||||
statement {
|
||||
actions = [
|
||||
"s3:GetObject*",
|
||||
"s3:PutObject*",
|
||||
"s3:ListBucket*",
|
||||
"s3:ListMultipartUploadParts*",
|
||||
"s3:DeleteObject",
|
||||
"s3:CreateMultipartUpload",
|
||||
"s3:AbortMultipartUpload",
|
||||
"s3:ListMultipartUploadParts",
|
||||
"s3:GetBucketLocation"
|
||||
]
|
||||
|
||||
resources = [
|
||||
aws_s3_bucket.carve_results_bucket.arn,
|
||||
"${aws_s3_bucket.carve_results_bucket.arn}/*"
|
||||
]
|
||||
}
|
||||
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = [
|
||||
"kms:Decrypt",
|
||||
"kms:GenerateDataKey",
|
||||
"kms:Encrypt"
|
||||
]
|
||||
resources = [aws_kms_key.s3_encryption_key.arn]
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "assume_role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
principals {
|
||||
identifiers = [var.fleet_iam_role_arn]
|
||||
type = "AWS"
|
||||
}
|
||||
dynamic "condition" {
|
||||
for_each = length(var.sts_external_id) > 0 ? [1] : []
|
||||
content {
|
||||
test = "StringEquals"
|
||||
variable = "sts:ExternalId"
|
||||
values = [var.sts_external_id]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "carve_s3_delegation_role" {
|
||||
assume_role_policy = data.aws_iam_policy_document.assume_role.json
|
||||
}
|
||||
|
||||
# Attach the policy to the role
|
||||
resource "aws_iam_role_policy_attachment" "s3_access_attachment" {
|
||||
role = aws_iam_role.carve_s3_delegation_role.name
|
||||
policy_arn = aws_iam_policy.s3_access_policy.arn
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
variable "bucket_name" {
|
||||
type = string
|
||||
description = "The name of the osquery carve results bucket"
|
||||
}
|
||||
|
||||
variable "fleet_iam_role_arn" {
|
||||
type = string
|
||||
description = "The IAM role ARN of the Fleet service"
|
||||
}
|
||||
|
||||
variable "sts_external_id" {
|
||||
type = string
|
||||
description = "Optional unique identifier that can be used by the principal assuming the role to assert its identity."
|
||||
default = ""
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# Logging Destination: Firehose
|
||||
This addon provides a Kinesis Firehose logging destination for Fleet.
|
||||
|
||||
First apply the `target-account` module which will provision the necessary bucket, KMS key, and policies.
|
||||
|
||||
Then apply the `firehose` module with the required variables.
|
||||
@@ -0,0 +1,41 @@
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.7 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.52.0 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.52.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_iam_policy.fleet-assume-role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_iam_policy_document.fleet-assume-role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_firehose_audit_name"></a> [firehose\_audit\_name](#input\_firehose\_audit\_name) | name of the firehose delivery stream for fleet audit logs | `string` | n/a | yes |
|
||||
| <a name="input_firehose_results_name"></a> [firehose\_results\_name](#input\_firehose\_results\_name) | name of the firehose delivery stream for osquery results logs | `string` | n/a | yes |
|
||||
| <a name="input_firehose_status_name"></a> [firehose\_status\_name](#input\_firehose\_status\_name) | name of the firehose delivery stream for osquery status logs | `string` | n/a | yes |
|
||||
| <a name="input_iam_role_arn"></a> [iam\_role\_arn](#input\_iam\_role\_arn) | IAM Role ARN to use for Firehose destination logging | `string` | n/a | yes |
|
||||
| <a name="input_region"></a> [region](#input\_region) | region the target firehose delivery stream is in | `string` | n/a | yes |
|
||||
| <a name="input_sts_external_id"></a> [sts\_external\_id](#input\_sts\_external\_id) | Optional unique identifier that can be used by the principal assuming the role to assert its identity. | `string` | `""` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_fleet_extra_environment_variables"></a> [fleet\_extra\_environment\_variables](#output\_fleet\_extra\_environment\_variables) | n/a |
|
||||
| <a name="output_fleet_extra_iam_policies"></a> [fleet\_extra\_iam\_policies](#output\_fleet\_extra\_iam\_policies) | n/a |
|
||||
@@ -0,0 +1,11 @@
|
||||
data "aws_iam_policy_document" "fleet-assume-role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
resources = [var.iam_role_arn]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "fleet-assume-role" {
|
||||
policy = data.aws_iam_policy_document.fleet-assume-role.json
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
output "fleet_extra_environment_variables" {
|
||||
value = {
|
||||
FLEET_FIREHOSE_STATUS_STREAM = var.firehose_status_name
|
||||
FLEET_FIREHOSE_RESULT_STREAM = var.firehose_results_name
|
||||
FLEET_FIREHOSE_AUDIT_STREAM = var.firehose_audit_name
|
||||
FLEET_FIREHOSE_STS_ASSUME_ROLE_ARN = var.iam_role_arn
|
||||
FLEET_FIREHOSE_STS_EXTERNAL_ID = var.sts_external_id
|
||||
FLEET_FIREHOSE_REGION = var.region
|
||||
FLEET_OSQUERY_STATUS_LOG_PLUGIN = length(var.firehose_status_name) > 0 ? "firehose" : ""
|
||||
FLEET_OSQUERY_RESULT_LOG_PLUGIN = length(var.firehose_results_name) > 0 ? "firehose" : ""
|
||||
FLEET_ACTIVITY_AUDIT_LOG_PLUGIN = length(var.firehose_audit_name) > 0 ? "firehose" : ""
|
||||
FLEET_ACTIVITY_ENABLE_AUDIT_LOG = length(var.firehose_audit_name) > 0 ? "true" : "false"
|
||||
}
|
||||
}
|
||||
|
||||
output "fleet_extra_iam_policies" {
|
||||
value = [
|
||||
aws_iam_policy.fleet-assume-role.arn
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
variable "iam_role_arn" {
|
||||
type = string
|
||||
description = "IAM Role ARN to use for Firehose destination logging"
|
||||
}
|
||||
|
||||
variable "firehose_results_name" {
|
||||
type = string
|
||||
description = "name of the firehose delivery stream for osquery results logs"
|
||||
}
|
||||
|
||||
variable "firehose_status_name" {
|
||||
type = string
|
||||
description = "name of the firehose delivery stream for osquery status logs"
|
||||
}
|
||||
|
||||
variable "firehose_audit_name" {
|
||||
type = string
|
||||
description = "name of the firehose delivery stream for fleet audit logs"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
type = string
|
||||
description = "region the target firehose delivery stream is in"
|
||||
}
|
||||
|
||||
variable "sts_external_id" {
|
||||
type = string
|
||||
description = "Optional unique identifier that can be used by the principal assuming the role to assert its identity."
|
||||
default = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">= 1.3.7"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 4.52.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
# Firehose Logging Destination Setup
|
||||
|
||||
In this Terraform code, we are defining an IAM Role named `fleet_role` in our AWS Account, that will be assumed by the Fleet application we are hosting. We are only allowing this specific IAM Role (identified by its ARN) to perform certain actions on the Firehose service, such as `DescribeDeliveryStream`, `PutRecord`, and `PutRecordBatch`.
|
||||
|
||||
The reason we need a local IAM role in your account is so that we can assume role into it, and you have full control over the permissions it has. The associated IAM policy in the same file specifies the minimum allowed permissions.
|
||||
|
||||
The Firehose service is KMS encrypted, so the IAM Role we assume into needs permission to the KMS key that is being used to encrypt the data going into Firehose. Additionally, if the data is being delivered to S3, it will also be encrypted with KMS using the AWS S3 KMS key that is managed by AWS. This is because only customer managed keys can be shared across accounts, and the Firehose delivery stream is actually the one writing to S3.
|
||||
|
||||
This code sets up a secure and controlled environment for the Fleet application to perform its necessary actions on the Firehose service within your AWS Account.
|
||||
|
||||
If you wanted to make changes to the individual files to fit your environment, feel free. However, it's recommended to use a module like the example below for simplicity.
|
||||
|
||||
```
|
||||
module "firehose_logging" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/byo-firehose-logging-destination/target-account"
|
||||
|
||||
# Variables
|
||||
osquery_logging_destination_bucket_name = {your-desired-bucket-prefix}
|
||||
fleet_iam_role_arn = {supplied by Fleet}
|
||||
sts_external_id = {if using}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,80 @@
|
||||
# Firehose Logging Destination Setup
|
||||
|
||||
In this Terraform code, we are defining an IAM Role named `fleet_role` in our AWS Account, that will be assumed by the Fleet application we are hosting. We are only allowing this specific IAM Role (identified by its ARN) to perform certain actions on the Firehose service, such as `DescribeDeliveryStream`, `PutRecord`, and `PutRecordBatch`.
|
||||
|
||||
The reason we need a local IAM role in your account is so that we can assume role into it, and you have full control over the permissions it has. The associated IAM policy in the same file specifies the minimum allowed permissions.
|
||||
|
||||
The Firehose service is KMS encrypted, so the IAM Role we assume into needs permission to the KMS key that is being used to encrypt the data going into Firehose. Additionally, if the data is being delivered to S3, it will also be encrypted with KMS using the AWS S3 KMS key that is managed by AWS. This is because only customer managed keys can be shared across accounts, and the Firehose delivery stream is actually the one writing to S3.
|
||||
|
||||
This code sets up a secure and controlled environment for the Fleet application to perform its necessary actions on the Firehose service within your AWS Account.
|
||||
|
||||
If you wanted to make changes to the individual files to fit your environment, feel free. However, it's recommended to use a module like the example below for simplicity.
|
||||
|
||||
```
|
||||
module "firehose_logging" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/byo-firehose-logging-destination/target-account"
|
||||
|
||||
# Variables
|
||||
osquery_logging_destination_bucket_name = {your-desired-bucket-prefix}
|
||||
fleet_iam_role_arn = {supplied by Fleet}
|
||||
sts_external_id = {if using}
|
||||
}
|
||||
```
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.7 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.29.0 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.29.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_iam_policy.firehose](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_iam_policy.fleet_firehose](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_iam_role.firehose](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
|
||||
| [aws_iam_role.fleet_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
|
||||
| [aws_iam_role_policy_attachment.firehose](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
|
||||
| [aws_iam_role_policy_attachment.fleet_firehose](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
|
||||
| [aws_kinesis_firehose_delivery_stream.fleet_log_destinations](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_firehose_delivery_stream) | resource |
|
||||
| [aws_kms_key.firehose_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
|
||||
| [aws_s3_bucket.destination](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
|
||||
| [aws_s3_bucket_public_access_block.destination](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
|
||||
| [aws_s3_bucket_server_side_encryption_configuration.destination](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
|
||||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
|
||||
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.firehose](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.firehose_policy](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_kms_alias.s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_alias) | data source |
|
||||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_fleet_iam_role_arn"></a> [fleet\_iam\_role\_arn](#input\_fleet\_iam\_role\_arn) | the arn of the fleet role that firehose will assume to write data to your bucket | `string` | n/a | yes |
|
||||
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | An optional KMS key ARN for server-side encryption. If not provided and encryption is enabled, a new key will be created. | `string` | `""` | no |
|
||||
| <a name="input_log_destinations"></a> [log\_destinations](#input\_log\_destinations) | A map of configurations for Firehose delivery streams. | <pre>map(object({<br> name = string<br> prefix = string<br> error_output_prefix = string<br> buffering_size = number<br> buffering_interval = number<br> compression_format = string<br> }))</pre> | <pre>{<br> "audit": {<br> "buffering_interval": 120,<br> "buffering_size": 20,<br> "compression_format": "UNCOMPRESSED",<br> "error_output_prefix": "audit/error/error=!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/",<br> "name": "fleet_audit",<br> "prefix": "audit/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"<br> },<br> "results": {<br> "buffering_interval": 120,<br> "buffering_size": 20,<br> "compression_format": "UNCOMPRESSED",<br> "error_output_prefix": "results/error/error=!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/",<br> "name": "osquery_results",<br> "prefix": "results/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"<br> },<br> "status": {<br> "buffering_interval": 120,<br> "buffering_size": 20,<br> "compression_format": "UNCOMPRESSED",<br> "error_output_prefix": "status/error/error=!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/",<br> "name": "osquery_status",<br> "prefix": "status/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"<br> }<br>}</pre> | no |
|
||||
| <a name="input_osquery_logging_destination_bucket_name"></a> [osquery\_logging\_destination\_bucket\_name](#input\_osquery\_logging\_destination\_bucket\_name) | name of the bucket to store osquery results & status logs | `string` | n/a | yes |
|
||||
| <a name="input_server_side_encryption_enabled"></a> [server\_side\_encryption\_enabled](#input\_server\_side\_encryption\_enabled) | A boolean flag to enable/disable server-side encryption. Defaults to true (enabled). | `bool` | `true` | no |
|
||||
| <a name="input_sts_external_id"></a> [sts\_external\_id](#input\_sts\_external\_id) | Optional unique identifier that can be used by the principal assuming the role to assert its identity. | `string` | `""` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_firehose_iam_role"></a> [firehose\_iam\_role](#output\_firehose\_iam\_role) | n/a |
|
||||
| <a name="output_log_destinations"></a> [log\_destinations](#output\_log\_destinations) | Map of Firehose delivery streams' names. |
|
||||
| <a name="output_s3_destination"></a> [s3\_destination](#output\_s3\_destination) | n/a |
|
||||
@@ -0,0 +1,90 @@
|
||||
data "aws_iam_policy_document" "osquery_firehose_assume_role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
principals {
|
||||
identifiers = ["firehose.amazonaws.com"]
|
||||
type = "Service"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "firehose_policy" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = [
|
||||
"s3:AbortMultipartUpload",
|
||||
"s3:GetBucketLocation",
|
||||
"s3:GetObject",
|
||||
"s3:ListBucket",
|
||||
"s3:ListBucketMultipartUploads",
|
||||
"s3:PutObject",
|
||||
"s3:PutObjectAcl" // required according to https://docs.aws.amazon.com/firehose/latest/dev/controlling-access.html#using-iam-s3
|
||||
]
|
||||
resources = [
|
||||
aws_s3_bucket.destination.arn,
|
||||
"${aws_s3_bucket.destination.arn}/*",
|
||||
]
|
||||
}
|
||||
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["logs:PutLogEvents"]
|
||||
resources = [
|
||||
for name in keys(var.log_destinations) : "arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/kinesisfirehose/${var.log_destinations[name].name}:*"
|
||||
]
|
||||
}
|
||||
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = [
|
||||
"kms:Decrypt",
|
||||
"kms:GenerateDataKey"
|
||||
]
|
||||
resources = [data.aws_kms_alias.s3.arn]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "firehose" {
|
||||
assume_role_policy = data.aws_iam_policy_document.osquery_firehose_assume_role.json
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "firehose" {
|
||||
policy = data.aws_iam_policy_document.firehose_policy.json
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "firehose" {
|
||||
policy_arn = aws_iam_policy.firehose.arn
|
||||
role = aws_iam_role.firehose.name
|
||||
}
|
||||
|
||||
resource "aws_kms_key" "firehose_key" {
|
||||
count = var.server_side_encryption_enabled && length(var.kms_key_arn) == 0 ? 1 : 0
|
||||
description = "KMS key for encrypting Firehose data."
|
||||
}
|
||||
|
||||
resource "aws_kinesis_firehose_delivery_stream" "fleet_log_destinations" {
|
||||
for_each = var.log_destinations
|
||||
name = each.value.name
|
||||
destination = "extended_s3"
|
||||
|
||||
dynamic "server_side_encryption" {
|
||||
for_each = var.server_side_encryption_enabled ? [1] : []
|
||||
content {
|
||||
enabled = var.server_side_encryption_enabled
|
||||
key_arn = length(var.kms_key_arn) > 0 ? var.kms_key_arn : aws_kms_key.firehose_key[0].arn
|
||||
key_type = "CUSTOMER_MANAGED_CMK"
|
||||
}
|
||||
}
|
||||
|
||||
extended_s3_configuration {
|
||||
bucket_arn = aws_s3_bucket.destination.arn
|
||||
role_arn = aws_iam_role.firehose.arn
|
||||
prefix = each.value.prefix
|
||||
error_output_prefix = each.value.error_output_prefix
|
||||
buffering_size = each.value.buffering_size
|
||||
buffering_interval = each.value.buffering_interval
|
||||
compression_format = each.value.compression_format
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
resource "aws_iam_role" "fleet_role" {
|
||||
assume_role_policy = data.aws_iam_policy_document.assume_role.json
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "assume_role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
principals {
|
||||
identifiers = [var.fleet_iam_role_arn]
|
||||
type = "AWS"
|
||||
}
|
||||
dynamic "condition" {
|
||||
for_each = length(var.sts_external_id) > 0 ? [1] : []
|
||||
content {
|
||||
test = "StringEquals"
|
||||
variable = "sts:ExternalId"
|
||||
values = [var.sts_external_id]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "firehose" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = [
|
||||
"firehose:DescribeDeliveryStream",
|
||||
"firehose:PutRecord",
|
||||
"firehose:PutRecordBatch",
|
||||
]
|
||||
resources = [
|
||||
for stream in aws_kinesis_firehose_delivery_stream.fleet_log_destinations : stream.arn
|
||||
]
|
||||
}
|
||||
|
||||
dynamic "statement" {
|
||||
for_each = var.server_side_encryption_enabled ? [1] : []
|
||||
|
||||
content {
|
||||
effect = "Allow"
|
||||
actions = [
|
||||
"kms:Decrypt",
|
||||
"kms:GenerateDataKey",
|
||||
]
|
||||
resources = [
|
||||
length(var.kms_key_arn) > 0 ? var.kms_key_arn : aws_kms_key.firehose_key[0].arn
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "fleet_firehose" {
|
||||
policy = data.aws_iam_policy_document.firehose.json
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "fleet_firehose" {
|
||||
policy_arn = aws_iam_policy.fleet_firehose.arn
|
||||
role = aws_iam_role.fleet_role.name
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
output "firehose_iam_role" {
|
||||
value = aws_iam_role.fleet_role.arn
|
||||
}
|
||||
|
||||
output "s3_destination" {
|
||||
value = aws_s3_bucket.destination.arn
|
||||
}
|
||||
|
||||
output "log_destinations" {
|
||||
description = "Map of Firehose delivery streams' names."
|
||||
value = { for key, stream in aws_kinesis_firehose_delivery_stream.fleet_log_destinations : key => stream.name }
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
data "aws_region" "current" {}
|
||||
data "aws_caller_identity" "current" {}
|
||||
data "aws_kms_alias" "s3" {
|
||||
name = "alias/aws/s3"
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket" "destination" {
|
||||
bucket = var.osquery_logging_destination_bucket_name
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_public_access_block" "destination" {
|
||||
bucket = aws_s3_bucket.destination.id
|
||||
block_public_acls = true
|
||||
block_public_policy = true
|
||||
ignore_public_acls = true
|
||||
restrict_public_buckets = true
|
||||
}
|
||||
|
||||
// Objects in S3 are now encrypted by default https://aws.amazon.com/blogs/aws/amazon-s3-encrypts-new-objects-by-default/
|
||||
// If you need more granular control, use a customer managed KMS Key
|
||||
resource "aws_s3_bucket_server_side_encryption_configuration" "destination" {
|
||||
bucket = aws_s3_bucket.destination.id
|
||||
rule {
|
||||
bucket_key_enabled = true
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "aws:kms"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
variable "osquery_logging_destination_bucket_name" {
|
||||
type = string
|
||||
description = "name of the bucket to store osquery results & status logs"
|
||||
}
|
||||
|
||||
variable "fleet_iam_role_arn" {
|
||||
type = string
|
||||
description = "The ARN of the IAM role that will be assumed to gain permissions required to write to the Kinesis Firehose delivery stream."
|
||||
}
|
||||
|
||||
variable "sts_external_id" {
|
||||
type = string
|
||||
description = "Optional unique identifier that can be used by the principal assuming the role to assert its identity."
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "log_destinations" {
|
||||
description = "A map of configurations for Firehose delivery streams."
|
||||
type = map(object({
|
||||
name = string
|
||||
prefix = string
|
||||
error_output_prefix = string
|
||||
buffering_size = number
|
||||
buffering_interval = number
|
||||
compression_format = string
|
||||
}))
|
||||
default = {
|
||||
results = {
|
||||
name = "osquery_results"
|
||||
prefix = "results/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
|
||||
error_output_prefix = "results/error/error=!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
|
||||
buffering_size = 20
|
||||
buffering_interval = 120
|
||||
compression_format = "UNCOMPRESSED"
|
||||
},
|
||||
status = {
|
||||
name = "osquery_status"
|
||||
prefix = "status/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
|
||||
error_output_prefix = "status/error/error=!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
|
||||
buffering_size = 20
|
||||
buffering_interval = 120
|
||||
compression_format = "UNCOMPRESSED"
|
||||
},
|
||||
audit = {
|
||||
name = "fleet_audit"
|
||||
prefix = "audit/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
|
||||
error_output_prefix = "audit/error/error=!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
|
||||
buffering_size = 20
|
||||
buffering_interval = 120
|
||||
compression_format = "UNCOMPRESSED"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "server_side_encryption_enabled" {
|
||||
description = "A boolean flag to enable/disable server-side encryption. Defaults to true (enabled)."
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "kms_key_arn" {
|
||||
description = "An optional KMS key ARN for server-side encryption. If not provided and encryption is enabled, a new key will be created."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">= 1.3.7"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 5.29.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# Logging Destination: Kinesis
|
||||
This addon provides a Kinesis Data Stream logging destination for Fleet.
|
||||
|
||||
First apply the `target-account` module which will provision the necessary data streams, KMS key, and policies.
|
||||
|
||||
Then apply the `kinesis` module with the required variables.
|
||||
@@ -0,0 +1,28 @@
|
||||
# Kinesis Data Stream Logging Destination Setup
|
||||
|
||||
## Usage
|
||||
|
||||
After `./target-account` module is applied you might use this module in the following manner:
|
||||
|
||||
```hcl
|
||||
module "kinesis" {
|
||||
source = "../../../../fleet/terraform/addons/byo-kinesis-logging-destination/kinesis"
|
||||
kinesis_results_name = "testing-log-stream"
|
||||
kinesis_status_name = "testing-log-stream"
|
||||
kinesis_audit_name = "testing-log-stream"
|
||||
iam_role_arn = "arn:aws:iam::123456789:role/terraform-20240524165353382600000001"
|
||||
region = "us-east-2"
|
||||
}
|
||||
```
|
||||
|
||||
And then supply the outputs to the `fleet_config` definition:
|
||||
```hcl
|
||||
fleet_config = {
|
||||
image = local.fleet_image
|
||||
extra_iam_policies = concat(module.kinesis.fleet_extra_iam_policies)
|
||||
extra_environment_variables = merge(
|
||||
local.extra_environment_variables,
|
||||
module.kinesis.fleet_extra_environment_variables,
|
||||
)
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,70 @@
|
||||
# Kinesis Data Stream Logging Destination Setup
|
||||
|
||||
## Usage
|
||||
|
||||
After `./target-account` module is applied you might use this module in the following manner:
|
||||
|
||||
```hcl
|
||||
module "kinesis" {
|
||||
source = "../../../../fleet/terraform/addons/byo-kinesis-logging-destination/kinesis"
|
||||
kinesis_results_name = "testing-log-stream"
|
||||
kinesis_status_name = "testing-log-stream"
|
||||
kinesis_audit_name = "testing-log-stream"
|
||||
iam_role_arn = "arn:aws:iam::123456789:role/terraform-20240524165353382600000001"
|
||||
region = "us-east-2"
|
||||
}
|
||||
```
|
||||
|
||||
And then supply the outputs to the `fleet_config` definition:
|
||||
```hcl
|
||||
fleet_config = {
|
||||
image = local.fleet_image
|
||||
extra_iam_policies = concat(module.kinesis.fleet_extra_iam_policies)
|
||||
extra_environment_variables = merge(
|
||||
local.extra_environment_variables,
|
||||
module.kinesis.fleet_extra_environment_variables,
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.7 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.52.0 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.52.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_iam_policy.fleet-assume-role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_iam_policy_document.fleet-assume-role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_iam_role_arn"></a> [iam\_role\_arn](#input\_iam\_role\_arn) | IAM Role ARN to use for Kinesis destination logging | `string` | n/a | yes |
|
||||
| <a name="input_kinesis_audit_name"></a> [kinesis\_audit\_name](#input\_kinesis\_audit\_name) | name of the kinesis data stream for fleet audit logs | `string` | n/a | yes |
|
||||
| <a name="input_kinesis_results_name"></a> [kinesis\_results\_name](#input\_kinesis\_results\_name) | name of the kinesis data stream for osquery results logs | `string` | n/a | yes |
|
||||
| <a name="input_kinesis_status_name"></a> [kinesis\_status\_name](#input\_kinesis\_status\_name) | name of the kinesis data stream for osquery status logs | `string` | n/a | yes |
|
||||
| <a name="input_region"></a> [region](#input\_region) | region the target kinesis data stream(s) is in | `string` | n/a | yes |
|
||||
| <a name="input_sts_external_id"></a> [sts\_external\_id](#input\_sts\_external\_id) | Optional unique identifier that can be used by the principal assuming the role to assert its identity. | `string` | `""` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_fleet_extra_environment_variables"></a> [fleet\_extra\_environment\_variables](#output\_fleet\_extra\_environment\_variables) | n/a |
|
||||
| <a name="output_fleet_extra_iam_policies"></a> [fleet\_extra\_iam\_policies](#output\_fleet\_extra\_iam\_policies) | n/a |
|
||||
@@ -0,0 +1,11 @@
|
||||
data "aws_iam_policy_document" "fleet-assume-role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
resources = [var.iam_role_arn]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "fleet-assume-role" {
|
||||
policy = data.aws_iam_policy_document.fleet-assume-role.json
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
output "fleet_extra_environment_variables" {
|
||||
value = {
|
||||
FLEET_KINESIS_STATUS_STREAM = var.kinesis_status_name
|
||||
FLEET_KINESIS_RESULT_STREAM = var.kinesis_results_name
|
||||
FLEET_KINESIS_AUDIT_STREAM = var.kinesis_audit_name
|
||||
FLEET_KINESIS_STS_ASSUME_ROLE_ARN = var.iam_role_arn
|
||||
FLEET_KINESIS_STS_EXTERNAL_ID = var.sts_external_id
|
||||
FLEET_KINESIS_REGION = var.region
|
||||
FLEET_OSQUERY_STATUS_LOG_PLUGIN = length(var.kinesis_status_name) > 0 ? "kinesis" : ""
|
||||
FLEET_OSQUERY_RESULT_LOG_PLUGIN = length(var.kinesis_results_name) > 0 ? "kinesis" : ""
|
||||
FLEET_ACTIVITY_AUDIT_LOG_PLUGIN = length(var.kinesis_audit_name) > 0 ? "kinesis" : ""
|
||||
FLEET_ACTIVITY_ENABLE_AUDIT_LOG = length(var.kinesis_audit_name) > 0 ? "true" : "false"
|
||||
}
|
||||
}
|
||||
|
||||
output "fleet_extra_iam_policies" {
|
||||
value = [
|
||||
aws_iam_policy.fleet-assume-role.arn
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
variable "iam_role_arn" {
|
||||
type = string
|
||||
description = "IAM Role ARN to use for Kinesis destination logging"
|
||||
}
|
||||
|
||||
variable "kinesis_results_name" {
|
||||
type = string
|
||||
description = "name of the kinesis data stream for osquery results logs"
|
||||
}
|
||||
|
||||
variable "kinesis_status_name" {
|
||||
type = string
|
||||
description = "name of the kinesis data stream for osquery status logs"
|
||||
}
|
||||
|
||||
variable "kinesis_audit_name" {
|
||||
type = string
|
||||
description = "name of the kinesis data stream for fleet audit logs"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
type = string
|
||||
description = "region the target kinesis data stream(s) is in"
|
||||
}
|
||||
|
||||
variable "sts_external_id" {
|
||||
type = string
|
||||
description = "Optional unique identifier that can be used by the principal assuming the role to assert its identity."
|
||||
default = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">= 1.3.7"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 5.29.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
# Kinesis Data Stream Logging Destination Setup
|
||||
|
||||
## How to use
|
||||
|
||||
Below is an example of defining the module to use a single Kinesis Data Stream for all log types (results, status, and audit):
|
||||
```hcl
|
||||
module "kinesis" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/byo-kinesis-logging-destination/target-account"
|
||||
|
||||
fleet_iam_role_arn = "arn:aws:iam::123456789:role/fleet-server-role" # this is the ARN of the IAM (ECS-task) role the fleet servers are running as
|
||||
log_destinations = {
|
||||
test = {
|
||||
name = "unified-log-stream"
|
||||
shard_count = 0 # shard count only matters if `stream_mode` is `PROVISIONED`
|
||||
stream_mode = "ON_DEMAND" # valid values are `ON_DEMAND` or `PROVISIONED`
|
||||
retention_period = 24 # number of hours you want the data to be retained on the stream
|
||||
shard_level_metrics = [] # IncomingBytes IncomingRecords OutgoingBytes OutgoingRecords WriteProvisionedThroughputExceeded ReadProvisionedThroughputExceeded IteratorAgeMilliseconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "kinesis_logging_destination" {
|
||||
value = module.kinesis
|
||||
}
|
||||
```
|
||||
|
||||
If you desired a Kinesis Data Stream per "topic":
|
||||
```hcl
|
||||
module "kinesis" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/byo-kinesis-logging-destination/target-account"
|
||||
|
||||
fleet_iam_role_arn = "arn:aws:iam::123456789:role/fleet-server-role" # this is the ARN of the IAM (ECS-task) role the fleet servers are running as
|
||||
log_destinations = {
|
||||
results = {
|
||||
name = "osquery-results"
|
||||
shard_count = 0 # shard count only matters if `stream_mode` is `PROVISIONED`
|
||||
stream_mode = "ON_DEMAND" # valid values are `ON_DEMAND` or `PROVISIONED`
|
||||
retention_period = 24 # number of hours you want the data to be retained on the stream
|
||||
shard_level_metrics = [] # IncomingBytes IncomingRecords OutgoingBytes OutgoingRecords WriteProvisionedThroughputExceeded ReadProvisionedThroughputExceeded IteratorAgeMilliseconds
|
||||
}
|
||||
status = {
|
||||
name = "osquery-status"
|
||||
shard_count = 0 # shard count only matters if `stream_mode` is `PROVISIONED`
|
||||
stream_mode = "ON_DEMAND" # valid values are `ON_DEMAND` or `PROVISIONED`
|
||||
retention_period = 24 # number of hours you want the data to be retained on the stream
|
||||
shard_level_metrics = [] # IncomingBytes IncomingRecords OutgoingBytes OutgoingRecords WriteProvisionedThroughputExceeded ReadProvisionedThroughputExceeded IteratorAgeMilliseconds
|
||||
}
|
||||
audit = {
|
||||
name = "fleet-audit"
|
||||
shard_count = 0 # shard count only matters if `stream_mode` is `PROVISIONED`
|
||||
stream_mode = "ON_DEMAND" # valid values are `ON_DEMAND` or `PROVISIONED`
|
||||
retention_period = 24 # number of hours you want the data to be retained on the stream
|
||||
shard_level_metrics = [] # IncomingBytes IncomingRecords OutgoingBytes OutgoingRecords WriteProvisionedThroughputExceeded ReadProvisionedThroughputExceeded IteratorAgeMilliseconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "kinesis_logging_destination" {
|
||||
value = module.kinesis
|
||||
}
|
||||
```
|
||||
|
||||
1. **Variables:**
|
||||
- `fleet_iam_role_arn`: A string variable that holds the ARN of the IAM role which will assume the role defined in this module to gain permissions for writing to the Kinesis Data Streams.
|
||||
- `sts_external_id`: An optional string variable that can be used as a unique identifier for the principal assuming the role to assert its identity. Default is an empty string.
|
||||
- `log_destinations`: A map variable that contains configurations for multiple Kinesis Data Streams. Each stream configuration includes its name, shard count, stream mode, retention period, and shard-level metrics. Default values are provided for three streams: `osquery_results`, `osquery_status`, and `fleet_audit`.
|
||||
|
||||
2. **IAM Role:**
|
||||
- `aws_iam_role.fleet_role`: Creates an IAM role with a trust policy that allows the specified IAM role ARN (`fleet_iam_role_arn`) to assume this role. If `sts_external_id` is provided, it adds a condition to the trust policy to require this external ID for the assume role operation.
|
||||
|
||||
3. **IAM Policy Documents:**
|
||||
- `data.aws_iam_policy_document.assume_role`: Defines the assume role policy for the IAM role. It allows the specified actions (`sts:AssumeRole`) for the specified principals.
|
||||
- `data.aws_iam_policy_document.kinesis`: Defines the policy document allowing the IAM role to perform Kinesis and KMS actions. It allows the IAM role to describe, put records into the Kinesis streams (defined in `log_destinations`), and use KMS keys for encryption.
|
||||
|
||||
4. **IAM Policy and Attachment:**
|
||||
- `aws_iam_policy.fleet_kinesis`: Creates an IAM policy using the defined policy document (`data.aws_iam_policy_document.kinesis`).
|
||||
- `aws_iam_role_policy_attachment.fleet_kinesis`: Attaches the created IAM policy to the IAM role (`aws_iam_role.fleet_role`).
|
||||
|
||||
5. **KMS Key:**
|
||||
- `aws_kms_key.kinesis_key`: Creates a KMS key for encrypting the Kinesis Data Streams.
|
||||
|
||||
6. **Kinesis Data Streams:**
|
||||
- `aws_kinesis_stream.fleet_log_destination`: Provisions Kinesis Data Streams based on the configurations defined in `log_destinations`. Each stream is created with the specified name, encryption type (using the KMS key), shard-level metrics, shard count (if the stream mode is not "ON_DEMAND"), and stream mode.
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,127 @@
|
||||
# Kinesis Data Stream Logging Destination Setup
|
||||
|
||||
## How to use
|
||||
|
||||
Below is an example of defining the module to use a single Kinesis Data Stream for all log types (results, status, and audit):
|
||||
```hcl
|
||||
module "kinesis" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/byo-kinesis-logging-destination/target-account"
|
||||
|
||||
fleet_iam_role_arn = "arn:aws:iam::123456789:role/fleet-server-role" # this is the ARN of the IAM (ECS-task) role the fleet servers are running as
|
||||
log_destinations = {
|
||||
test = {
|
||||
name = "unified-log-stream"
|
||||
shard_count = 0 # shard count only matters if `stream_mode` is `PROVISIONED`
|
||||
stream_mode = "ON_DEMAND" # valid values are `ON_DEMAND` or `PROVISIONED`
|
||||
retention_period = 24 # number of hours you want the data to be retained on the stream
|
||||
shard_level_metrics = [] # IncomingBytes IncomingRecords OutgoingBytes OutgoingRecords WriteProvisionedThroughputExceeded ReadProvisionedThroughputExceeded IteratorAgeMilliseconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "kinesis_logging_destination" {
|
||||
value = module.kinesis
|
||||
}
|
||||
```
|
||||
|
||||
If you desired a Kinesis Data Stream per "topic":
|
||||
```hcl
|
||||
module "kinesis" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/byo-kinesis-logging-destination/target-account"
|
||||
|
||||
fleet_iam_role_arn = "arn:aws:iam::123456789:role/fleet-server-role" # this is the ARN of the IAM (ECS-task) role the fleet servers are running as
|
||||
log_destinations = {
|
||||
results = {
|
||||
name = "osquery-results"
|
||||
shard_count = 0 # shard count only matters if `stream_mode` is `PROVISIONED`
|
||||
stream_mode = "ON_DEMAND" # valid values are `ON_DEMAND` or `PROVISIONED`
|
||||
retention_period = 24 # number of hours you want the data to be retained on the stream
|
||||
shard_level_metrics = [] # IncomingBytes IncomingRecords OutgoingBytes OutgoingRecords WriteProvisionedThroughputExceeded ReadProvisionedThroughputExceeded IteratorAgeMilliseconds
|
||||
}
|
||||
status = {
|
||||
name = "osquery-status"
|
||||
shard_count = 0 # shard count only matters if `stream_mode` is `PROVISIONED`
|
||||
stream_mode = "ON_DEMAND" # valid values are `ON_DEMAND` or `PROVISIONED`
|
||||
retention_period = 24 # number of hours you want the data to be retained on the stream
|
||||
shard_level_metrics = [] # IncomingBytes IncomingRecords OutgoingBytes OutgoingRecords WriteProvisionedThroughputExceeded ReadProvisionedThroughputExceeded IteratorAgeMilliseconds
|
||||
}
|
||||
audit = {
|
||||
name = "fleet-audit"
|
||||
shard_count = 0 # shard count only matters if `stream_mode` is `PROVISIONED`
|
||||
stream_mode = "ON_DEMAND" # valid values are `ON_DEMAND` or `PROVISIONED`
|
||||
retention_period = 24 # number of hours you want the data to be retained on the stream
|
||||
shard_level_metrics = [] # IncomingBytes IncomingRecords OutgoingBytes OutgoingRecords WriteProvisionedThroughputExceeded ReadProvisionedThroughputExceeded IteratorAgeMilliseconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "kinesis_logging_destination" {
|
||||
value = module.kinesis
|
||||
}
|
||||
```
|
||||
|
||||
1. **Variables:**
|
||||
- `fleet_iam_role_arn`: A string variable that holds the ARN of the IAM role which will assume the role defined in this module to gain permissions for writing to the Kinesis Data Streams.
|
||||
- `sts_external_id`: An optional string variable that can be used as a unique identifier for the principal assuming the role to assert its identity. Default is an empty string.
|
||||
- `log_destinations`: A map variable that contains configurations for multiple Kinesis Data Streams. Each stream configuration includes its name, shard count, stream mode, retention period, and shard-level metrics. Default values are provided for three streams: `osquery_results`, `osquery_status`, and `fleet_audit`.
|
||||
|
||||
2. **IAM Role:**
|
||||
- `aws_iam_role.fleet_role`: Creates an IAM role with a trust policy that allows the specified IAM role ARN (`fleet_iam_role_arn`) to assume this role. If `sts_external_id` is provided, it adds a condition to the trust policy to require this external ID for the assume role operation.
|
||||
|
||||
3. **IAM Policy Documents:**
|
||||
- `data.aws_iam_policy_document.assume_role`: Defines the assume role policy for the IAM role. It allows the specified actions (`sts:AssumeRole`) for the specified principals.
|
||||
- `data.aws_iam_policy_document.kinesis`: Defines the policy document allowing the IAM role to perform Kinesis and KMS actions. It allows the IAM role to describe, put records into the Kinesis streams (defined in `log_destinations`), and use KMS keys for encryption.
|
||||
|
||||
4. **IAM Policy and Attachment:**
|
||||
- `aws_iam_policy.fleet_kinesis`: Creates an IAM policy using the defined policy document (`data.aws_iam_policy_document.kinesis`).
|
||||
- `aws_iam_role_policy_attachment.fleet_kinesis`: Attaches the created IAM policy to the IAM role (`aws_iam_role.fleet_role`).
|
||||
|
||||
5. **KMS Key:**
|
||||
- `aws_kms_key.kinesis_key`: Creates a KMS key for encrypting the Kinesis Data Streams.
|
||||
|
||||
6. **Kinesis Data Streams:**
|
||||
- `aws_kinesis_stream.fleet_log_destination`: Provisions Kinesis Data Streams based on the configurations defined in `log_destinations`. Each stream is created with the specified name, encryption type (using the KMS key), shard-level metrics, shard count (if the stream mode is not "ON\_DEMAND"), and stream mode.
|
||||
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.7 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.29.0 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.51.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_iam_policy.fleet_kinesis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_iam_role.fleet_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
|
||||
| [aws_iam_role_policy_attachment.fleet_kinesis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
|
||||
| [aws_kinesis_stream.fleet_log_destination](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_stream) | resource |
|
||||
| [aws_kms_key.kinesis_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
|
||||
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.kinesis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_fleet_iam_role_arn"></a> [fleet\_iam\_role\_arn](#input\_fleet\_iam\_role\_arn) | The ARN of the IAM role that will be assuming into the IAM role defined in this module to gain permissions required to write to the Kinesis Data Stream(s). | `string` | n/a | yes |
|
||||
| <a name="input_log_destinations"></a> [log\_destinations](#input\_log\_destinations) | A map of configurations for Kinesis data streams. | <pre>map(object({<br> name = string<br> shard_count = number<br> stream_mode = string<br> retention_period = number<br> shard_level_metrics = list(string)<br> }))</pre> | <pre>{<br> "audit": {<br> "name": "fleet_audit",<br> "retention_period": 24,<br> "shard_count": 0,<br> "shard_level_metrics": [],<br> "stream_mode": "ON_DEMAND"<br> },<br> "results": {<br> "name": "osquery_results",<br> "retention_period": 24,<br> "shard_count": 0,<br> "shard_level_metrics": [],<br> "stream_mode": "ON_DEMAND"<br> },<br> "status": {<br> "name": "osquery_status",<br> "retention_period": 24,<br> "shard_count": 0,<br> "shard_level_metrics": [],<br> "stream_mode": "ON_DEMAND"<br> }<br>}</pre> | no |
|
||||
| <a name="input_sts_external_id"></a> [sts\_external\_id](#input\_sts\_external\_id) | Optional unique identifier that can be used by the principal assuming the role to assert its identity. | `string` | `""` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_kinesis_iam_role"></a> [kinesis\_iam\_role](#output\_kinesis\_iam\_role) | n/a |
|
||||
| <a name="output_kinesis_streams"></a> [kinesis\_streams](#output\_kinesis\_streams) | A map of Kinesis streams with their names and ARNs. |
|
||||
@@ -0,0 +1,57 @@
|
||||
resource "aws_iam_role" "fleet_role" {
|
||||
assume_role_policy = data.aws_iam_policy_document.assume_role.json
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "assume_role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
principals {
|
||||
identifiers = [var.fleet_iam_role_arn]
|
||||
type = "AWS"
|
||||
}
|
||||
dynamic "condition" {
|
||||
for_each = length(var.sts_external_id) > 0 ? [1] : []
|
||||
content {
|
||||
test = "StringEquals"
|
||||
variable = "sts:ExternalId"
|
||||
values = [var.sts_external_id]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "kinesis" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = [
|
||||
"kinesis:DescribeStreamSummary",
|
||||
"kinesis:DescribeStream",
|
||||
"kinesis:PutRecord",
|
||||
"kinesis:PutRecords"
|
||||
]
|
||||
resources = [
|
||||
for stream in aws_kinesis_stream.fleet_log_destination : stream.arn
|
||||
]
|
||||
}
|
||||
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = [
|
||||
"kms:Decrypt",
|
||||
"kms:GenerateDataKey",
|
||||
]
|
||||
resources = [
|
||||
aws_kms_key.kinesis_key.arn
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "fleet_kinesis" {
|
||||
policy = data.aws_iam_policy_document.kinesis.json
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "fleet_kinesis" {
|
||||
policy_arn = aws_iam_policy.fleet_kinesis.arn
|
||||
role = aws_iam_role.fleet_role.name
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
resource "aws_kms_key" "kinesis_key" {
|
||||
description = "KMS key for encrypting Kinesis Data Streams for Fleet logging destinations."
|
||||
}
|
||||
|
||||
resource "aws_kinesis_stream" "fleet_log_destination" {
|
||||
for_each = var.log_destinations
|
||||
name = each.value.name
|
||||
encryption_type = "KMS"
|
||||
kms_key_id = aws_kms_key.kinesis_key.id
|
||||
shard_level_metrics = each.value.shard_level_metrics
|
||||
shard_count = each.value.stream_mode == "ON_DEMAND" ? null : each.value.shard_count
|
||||
stream_mode_details {
|
||||
stream_mode = each.value.stream_mode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
output "kinesis_iam_role" {
|
||||
value = aws_iam_role.fleet_role.arn
|
||||
}
|
||||
|
||||
output "kinesis_streams" {
|
||||
description = "A map of Kinesis streams with their names and ARNs."
|
||||
value = {
|
||||
for k, stream in aws_kinesis_stream.fleet_log_destination : k => {
|
||||
stream_name = stream.name
|
||||
stream_arn = stream.arn
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
variable "fleet_iam_role_arn" {
|
||||
type = string
|
||||
description = "The ARN of the IAM role that will be assuming into the IAM role defined in this module to gain permissions required to write to the Kinesis Data Stream(s)."
|
||||
}
|
||||
|
||||
variable "sts_external_id" {
|
||||
type = string
|
||||
description = "Optional unique identifier that can be used by the principal assuming the role to assert its identity."
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "log_destinations" {
|
||||
description = "A map of configurations for Kinesis data streams."
|
||||
type = map(object({
|
||||
name = string
|
||||
shard_count = number
|
||||
stream_mode = string
|
||||
retention_period = number
|
||||
shard_level_metrics = list(string)
|
||||
}))
|
||||
default = {
|
||||
results = {
|
||||
name = "osquery_results"
|
||||
shard_count = 0
|
||||
stream_mode = "ON_DEMAND"
|
||||
retention_period = 24
|
||||
shard_level_metrics = []
|
||||
},
|
||||
status = {
|
||||
name = "osquery_status"
|
||||
shard_count = 0
|
||||
stream_mode = "ON_DEMAND"
|
||||
retention_period = 24
|
||||
shard_level_metrics = []
|
||||
},
|
||||
audit = {
|
||||
name = "fleet_audit"
|
||||
shard_count = 0
|
||||
stream_mode = "ON_DEMAND"
|
||||
retention_period = 24
|
||||
shard_level_metrics = []
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">= 1.3.7"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 5.29.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# External Vulnerability Scans addon
|
||||
This addon creates an additional ECS service that only runs a single task, responsible for vuln processing. It receives
|
||||
no web traffic. We utilize [current instance checks](https://fleetdm.com/docs/configuration/fleet-server-configuration#current-instance-checks) to make this happen. The advantages of this mechanism:
|
||||
|
||||
1. dedicating processing power to vuln processing
|
||||
2. ensures task responsible for vuln processing isn't also trying to serve web traffic
|
||||
2. caching of vulnerability artifacts/dependencies
|
||||
|
||||
|
||||
Usage is simplified by using the output from the fleet byo-ecs module (../terraform/byo-vpc/byo-db/byo-ecs/README.md)
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,57 @@
|
||||
# External Vulnerability Scans addon
|
||||
This addon creates an additional ECS service that only runs a single task, responsible for vuln processing. It receives
|
||||
no web traffic. We utilize [current instance checks](https://fleetdm.com/docs/configuration/fleet-server-configuration#current-instance-checks) to make this happen. The advantages of this mechanism:
|
||||
|
||||
1. dedicating processing power to vuln processing
|
||||
2. ensures task responsible for vuln processing isn't also trying to serve web traffic
|
||||
2. caching of vulnerability artifacts/dependencies
|
||||
|
||||
Usage is simplified by using the output from the fleet byo-ecs module (../terraform/byo-vpc/byo-db/byo-ecs/README.md)
|
||||
|
||||
## Requirements
|
||||
|
||||
No requirements.
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.11.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_ecs_service.fleet](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_service) | resource |
|
||||
| [aws_ecs_task_definition.vuln-processing](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition) | resource |
|
||||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_awslogs_config"></a> [awslogs\_config](#input\_awslogs\_config) | n/a | <pre>object({<br> group = string<br> region = string<br> prefix = string<br> })</pre> | n/a | yes |
|
||||
| <a name="input_customer_prefix"></a> [customer\_prefix](#input\_customer\_prefix) | n/a | `string` | `"fleet"` | no |
|
||||
| <a name="input_ecs_cluster"></a> [ecs\_cluster](#input\_ecs\_cluster) | The ecs cluster module that is created by the byo-db module | `any` | n/a | yes |
|
||||
| <a name="input_execution_iam_role_arn"></a> [execution\_iam\_role\_arn](#input\_execution\_iam\_role\_arn) | The ARN of the fleet execution role, this is necessary to pass role from ecs events | `any` | n/a | yes |
|
||||
| <a name="input_fleet_config"></a> [fleet\_config](#input\_fleet\_config) | The root Fleet config object | `any` | n/a | yes |
|
||||
| <a name="input_fleet_s3_software_installers_config"></a> [fleet\_s3\_software\_installers\_config](#input\_fleet\_s3\_software\_installers\_config) | use the output of the byo-vpc module with the same name | `map(string)` | n/a | yes |
|
||||
| <a name="input_fleet_server_private_key_secret_arn"></a> [fleet\_server\_private\_key\_secret\_arn](#input\_fleet\_server\_private\_key\_secret\_arn) | The ARN of the secret that stores the Fleet private key | `string` | n/a | yes |
|
||||
| <a name="input_security_groups"></a> [security\_groups](#input\_security\_groups) | n/a | `list(string)` | n/a | yes |
|
||||
| <a name="input_subnets"></a> [subnets](#input\_subnets) | n/a | `list(string)` | n/a | yes |
|
||||
| <a name="input_task_role_arn"></a> [task\_role\_arn](#input\_task\_role\_arn) | The ARN of the fleet task role, this is necessary to pass role from ecs events | `any` | n/a | yes |
|
||||
| <a name="input_vuln_processing_cpu"></a> [vuln\_processing\_cpu](#input\_vuln\_processing\_cpu) | The amount of CPU to dedicate to the vuln processing command | `number` | `1024` | no |
|
||||
| <a name="input_vuln_processing_memory"></a> [vuln\_processing\_memory](#input\_vuln\_processing\_memory) | The amount of memory to dedicate to the vuln processing command | `number` | `4096` | no |
|
||||
| <a name="input_vuln_processing_task_cpu"></a> [vuln\_processing\_task\_cpu](#input\_vuln\_processing\_task\_cpu) | The amount of CPU to dedicate to the vuln processing task including sidecars | `number` | `1024` | no |
|
||||
| <a name="input_vuln_processing_task_memory"></a> [vuln\_processing\_task\_memory](#input\_vuln\_processing\_task\_memory) | The amount of memory to dedicate to the vuln processing task including sidecars | `number` | `4096` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_extra_environment_variables"></a> [extra\_environment\_variables](#output\_extra\_environment\_variables) | n/a |
|
||||
| <a name="output_vuln_service_arn"></a> [vuln\_service\_arn](#output\_vuln\_service\_arn) | n/a |
|
||||
@@ -0,0 +1,137 @@
|
||||
data "aws_region" "current" {}
|
||||
|
||||
locals {
|
||||
environment = [
|
||||
// specifically overriding disable schedule here because the output of this module sets this to true
|
||||
// and then we pull in the output of fleet ecs module
|
||||
for k, v in merge(
|
||||
var.fleet_config.extra_environment_variables,
|
||||
{ FLEET_VULNERABILITIES_DISABLE_SCHEDULE = "false" }
|
||||
) : {
|
||||
name = k
|
||||
value = v
|
||||
}
|
||||
]
|
||||
secrets = [
|
||||
for k, v in merge(var.fleet_config.extra_secrets, {
|
||||
FLEET_MYSQL_PASSWORD = var.fleet_config.database.password_secret_arn
|
||||
FLEET_MYSQL_READ_REPLICA_PASSWORD = var.fleet_config.database.password_secret_arn
|
||||
FLEET_SERVER_PRIVATE_KEY = var.fleet_server_private_key_secret_arn
|
||||
}) : {
|
||||
name = k
|
||||
valueFrom = v
|
||||
}
|
||||
]
|
||||
repository_credentials = var.fleet_config.repository_credentials != "" ? {
|
||||
repositoryCredentials = {
|
||||
credentialsParameter = var.fleet_config.repository_credentials
|
||||
}
|
||||
} : null
|
||||
}
|
||||
|
||||
resource "aws_ecs_service" "fleet" {
|
||||
name = "${var.fleet_config.service.name}-vuln-processing"
|
||||
launch_type = "FARGATE"
|
||||
cluster = var.ecs_cluster
|
||||
task_definition = aws_ecs_task_definition.vuln-processing.arn
|
||||
desired_count = 1
|
||||
deployment_minimum_healthy_percent = 100
|
||||
deployment_maximum_percent = 200
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [desired_count]
|
||||
}
|
||||
|
||||
network_configuration {
|
||||
subnets = var.subnets
|
||||
security_groups = var.security_groups
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_ecs_task_definition" "vuln-processing" {
|
||||
family = "${var.fleet_config.family}-vuln-processing"
|
||||
cpu = var.vuln_processing_task_cpu
|
||||
memory = var.vuln_processing_task_memory
|
||||
execution_role_arn = var.execution_iam_role_arn
|
||||
task_role_arn = var.task_role_arn
|
||||
network_mode = "awsvpc"
|
||||
pid_mode = var.fleet_config.pid_mode
|
||||
requires_compatibilities = ["FARGATE"]
|
||||
|
||||
container_definitions = jsonencode(concat([
|
||||
{
|
||||
name = "fleet-vuln-processing"
|
||||
image = var.fleet_config.image
|
||||
cpu = var.vuln_processing_cpu
|
||||
memory = var.vuln_processing_memory
|
||||
essential = true
|
||||
networkMode = "awsvpc"
|
||||
secrets = local.secrets
|
||||
repositoryCredentials = local.repository_credentials
|
||||
ulimits = [
|
||||
{
|
||||
name = "nofile"
|
||||
softLimit = 999999
|
||||
hardLimit = 999999
|
||||
}
|
||||
],
|
||||
environment = concat([
|
||||
{
|
||||
name = "FLEET_MYSQL_USERNAME"
|
||||
value = var.fleet_config.database.user
|
||||
},
|
||||
{
|
||||
name = "FLEET_MYSQL_DATABASE"
|
||||
value = var.fleet_config.database.database
|
||||
},
|
||||
{
|
||||
name = "FLEET_MYSQL_ADDRESS"
|
||||
value = var.fleet_config.database.address
|
||||
},
|
||||
{
|
||||
name = "FLEET_MYSQL_READ_REPLICA_USERNAME"
|
||||
value = var.fleet_config.database.user
|
||||
},
|
||||
{
|
||||
name = "FLEET_MYSQL_READ_REPLICA_DATABASE"
|
||||
value = var.fleet_config.database.database
|
||||
},
|
||||
{
|
||||
name = "FLEET_MYSQL_READ_REPLICA_ADDRESS"
|
||||
value = var.fleet_config.database.rr_address == null ? var.fleet_config.database.address : var.fleet_config.database.rr_address
|
||||
},
|
||||
{
|
||||
name = "FLEET_REDIS_ADDRESS"
|
||||
value = var.fleet_config.redis.address
|
||||
},
|
||||
{
|
||||
name = "FLEET_REDIS_USE_TLS"
|
||||
value = tostring(var.fleet_config.redis.use_tls)
|
||||
},
|
||||
{
|
||||
name = "FLEET_SERVER_TLS"
|
||||
value = "false"
|
||||
},
|
||||
{
|
||||
name = "FLEET_S3_SOFTWARE_INSTALLERS_BUCKET"
|
||||
value = var.fleet_s3_software_installers_config.bucket_name
|
||||
},
|
||||
{
|
||||
name = "FLEET_S3_SOFTWARE_INSTALLERS_PREFIX"
|
||||
value = var.fleet_s3_software_installers_config.s3_object_prefix
|
||||
},
|
||||
], local.environment),
|
||||
logConfiguration = {
|
||||
logDriver = "awslogs"
|
||||
options = {
|
||||
awslogs-group = var.awslogs_config.group
|
||||
awslogs-region = var.awslogs_config.region == null ? data.aws_region.current.name : var.awslogs_config.region
|
||||
awslogs-stream-prefix = "${var.awslogs_config.prefix}-vuln-processing"
|
||||
}
|
||||
}
|
||||
}]
|
||||
, var.fleet_config.sidecars))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
output "extra_environment_variables" {
|
||||
value = {
|
||||
FLEET_VULNERABILITIES_DISABLE_SCHEDULE = "true"
|
||||
}
|
||||
}
|
||||
|
||||
output "vuln_service_arn" {
|
||||
value = aws_ecs_service.fleet.id
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
variable "ecs_cluster" {
|
||||
description = "The ecs cluster module that is created by the byo-db module"
|
||||
}
|
||||
|
||||
variable "fleet_config" {
|
||||
description = "The root Fleet config object"
|
||||
type = any
|
||||
}
|
||||
|
||||
variable "awslogs_config" {
|
||||
type = object({
|
||||
group = string
|
||||
region = string
|
||||
prefix = string
|
||||
})
|
||||
}
|
||||
|
||||
variable "subnets" {
|
||||
type = list(string)
|
||||
nullable = false
|
||||
}
|
||||
|
||||
variable "security_groups" {
|
||||
type = list(string)
|
||||
nullable = false
|
||||
}
|
||||
|
||||
|
||||
variable "customer_prefix" {
|
||||
type = string
|
||||
default = "fleet"
|
||||
}
|
||||
|
||||
variable "fleet_s3_software_installers_config" {
|
||||
type = map(string)
|
||||
description = "use the output of the byo-vpc module with the same name"
|
||||
}
|
||||
|
||||
variable "fleet_server_private_key_secret_arn" {
|
||||
type = string
|
||||
description = "The ARN of the secret that stores the Fleet private key"
|
||||
}
|
||||
|
||||
variable "execution_iam_role_arn" {
|
||||
description = "The ARN of the fleet execution role, this is necessary to pass role from ecs events"
|
||||
}
|
||||
|
||||
variable "task_role_arn" {
|
||||
description = "The ARN of the fleet task role, this is necessary to pass role from ecs events"
|
||||
}
|
||||
|
||||
variable "vuln_processing_task_memory" {
|
||||
// note must conform to FARGATE breakpoints https://docs.aws.amazon.com/AmazonECS/latest/userguide/fargate-task-defs.html
|
||||
default = 4096
|
||||
description = "The amount of memory to dedicate to the vuln processing task including sidecars"
|
||||
}
|
||||
|
||||
variable "vuln_processing_task_cpu" {
|
||||
// note must conform to FARGETE breakpoints https://docs.aws.amazon.com/AmazonECS/latest/userguide/fargate-task-defs.html
|
||||
default = 1024
|
||||
description = "The amount of CPU to dedicate to the vuln processing task including sidecars"
|
||||
}
|
||||
|
||||
|
||||
variable "vuln_processing_memory" {
|
||||
// note must conform to FARGATE breakpoints https://docs.aws.amazon.com/AmazonECS/latest/userguide/fargate-task-defs.html
|
||||
default = 4096
|
||||
description = "The amount of memory to dedicate to the vuln processing command"
|
||||
}
|
||||
|
||||
variable "vuln_processing_cpu" {
|
||||
// note must conform to FARGETE breakpoints https://docs.aws.amazon.com/AmazonECS/latest/userguide/fargate-task-defs.html
|
||||
default = 1024
|
||||
description = "The amount of CPU to dedicate to the vuln processing command"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# Geoip Terraform module for Fleet
|
||||
|
||||
This module adds Geoip data to the Fleet docker image for use with the Fleet Terraform module.
|
||||
|
||||
See the [documentation](https://fleetdm.com/docs/configuration/fleet-server-configuration#geoip) for some basic information about what happens under the hood.
|
||||
|
||||
You will need to supply a Maxmind license key and a destination docker registry (such as ECR) to hold the new image.
|
||||
|
||||
Outputs will be added to the environment variables in Fleet via the `extra_environment_variables` list.
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,15 @@
|
||||
ARG FLEET_IMAGE
|
||||
|
||||
FROM ${FLEET_IMAGE}
|
||||
|
||||
ARG LICENSE_KEY
|
||||
USER root
|
||||
|
||||
RUN wget "https://github.com/osquery/osquery/releases/download/5.12.2/osquery-5.12.2_1.linux_x86_64.tar.gz" -O /tmp/osquery.tar.gz &&\
|
||||
[ "101b61d760d530be9e41165c858d40353e03412676824b9fb6847a9febaab853" == "$(sha256sum /tmp/osquery.tar.gz | awk '{ print $1 }')" ] &&\
|
||||
tar -xzvf /tmp/osquery.tar.gz -C / &&\
|
||||
rm /tmp/osquery.tar.gz
|
||||
|
||||
USER fleet
|
||||
# Might not be needed again, but keep it just in case
|
||||
CMD ["fleet", "serve"]
|
||||
@@ -0,0 +1,48 @@
|
||||
# Geoip Terraform module for Fleet
|
||||
|
||||
This module adds Geoip data to the Fleet docker image for use with the Fleet Terraform module.
|
||||
|
||||
See the [documentation](https://fleetdm.com/docs/configuration/fleet-server-configuration#geoip) for some basic information about what happens under the hood.
|
||||
|
||||
You will need to supply a Maxmind license key and a destination docker registry (such as ECR) to hold the new image.
|
||||
|
||||
Outputs will be added to the environment variables in Fleet via the `extra_environment_variables` list.
|
||||
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_docker"></a> [docker](#requirement\_docker) | 3.0.2 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_docker"></a> [docker](#provider\_docker) | 3.0.2 |
|
||||
| <a name="provider_local"></a> [local](#provider\_local) | 2.4.1 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [docker_image.maxmind_fleet](https://registry.terraform.io/providers/kreuzwerker/docker/3.0.2/docs/resources/image) | resource |
|
||||
| [docker_registry_image.maxmind_fleet](https://registry.terraform.io/providers/kreuzwerker/docker/3.0.2/docs/resources/registry_image) | resource |
|
||||
| [local_file.dockerfile](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_destination_image"></a> [destination\_image](#input\_destination\_image) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_fleet_image"></a> [fleet\_image](#input\_fleet\_image) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_license_key"></a> [license\_key](#input\_license\_key) | n/a | `string` | n/a | yes |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_extra_environment_variables"></a> [extra\_environment\_variables](#output\_extra\_environment\_variables) | n/a |
|
||||
@@ -0,0 +1,9 @@
|
||||
# Geoip Terraform module for Fleet
|
||||
|
||||
This module adds Geoip data to the Fleet docker image for use with the Fleet Terraform module.
|
||||
|
||||
See the [documentation](https://fleetdm.com/docs/configuration/fleet-server-configuration#geoip) for some basic information about what happens under the hood.
|
||||
|
||||
You will need to supply a Maxmind license key and a destination docker registry (such as ECR) to hold the new image.
|
||||
|
||||
Outputs will be added to the environment variables in Fleet via the `extra_environment_variables` list.
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,17 @@
|
||||
ARG FLEET_IMAGE
|
||||
|
||||
FROM ${FLEET_IMAGE}
|
||||
|
||||
ARG LICENSE_KEY
|
||||
USER root
|
||||
|
||||
RUN mkdir -p /opt/GeoLite2 && cd /opt/GeoLite2 &&\
|
||||
wget --max-redirect 10 "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${LICENSE_KEY}&suffix=tar.gz" -O GeoLite2-City.tar.gz &&\
|
||||
wget --max-redirect 10 "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${LICENSE_KEY}&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256 &&\
|
||||
[ "$(awk '{ print $1 }' GeoLite2-City.tar.gz.sha256)" == "$(sha256sum GeoLite2-City.tar.gz | awk '{ print $1 }')" ] &&\
|
||||
(tar -xzvf GeoLite2-City.tar.gz "*/GeoLite2-City.mmdb" --strip-components 1 2>/dev/null || true) &&\
|
||||
rm -f GeoLite2-City.tar.gz*
|
||||
|
||||
USER fleet
|
||||
# Might not be needed again, but keep it just in case
|
||||
CMD ["fleet", "serve"]
|
||||
@@ -0,0 +1,48 @@
|
||||
# Geoip Terraform module for Fleet
|
||||
|
||||
This module adds Geoip data to the Fleet docker image for use with the Fleet Terraform module.
|
||||
|
||||
See the [documentation](https://fleetdm.com/docs/configuration/fleet-server-configuration#geoip) for some basic information about what happens under the hood.
|
||||
|
||||
You will need to supply a Maxmind license key and a destination docker registry (such as ECR) to hold the new image.
|
||||
|
||||
Outputs will be added to the environment variables in Fleet via the `extra_environment_variables` list.
|
||||
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_docker"></a> [docker](#requirement\_docker) | 3.0.2 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_docker"></a> [docker](#provider\_docker) | 3.0.2 |
|
||||
| <a name="provider_local"></a> [local](#provider\_local) | 2.4.1 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [docker_image.maxmind_fleet](https://registry.terraform.io/providers/kreuzwerker/docker/3.0.2/docs/resources/image) | resource |
|
||||
| [docker_registry_image.maxmind_fleet](https://registry.terraform.io/providers/kreuzwerker/docker/3.0.2/docs/resources/registry_image) | resource |
|
||||
| [local_file.dockerfile](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_destination_image"></a> [destination\_image](#input\_destination\_image) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_fleet_image"></a> [fleet\_image](#input\_fleet\_image) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_license_key"></a> [license\_key](#input\_license\_key) | n/a | `string` | n/a | yes |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_extra_environment_variables"></a> [extra\_environment\_variables](#output\_extra\_environment\_variables) | n/a |
|
||||
@@ -0,0 +1,32 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
docker = {
|
||||
source = "kreuzwerker/docker"
|
||||
version = "3.0.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Build the new image
|
||||
resource "docker_image" "maxmind_fleet" {
|
||||
name = var.destination_image
|
||||
|
||||
build {
|
||||
context = path.module
|
||||
platform = "linux/amd64"
|
||||
build_args = {
|
||||
FLEET_IMAGE = var.fleet_image
|
||||
LICENSE_KEY = var.license_key
|
||||
}
|
||||
pull_parent = true
|
||||
}
|
||||
}
|
||||
|
||||
# push it to the specified repo
|
||||
resource "docker_registry_image" "maxmind_fleet" {
|
||||
triggers = {
|
||||
fleet_digest = docker_image.maxmind_fleet.repo_digest
|
||||
}
|
||||
name = docker_image.maxmind_fleet.name
|
||||
keep_remotely = true
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
output "extra_environment_variables" {
|
||||
value = {
|
||||
FLEET_GEOIP_DATABASE_PATH = "/opt/GeoLite2/GeoLite2-City.mmdb"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
variable "fleet_image" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "destination_image" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "license_key" {
|
||||
type = string
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
docker = {
|
||||
source = "kreuzwerker/docker"
|
||||
version = "3.0.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Build the new image
|
||||
resource "docker_image" "maxmind_fleet" {
|
||||
name = var.destination_image
|
||||
|
||||
build {
|
||||
context = path.module
|
||||
platform = "linux/amd64"
|
||||
build_args = {
|
||||
FLEET_IMAGE = var.fleet_image
|
||||
LICENSE_KEY = var.license_key
|
||||
}
|
||||
pull_parent = true
|
||||
}
|
||||
}
|
||||
|
||||
# push it to the specified repo
|
||||
resource "docker_registry_image" "maxmind_fleet" {
|
||||
triggers = {
|
||||
fleet_digest = docker_image.maxmind_fleet.repo_digest
|
||||
}
|
||||
name = docker_image.maxmind_fleet.name
|
||||
keep_remotely = true
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
output "extra_environment_variables" {
|
||||
value = {
|
||||
FLEET_GEOIP_DATABASE_PATH = "/opt/GeoLite2/GeoLite2-City.mmdb"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
variable "fleet_image" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "destination_image" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "license_key" {
|
||||
type = string
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# Geoip Terraform module for Fleet
|
||||
|
||||
This module adds Geoip data to the Fleet docker image for use with the Fleet Terraform module.
|
||||
|
||||
See the [documentation](https://fleetdm.com/docs/configuration/fleet-server-configuration#geoip) for some basic information about what happens under the hood.
|
||||
|
||||
You will need to supply a Maxmind license key and a destination docker registry (such as ECR) to hold the new image.
|
||||
|
||||
Outputs will be added to the environment variables in Fleet via the `extra_environment_variables` list.
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,17 @@
|
||||
ARG FLEET_IMAGE
|
||||
|
||||
FROM ${FLEET_IMAGE}
|
||||
|
||||
ARG LICENSE_KEY
|
||||
USER root
|
||||
|
||||
RUN mkdir -p /opt/GeoLite2 && cd /opt/GeoLite2 &&\
|
||||
wget --max-redirect 10 "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${LICENSE_KEY}&suffix=tar.gz" -O GeoLite2-City.tar.gz &&\
|
||||
wget --max-redirect 10 "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${LICENSE_KEY}&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256 &&\
|
||||
[ "$(awk '{ print $1 }' GeoLite2-City.tar.gz.sha256)" == "$(sha256sum GeoLite2-City.tar.gz | awk '{ print $1 }')" ] &&\
|
||||
(tar -xzvf GeoLite2-City.tar.gz "*/GeoLite2-City.mmdb" --strip-components 1 2>/dev/null || true) &&\
|
||||
rm -f GeoLite2-City.tar.gz*
|
||||
|
||||
USER fleet
|
||||
# Might not be needed again, but keep it just in case
|
||||
CMD ["fleet", "serve"]
|
||||
@@ -0,0 +1,48 @@
|
||||
# Geoip Terraform module for Fleet
|
||||
|
||||
This module adds Geoip data to the Fleet docker image for use with the Fleet Terraform module.
|
||||
|
||||
See the [documentation](https://fleetdm.com/docs/configuration/fleet-server-configuration#geoip) for some basic information about what happens under the hood.
|
||||
|
||||
You will need to supply a Maxmind license key and a destination docker registry (such as ECR) to hold the new image.
|
||||
|
||||
Outputs will be added to the environment variables in Fleet via the `extra_environment_variables` list.
|
||||
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_docker"></a> [docker](#requirement\_docker) | 3.0.2 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_docker"></a> [docker](#provider\_docker) | 3.0.2 |
|
||||
| <a name="provider_local"></a> [local](#provider\_local) | 2.4.1 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [docker_image.maxmind_fleet](https://registry.terraform.io/providers/kreuzwerker/docker/3.0.2/docs/resources/image) | resource |
|
||||
| [docker_registry_image.maxmind_fleet](https://registry.terraform.io/providers/kreuzwerker/docker/3.0.2/docs/resources/registry_image) | resource |
|
||||
| [local_file.dockerfile](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_destination_image"></a> [destination\_image](#input\_destination\_image) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_fleet_image"></a> [fleet\_image](#input\_fleet\_image) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_license_key"></a> [license\_key](#input\_license\_key) | n/a | `string` | n/a | yes |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_extra_environment_variables"></a> [extra\_environment\_variables](#output\_extra\_environment\_variables) | n/a |
|
||||
@@ -0,0 +1,32 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
docker = {
|
||||
source = "kreuzwerker/docker"
|
||||
version = "3.0.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Build the new image
|
||||
resource "docker_image" "maxmind_fleet" {
|
||||
name = var.destination_image
|
||||
|
||||
build {
|
||||
context = path.module
|
||||
platform = "linux/amd64"
|
||||
build_args = {
|
||||
FLEET_IMAGE = var.fleet_image
|
||||
LICENSE_KEY = var.license_key
|
||||
}
|
||||
pull_parent = true
|
||||
}
|
||||
}
|
||||
|
||||
# push it to the specified repo
|
||||
resource "docker_registry_image" "maxmind_fleet" {
|
||||
triggers = {
|
||||
fleet_digest = docker_image.maxmind_fleet.repo_digest
|
||||
}
|
||||
name = docker_image.maxmind_fleet.name
|
||||
keep_remotely = true
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
output "extra_environment_variables" {
|
||||
value = {
|
||||
FLEET_GEOIP_DATABASE_PATH = "/opt/GeoLite2/GeoLite2-City.mmdb"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
variable "fleet_image" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "destination_image" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "license_key" {
|
||||
type = string
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
# ALB Logging Addon
|
||||
This addon creates alb logging bucket(s) in s3 and optionally an athena database for those logs.
|
||||
|
||||
# Example Configuration
|
||||
|
||||
This assumes your fleet module is `main` and is configured with it's default documentation.
|
||||
|
||||
See https://github.com/fleetdm/fleet/blob/main/terraform/example/main.tf for details.
|
||||
|
||||
```
|
||||
module "main" {
|
||||
source = "github.com/fleetdm/fleet-terraform/?ref=main"
|
||||
certificate_arn = module.acm.acm_certificate_arn
|
||||
vpc = {
|
||||
name = random_pet.main.id
|
||||
}
|
||||
fleet_config = {
|
||||
extra_environment_variables = module.firehose-logging.fleet_extra_environment_variables
|
||||
extra_iam_policies = module.firehose-logging.fleet_extra_iam_policies
|
||||
}
|
||||
alb_config = {
|
||||
access_logs = {
|
||||
bucket = module.logging_alb.log_s3_bucket_id
|
||||
prefix = "fleet"
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module "logging_alb" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/logging-alb?ref=main"
|
||||
prefix = "fleet"
|
||||
enable_athena = true
|
||||
}
|
||||
```
|
||||
|
||||
# Additional Information
|
||||
|
||||
Once this terraform is applied, the Athena table will need to be created. See https://docs.aws.amazon.com/athena/latest/ug/application-load-balancer-logs.html for help with creating the table.
|
||||
|
||||
For this implementation, the S3 pattern for the `CREATE TABLE` query should look like this:
|
||||
|
||||
```
|
||||
s3://your-alb-logs-bucket/<PREFIX>/AWSLogs/<ACCOUNT-ID>/elasticloadbalancing/<REGION>/
|
||||
```
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,96 @@
|
||||
# ALB Logging Addon
|
||||
This addon creates alb logging bucket(s) in s3 and optionally an athena database for those logs.
|
||||
|
||||
# Example Configuration
|
||||
|
||||
This assumes your fleet module is `main` and is configured with it's default documentation.
|
||||
|
||||
See https://github.com/fleetdm/fleet/blob/main/terraform/example/main.tf for details.
|
||||
|
||||
```
|
||||
module "main" {
|
||||
source = "github.com/fleetdm/fleet-terraform/?ref=main"
|
||||
certificate_arn = module.acm.acm_certificate_arn
|
||||
vpc = {
|
||||
name = random_pet.main.id
|
||||
}
|
||||
fleet_config = {
|
||||
extra_environment_variables = module.firehose-logging.fleet_extra_environment_variables
|
||||
extra_iam_policies = module.firehose-logging.fleet_extra_iam_policies
|
||||
}
|
||||
alb_config = {
|
||||
access_logs = {
|
||||
bucket = module.logging_alb.log_s3_bucket_id
|
||||
prefix = "fleet"
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module "logging_alb" {
|
||||
source = "github.com/fleetdm/fleet-terraform//addons/logging-alb?ref=main"
|
||||
prefix = "fleet"
|
||||
enable_athena = true
|
||||
}
|
||||
```
|
||||
|
||||
# Additional Information
|
||||
|
||||
Once this terraform is applied, the Athena table will need to be created. See https://docs.aws.amazon.com/athena/latest/ug/application-load-balancer-logs.html for help with creating the table.
|
||||
|
||||
For this implementation, the S3 pattern for the `CREATE TABLE` query should look like this:
|
||||
|
||||
```
|
||||
s3://your-alb-logs-bucket/<PREFIX>/AWSLogs/<ACCOUNT-ID>/elasticloadbalancing/<REGION>/
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
No requirements.
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.25.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
| Name | Source | Version |
|
||||
|------|--------|---------|
|
||||
| <a name="module_athena-s3-bucket"></a> [athena-s3-bucket](#module\_athena-s3-bucket) | terraform-aws-modules/s3-bucket/aws | 3.15.1 |
|
||||
| <a name="module_s3_bucket_for_logs"></a> [s3\_bucket\_for\_logs](#module\_s3\_bucket\_for\_logs) | terraform-aws-modules/s3-bucket/aws | 3.15.1 |
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_athena_database.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/athena_database) | resource |
|
||||
| [aws_athena_workgroup.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/athena_workgroup) | resource |
|
||||
| [aws_kms_alias.logs_alias](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_alias) | resource |
|
||||
| [aws_kms_key.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
|
||||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
|
||||
| [aws_iam_policy_document.kms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.s3_athena_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.s3_log_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_enable_athena"></a> [enable\_athena](#input\_enable\_athena) | n/a | `bool` | `true` | no |
|
||||
| <a name="input_extra_kms_policies"></a> [extra\_kms\_policies](#input\_extra\_kms\_policies) | n/a | `list(any)` | `[]` | no |
|
||||
| <a name="input_extra_s3_athena_policies"></a> [extra\_s3\_athena\_policies](#input\_extra\_s3\_athena\_policies) | n/a | `list(any)` | `[]` | no |
|
||||
| <a name="input_extra_s3_log_policies"></a> [extra\_s3\_log\_policies](#input\_extra\_s3\_log\_policies) | n/a | `list(any)` | `[]` | no |
|
||||
| <a name="input_prefix"></a> [prefix](#input\_prefix) | n/a | `string` | `"fleet"` | no |
|
||||
| <a name="input_s3_expiration_days"></a> [s3\_expiration\_days](#input\_s3\_expiration\_days) | n/a | `number` | `90` | no |
|
||||
| <a name="input_s3_newer_noncurrent_versions"></a> [s3\_newer\_noncurrent\_versions](#input\_s3\_newer\_noncurrent\_versions) | n/a | `number` | `5` | no |
|
||||
| <a name="input_s3_noncurrent_version_expiration_days"></a> [s3\_noncurrent\_version\_expiration\_days](#input\_s3\_noncurrent\_version\_expiration\_days) | n/a | `number` | `30` | no |
|
||||
| <a name="input_s3_transition_days"></a> [s3\_transition\_days](#input\_s3\_transition\_days) | n/a | `number` | `30` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_log_s3_bucket_id"></a> [log\_s3\_bucket\_id](#output\_log\_s3\_bucket\_id) | n/a |
|
||||
@@ -0,0 +1,255 @@
|
||||
data "aws_caller_identity" "current" {}
|
||||
|
||||
data "aws_region" "current" {}
|
||||
|
||||
locals {
|
||||
|
||||
kms_policies = concat([{
|
||||
actions = ["kms:*"],
|
||||
principals = [{
|
||||
type = "AWS"
|
||||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
|
||||
}]
|
||||
resources = ["*"]
|
||||
|
||||
},
|
||||
{
|
||||
actions = [
|
||||
"kms:Encrypt*",
|
||||
"kms:Decrypt*",
|
||||
"kms:ReEncrypt*",
|
||||
"kms:GenerateDataKey*",
|
||||
"kms:Describe*",
|
||||
]
|
||||
resources = ["*"]
|
||||
principals = [{
|
||||
type = "Service"
|
||||
identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"]
|
||||
}]
|
||||
}], var.extra_kms_policies)
|
||||
|
||||
}
|
||||
|
||||
|
||||
data "aws_iam_policy_document" "kms" {
|
||||
dynamic "statement" {
|
||||
for_each = local.kms_policies
|
||||
content {
|
||||
sid = try(statement.value.sid, "")
|
||||
actions = try(statement.value.actions, [])
|
||||
resources = try(statement.value.resources, [])
|
||||
effect = try(statement.value.effect, null)
|
||||
dynamic "principals" {
|
||||
for_each = try(statement.value.principals, [])
|
||||
content {
|
||||
type = principals.value.type
|
||||
identifiers = principals.value.identifiers
|
||||
}
|
||||
}
|
||||
dynamic "condition" {
|
||||
for_each = try(statement.value.conditions, [])
|
||||
content {
|
||||
test = condition.value.test
|
||||
variable = condition.value.variable
|
||||
values = condition.value.values
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "s3_log_bucket" {
|
||||
count = var.extra_s3_log_policies == [] ? 0 : 1
|
||||
dynamic "statement" {
|
||||
for_each = var.extra_s3_log_policies
|
||||
content {
|
||||
sid = try(statement.value.sid, "")
|
||||
actions = try(statement.value.actions, [])
|
||||
resources = try(statement.value.resources, [])
|
||||
effect = try(statement.value.effect, null)
|
||||
dynamic "principals" {
|
||||
for_each = try(statement.value.principals, [])
|
||||
content {
|
||||
type = principals.value.type
|
||||
identifiers = principals.value.identifiers
|
||||
}
|
||||
}
|
||||
dynamic "condition" {
|
||||
for_each = try(statement.value.conditions, [])
|
||||
content {
|
||||
test = condition.value.test
|
||||
variable = condition.value.variable
|
||||
values = condition.value.values
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "s3_athena_bucket" {
|
||||
count = var.extra_s3_athena_policies == [] ? 0 : 1
|
||||
dynamic "statement" {
|
||||
for_each = var.extra_s3_athena_policies
|
||||
content {
|
||||
sid = try(statement.value.sid, "")
|
||||
actions = try(statement.value.actions, [])
|
||||
resources = try(statement.value.resources, [])
|
||||
effect = try(statement.value.effect, null)
|
||||
dynamic "principals" {
|
||||
for_each = try(statement.value.principals, [])
|
||||
content {
|
||||
type = principals.value.type
|
||||
identifiers = principals.value.identifiers
|
||||
}
|
||||
}
|
||||
dynamic "condition" {
|
||||
for_each = try(statement.value.conditions, [])
|
||||
content {
|
||||
test = condition.value.test
|
||||
variable = condition.value.variable
|
||||
values = condition.value.values
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_kms_key" "logs" {
|
||||
policy = data.aws_iam_policy_document.kms.json
|
||||
enable_key_rotation = true
|
||||
}
|
||||
|
||||
resource "aws_kms_alias" "logs_alias" {
|
||||
name_prefix = "alias/${var.prefix}-logs"
|
||||
target_key_id = aws_kms_key.logs.id
|
||||
}
|
||||
|
||||
module "s3_bucket_for_logs" {
|
||||
source = "terraform-aws-modules/s3-bucket/aws"
|
||||
version = "3.15.1"
|
||||
|
||||
bucket = "${var.prefix}-alb-logs"
|
||||
|
||||
# Allow deletion of non-empty bucket
|
||||
force_destroy = true
|
||||
|
||||
attach_elb_log_delivery_policy = true # Required for ALB logs
|
||||
attach_lb_log_delivery_policy = true # Required for ALB/NLB logs
|
||||
attach_deny_insecure_transport_policy = true
|
||||
attach_require_latest_tls_policy = true
|
||||
attach_policy = var.extra_s3_log_policies != []
|
||||
policy = var.extra_s3_log_policies != [] ? data.aws_iam_policy_document.s3_log_bucket[0].json : null
|
||||
block_public_acls = true
|
||||
block_public_policy = true
|
||||
ignore_public_acls = true
|
||||
restrict_public_buckets = true
|
||||
server_side_encryption_configuration = {
|
||||
rule = {
|
||||
bucket_key_enabled = true
|
||||
apply_server_side_encryption_by_default = {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
}
|
||||
}
|
||||
lifecycle_rule = [
|
||||
{
|
||||
id = "log"
|
||||
enabled = true
|
||||
|
||||
transition = [
|
||||
{
|
||||
days = var.s3_transition_days
|
||||
storage_class = "ONEZONE_IA"
|
||||
}
|
||||
]
|
||||
expiration = {
|
||||
days = var.s3_expiration_days
|
||||
# Always resets to false anyhow showing terraform changes constantly
|
||||
expired_object_delete_marker = false
|
||||
}
|
||||
noncurrent_version_expiration = {
|
||||
newer_noncurrent_versions = var.s3_newer_noncurrent_versions
|
||||
days = var.s3_noncurrent_version_expiration_days
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
resource "aws_athena_database" "logs" {
|
||||
count = var.enable_athena == true ? 1 : 0
|
||||
name = replace("${var.prefix}-alb-logs", "-", "_")
|
||||
bucket = module.athena-s3-bucket[0].s3_bucket_id
|
||||
}
|
||||
|
||||
module "athena-s3-bucket" {
|
||||
count = var.enable_athena == true ? 1 : 0
|
||||
source = "terraform-aws-modules/s3-bucket/aws"
|
||||
version = "3.15.1"
|
||||
|
||||
bucket = "${var.prefix}-alb-logs-athena"
|
||||
|
||||
# Allow deletion of non-empty bucket
|
||||
force_destroy = true
|
||||
|
||||
attach_elb_log_delivery_policy = true # Required for ALB logs
|
||||
attach_lb_log_delivery_policy = true # Required for ALB/NLB logs
|
||||
attach_deny_insecure_transport_policy = true
|
||||
attach_require_latest_tls_policy = true
|
||||
attach_policy = var.extra_s3_athena_policies != []
|
||||
policy = var.extra_s3_athena_policies != [] ? data.aws_iam_policy_document.s3_athena_bucket[0].json : null
|
||||
block_public_acls = true
|
||||
block_public_policy = true
|
||||
ignore_public_acls = true
|
||||
restrict_public_buckets = true
|
||||
server_side_encryption_configuration = {
|
||||
rule = {
|
||||
apply_server_side_encryption_by_default = {
|
||||
kms_master_key_id = aws_kms_key.logs.arn
|
||||
sse_algorithm = "aws:kms"
|
||||
}
|
||||
}
|
||||
}
|
||||
lifecycle_rule = [
|
||||
{
|
||||
id = "log"
|
||||
enabled = true
|
||||
|
||||
transition = [
|
||||
{
|
||||
days = var.s3_transition_days
|
||||
storage_class = "ONEZONE_IA"
|
||||
}
|
||||
]
|
||||
expiration = {
|
||||
days = var.s3_expiration_days
|
||||
# Always resets to false anyhow showing terraform changes constantly
|
||||
expired_object_delete_marker = false
|
||||
}
|
||||
noncurrent_version_expiration = {
|
||||
newer_noncurrent_versions = var.s3_newer_noncurrent_versions
|
||||
days = var.s3_noncurrent_version_expiration_days
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
resource "aws_athena_workgroup" "logs" {
|
||||
count = var.enable_athena == true ? 1 : 0
|
||||
name = "${var.prefix}-logs"
|
||||
|
||||
configuration {
|
||||
enforce_workgroup_configuration = true
|
||||
publish_cloudwatch_metrics_enabled = true
|
||||
|
||||
result_configuration {
|
||||
output_location = "s3://${module.athena-s3-bucket[0].s3_bucket_id}/output/"
|
||||
|
||||
encryption_configuration {
|
||||
encryption_option = "SSE_KMS"
|
||||
kms_key_arn = aws_kms_key.logs.arn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
force_destroy = true
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
output "log_s3_bucket_id" {
|
||||
value = module.s3_bucket_for_logs.s3_bucket_id
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
variable "prefix" {
|
||||
type = string
|
||||
default = "fleet"
|
||||
}
|
||||
|
||||
variable "enable_athena" {
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "s3_transition_days" {
|
||||
type = number
|
||||
default = 30
|
||||
}
|
||||
|
||||
variable "s3_expiration_days" {
|
||||
type = number
|
||||
default = 90
|
||||
}
|
||||
|
||||
variable "s3_newer_noncurrent_versions" {
|
||||
type = number
|
||||
default = 5
|
||||
}
|
||||
|
||||
variable "s3_noncurrent_version_expiration_days" {
|
||||
type = number
|
||||
default = 30
|
||||
}
|
||||
|
||||
variable "extra_kms_policies" {
|
||||
type = list(any)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "extra_s3_log_policies" {
|
||||
type = list(any)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "extra_s3_athena_policies" {
|
||||
type = list(any)
|
||||
default = []
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# Logging Destination: Firehose
|
||||
This addon provides a Kinesis Firehose logging destination for Fleet.
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,58 @@
|
||||
# Logging Destination: Firehose
|
||||
This addon provides a Kinesis Firehose logging destination for Fleet.
|
||||
|
||||
## Requirements
|
||||
|
||||
No requirements.
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.44.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [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-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-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.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.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.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.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.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.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 |
|
||||
| [aws_iam_policy_document.osquery_status_policy_doc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_compression_format"></a> [compression\_format](#input\_compression\_format) | n/a | `string` | `"UNCOMPRESSED"` | no |
|
||||
| <a name="input_osquery_results_s3_bucket"></a> [osquery\_results\_s3\_bucket](#input\_osquery\_results\_s3\_bucket) | n/a | <pre>object({<br> name = optional(string, "fleet-osquery-results-archive")<br> expires_days = optional(number, 1)<br> })</pre> | <pre>{<br> "expires_days": 1,<br> "name": "fleet-osquery-results-archive"<br>}</pre> | no |
|
||||
| <a name="input_osquery_status_s3_bucket"></a> [osquery\_status\_s3\_bucket](#input\_osquery\_status\_s3\_bucket) | n/a | <pre>object({<br> name = optional(string, "fleet-osquery-status-archive")<br> expires_days = optional(number, 1)<br> })</pre> | <pre>{<br> "expires_days": 1,<br> "name": "fleet-osquery-status-archive"<br>}</pre> | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_fleet_extra_environment_variables"></a> [fleet\_extra\_environment\_variables](#output\_fleet\_extra\_environment\_variables) | n/a |
|
||||
| <a name="output_fleet_extra_iam_policies"></a> [fleet\_extra\_iam\_policies](#output\_fleet\_extra\_iam\_policies) | n/a |
|
||||
@@ -0,0 +1,185 @@
|
||||
// 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
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_lifecycle_configuration" "osquery-results" {
|
||||
bucket = aws_s3_bucket.osquery-results.bucket
|
||||
rule {
|
||||
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
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_lifecycle_configuration" "osquery-status" {
|
||||
bucket = aws_s3_bucket.osquery-status.bucket
|
||||
rule {
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "firehose-results" {
|
||||
name = "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"
|
||||
policy = data.aws_iam_policy_document.osquery_status_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_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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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_OSQUERY_STATUS_LOG_PLUGIN = "firehose"
|
||||
FLEET_OSQUERY_RESULT_LOG_PLUGIN = "firehose"
|
||||
}
|
||||
}
|
||||
|
||||
output "fleet_extra_iam_policies" {
|
||||
value = [
|
||||
aws_iam_policy.firehose-logging.arn
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
variable "osquery_results_s3_bucket" {
|
||||
type = object({
|
||||
name = optional(string, "fleet-osquery-results-archive")
|
||||
expires_days = optional(number, 1)
|
||||
})
|
||||
default = {
|
||||
name = "fleet-osquery-results-archive"
|
||||
expires_days = 1
|
||||
}
|
||||
}
|
||||
|
||||
variable "osquery_status_s3_bucket" {
|
||||
type = object({
|
||||
name = optional(string, "fleet-osquery-status-archive")
|
||||
expires_days = optional(number, 1)
|
||||
})
|
||||
default = {
|
||||
name = "fleet-osquery-status-archive"
|
||||
expires_days = 1
|
||||
}
|
||||
}
|
||||
|
||||
variable "compression_format" {
|
||||
default = "UNCOMPRESSED"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
# MDM addon
|
||||
|
||||
Notice: Previous versions of this module referred to `dep`, but to reduce confusion that has been replaces with `abm`
|
||||
to mach the change to the newer Apple Busines Manager. For each key/value pair below, the key names have been changed
|
||||
from previous version to match the name of the env var for easier usability. Older unused env vars were also removed
|
||||
for simplification. This includes removing the need for `extra_environment_variables` completely.
|
||||
|
||||
This addon enables MDM functionality for Fleet. It does this via several secrets in AWS that stores the necessary values.
|
||||
The following secrets are created:
|
||||
- abm
|
||||
- scep
|
||||
- apn
|
||||
|
||||
Note: ABM is optional. If Apple Business Manager (ABM) is not used, set the abm variable to `null` and it will be omitted.
|
||||
|
||||
Since this module cannot determine the value for the secrets at apply time, this module must be applied in 2 phases:
|
||||
|
||||
1. In the first phase, just add the module without passing additional config to the main Fleet module
|
||||
1. In the second phase, after the secret values have been populated, apply while also passing the additional config to the main Fleet module.
|
||||
|
||||
The secrets should have the following layouts, note that all values are strings. If a value is a JSON object, string escape it.:
|
||||
## ABM
|
||||
```
|
||||
{
|
||||
"FLEET_MDM_APPLE_BM_CERT_BYTES": <ABM cert>,
|
||||
"FLEET_MDM_APPLE_BM_KEY_BYTES": <ABM key>,
|
||||
"FLEET_MDM_APPLE_BM_SERVER_TOKEN_BYTES": <ABM p7m token>
|
||||
}
|
||||
```
|
||||
|
||||
## SCEP
|
||||
```
|
||||
{
|
||||
"FLEET_MDM_APPLE_SCEP_CERT_BYTES": <SCEP cert>,
|
||||
"FLEET_MDM_APPLE_SCEP_KEY_BYTES": <SCEP key>,
|
||||
"FLEET_MDM_APPLE_SCEP_CHALLENGE": <SCEP challenge>
|
||||
}
|
||||
```
|
||||
|
||||
Please note that for Windows, the same SCEP cert is used and the cert+key above will populate the following environment variables:
|
||||
```
|
||||
"FLEET_MDM_WINDOWS_WSTEP_IDENTITY_CERT_BYTES"
|
||||
"FLEET_MDM_WINDOWS_WSTEP_IDENTITY_KEY_BYTES"
|
||||
```
|
||||
## APN
|
||||
```
|
||||
{
|
||||
"FLEET_MDM_APPLE_APNS_CERT_BYTES": <APNS cert>,
|
||||
"FLEET_MDM_APPLE_APNS_KEY_BYTES ": <APNS key>
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,97 @@
|
||||
# MDM addon
|
||||
|
||||
Notice: Previous versions of this module referred to `dep`, but to reduce confusion that has been replaces with `abm`
|
||||
to mach the change to the newer Apple Business Manager. For each key/value pair below, the key names have been changed
|
||||
from previous version to match the name of the env var for easier usability. Older unused env vars were also removed
|
||||
for simplification. This includes removing the need for `extra_environment_variables` completely.
|
||||
|
||||
This addon enables MDM functionality for Fleet. It does this via several secrets in AWS that stores the necessary values.
|
||||
The following secrets are created:
|
||||
- abm
|
||||
- scep
|
||||
- apn
|
||||
|
||||
Note: ABM is optional. If Apple Business Manager (ABM) is not used, set the abm variable to `null` and it will be omitted.
|
||||
|
||||
Since this module cannot determine the value for the secrets at apply time, this module must be applied in 2 phases:
|
||||
|
||||
1. In the first phase, just add the module without passing additional config to the main Fleet module
|
||||
1. In the second phase, after the secret values have been populated, apply while also passing the additional config to the main Fleet module.
|
||||
|
||||
The secrets should have the following layouts, note that all values are strings. If a value is a JSON object, string escape it.:
|
||||
## ABM
|
||||
```
|
||||
{
|
||||
"FLEET_MDM_APPLE_BM_CERT_BYTES": <ABM cert>,
|
||||
"FLEET_MDM_APPLE_BM_KEY_BYTES": <ABM key>,
|
||||
"FLEET_MDM_APPLE_BM_SERVER_TOKEN_BYTES": <ABM p7m token>
|
||||
}
|
||||
```
|
||||
|
||||
## SCEP
|
||||
```
|
||||
{
|
||||
"FLEET_MDM_APPLE_SCEP_CERT_BYTES": <SCEP cert>,
|
||||
"FLEET_MDM_APPLE_SCEP_KEY_BYTES": <SCEP key>,
|
||||
"FLEET_MDM_APPLE_SCEP_CHALLENGE": <SCEP challenge>
|
||||
}
|
||||
```
|
||||
|
||||
Please note that for Windows, the same SCEP cert is used and the cert+key above will populate the following environment variables:
|
||||
```
|
||||
"FLEET_MDM_WINDOWS_WSTEP_IDENTITY_CERT_BYTES"
|
||||
"FLEET_MDM_WINDOWS_WSTEP_IDENTITY_KEY_BYTES"
|
||||
```
|
||||
## APN
|
||||
```
|
||||
{
|
||||
"FLEET_MDM_APPLE_APNS_CERT_BYTES": <APNS cert>,
|
||||
"FLEET_MDM_APPLE_APNS_KEY_BYTES ": <APNS key>
|
||||
}
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
No requirements.
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.53.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_iam_policy.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
|
||||
| [aws_secretsmanager_secret.abm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
|
||||
| [aws_secretsmanager_secret.apn](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
|
||||
| [aws_secretsmanager_secret.scep](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
|
||||
| [aws_iam_policy_document.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_abm_secret_name"></a> [abm\_secret\_name](#input\_abm\_secret\_name) | n/a | `string` | `"fleet-abm"` | no |
|
||||
| <a name="input_apn_secret_name"></a> [apn\_secret\_name](#input\_apn\_secret\_name) | n/a | `string` | `"fleet-apn"` | no |
|
||||
| <a name="input_enable_apple_mdm"></a> [enable\_apple\_mdm](#input\_enable\_apple\_mdm) | n/a | `bool` | `true` | no |
|
||||
| <a name="input_enable_windows_mdm"></a> [enable\_windows\_mdm](#input\_enable\_windows\_mdm) | n/a | `bool` | `false` | no |
|
||||
| <a name="input_public_domain_name"></a> [public\_domain\_name](#input\_public\_domain\_name) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_scep_secret_name"></a> [scep\_secret\_name](#input\_scep\_secret\_name) | n/a | `string` | `"fleet-scep"` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_abm"></a> [abm](#output\_abm) | n/a |
|
||||
| <a name="output_apn"></a> [apn](#output\_apn) | n/a |
|
||||
| <a name="output_extra_execution_iam_policies"></a> [extra\_execution\_iam\_policies](#output\_extra\_execution\_iam\_policies) | n/a |
|
||||
| <a name="output_extra_secrets"></a> [extra\_secrets](#output\_extra\_secrets) | n/a |
|
||||
| <a name="output_scep"></a> [scep](#output\_scep) | n/a |
|
||||
@@ -0,0 +1,43 @@
|
||||
data "aws_region" "current" {}
|
||||
|
||||
resource "aws_secretsmanager_secret" "apn" {
|
||||
count = var.apn_secret_name == null ? 0 : 1
|
||||
name = var.apn_secret_name
|
||||
|
||||
recovery_window_in_days = "0"
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_secretsmanager_secret" "scep" {
|
||||
name = var.scep_secret_name
|
||||
|
||||
recovery_window_in_days = "0"
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_secretsmanager_secret" "abm" {
|
||||
count = var.abm_secret_name == null ? 0 : 1
|
||||
name = var.abm_secret_name
|
||||
|
||||
recovery_window_in_days = "0"
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "main" {
|
||||
statement {
|
||||
actions = ["secretsmanager:GetSecretValue"]
|
||||
resources = concat(var.enable_apple_mdm == false ? [] : [aws_secretsmanager_secret.apn[0].arn],
|
||||
[aws_secretsmanager_secret.scep.arn],
|
||||
var.abm_secret_name == null ? [] : [aws_secretsmanager_secret.abm[0].arn])
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "main" {
|
||||
policy = data.aws_iam_policy_document.main.json
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
output "extra_secrets" {
|
||||
value = merge(var.enable_apple_mdm == false ? {} : {
|
||||
FLEET_MDM_APPLE_SCEP_CERT_BYTES = "${aws_secretsmanager_secret.scep.arn}:FLEET_MDM_APPLE_SCEP_CERT_BYTES::"
|
||||
FLEET_MDM_APPLE_SCEP_KEY_BYTES = "${aws_secretsmanager_secret.scep.arn}:FLEET_MDM_APPLE_SCEP_KEY_BYTES::"
|
||||
FLEET_MDM_APPLE_SCEP_CHALLENGE = "${aws_secretsmanager_secret.scep.arn}:FLEET_MDM_APPLE_SCEP_CHALLENGE::"
|
||||
FLEET_MDM_APPLE_APNS_CERT_BYTES = "${aws_secretsmanager_secret.apn[0].arn}:FLEET_MDM_APPLE_APNS_CERT_BYTES::"
|
||||
FLEET_MDM_APPLE_APNS_KEY_BYTES = "${aws_secretsmanager_secret.apn[0].arn}:FLEET_MDM_APPLE_APNS_KEY_BYTES::"
|
||||
}, var.abm_secret_name == null || var.enable_apple_mdm == false ? {} : {
|
||||
FLEET_MDM_APPLE_BM_SERVER_TOKEN_BYTES = "${aws_secretsmanager_secret.abm[0].arn}:FLEET_MDM_APPLE_BM_SERVER_TOKEN_BYTES::"
|
||||
FLEET_MDM_APPLE_BM_CERT_BYTES = "${aws_secretsmanager_secret.abm[0].arn}:FLEET_MDM_APPLE_BM_CERT_BYTES::"
|
||||
FLEET_MDM_APPLE_BM_KEY_BYTES = "${aws_secretsmanager_secret.abm[0].arn}:FLEET_MDM_APPLE_BM_KEY_BYTES::"
|
||||
}, var.enable_windows_mdm == false ? {} : {
|
||||
FLEET_MDM_WINDOWS_WSTEP_IDENTITY_CERT_BYTES = "${aws_secretsmanager_secret.scep.arn}:FLEET_MDM_APPLE_SCEP_CERT_BYTES::"
|
||||
FLEET_MDM_WINDOWS_WSTEP_IDENTITY_KEY_BYTES = "${aws_secretsmanager_secret.scep.arn}:FLEET_MDM_APPLE_SCEP_KEY_BYTES::"
|
||||
})
|
||||
}
|
||||
|
||||
output "extra_execution_iam_policies" {
|
||||
value = [
|
||||
aws_iam_policy.main.arn
|
||||
]
|
||||
}
|
||||
|
||||
output "scep" {
|
||||
value = aws_secretsmanager_secret.scep
|
||||
}
|
||||
|
||||
output "abm" {
|
||||
value = var.abm_secret_name == null ? null : aws_secretsmanager_secret.abm[0]
|
||||
}
|
||||
|
||||
output "apn" {
|
||||
value = var.enable_apple_mdm == false ? null : aws_secretsmanager_secret.apn[0]
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
variable "apn_secret_name" {
|
||||
default = "fleet-apn"
|
||||
nullable = true
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "scep_secret_name" {
|
||||
default = "fleet-scep"
|
||||
nullable = false
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "abm_secret_name" {
|
||||
default = "fleet-abm"
|
||||
nullable = true
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "enable_windows_mdm" {
|
||||
default = false
|
||||
nullable = false
|
||||
type = bool
|
||||
}
|
||||
|
||||
variable "enable_apple_mdm" {
|
||||
default = true
|
||||
nullable = false
|
||||
type = bool
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
data "aws_iam_policy_document" "mdmproxy" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["cloudwatch:PutMetricData"]
|
||||
resources = ["*"]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "assume_role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
principals {
|
||||
identifiers = ["ecs.amazonaws.com", "ecs-tasks.amazonaws.com"]
|
||||
type = "Service"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "mdm_execution" {
|
||||
// allow fleet application to obtain the database password from secrets manager
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["secretsmanager:GetSecretValue"]
|
||||
resources = [aws_secretsmanager_secret.mdmproxy.arn]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "execution_extras" {
|
||||
for_each = toset(var.config.extra_execution_iam_policies)
|
||||
policy_arn = each.value
|
||||
role = aws_iam_role.execution.name
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "execution" {
|
||||
name = var.config.iam.execution.policy_name
|
||||
description = "IAM policy that Fleet mdmproxy uses to define access to AWS resources"
|
||||
policy = data.aws_iam_policy_document.mdm_execution.json
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "execution" {
|
||||
policy_arn = aws_iam_policy.execution.arn
|
||||
role = aws_iam_role.execution.name
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "execution" {
|
||||
name = var.config.iam.execution.name
|
||||
description = "The execution role for the mdmproxy in ECS"
|
||||
assume_role_policy = data.aws_iam_policy_document.assume_role.json
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "role_attachment" {
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
|
||||
role = aws_iam_role.execution.name
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
data "aws_region" "current" {}
|
||||
|
||||
locals {
|
||||
mdmproxy_secrets = {
|
||||
MDMPROXY_AUTH_TOKEN = var.config.auth_token
|
||||
MDMPROXY_MIGRATE_UDIDS = join(" ", var.config.migrate_udids)
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "mdmproxy" {
|
||||
count = var.config.networking.security_groups == null ? 1 : 0
|
||||
name = var.config.networking.security_group_name
|
||||
description = "Fleet ECS Service Security Group"
|
||||
vpc_id = var.vpc_id
|
||||
egress {
|
||||
description = "Egress to all"
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
ipv6_cidr_blocks = ["::/0"]
|
||||
}
|
||||
ingress {
|
||||
description = "Ingress only on container port"
|
||||
from_port = 8080
|
||||
to_port = 8080
|
||||
protocol = "TCP"
|
||||
cidr_blocks = var.config.networking.ingress_sources.cidr_blocks
|
||||
ipv6_cidr_blocks = var.config.networking.ingress_sources.ipv6_cidr_blocks
|
||||
security_groups = concat(var.config.networking.ingress_sources.security_groups, [aws_security_group.alb.id])
|
||||
prefix_list_ids = var.config.networking.ingress_sources.prefix_list_ids
|
||||
}
|
||||
}
|
||||
|
||||
module "alb" {
|
||||
source = "terraform-aws-modules/alb/aws"
|
||||
version = "8.3.0"
|
||||
|
||||
name = var.alb_config.name
|
||||
|
||||
load_balancer_type = "application"
|
||||
|
||||
vpc_id = var.vpc_id
|
||||
subnets = var.alb_config.subnets
|
||||
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
|
||||
|
||||
target_groups = concat([
|
||||
{
|
||||
name = var.alb_config.name
|
||||
backend_protocol = "HTTP"
|
||||
backend_port = 80
|
||||
target_type = "ip"
|
||||
health_check = {
|
||||
path = "/healthz"
|
||||
matcher = "200"
|
||||
timeout = 10
|
||||
interval = 15
|
||||
healthy_threshold = 5
|
||||
unhealthy_threshold = 5
|
||||
}
|
||||
}
|
||||
], var.alb_config.extra_target_groups)
|
||||
|
||||
# Require TLS 1.2 as earlier versions are insecure
|
||||
listener_ssl_policy_default = var.alb_config.tls_policy
|
||||
|
||||
https_listeners = [
|
||||
{
|
||||
port = 443
|
||||
protocol = "HTTPS"
|
||||
certificate_arn = var.alb_config.certificate_arn
|
||||
target_group_index = 0
|
||||
}
|
||||
]
|
||||
|
||||
https_listener_rules = var.alb_config.https_listener_rules
|
||||
|
||||
http_tcp_listeners = [
|
||||
{
|
||||
port = 80
|
||||
protocol = "HTTP"
|
||||
action_type = "redirect"
|
||||
redirect = {
|
||||
port = "443"
|
||||
protocol = "HTTPS"
|
||||
status_code = "HTTP_301"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
resource "aws_security_group" "alb" {
|
||||
#checkov:skip=CKV2_AWS_5:False positive
|
||||
vpc_id = var.vpc_id
|
||||
description = "Fleet-mdmproxy ALB Security Group"
|
||||
ingress {
|
||||
description = "Ingress from all, its a public load balancer"
|
||||
from_port = 443
|
||||
to_port = 443
|
||||
protocol = "tcp"
|
||||
cidr_blocks = var.alb_config.allowed_cidrs
|
||||
ipv6_cidr_blocks = var.alb_config.allowed_ipv6_cidrs
|
||||
}
|
||||
|
||||
ingress {
|
||||
description = "For http to https redirect"
|
||||
from_port = 80
|
||||
to_port = 80
|
||||
protocol = "tcp"
|
||||
cidr_blocks = var.alb_config.allowed_cidrs
|
||||
ipv6_cidr_blocks = var.alb_config.allowed_ipv6_cidrs
|
||||
}
|
||||
|
||||
egress {
|
||||
description = "Egress to all"
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = var.alb_config.egress_cidrs
|
||||
ipv6_cidr_blocks = var.alb_config.egress_ipv6_cidrs
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_secretsmanager_secret" "mdmproxy" {
|
||||
name = "${var.customer_prefix}-mdmproxy"
|
||||
}
|
||||
|
||||
resource "aws_secretsmanager_secret_version" "mdmproxy" {
|
||||
secret_id = aws_secretsmanager_secret.mdmproxy.id
|
||||
secret_string = jsonencode(local.mdmproxy_secrets)
|
||||
}
|
||||
|
||||
resource "aws_ecs_service" "mdmproxy" {
|
||||
name = "${var.customer_prefix}-mdmproxy"
|
||||
launch_type = "FARGATE"
|
||||
cluster = var.ecs_cluster
|
||||
task_definition = aws_ecs_task_definition.mdmproxy.arn
|
||||
desired_count = var.config.desired_count
|
||||
deployment_minimum_healthy_percent = 100
|
||||
deployment_maximum_percent = 200
|
||||
force_new_deployment = true
|
||||
|
||||
triggers = {
|
||||
redeployment = md5(jsonencode(aws_secretsmanager_secret_version.mdmproxy.secret_string))
|
||||
}
|
||||
|
||||
load_balancer {
|
||||
target_group_arn = module.alb.target_group_arns[0]
|
||||
container_name = "mdmproxy"
|
||||
container_port = 8080
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [desired_count]
|
||||
}
|
||||
|
||||
network_configuration {
|
||||
subnets = var.config.networking.subnets
|
||||
security_groups = var.config.networking.security_groups == null ? aws_security_group.mdmproxy.*.id : var.config.networking.security_groups
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_ecs_task_definition" "mdmproxy" {
|
||||
family = "${var.customer_prefix}-mdmproxy"
|
||||
cpu = var.config.cpu
|
||||
memory = var.config.mem
|
||||
execution_role_arn = aws_iam_role.execution.arn
|
||||
network_mode = "awsvpc"
|
||||
requires_compatibilities = ["FARGATE"]
|
||||
|
||||
container_definitions = jsonencode([
|
||||
{
|
||||
name = "mdmproxy"
|
||||
image = var.config.image
|
||||
cpu = var.config.cpu
|
||||
memory = var.config.mem
|
||||
essential = true
|
||||
portMappings = [
|
||||
{
|
||||
# This port is the same that the contained application also uses
|
||||
containerPort = 8080
|
||||
protocol = "tcp"
|
||||
}
|
||||
]
|
||||
networkMode = "awsvpc"
|
||||
secrets = [
|
||||
{
|
||||
name = "MDMPROXY_AUTH_TOKEN"
|
||||
valueFrom = "${aws_secretsmanager_secret.mdmproxy.arn}:MDMPROXY_AUTH_TOKEN::"
|
||||
},
|
||||
{
|
||||
name = "MDMPROXY_MIGRATE_UDIDS"
|
||||
valueFrom = "${aws_secretsmanager_secret.mdmproxy.arn}:MDMPROXY_MIGRATE_UDIDS::"
|
||||
},
|
||||
]
|
||||
repositoryCredentials = var.config.repository_credentials
|
||||
ulimits = [
|
||||
{
|
||||
name = "nofile"
|
||||
softLimit = 999999
|
||||
hardLimit = 999999
|
||||
}
|
||||
]
|
||||
environment = [
|
||||
{
|
||||
name = "MDMPROXY_SERVER_ADDRESS"
|
||||
value = ":8080"
|
||||
},
|
||||
{
|
||||
name = "MDMPROXY_MIGRATE_PERCENTAGE"
|
||||
value = tostring(var.config.migrate_percentage)
|
||||
},
|
||||
{
|
||||
name = "MDMPROXY_EXISTING_HOSTNAME"
|
||||
value = var.config.existing_hostname
|
||||
},
|
||||
{
|
||||
name = "MDMPROXY_EXISTING_URL"
|
||||
value = var.config.existing_url
|
||||
},
|
||||
{
|
||||
name = "MDMPROXY_FLEET_URL"
|
||||
value = var.config.fleet_url
|
||||
},
|
||||
]
|
||||
logConfiguration = {
|
||||
logDriver = "awslogs"
|
||||
options = {
|
||||
awslogs-group = var.awslogs_config.group
|
||||
awslogs-region = var.awslogs_config.region == null ? data.aws_region.current.name : var.awslogs_config.region
|
||||
awslogs-stream-prefix = "${var.awslogs_config.prefix}-mdmproxy"
|
||||
}
|
||||
}
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
output "alb" {
|
||||
value = module.alb
|
||||
}
|
||||
|
||||
output "ecs_service_name" {
|
||||
value = aws_ecs_service.mdmproxy.name
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
variable "awslogs_config" {
|
||||
type = object({
|
||||
group = string
|
||||
region = string
|
||||
prefix = optional(string, "mdmproxy")
|
||||
})
|
||||
}
|
||||
|
||||
variable "ecs_cluster" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vpc_id" {
|
||||
type = string
|
||||
nullable = false
|
||||
}
|
||||
|
||||
variable "customer_prefix" {
|
||||
type = string
|
||||
default = "fleet"
|
||||
}
|
||||
|
||||
variable "config" {
|
||||
type = object({
|
||||
extra_execution_iam_policies = optional(list(string), [])
|
||||
mem = optional(number, 2048)
|
||||
cpu = optional(number, 1024)
|
||||
image = string
|
||||
desired_count = optional(number, 1)
|
||||
repository_credentials = optional(string, null)
|
||||
migrate_percentage = number
|
||||
existing_hostname = string
|
||||
existing_url = string
|
||||
fleet_url = string
|
||||
migrate_udids = optional(list(string), [])
|
||||
auth_token = optional(string, "")
|
||||
iam = optional(object({
|
||||
execution = optional(object({
|
||||
name = optional(string, "mdmproxy-execution-role")
|
||||
policy_name = optional(string, "mdmproxy-iam-policy-execution")
|
||||
}), {
|
||||
name = "mdmproxy-execution-role"
|
||||
policy_name = "mdmproxy-iam-policy-execution"
|
||||
})
|
||||
}), {
|
||||
name = "mdmproxy-execution-role"
|
||||
policy_name = "mdmproxy-iam-policy-execution"
|
||||
})
|
||||
networking = object({
|
||||
subnets = list(string)
|
||||
security_groups = optional(list(string), null)
|
||||
security_group_name = optional(string, "fleet-mdmproxy")
|
||||
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 = []
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
variable "alb_config" {
|
||||
type = object({
|
||||
name = optional(string, "fleet-mdmproxy")
|
||||
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, [])
|
||||
tls_policy = optional(string, "ELBSecurityPolicy-TLS-1-2-2017-01")
|
||||
idle_timeout = optional(number, 905)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# Migrations addon
|
||||
This addon enables automatic migrations for Fleet.
|
||||
Due to limitations in the AWS provider for Terraform, only Linux platforms are supported.
|
||||
This module uses the local-exec provisioner to call aws-cli to complete migrations.
|
||||
Due to this, the following commands must be available to the shell:
|
||||
- aws
|
||||
@@ -0,0 +1 @@
|
||||
header-from: .header.md
|
||||
@@ -0,0 +1,45 @@
|
||||
# Migrations addon
|
||||
This addon enables automatic migrations for Fleet.
|
||||
Due to limitations in the AWS provider for Terraform, only Linux platforms are supported.
|
||||
This module uses the local-exec provisioner to call aws-cli to complete migrations.
|
||||
Due to this, the following commands must be available to the shell:
|
||||
- aws
|
||||
|
||||
## Requirements
|
||||
|
||||
No requirements.
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.31.0 |
|
||||
| <a name="provider_null"></a> [null](#provider\_null) | 3.2.2 |
|
||||
|
||||
## Modules
|
||||
|
||||
No modules.
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [null_resource.main](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
|
||||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_desired_count"></a> [desired\_count](#input\_desired\_count) | n/a | `number` | n/a | yes |
|
||||
| <a name="input_ecs_cluster"></a> [ecs\_cluster](#input\_ecs\_cluster) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_ecs_service"></a> [ecs\_service](#input\_ecs\_service) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_min_capacity"></a> [min\_capacity](#input\_min\_capacity) | n/a | `number` | n/a | yes |
|
||||
| <a name="input_security_groups"></a> [security\_groups](#input\_security\_groups) | n/a | `list(string)` | n/a | yes |
|
||||
| <a name="input_subnets"></a> [subnets](#input\_subnets) | n/a | `list(string)` | n/a | yes |
|
||||
| <a name="input_task_definition"></a> [task\_definition](#input\_task\_definition) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_task_definition_revision"></a> [task\_definition\_revision](#input\_task\_definition\_revision) | n/a | `number` | n/a | yes |
|
||||
|
||||
## Outputs
|
||||
|
||||
No outputs.
|
||||
@@ -0,0 +1,10 @@
|
||||
data "aws_region" "current" {}
|
||||
|
||||
resource "null_resource" "main" {
|
||||
triggers = {
|
||||
task_definition_revision = var.task_definition_revision
|
||||
}
|
||||
provisioner "local-exec" {
|
||||
command = "/bin/bash ${path.module}/migrate.sh REGION=${data.aws_region.current.name} VULN_SERVICE=${var.vuln_service} ECS_CLUSTER=${var.ecs_cluster} TASK_DEFINITION=${var.task_definition} TASK_DEFINITION_REVISION=${var.task_definition_revision} SUBNETS=${jsonencode(var.subnets)} SECURITY_GROUPS=${jsonencode(var.security_groups)} ECS_SERVICE=${var.ecs_service} MIN_CAPACITY=${var.min_capacity} DESIRED_COUNT=${var.desired_count}"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
function scale_services(){
|
||||
UP_DOWN="${1:?}"
|
||||
SERVICE_NAME="${2:?}" # Take service name as an argument
|
||||
ADJUST_AUTOSCALING="${3:-}"
|
||||
COUNT="${4:-1}"
|
||||
|
||||
# Set the minimum capacity and desired count in the cluster to 0 to scale down or to the original size to scale back to normal.
|
||||
|
||||
# This is a bit hacky, but the update-service has to happen first when scaling up and second when scaling down.
|
||||
# Assume scaling down unless "up".
|
||||
CAPACITY=0
|
||||
if [ "${UP_DOWN:?}" = "up" ]; then
|
||||
aws ecs update-service --region "${REGION:?}" --cluster "${ECS_CLUSTER:?}" --service "${SERVICE_NAME:?}" --desired-count "${COUNT:?}"
|
||||
CAPACITY="${MIN_CAPACITY:?}"
|
||||
fi
|
||||
|
||||
if [ -n "${ADJUST_AUTOSCALING}" ]; then
|
||||
aws application-autoscaling register-scalable-target --region "${REGION:?}" --service-namespace ecs --resource-id "service/${ECS_CLUSTER:?}/${SERVICE_NAME:?}" --scalable-dimension "ecs:service:DesiredCount" --min-capacity "${CAPACITY:?}"
|
||||
fi
|
||||
# We are scaling down, make it 0
|
||||
if [ "${UP_DOWN:?}" != "up" ]; then
|
||||
aws ecs update-service --region "${REGION:?}" --cluster "${ECS_CLUSTER:?}" --service "${SERVICE_NAME:?}" --desired-count 0
|
||||
fi
|
||||
# The first task definition might never get stable because it never had initial migrations so don't wait before continuing
|
||||
if [ "${TASK_DEFINITION_REVISION}" != "1" ]; then
|
||||
# Wait for scale-down to succeed
|
||||
aws ecs wait services-stable --region "${REGION:?}" --cluster "${ECS_CLUSTER:?}" --services "${SERVICE_NAME:?}"
|
||||
fi
|
||||
}
|
||||
|
||||
for ARGUMENT in "$@"
|
||||
do
|
||||
KEY=$(echo $ARGUMENT | cut -f1 -d=)
|
||||
KEY_LENGTH=${#KEY}
|
||||
VALUE="${ARGUMENT:$KEY_LENGTH+1}"
|
||||
export "$KEY"="$VALUE"
|
||||
done
|
||||
|
||||
scale_services down "${ECS_SERVICE:?}" true "${DESIRED_COUNT}"
|
||||
|
||||
if [ -n "${VULN_SERVICE}" ]; then
|
||||
scale_services down "${VULN_SERVICE:?}"
|
||||
fi
|
||||
|
||||
# Call aws ecs run-task
|
||||
TASK_ARN="$(aws ecs run-task --region "${REGION:?}" --cluster "${ECS_CLUSTER:?}" --task-definition "${TASK_DEFINITION:?}":"${TASK_DEFINITION_REVISION:?}" --launch-type FARGATE --network-configuration "awsvpcConfiguration={subnets="${SUBNETS:?}",securityGroups="${SECURITY_GROUPS:?}"}" --query 'tasks[].taskArn' --overrides '{"containerOverrides": [{"name": "fleet", "command": ["fleet", "prepare", "db"]}]}' --output text | rev | cut -d'/' -f1 | rev)"
|
||||
|
||||
# Wait for completion
|
||||
aws ecs wait tasks-stopped --region "${REGION:?}" --cluster="${ECS_CLUSTER:?}" --tasks="${TASK_ARN:?}"
|
||||
|
||||
scale_services up "${ECS_SERVICE:?}" true "${DESIRED_COUNT}"
|
||||
|
||||
if [ -n "${VULN_SERVICE}" ]; then
|
||||
scale_services up "${VULN_SERVICE:?}"
|
||||
fi
|
||||
|
||||
# Exit with task's exit code
|
||||
TASK_EXIT_CODE=$(aws ecs describe-tasks --region "${REGION:?}" --cluster "${ECS_CLUSTER:?}" --tasks "${TASK_ARN:?}" --query "tasks[0].containers[?name=='fleet'].exitCode" --output text)
|
||||
exit "${TASK_EXIT_CODE}"
|
||||
Binary file not shown.
Whitespace-only changes.
Loaded 100 of 186 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user