diff --git a/k8s/README.md b/k8s/README.md index 34626ad..8552219 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -292,7 +292,7 @@ No requirements. | Name | Version | |------|---------| -| [kubernetes](#provider\_kubernetes) | 2.37.1 | +| [kubernetes](#provider\_kubernetes) | 2.38.0 | ## Modules @@ -316,31 +316,31 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [affinity\_rules](#input\_affinity\_rules) | Used to configure affinity rules for the fleet deployment, migration job, and vuln-processing cron job. |
object({ 
required_during_scheduling_ignored_during_execution = optional(list(any), [])
preferred_during_scheduling_ignored_during_execution = optional(list(any), [])
})
| n/a | yes | -| [anti\_affinity\_rules](#input\_anti\_affinity\_rules) | Used to configure anti-affinity rules for the fleet deployment, migration job, and vuln-processing cron job. |
object({ 
required_during_scheduling_ignored_during_execution = optional(list(any), [])
preferred_during_scheduling_ignored_during_execution = optional(list(any),
[
{
weight = 100
label_selector = {
match_expressions = [
{
key = "app"
operator = "In"
values = ["fleet"]
}
]
}
topology_key = "kubernetes.io/hostname"
}
])
})
| n/a | yes | -| [cache](#input\_cache) | Used to configure redis specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
enabled = optional(bool, false)
address = optional(string, "redis:6379")
database = optional(number, 0)
use_password = optional(bool, false)
secret_name = optional(string, "redis")
password_key = optional(string, "password")
})
| n/a | yes | -| [database](#input\_database) | Used to configure database specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
enabled = optional(bool, false)
secret_name = optional(string, "mysql")
address = optional(string, "mysql:3306")
database = optional(string, "fleet")
username = optional(string, "fleet")
password_key = optional(string, "password")
max_open_conns = optional(number, 50)
max_idle_conns = optional(number, 50)
conn_max_lifetime = optional(number, 0)

tls = object({
enabled = optional(bool, false)
config = optional(string, "")
server_name = optional(string, "")
ca_cert_key = optional(string, "")
cert_key = optional(string, "")
key_key = optional(string, "")
})
})
| n/a | yes | -| [database\_read\_replica](#input\_database\_read\_replica) | Used to configure database\_read\_replica specific values for use in the Fleet deployment and vuln-processing cron job. |
object({
enabled = optional(bool, false)
secret_name = optional(string, "mysql")
address = optional(string, "mysql-ro:3306")
database = optional(string, "fleet")
username = optional(string, "fleet-ro")
password_key = optional(string, "ro-password")
password_path = optional(string,"")
max_open_conns = optional(number, 50)
max_idle_conns = optional(number, 50)
conn_max_lifetime = optional(number, 0)

tls = object({
enabled = optional(bool, false)
config = optional(string, "")
server_name = optional(string, "")
ca_cert_key = optional(string, "")
cert_key = optional(string, "")
key_key = optional(string, "")
})
})
| n/a | yes | +| [affinity\_rules](#input\_affinity\_rules) | Used to configure affinity rules for the fleet deployment, migration job, and vuln-processing cron job. |
object({
required_during_scheduling_ignored_during_execution = optional(list(any), [])
preferred_during_scheduling_ignored_during_execution = optional(list(any), [])
})
| n/a | yes | +| [anti\_affinity\_rules](#input\_anti\_affinity\_rules) | Used to configure anti-affinity rules for the fleet deployment, migration job, and vuln-processing cron job. |
object({
required_during_scheduling_ignored_during_execution = optional(list(any), [])
preferred_during_scheduling_ignored_during_execution = optional(list(any),
[
{
weight = 100
label_selector = {
match_expressions = [
{
key = "app"
operator = "In"
values = ["fleet"]
}
]
}
topology_key = "kubernetes.io/hostname"
}
])
})
| n/a | yes | +| [cache](#input\_cache) | Used to configure redis specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
enabled = optional(bool, false)
address = optional(string, "redis:6379")
database = optional(number, 0)
use_password = optional(bool, false)
secret_name = optional(string, "redis")
password_key = optional(string, "password")
})
| n/a | yes | +| [database](#input\_database) | Used to configure database specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
enabled = optional(bool, false)
secret_name = optional(string, "mysql")
address = optional(string, "mysql:3306")
database = optional(string, "fleet")
username = optional(string, "fleet")
password_key = optional(string, "password")
max_open_conns = optional(number, 50)
max_idle_conns = optional(number, 50)
conn_max_lifetime = optional(number, 0)

tls = object({
enabled = optional(bool, false)
config = optional(string, "")
server_name = optional(string, "")
ca_cert_key = optional(string, "")
cert_key = optional(string, "")
key_key = optional(string, "")
})
})
| n/a | yes | +| [database\_read\_replica](#input\_database\_read\_replica) | Used to configure database\_read\_replica specific values for use in the Fleet deployment and vuln-processing cron job. |
object({
enabled = optional(bool, false)
secret_name = optional(string, "mysql")
address = optional(string, "mysql-ro:3306")
database = optional(string, "fleet")
username = optional(string, "fleet-ro")
password_key = optional(string, "ro-password")
password_path = optional(string, "")
max_open_conns = optional(number, 50)
max_idle_conns = optional(number, 50)
conn_max_lifetime = optional(number, 0)

tls = optional(object({
enabled = optional(bool, false)
config = optional(string, "")
server_name = optional(string, "")
ca_cert_key = optional(string, "")
cert_key = optional(string, "")
key_key = optional(string, "")
}))
})
| n/a | yes | | [environment\_from\_config\_maps](#input\_environment\_from\_config\_maps) | Used to configure additional environment variables from a config map for the fleet deployment and vuln-processing cron job. | `list(map(string))` | `[]` | no | | [environment\_from\_secrets](#input\_environment\_from\_secrets) | Used to configure additional environment variables from a secret for the fleet deployment and vuln-processing cron job. | `list(map(string))` | `[]` | no | | [environment\_variables](#input\_environment\_variables) | Used to configure additional environment variables for the fleet deployment and vuln-processing cron job. | `list(map(string))` | `[]` | no | -| [fleet](#input\_fleet) | Used to configure Fleet specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
listen_port = optional(number, 8080)
secret_name = optional(string, "fleet")
migrations = object({
auto_apply_sql_migrations = optional(bool, true)
migration_job_annotations = optional(map(string), {})
parallelism = optional(number, 1)
completions = optional(number, 1)
active_deadline_seconds = optional(number, 900)
backoff_limit = optional(number, 6)
manual_selector = optional(bool, false)
restart_policy = optional(string, "Never")
})
tls = object({
enabled = optional(bool, false)
unique_tls_secret = optional(bool, false)
secret_name = optional(string, "fleet-tls")
compatibility = optional(string, "modern")
cert_secret_key = optional(string, "server.cert")
key_secret_key = optional(string, "server.key")
})
auth = object({
b_crypto_cost = optional(number, 12)
salt_key_size = optional(number, 24)
})
app = object({
token_key_size = optional(number, 24)
invite_token_validity_period = optional(string, "120h")
})
session = object({
key_size = optional(number, 64)
duration = optional(string, "2160h")
})
logging = object({
debug = optional(bool, false)
json = optional(bool, false)
disable_banner = optional(bool, false)
})
carving = object({
s3 = object({
bucket_name = optional(string, "")
prefix = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "s3-bucket")
sts_assume_role_arn = optional(string, "")
})
})
license = object({
secret_name = optional(string, "")
license_key = optional(string, "license-key")
})
extra_volumes = optional(list(any), [])
extra_volume_mounts = optional(list(any), [])
security_context = object({
run_as_user = optional(number, null)
run_as_group = optional(number, null)
run_as_non_root = optional(bool, true)
})
})
| n/a | yes | -| [gke](#input\_gke) | Used to configure gke specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
workload_identity_email = optional(string, "")
cloud_sql = object({
enable_proxy = optional(bool, false)
image_repository = optional(string, "gcr.io/cloudsql-docker/gce-proxy")
image_tag = optional(string, "1.17-alpine")
verbose = optional(bool, true)
instance_name = optional(string, "")
})
ingress = object({
use_managed_certificate = optional(bool, false)
use_gke_ingress = optional(bool, false)
node_port = optional(number, 0)
hostnames = optional(list(string), [""])
})
})
| n/a | yes | +| [fleet](#input\_fleet) | Used to configure Fleet specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
listen_port = optional(number, 8080)
secret_name = optional(string, "fleet")
migrations = object({
auto_apply_sql_migrations = optional(bool, true)
migration_job_annotations = optional(map(string), {})
parallelism = optional(number, 1)
completions = optional(number, 1)
active_deadline_seconds = optional(number, 900)
backoff_limit = optional(number, 6)
manual_selector = optional(bool, false)
restart_policy = optional(string, "Never")
})
tls = object({
enabled = optional(bool, false)
unique_tls_secret = optional(bool, false)
secret_name = optional(string, "fleet-tls")
compatibility = optional(string, "modern")
cert_secret_key = optional(string, "server.cert")
key_secret_key = optional(string, "server.key")
})
auth = object({
b_crypto_cost = optional(number, 12)
salt_key_size = optional(number, 24)
})
app = object({
token_key_size = optional(number, 24)
invite_token_validity_period = optional(string, "120h")
})
session = object({
key_size = optional(number, 64)
duration = optional(string, "2160h")
})
logging = object({
debug = optional(bool, false)
json = optional(bool, false)
disable_banner = optional(bool, false)
})
software_installers = object({
s3 = object({
bucket_name = optional(string, "")
prefix = optional(string, "")
endpoint_url = optional(string, "")
force_s3_path_style = optional(bool, false)
region = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "s3-software-installers")
sts_assume_role_arn = optional(string, "")
})
})
carving = object({
s3 = object({
bucket_name = optional(string, "")
prefix = optional(string, "")
endpoint_url = optional(string, "")
force_s3_path_style = optional(bool, false)
region = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "s3-bucket")
sts_assume_role_arn = optional(string, "")
})
})
license = object({
secret_name = optional(string, "")
license_key = optional(string, "license-key")
})
extra_volumes = optional(list(any), [])
extra_volume_mounts = optional(list(any), [])
security_context = object({
run_as_user = optional(number, null)
run_as_group = optional(number, null)
run_as_non_root = optional(bool, true)
})
})
| n/a | yes | +| [gke](#input\_gke) | Used to configure gke specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
workload_identity_email = optional(string, "")
cloud_sql = object({
enable_proxy = optional(bool, false)
image_repository = optional(string, "gcr.io/cloudsql-docker/gce-proxy")
image_tag = optional(string, "1.17-alpine")
verbose = optional(bool, true)
instance_name = optional(string, "")
})
ingress = object({
use_managed_certificate = optional(bool, false)
use_gke_ingress = optional(bool, false)
node_port = optional(number, 0)
hostnames = optional(list(string), [""])
})
})
| n/a | yes | | [hostname](#input\_hostname) | Used as the hostname that you will access fleet on. | `string` | `"fleet.localhost"` | no | -| [image\_pull\_secrets](#input\_image\_pull\_secrets) | Used to inject image pull secrets for access to a private container registry. |
list(object({
name = string
}))
| `[]` | no | +| [image\_pull\_secrets](#input\_image\_pull\_secrets) | Used to inject image pull secrets for access to a private container registry. |
list(object({
name = string
}))
| `[]` | no | | [image\_repository](#input\_image\_repository) | Used to populate the image repository for fleet. | `string` | `"fleetdm/fleet"` | no | | [image\_tag](#input\_image\_tag) | Used to populate the fleet version that will be deployed. | `string` | `"v4.66.0"` | no | -| [ingress](#input\_ingress) | Used to configure values for ingress. |
object({
enabled = optional(bool, false)
class_name = optional(string, "nginx")
labels = optional(map(string), {})
annotations = optional(map(string), {})
hosts = optional(list(any), [])
tls = object({
secret_name = optional(string, "")
hosts = optional(list(string),[])
})
})
| n/a | yes | +| [ingress](#input\_ingress) | Used to configure values for ingress. |
object({
enabled = optional(bool, false)
class_name = optional(string, "nginx")
labels = optional(map(string), {})
annotations = optional(map(string), {})
hosts = optional(list(any), [])
tls = object({
secret_name = optional(string, "")
hosts = optional(list(string), [])
})
})
| n/a | yes | | [namespace](#input\_namespace) | The value for this variable will be used as the name of the namespace that fleet will be deployed to. | `string` | `"fleet"` | no | -| [node\_selector](#input\_node\_selector) | Used to populate node selector values. | `map` | `{}` | no | -| [osquery](#input\_osquery) | Used to configure osquery specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
secret_name = optional(string, "osquery")
node_key_size = optional(number, 24)
label_update_interval = optional(string, "30m")
detail_update_interval = optional(string, "30m")
logging = object({
status_plugin = optional(string, "filesystem")
result_plugin = optional(string, "filesystem")
filesystem = object({
status_log_file = optional(string, "osquery_status")
result_log_file = optional(string, "osquery_result")
enable_rotation = optional(bool, false)
enable_compression = optional(bool, false)
volume_size = optional(string, "20Gi")
})
firehose = object({
region = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "firehose")
sts_assume_role_arn = optional(string, "")
status_stream = optional(string, "")
result_stream = optional(string, "")
})
kinesis = object({
region = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "kinesis")
sts_assume_role_arn = optional(string, "")
status_stream = optional(string, "")
result_stream = optional(string, "")
})
lambda = object({
region = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "lambda")
sts_assume_role_arn = optional(string, "")
status_stream = optional(string, "")
result_stream = optional(string, "")
})
pubsub = object({
project = optional(string, "")
status_topic = optional(string, "")
result_topic = optional(string, "")
})
})
})
| n/a | yes | -| [pod\_annotations](#input\_pod\_annotations) | Used to populate the annotations for pods. | `map` | `{}` | no | +| [node\_selector](#input\_node\_selector) | Used to populate node selector values. | `map(any)` | `{}` | no | +| [osquery](#input\_osquery) | Used to configure osquery specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. |
object({
secret_name = optional(string, "osquery")
node_key_size = optional(number, 24)
label_update_interval = optional(string, "30m")
detail_update_interval = optional(string, "30m")
logging = object({
status_plugin = optional(string, "filesystem")
result_plugin = optional(string, "filesystem")
filesystem = object({
status_log_file = optional(string, "osquery_status")
result_log_file = optional(string, "osquery_result")
enable_rotation = optional(bool, false)
enable_compression = optional(bool, false)
volume_size = optional(string, "20Gi")
})
firehose = object({
region = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "firehose")
sts_assume_role_arn = optional(string, "")
status_stream = optional(string, "")
result_stream = optional(string, "")
})
kinesis = object({
region = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "kinesis")
sts_assume_role_arn = optional(string, "")
status_stream = optional(string, "")
result_stream = optional(string, "")
})
lambda = object({
region = optional(string, "")
access_key_id = optional(string, "")
secret_key = optional(string, "lambda")
sts_assume_role_arn = optional(string, "")
status_stream = optional(string, "")
result_stream = optional(string, "")
})
pubsub = object({
project = optional(string, "")
status_topic = optional(string, "")
result_topic = optional(string, "")
})
})
})
| n/a | yes | +| [pod\_annotations](#input\_pod\_annotations) | Used to populate the annotations for pods. | `map(any)` | `{}` | no | | [replicas](#input\_replicas) | Used to drive the number of fleet deployment replicas. | `number` | `3` | no | -| [resources](#input\_resources) | Used to populate resource values for the fleet deployment and migration job. |
object({
limits = optional(object({
cpu = optional(string, "1")
memory = optional(string, "4Gi")
}),{
cpu = "1"
memory = "4Gi"
})
requests = optional(object({
cpu = optional(string, "0.1")
memory = optional(string, "50Mi")
}),{
cpu = "0.1"
memory = "50Mi"
})
})
| n/a | yes | -| [service\_account\_annotations](#input\_service\_account\_annotations) | Used to populate the annotations for the fleet service account. | `map` | `{}` | no | -| [service\_annotations](#input\_service\_annotations) | Used to populate the annotations for the fleet service. | `map` | `{}` | no | +| [resources](#input\_resources) | Used to populate resource values for the fleet deployment and migration job. |
object({
limits = optional(object({
cpu = optional(string, "1")
memory = optional(string, "4Gi")
}), {
cpu = "1"
memory = "4Gi"
})
requests = optional(object({
cpu = optional(string, "0.1")
memory = optional(string, "50Mi")
}), {
cpu = "0.1"
memory = "50Mi"
})
})
| n/a | yes | +| [service\_account\_annotations](#input\_service\_account\_annotations) | Used to populate the annotations for the fleet service account. | `map(any)` | `{}` | no | +| [service\_annotations](#input\_service\_annotations) | Used to populate the annotations for the fleet service. | `map(any)` | `{}` | no | | [tolerations](#input\_tolerations) | Used to configure tolerations. | `list(any)` | `[]` | no | -| [vuln\_processing](#input\_vuln\_processing) | Used to configure the values for the vuln-processing cron job. |
object({
ttl_seconds_after_finished = optional(number, 100)
restart_policy = optional(string, "Never")
dedicated = optional(bool, false)
schedule = optional(string, "0 * * * *")
resources = object({
limits = optional(object({
cpu = optional(string, "1")
memory = optional(string, "4Gi")
}),{
cpu = "1"
memory = "4Gi"
})
requests = optional(object({
cpu = optional(string, "0.1")
memory = optional(string, "50Mi")
}),{
cpu = "0.1"
memory = "50Mi"
})
})
})
| n/a | yes | +| [vuln\_processing](#input\_vuln\_processing) | Used to configure the values for the vuln-processing cron job. |
object({
ttl_seconds_after_finished = optional(number, 100)
restart_policy = optional(string, "Never")
dedicated = optional(bool, false)
schedule = optional(string, "0 * * * *")
resources = object({
limits = optional(object({
cpu = optional(string, "1")
memory = optional(string, "4Gi")
}), {
cpu = "1"
memory = "4Gi"
})
requests = optional(object({
cpu = optional(string, "0.1")
memory = optional(string, "50Mi")
}), {
cpu = "0.1"
memory = "50Mi"
})
})
})
| n/a | yes | ## Outputs diff --git a/k8s/cronjob.tf b/k8s/cronjob.tf index 00f490b..bed6b7d 100644 --- a/k8s/cronjob.tf +++ b/k8s/cronjob.tf @@ -1,446 +1,461 @@ resource "kubernetes_cron_job_v1" "fleet_vuln_processing_cron_job" { - metadata { - name = "fleet-vulnprocessing" - namespace = data.kubernetes_namespace.fleet.metadata[0].name - } - spec { - schedule = local.vuln_processing.schedule - concurrency_policy = "Forbid" + metadata { + name = "fleet-vulnprocessing" + namespace = data.kubernetes_namespace.fleet.metadata[0].name + } + spec { + schedule = local.vuln_processing.schedule + concurrency_policy = "Forbid" - job_template { - metadata { - labels = { - app = "fleet" - } - } - - spec { - ttl_seconds_after_finished = local.vuln_processing.ttl_seconds_after_finished - template { - metadata { - labels = { - app = "fleet" - } - annotations = local.pod_annotations - } - spec { - share_process_namespace = "true" - restart_policy = local.vuln_processing.restart_policy - service_account_name = resource.kubernetes_service_account.fleet-sa.metadata[0].name - - container { - name = "fleet-vulnprocessing" - image = "${local.image_repository}:${local.image_tag}" - - command = ["/bin/sh", "-c"] - args = local.gke.cloud_sql.enable_proxy ? [ - "/usr/bin/fleet vuln_processing; sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;" - ] : [ - "/usr/bin/fleet vuln_processing;" - ] - - dynamic "env" { - for_each = [ - { name = "FLEET_VULNERABILITIES_DATABASES_PATH", value = "/tmp/vuln" }, - { name = "FLEET_LOGGING_DEBUG", value = local.fleet.logging.debug }, - { name = "FLEET_LOGGING_JSON", value = local.fleet.logging.json }, - { name = "FLEET_LOGGING_DISABLE_BANNER", value = local.fleet.logging.disable_banner } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.fleet.license.secret_name != "" ? [ - { - name = "FLEET_LICENSE_KEY", - value_from = { - secret_key_ref = { - name = local.fleet.license.secret_name - key = local.fleet.license.license_key - } - } - } - ] : [] - - content { - name = env.value.name - value_from { - secret_key_ref { - name = env.value.value_from.secret_key_ref.name - key = env.value.value_from.secret_key_ref.key - } - } - } - } - - dynamic "env" { - for_each = [ - { name = "FLEET_MYSQL_ADDRESS", value = local.database.address }, - { name = "FLEET_MYSQL_DATABASE", value = local.database.database }, - { name = "FLEET_MYSQL_USERNAME", value = local.database.username }, - { name = "FLEET_MYSQL_MAX_OPEN_CONNS", value = local.database.max_open_conns }, - { name = "FLEET_MYSQL_MAX_IDLE_CONNS", value = local.database.max_idle_conns }, - { name = "FLEET_MYSQL_CONN_MAX_LIFETIME", value = local.database.conn_max_lifetime } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - env { - name = "FLEET_MYSQL_PASSWORD" - value_from { - secret_key_ref { - name = local.database.secret_name - key = local.database.password_key - } - } - } - - dynamic "env" { - for_each = local.database.tls.enabled ? [ - { name = "FLEET_MYSQL_TLS_CA", value = "/secrets/mysql/${local.database.tls.ca_cert_key}" }, - { name = "FLEET_MYSQL_TLS_CERT", value = "/secrets/mysql/${local.database.tls.cert_secret_key}" }, - { name = "FLEET_MYSQL_TLS_KEY", value = "/secrets/mysql/${local.database.tls.key_key}" }, - { name = "FLEET_MYSQL_TLS_CONFIG", value = local.database.tls.config }, - { name = "FLEET_MYSQL_TLS_SERVER_NAME", value = local.database.tls.server_name } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = [ - { name = "FLEET_MYSQL_READ_REPLICA_ADDRESS", value = local.database_read_replica.address }, - { name = "FLEET_MYSQL_READ_REPLICA_DATABASE", value = local.database_read_replica.database }, - { name = "FLEET_MYSQL_READ_REPLICA_USERNAME", value = local.database_read_replica.username }, - { name = "FLEET_MYSQL_READ_REPLICA_PASSWORD_PATH", value = local.database_read_replica.password_path }, - { name = "FLEET_MYSQL_READ_REPLICA_MAX_OPEN_CONNS", value = local.database_read_replica.max_open_conns }, - { name = "FLEET_MYSQL_READ_REPLICA_MAX_IDLE_CONNS", value = local.database_read_replica.max_idle_conns }, - { name = "FLEET_MYSQL_READ_REPLICA_CONN_MAX_LIFETIME", value = local.database_read_replica.conn_max_lifetime } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - env { - name = "FLEET_MYSQL_READ_REPLICA_PASSWORD" - value_from { - secret_key_ref { - name = local.database_read_replica.secret_name - key = local.database_read_replica.password_key - } - } - } - - dynamic "env" { - for_each = local.database.tls.enabled ? [ - { name = "FLEET_MYSQL_READ_REPLICA_TLS_CA", value = "/secrets/mysql/${local.database_read_replica.tls.ca_cert_key}" }, - { name = "FLEET_MYSQL_READ_REPLICA_TLS_CERT", value = "/secrets/mysql/${local.database_read_replica.tls.cert_secret_key}" }, - { name = "FLEET_MYSQL_READ_REPLICA_TLS_KEY", value = "/secrets/mysql/${local.database_read_replica.tls.key_key}" }, - { name = "FLEET_MYSQL_READ_REPLICA_TLS_CONFIG", value = local.database_read_replica.tls.config }, - { name = "FLEET_MYSQL_READ_REPLICA_TLS_SERVER_NAME", value = local.database_read_replica.tls.server_name } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = [ - { name = "FLEET_REDIS_ADDRESS", value = local.cache.address }, - { name = "FLEET_REDIS_DATABASE", value = local.cache.database } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.cache.use_password ? [ - { - name = "FLEET_REDIS_PASSWORD", - value_from = { - secret_key_ref = { - name = local.cache.secret_name - key = local.cache.password_key - } - } - } - ] : [] - - content { - name = env.value.name - value_from { - secret_key_ref { - name = env.value.value_from.secret_key_ref.name - key = env.value.value_from.secret_key_ref.key - } - } - } - } - - dynamic "env"{ - for_each = local.environment_variables - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env_from" { - for_each = local.environment_from_config_maps - - content { - config_map_ref { - name = env_from.value.name - } - } - } - - dynamic "env_from" { - for_each = local.environment_from_secrets - - content { - secret_ref { - name = env_from.value.name - } - } - } - - security_context { - run_as_user = local.fleet.security_context.run_as_user - run_as_group = local.fleet.security_context.run_as_group - run_as_non_root = local.fleet.security_context.run_as_non_root - read_only_root_filesystem = "true" - privileged = "false" - allow_privilege_escalation = "false" - capabilities { - drop = ["ALL"] - } - } - - resources { - limits = { - cpu = local.vuln_processing.resources.limits.cpu - memory = local.vuln_processing.resources.limits.memory - } - requests = { - cpu = local.vuln_processing.resources.requests.cpu - memory = local.vuln_processing.resources.requests.memory - } - } - - volume_mount { - name = "tmp" - mount_path = "/tmp" - } - - dynamic "volume_mount" { - for_each = local.database.tls.enabled ? [ - { name = "mysql-tls", read_only = true, mount_path = "/secrets/mysql" } - ] : [] - - content { - name = volume_mount.value.name - read_only = volume_mount.value.read_only - mount_path = volume_mount.value.mount_path - } - } - } - - dynamic "container" { - for_each = local.gke.cloud_sql.enable_proxy ? [ - { - name = "cloudql-proxy", - image = "${local.gke.cloud_sql.image_repository}:${local.gke.cloud_sql.image_tag}", - command = ["/cloud_sql_proxy", "-verbose=${local.gke.cloud_sql.verbose}", "-instances=${local.gke.cloud_sql.instance_name}=tcp:3306"] - resources = { - limits = { - cpu = "0.5", - memory = "150Mi" - }, - requests = { - cpu = "0.1", - memory = "50Mi" - } - } - security_context = { - allow_privilege_escalation = false, - capabilities = { - drop = ["ALL"] - }, - privileged = false, - read_only_root_filesystem = true, - run_as_user = local.fleet.security_context.run_as_user, - run_as_group = local.fleet.security_context.run_as_group, - run_as_non_root = local.fleet.security_context.run_as_non_root - } - } - ] : [] - - content { - name = container.value.name - image = container.value.image - command = container.value.command - resources { - limits = { - cpu = container.value.resources.limits.cpu - memory = container.value.resources.limits.memory - } - requests = { - cpu = container.value.resources.requests.cpu - memory = container.value.resources.requests.memory - } - } - security_context { - allow_privilege_escalation = container.value.security_context.allow_privilege_escalation - capabilities { - drop = container.value.security_context.capabilities.drop - } - privileged = container.value.security_context.privileged - read_only_root_filesystem = container.value.security_context.read_only_root_filesystem - run_as_user = container.value.security_context.run_as_user - run_as_group = container.value.security_context.run_as_group - run_as_non_root = container.value.security_context.run_as_non_root - } - } - } - - volume { - name = "tmp" - empty_dir {} - } - - dynamic "volume" { - for_each = local.database.tls.enabled ? [ - { - name = "mysql-tls", - secret_name = local.database.tls.secret_name - } - ] : [] - - content { - name = volume.value.name - secret { - secret_name = volume.value.secret_name - } - } - } - - dynamic "affinity" { - for_each = local.affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null - - content { - pod_affinity { - required_during_scheduling_ignored_during_execution { - label_selector { - match_expressions { - key = affinity.value.label_selector.match_expressions[*].key - operator = affinity.value.label_selector.match_expressions[*].operator - values = affinity.value.label_selector.match_expressions[*].values - } - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "affinity" { - for_each = local.affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null - - content { - pod_affinity { - preferred_during_scheduling_ignored_during_execution { - pod_affinity_term { - preference = affinity.value.preference - } - topology_key = affinity.value.topology_key - } - } - } - } - - - dynamic "affinity" { - for_each = local.anti_affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null - - content { - pod_anti_affinity { - required_during_scheduling_ignored_during_execution { - label_selector { - match_expressions { - key = affinity.value.label_selector.match_expressions[*].key - operator = affinity.value.label_selector.match_expressions[*].operator - values = affinity.value.label_selector.match_expressions[*].values - } - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "affinity" { - for_each = local.anti_affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null - - content { - pod_anti_affinity { - preferred_during_scheduling_ignored_during_execution { - pod_affinity_term { - label_selector = affinity.value.label_selector.label_selector - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "toleration" { - for_each = local.tolerations - - content { - key = toleration.env.key - operator = toleration.env.operator - value = toleration.env.value - effect = toleration.env.effect - } - } - - node_selector = local.node_selector - - dynamic "image_pull_secrets" { - for_each = var.image_pull_secrets - - content { - name = image_pull_secrets.value["name"] - } - } - } - } - } + job_template { + metadata { + labels = { + app = "fleet" } + } + + spec { + ttl_seconds_after_finished = local.vuln_processing.ttl_seconds_after_finished + template { + metadata { + labels = { + app = "fleet" + } + annotations = local.pod_annotations + } + spec { + share_process_namespace = "true" + restart_policy = local.vuln_processing.restart_policy + service_account_name = resource.kubernetes_service_account.fleet-sa.metadata[0].name + + container { + name = "fleet-vulnprocessing" + image = "${local.image_repository}:${local.image_tag}" + + command = ["/bin/sh", "-c"] + args = local.gke.cloud_sql.enable_proxy ? [ + "/usr/bin/fleet vuln_processing; sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;" + ] : [ + "/usr/bin/fleet vuln_processing;" + ] + + dynamic "env" { + for_each = [ + { name = "FLEET_VULNERABILITIES_DATABASES_PATH", value = "/tmp/vuln" }, + { name = "FLEET_LOGGING_DEBUG", value = local.fleet.logging.debug }, + { name = "FLEET_LOGGING_JSON", value = local.fleet.logging.json }, + { name = "FLEET_LOGGING_DISABLE_BANNER", value = local.fleet.logging.disable_banner } + ] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.license.secret_name != "" ? [ + { + name = "FLEET_LICENSE_KEY", + value_from = { + secret_key_ref = { + name = local.fleet.license.secret_name + key = local.fleet.license.license_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = [ + { name = "FLEET_MYSQL_ADDRESS", value = local.database.address }, + { name = "FLEET_MYSQL_DATABASE", value = local.database.database }, + { name = "FLEET_MYSQL_USERNAME", value = local.database.username }, + { name = "FLEET_MYSQL_MAX_OPEN_CONNS", value = local.database.max_open_conns }, + { name = "FLEET_MYSQL_MAX_IDLE_CONNS", value = local.database.max_idle_conns }, + { name = "FLEET_MYSQL_CONN_MAX_LIFETIME", value = local.database.conn_max_lifetime } + ] + + content { + name = env.value.name + value = env.value.value + } + } + + env { + name = "FLEET_MYSQL_PASSWORD" + + value_from { + secret_key_ref { + name = local.database.secret_name + key = local.database.password_key + } + } + } + + dynamic "env" { + for_each = local.database.tls.enabled ? [ + { name = "FLEET_MYSQL_TLS_CA", value = "/secrets/mysql/${local.database.tls.ca_cert_key}" }, + { name = "FLEET_MYSQL_TLS_CERT", value = "/secrets/mysql/${local.database.tls.cert_secret_key}" }, + { name = "FLEET_MYSQL_TLS_KEY", value = "/secrets/mysql/${local.database.tls.key_key}" }, + { name = "FLEET_MYSQL_TLS_CONFIG", value = local.database.tls.config }, + { name = "FLEET_MYSQL_TLS_SERVER_NAME", value = local.database.tls.server_name } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.database_read_replica.enabled ? [ + { name = "FLEET_MYSQL_READ_REPLICA_ADDRESS", value = local.database_read_replica.address }, + { name = "FLEET_MYSQL_READ_REPLICA_DATABASE", value = local.database_read_replica.database }, + { name = "FLEET_MYSQL_READ_REPLICA_USERNAME", value = local.database_read_replica.username }, + { name = "FLEET_MYSQL_READ_REPLICA_PASSWORD_PATH", value = local.database_read_replica.password_path }, + { name = "FLEET_MYSQL_READ_REPLICA_MAX_OPEN_CONNS", value = local.database_read_replica.max_open_conns }, + { name = "FLEET_MYSQL_READ_REPLICA_MAX_IDLE_CONNS", value = local.database_read_replica.max_idle_conns }, + { name = "FLEET_MYSQL_READ_REPLICA_CONN_MAX_LIFETIME", value = local.database_read_replica.conn_max_lifetime } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.database_read_replica.enabled ? [ + { + name = "FLEET_MYSQL_READ_REPLICA_PASSWORD", + value_from = { + secret_key_ref = { + name = local.database_read_replica.secret_name + key = local.database_read_replica.password_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = local.database_read_replica.enabled && local.database.tls.enabled ? [ + { name = "FLEET_MYSQL_READ_REPLICA_TLS_CA", value = "/secrets/mysql/${local.database_read_replica.tls.ca_cert_key}" }, + { name = "FLEET_MYSQL_READ_REPLICA_TLS_CERT", value = "/secrets/mysql/${local.database_read_replica.tls.cert_secret_key}" }, + { name = "FLEET_MYSQL_READ_REPLICA_TLS_KEY", value = "/secrets/mysql/${local.database_read_replica.tls.key_key}" }, + { name = "FLEET_MYSQL_READ_REPLICA_TLS_CONFIG", value = local.database_read_replica.tls.config }, + { name = "FLEET_MYSQL_READ_REPLICA_TLS_SERVER_NAME", value = local.database_read_replica.tls.server_name } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = [ + { name = "FLEET_REDIS_ADDRESS", value = local.cache.address }, + { name = "FLEET_REDIS_DATABASE", value = local.cache.database } + ] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.cache.use_password ? [ + { + name = "FLEET_REDIS_PASSWORD", + value_from = { + secret_key_ref = { + name = local.cache.secret_name + key = local.cache.password_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = local.environment_variables + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env_from" { + for_each = local.environment_from_config_maps + + content { + config_map_ref { + name = env_from.value.name + } + } + } + + dynamic "env_from" { + for_each = local.environment_from_secrets + + content { + secret_ref { + name = env_from.value.name + } + } + } + + security_context { + run_as_user = local.fleet.security_context.run_as_user + run_as_group = local.fleet.security_context.run_as_group + run_as_non_root = local.fleet.security_context.run_as_non_root + read_only_root_filesystem = "true" + privileged = "false" + allow_privilege_escalation = "false" + capabilities { + drop = ["ALL"] + } + } + + resources { + limits = { + cpu = local.vuln_processing.resources.limits.cpu + memory = local.vuln_processing.resources.limits.memory + } + requests = { + cpu = local.vuln_processing.resources.requests.cpu + memory = local.vuln_processing.resources.requests.memory + } + } + + volume_mount { + name = "tmp" + mount_path = "/tmp" + } + + dynamic "volume_mount" { + for_each = local.database.tls.enabled ? [ + { name = "mysql-tls", read_only = true, mount_path = "/secrets/mysql" } + ] : [] + + content { + name = volume_mount.value.name + read_only = volume_mount.value.read_only + mount_path = volume_mount.value.mount_path + } + } + } + + dynamic "container" { + for_each = local.gke.cloud_sql.enable_proxy ? [ + { + name = "cloudql-proxy", + image = "${local.gke.cloud_sql.image_repository}:${local.gke.cloud_sql.image_tag}", + command = ["/cloud_sql_proxy", "-verbose=${local.gke.cloud_sql.verbose}", "-instances=${local.gke.cloud_sql.instance_name}=tcp:3306"] + resources = { + limits = { + cpu = "0.5", + memory = "150Mi" + }, + requests = { + cpu = "0.1", + memory = "50Mi" + } + } + security_context = { + allow_privilege_escalation = false, + capabilities = { + drop = ["ALL"] + }, + privileged = false, + read_only_root_filesystem = true, + run_as_user = local.fleet.security_context.run_as_user, + run_as_group = local.fleet.security_context.run_as_group, + run_as_non_root = local.fleet.security_context.run_as_non_root + } + } + ] : [] + + content { + name = container.value.name + image = container.value.image + command = container.value.command + resources { + limits = { + cpu = container.value.resources.limits.cpu + memory = container.value.resources.limits.memory + } + requests = { + cpu = container.value.resources.requests.cpu + memory = container.value.resources.requests.memory + } + } + security_context { + allow_privilege_escalation = container.value.security_context.allow_privilege_escalation + capabilities { + drop = container.value.security_context.capabilities.drop + } + privileged = container.value.security_context.privileged + read_only_root_filesystem = container.value.security_context.read_only_root_filesystem + run_as_user = container.value.security_context.run_as_user + run_as_group = container.value.security_context.run_as_group + run_as_non_root = container.value.security_context.run_as_non_root + } + } + } + + volume { + name = "tmp" + empty_dir {} + } + + dynamic "volume" { + for_each = local.database.tls.enabled ? [ + { + name = "mysql-tls", + secret_name = local.database.tls.secret_name + } + ] : [] + + content { + name = volume.value.name + secret { + secret_name = volume.value.secret_name + } + } + } + + dynamic "affinity" { + for_each = local.affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null + + content { + pod_affinity { + required_during_scheduling_ignored_during_execution { + label_selector { + match_expressions { + key = affinity.value.label_selector.match_expressions[*].key + operator = affinity.value.label_selector.match_expressions[*].operator + values = affinity.value.label_selector.match_expressions[*].values + } + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "affinity" { + for_each = local.affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null + + content { + pod_affinity { + preferred_during_scheduling_ignored_during_execution { + pod_affinity_term { + preference = affinity.value.preference + } + topology_key = affinity.value.topology_key + } + } + } + } + + + dynamic "affinity" { + for_each = local.anti_affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null + + content { + pod_anti_affinity { + required_during_scheduling_ignored_during_execution { + label_selector { + match_expressions { + key = affinity.value.label_selector.match_expressions[*].key + operator = affinity.value.label_selector.match_expressions[*].operator + values = affinity.value.label_selector.match_expressions[*].values + } + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "affinity" { + for_each = local.anti_affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null + + content { + pod_anti_affinity { + preferred_during_scheduling_ignored_during_execution { + pod_affinity_term { + label_selector = affinity.value.label_selector.label_selector + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "toleration" { + for_each = local.tolerations + + content { + key = toleration.env.key + operator = toleration.env.operator + value = toleration.env.value + effect = toleration.env.effect + } + } + + node_selector = local.node_selector + + dynamic "image_pull_secrets" { + for_each = var.image_pull_secrets + + content { + name = image_pull_secrets.value["name"] + } + } + } + } + } } - depends_on = [ - resource.kubernetes_job.migration, // Include when migration is enabled - resource.kubernetes_service_account.fleet-sa - ] + } + depends_on = [ + resource.kubernetes_job.migration, // Include when migration is enabled + resource.kubernetes_service_account.fleet-sa + ] } \ No newline at end of file diff --git a/k8s/deploy.tf b/k8s/deploy.tf index 6189cd8..32c3d61 100644 --- a/k8s/deploy.tf +++ b/k8s/deploy.tf @@ -1,917 +1,1006 @@ resource "kubernetes_deployment" "fleet" { - /* + /* if local.jobmigration = true don't run this block if local.jobmigration = false run this block */ - metadata { - name = "fleet" - namespace = data.kubernetes_namespace.fleet.metadata[0].name + metadata { + name = "fleet" + namespace = data.kubernetes_namespace.fleet.metadata[0].name + labels = { + app = "fleet" + } + } + + spec { + replicas = local.replicas + + selector { + match_labels = { + app = "fleet" + component = "fleet-server" + } + } + + strategy { + type = "RollingUpdate" + rolling_update { + max_unavailable = "25%" + max_surge = "25%" + } + } + + template { + metadata { labels = { - app = "fleet" + app = "fleet" + component = "fleet-server" } + annotations = local.pod_annotations + } + + spec { + service_account_name = resource.kubernetes_service_account.fleet-sa.metadata[0].name + container { + name = "fleet" + image = "${local.image_repository}:${local.image_tag}" + + command = ["/usr/bin/fleet"] + args = ["serve"] + + dynamic "env" { + for_each = [ + { name = "FLEET_VULNERABILITIES_DATABASES_PATH", value = "/tmp/vuln" }, + { name = "FLEET_SERVER_ADDRESS", value = "0.0.0.0:${local.fleet.listen_port}" }, + { name = "FLEET_AUTH_BCRYPT_COST", value = local.fleet.auth.b_crypto_cost }, + { name = "FLEET_AUTH_SALT_KEY_SIZE", value = local.fleet.auth.salt_key_size }, + { name = "FLEET_APP_TOKEN_KEY_SIZE", value = local.fleet.app.token_key_size }, + { name = "FLEET_APP_TOKEN_VALIDITY_PERIOD", value = local.fleet.app.invite_token_validity_period }, + { name = "FLEET_SESSION_KEY_SIZE", value = local.fleet.session.key_size }, + { name = "FLEET_SESSION_DURATION", value = local.fleet.session.duration }, + { name = "FLEET_LOGGING_DEBUG", value = local.fleet.logging.debug }, + { name = "FLEET_LOGGING_JSON", value = local.fleet.logging.json }, + { name = "FLEET_LOGGING_DISABLE_BANNER", value = local.fleet.logging.disable_banner }, + { name = "FLEET_SERVER_TLS", value = local.fleet.tls.enabled } + ] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.tls.enabled ? [ + { name = "FLEET_SERVER_TLS_COMPATIBILITY", value = local.fleet.tls.compatibility }, + { name = "FLEET_SERVER_CERT", value = local.fleet.tls.cert_secret_key }, + { name = "FLEET_SERVER_KEY", value = local.fleet.tls.key_secret_key } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.software_installers.s3.bucket_name != "" ? [ + { name = "FLEET_S3_SOFTWARE_INSTALLERS_BUCKET", value = local.fleet.software_installers.s3.bucket_name }, + { name = "FLEET_S3_SOFTWARE_INSTALLERS_PREFIX", value = local.fleet.software_installers.s3.prefix }, + { name = "FLEET_S3_SOFTWARE_INSTALLERS_ENDPOINT_URL", value = local.fleet.software_installers.s3.endpoint_url }, + { name = "FLEET_S3_SOFTWARE_INSTALLERS_FORCE_S3_PATH_STYLE", value = local.fleet.software_installers.s3.force_s3_path_style }, + { name = "FLEET_S3_SOFTWARE_INSTALLERS_REGION", value = local.fleet.software_installers.s3.region } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.software_installers.s3.access_key_id != "" ? [ + { name = "FLEET_S3_SOFTWARE_INSTALLERS_ACCESS_KEY_ID", value = local.fleet.software_installers.s3.access_key_id } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.software_installers.s3.access_key_id != "" ? [ + { + name = "FLEET_S3_SOFTWARE_INSTALLERS_SECRET_ACCESS_KEY", + value_from = { + secret_key_ref = { + name = local.fleet.secret_name + key = local.fleet.software_installers.s3.secret_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = local.fleet.software_installers.s3.access_key_id == "" ? [ + { name = "FLEET_S3_SOFTWARE_INSTALLERS_STS_ASSUME_ROLE_ARN", value = local.fleet.software_installers.s3.sts_assume_role_arn } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.carving.s3.bucket_name != "" ? [ + { name = "FLEET_S3_BUCKET", value = local.fleet.carving.s3.bucket_name }, + { name = "FLEET_S3_PREFIX", value = local.fleet.carving.s3.prefix }, + { name = "FLEET_S3_ENDPOINT_URL", value = local.fleet.carving.s3.endpoint_url }, + { name = "FLEET_S3_FORCE_S3_PATH_STYLE", value = local.fleet.carving.s3.force_s3_path_style }, + { name = "FLEET_S3_CARVES_REGION", value = local.fleet.carving.s3.region } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.carving.s3.access_key_id != "" ? [ + { name = "FLEET_S3_ACCESS_KEY_ID", value = local.fleet.carving.s3.access_key_id } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.carving.s3.access_key_id != "" ? [ + { + name = "FLEET_S3_SECRET_ACCESS_KEY", + value_from = { + secret_key_ref = { + name = local.fleet.secret_name + key = local.fleet.carving.s3.secret_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = local.fleet.carving.s3.access_key_id == "" ? [ + { name = "FLEET_S3_STS_ASSUME_ROLE_ARN", value = local.fleet.carving.s3.sts_assume_role_arn } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.fleet.license.secret_name != "" ? [ + { + name = "FLEET_LICENSE_KEY", + value_from = { + secret_key_ref = { + name = local.fleet.license.secret_name + key = local.fleet.license.license_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = [ + { name = "FLEET_MYSQL_ADDRESS", value = local.database.address }, + { name = "FLEET_MYSQL_DATABASE", value = local.database.database }, + { name = "FLEET_MYSQL_USERNAME", value = local.database.username }, + { name = "FLEET_MYSQL_MAX_OPEN_CONNS", value = local.database.max_open_conns }, + { name = "FLEET_MYSQL_MAX_IDLE_CONNS", value = local.database.max_idle_conns }, + { name = "FLEET_MYSQL_CONN_MAX_LIFETIME", value = local.database.conn_max_lifetime } + ] + + content { + name = env.value.name + value = env.value.value + } + } + + env { + name = "FLEET_MYSQL_PASSWORD" + value_from { + secret_key_ref { + name = local.database.secret_name + key = local.database.password_key + } + } + } + + dynamic "env" { + for_each = local.database.tls.enabled ? [ + { name = "FLEET_MYSQL_TLS_CA", value = "/secrets/mysql/${local.database.tls.ca_cert_key}" }, + { name = "FLEET_MYSQL_TLS_CERT", value = "/secrets/mysql/${local.database.tls.cert_secret_key}" }, + { name = "FLEET_MYSQL_TLS_KEY", value = "/secrets/mysql/${local.database.tls.key_key}" }, + { name = "FLEET_MYSQL_TLS_CONFIG", value = local.database.tls.config }, + { name = "FLEET_MYSQL_TLS_SERVER_NAME", value = local.database.tls.server_name } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.database_read_replica.enabled ? [ + { name = "FLEET_MYSQL_READ_REPLICA_ADDRESS", value = local.database_read_replica.address }, + { name = "FLEET_MYSQL_READ_REPLICA_DATABASE", value = local.database_read_replica.database }, + { name = "FLEET_MYSQL_READ_REPLICA_USERNAME", value = local.database_read_replica.username }, + { name = "FLEET_MYSQL_READ_REPLICA_PASSWORD_PATH", value = local.database_read_replica.password_path }, + { name = "FLEET_MYSQL_READ_REPLICA_MAX_OPEN_CONNS", value = local.database_read_replica.max_open_conns }, + { name = "FLEET_MYSQL_READ_REPLICA_MAX_IDLE_CONNS", value = local.database_read_replica.max_idle_conns }, + { name = "FLEET_MYSQL_READ_REPLICA_CONN_MAX_LIFETIME", value = local.database_read_replica.conn_max_lifetime } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.database_read_replica.enabled ? [ + { + name = "FLEET_MYSQL_READ_REPLICA_PASSWORD", + value_from = { + secret_key_ref = { + name = local.database_read_replica.secret_name + key = local.database_read_replica.password_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = local.database_read_replica.enabled && local.database.tls.enabled ? [ + { name = "FLEET_MYSQL_READ_REPLICA_TLS_CA", value = "/secrets/mysql/${local.database_read_replica.tls.ca_cert_key}" }, + { name = "FLEET_MYSQL_READ_REPLICA_TLS_CERT", value = "/secrets/mysql/${local.database_read_replica.tls.cert_secret_key}" }, + { name = "FLEET_MYSQL_READ_REPLICA_TLS_KEY", value = "/secrets/mysql/${local.database_read_replica.tls.key_key}" }, + { name = "FLEET_MYSQL_READ_REPLICA_TLS_CONFIG", value = local.database_read_replica.tls.config }, + { name = "FLEET_MYSQL_READ_REPLICA_TLS_SERVER_NAME", value = local.database_read_replica.tls.server_name } + ] : [] + + content { + name = env.value.name + value = ocal.database.tls.enabled + } + } + + dynamic "env" { + for_each = [ + { name = "FLEET_REDIS_ADDRESS", value = local.cache.address }, + { name = "FLEET_REDIS_DATABASE", value = local.cache.database } + ] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.cache.use_password ? [ + { + name = "FLEET_REDIS_PASSWORD", + value_from = { + secret_key_ref = { + name = local.cache.secret_name + key = local.cache.password_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = [ + { name = "FLEET_OSQUERY_NODE_KEY_SIZE", value = local.osquery.node_key_size }, + { name = "FLEET_OSQUERY_LABEL_UPDATE_INTERVAL", value = local.osquery.label_update_interval }, + { name = "FLEET_OSQUERY_DETAIL_UPDATE_INTERVAL", value = local.osquery.detail_update_interval }, + { name = "FLEET_OSQUERY_STATUS_LOG_PLUGIN", value = local.osquery.logging.status_plugin }, + { name = "FLEET_OSQUERY_RESULT_LOG_PLUGIN", value = local.osquery.logging.result_plugin } + ] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "filesystem" ? [ + { name = "FLEET_FILESYSTEM_STATUS_LOG_FILE", value = "/logs/${local.osquery.logging.filesystem.status_log_file}" } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.result_plugin == "filesystem" ? [ + { name = "FLEET_FILESYSTEM_RESULT_LOG_FILE", value = "/logs/${local.osquery.logging.filesystem.result_log_file}" } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "filesystem" || local.osquery.logging.result_plugin == "filesystem" ? [ + { name = "FLEET_FILESYSTEM_ENABLE_LOG_ROTATION", value = local.osquery.logging.filesystem.enable_rotation }, + { name = "FLEET_FILESYSTEM_ENABLE_LOG_COMPRESSION", value = local.osquery.logging.filesystem.enable_compression } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "firehose" || local.osquery.logging.result_plugin == "firehose" ? [ + { name = "FLEET_FIREHOSE_REGION", value = local.osquery.logging.firehose.region } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "firehose" ? [ + { name = "FLEET_FIREHOSE_STATUS_STREAM", value = local.osquery.logging.firehose.status_stream } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.result_plugin == "firehose" ? [ + { name = "FLEET_FIREHOSE_RESULT_STREAM", value = local.osquery.logging.firehose.result_stream } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.firehose.access_key_id != "" ? [ + { + name = "FLEET_FIREHOSE_SECRET_ACCESS_KEY", + value_from = { + secret_key_ref = { + name = local.osquery.secret_name + key = local.osquery.logging.firehose.secret_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = local.osquery.logging.firehose.access_key_id == "" ? [ + { name = "FLEET_FIREHOSE_STS_ASSUME_ROLE_ARN", value = local.osquery.logging.firehose.sts_assume_role_arn } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "kinesis" || local.osquery.logging.result_plugin == "kinesis" ? [ + { name = "FLEET_KINESIS_REGION", value = local.osquery.logging.kinesis.region } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "kinesis" ? [ + { name = "FLEET_KINESIS_STATUS_STREAM", value = local.osquery.logging.kinesis.status_stream } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.result_plugin == "kinesis" ? [ + { name = "FLEET_KINESIS_RESULT_STREAM", value = local.osquery.logging.kinesis.result_stream } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.kinesis.access_key_id != "" ? [ + { name = "FLEET_KINESIS_ACCESS_KEY_ID", value = local.osquery.logging.kinesis.access_key_id } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.kinesis.access_key_id != "" ? [ + { + name = "FLEET_KINESIS_SECRET_ACCESS_KEY", + value_from = { + secret_key_ref = { + name = local.osquery.secret_name + key = local.osquery.logging.kinesis.secret_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = local.osquery.logging.kinesis.access_key_id == "" ? [ + { name = "FLEET_KINESIS_STS_ASSUME_ROLE_ARN", value = local.osquery.logging.kinesis.sts_assume_role_arn } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "lambda" || local.osquery.logging.result_plugin == "lambda" ? [ + { name = "FLEET_LAMBDA_REGION", value = local.osquery.logging.lambda.region } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "lambda" ? [ + { name = "FLEET_LAMBDA_STATUS_FUNCTION", value = local.osquery.logging.lambda.status_stream } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.result_plugin == "lambda" ? [ + { name = "FLEET_LAMBDA_RESULT_FUNCTION", value = local.osquery.logging.lambda.result_stream } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.lambda.access_key_id != "" ? [ + { name = "FLEET_LAMBDA_ACCESS_KEY_ID", value = local.osquery.logging.lambda.access_key_id } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.lambda.access_key_id != "" ? [ + { + name = "FLEET_LAMBDA_SECRET_ACCESS_KEY", + value_from = { + secret_key_ref = { + name = local.osquery.secret_name + key = local.osquery.logging.lambda.secret_key + } + } + } + ] : [] + + content { + name = env.value.name + value_from { + secret_key_ref { + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + } + } + } + } + + dynamic "env" { + for_each = local.osquery.logging.lambda.access_key_id == "" ? [ + { name = "FLEET_LAMBDA_STS_ASSUME_ROLE_ARN", value = local.osquery.logging.lambda.sts_assume_role_arn } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "pubsub" || local.osquery.logging.result_plugin == "pubsub" ? [ + { name = "FLEET_PUBSUB_PROJECT", value = local.osquery.logging.pubsub.project } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.status_plugin == "pubsub" ? [ + { name = "FLEET_PUBSUB_STATUS_TOPIC", value = local.osquery.logging.pubsub.status_topic } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.osquery.logging.result_plugin == "pubsub" ? [ + { name = "FLEET_PUBSUB_RESULT_TOPIC", value = local.osquery.logging.pubsub.result_topic } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.vuln_processing.dedicated ? [ + { name = "FLEET_VULNERABILITIES_DISABLE_SCHEDULE", value = local.vuln_processing.dedicated } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + dynamic "env" { + for_each = local.environment_variables + + content { + name = env.value.name + value = env.value.value + } + } + + + dynamic "env_from" { + for_each = local.environment_from_config_maps + + content { + config_map_ref { + name = env_from.value.name + } + } + } + + dynamic "env_from" { + for_each = local.environment_from_secrets + + content { + secret_ref { + name = env_from.value.name + } + } + } + + security_context { + run_as_user = local.fleet.security_context.run_as_user + run_as_group = local.fleet.security_context.run_as_group + run_as_non_root = local.fleet.security_context.run_as_non_root + read_only_root_filesystem = "true" + privileged = "false" + allow_privilege_escalation = "false" + capabilities { + drop = ["ALL"] + } + } + + port { + name = "fleet" + container_port = local.fleet.listen_port + protocol = "TCP" + } + + liveness_probe { + http_get { + path = "healthz" + port = local.fleet.listen_port + scheme = local.fleet.tls.enabled ? "HTTPS" : "HTTP" + } + failure_threshold = "3" + period_seconds = "3" + success_threshold = "1" + timeout_seconds = "1" + } + + readiness_probe { + http_get { + path = "healthz" + port = local.fleet.listen_port + scheme = local.fleet.tls.enabled ? "HTTPS" : "HTTP" + } + failure_threshold = "3" + period_seconds = "10" + success_threshold = "1" + timeout_seconds = "1" + } + + resources { + limits = { + cpu = local.resources.limits.cpu + memory = local.resources.limits.memory + } + requests = { + cpu = local.resources.requests.cpu + memory = local.resources.requests.memory + } + } + + volume_mount { + name = "tmp" + mount_path = "/tmp" + } + + dynamic "volume_mount" { + for_each = local.fleet.tls.enabled ? [ + { name = "fleet-tls", read_only = true, mount_path = "/secrets/tls" } + ] : [] + + content { + name = volume_mount.value.name + read_only = volume_mount.value.read_only + mount_path = volume_mount.value.mount_path + } + } + + dynamic "volume_mount" { + for_each = local.database.tls.enabled ? [ + { name = "mysql-tls", read_only = true, mount_path = "/secrets/mysql" } + ] : [] + + content { + name = volume_mount.value.name + read_only = volume_mount.value.read_only + mount_path = volume_mount.value.mount_path + } + } + + dynamic "volume_mount" { + for_each = local.osquery.logging.status_plugin == "filesystem" || local.osquery.logging.result_plugin == "filesystem" ? [ + { name = "osquery-logs", mount_path = "/logs" } + ] : [] + + content { + name = volume_mount.value.name + mount_path = volume_mount.value.mount_path + } + } + } + + dynamic "container" { + for_each = local.gke.cloud_sql.enable_proxy ? [ + { + name = "cloudql-proxy", + image = "${local.gke.cloud_sql.image_repository}:${local.gke.cloud_sql.image_tag}", + command = ["/cloud_sql_proxy", "-verbose=${local.gke.cloud_sql.verbose}", "-instances=${local.gke.cloud_sql.instance_name}=tcp:3306"] + resources = { + limits = { + cpu = "0.1", + memory = "150Mi" + }, + requests = { + cpu = "0.1", + memory = "50Mi" + } + } + security_context = { + allow_privilege_escalation = false, + capabilities = { + drop = ["ALL"] + }, + privileged = false, + read_only_root_filesystem = true, + run_as_user = local.fleet.security_context.run_as_user, + run_as_group = local.fleet.security_context.run_as_group, + run_as_non_root = local.fleet.security_context.run_as_non_root + } + } + ] : [] + + content { + name = container.value.name + image = container.value.image + command = container.value.command + resources { + limits = { + cpu = container.value.resources.limits.cpu + memory = container.value.resources.limits.memory + } + requests = { + cpu = container.value.resources.requests.cpu + memory = container.value.resources.requests.memory + } + } + security_context { + allow_privilege_escalation = container.value.security_context.allow_privilege_escalation + capabilities { + drop = container.value.security_context.capabilities.drop + } + privileged = container.value.security_context.privileged + read_only_root_filesystem = container.value.security_context.read_only_root_filesystem + run_as_group = container.value.security_context.run_as_group + run_as_user = container.value.security_context.run_as_user + run_as_non_root = container.value.security_context.run_as_non_root + } + } + } + + host_pid = false + host_network = false + host_ipc = false + + volume { + name = "tmp" + empty_dir {} + } + + dynamic "volume" { + for_each = local.fleet.tls.enabled ? [ + { + name = "fleet-tls", + secret_name = local.fleet.tls.unique_tls_secret ? local.fleet.tls.secretName : local.fleet.secret_name + } + ] : [] + + content { + name = volume.value.name + secret { + secret_name = volume.value.secret_name + } + } + } + + dynamic "volume" { + for_each = local.database.tls.enabled ? [ + { + name = "mysql-tls", + secret_name = local.database.tls.secret_name + } + ] : [] + + content { + name = volume.value.name + secret { + secret_name = volume.value.secret_name + } + } + } + + dynamic "volume" { + for_each = local.osquery.logging.status_plugin == "filesystem" || local.osquery.logging.result_plugin == "filesystem" ? [ + { + name = "osquery-logs", + size_limit = local.osquery.logging.filesystem.volume_size + } + ] : [] + + content { + name = volume.value.name + empty_dir { + size_limit = volume.value.size_limit + } + } + } + + dynamic "affinity" { + for_each = local.affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null + + content { + pod_affinity { + required_during_scheduling_ignored_during_execution { + label_selector { + match_expressions { + key = affinity.value.label_selector.match_expressions[*].key + operator = affinity.value.label_selector.match_expressions[*].operator + values = affinity.value.label_selector.match_expressions[*].values + } + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "affinity" { + for_each = local.affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null + + content { + pod_affinity { + preferred_during_scheduling_ignored_during_execution { + pod_affinity_term { + preference = affinity.value.preference + } + topology_key = affinity.value.topology_key + } + } + } + } + + + dynamic "affinity" { + for_each = local.anti_affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null + + content { + pod_anti_affinity { + required_during_scheduling_ignored_during_execution { + label_selector { + match_expressions { + key = affinity.value.label_selector.match_expressions[*].key + operator = affinity.value.label_selector.match_expressions[*].operator + values = affinity.value.label_selector.match_expressions[*].values + } + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "affinity" { + for_each = local.anti_affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null + + content { + pod_anti_affinity { + preferred_during_scheduling_ignored_during_execution { + pod_affinity_term { + label_selector = affinity.value.label_selector.label_selector + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "image_pull_secrets" { + for_each = var.image_pull_secrets + + content { + name = image_pull_secrets.value["name"] + } + } + } } - - spec { - replicas = local.replicas - - selector { - match_labels = { - app = "fleet" - component = "fleet-server" - } - } - - strategy { - type = "RollingUpdate" - rolling_update { - max_unavailable = "25%" - max_surge = "25%" - } - } - - template { - metadata { - labels = { - app = "fleet" - component = "fleet-server" - } - annotations = local.pod_annotations - } - - spec { - service_account_name = resource.kubernetes_service_account.fleet-sa.metadata[0].name - container { - name = "fleet" - image = "${local.image_repository}:${local.image_tag}" - - command = ["/usr/bin/fleet"] - args = ["serve"] - - dynamic "env" { - for_each = [ - { name = "FLEET_VULNERABILITIES_DATABASES_PATH", value = "/tmp/vuln" }, - { name = "FLEET_SERVER_ADDRESS", value = "0.0.0.0:${local.fleet.listen_port}" }, - { name = "FLEET_AUTH_BCRYPT_COST", value = local.fleet.auth.b_crypto_cost }, - { name = "FLEET_AUTH_SALT_KEY_SIZE", value = local.fleet.auth.salt_key_size }, - { name = "FLEET_APP_TOKEN_KEY_SIZE", value = local.fleet.app.token_key_size }, - { name = "FLEET_APP_TOKEN_VALIDITY_PERIOD", value = local.fleet.app.invite_token_validity_period }, - { name = "FLEET_SESSION_KEY_SIZE", value = local.fleet.session.key_size }, - { name = "FLEET_SESSION_DURATION", value = local.fleet.session.duration }, - { name = "FLEET_LOGGING_DEBUG", value = local.fleet.logging.debug }, - { name = "FLEET_LOGGING_JSON", value = local.fleet.logging.json }, - { name = "FLEET_LOGGING_DISABLE_BANNER", value = local.fleet.logging.disable_banner }, - { name = "FLEET_SERVER_TLS", value = local.fleet.tls.enabled } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.fleet.tls.enabled ? [ - { name = "FLEET_SERVER_TLS_COMPATIBILITY", value = local.fleet.tls.compatibility }, - { name = "FLEET_SERVER_CERT", value = local.fleet.tls.cert_secret_key }, - { name = "FLEET_SERVER_KEY", value = local.fleet.tls.key_secret_key } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.fleet.carving.s3.bucket_name != "" ? [ - { name = "FLEET_S3_BUCKET", value = local.fleet.carving.s3.bucket_name }, - { name = "FLEET_S3_PREFIX", value = local.fleet.carving.s3.prefix } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.fleet.carving.s3.access_key_id != "" ? [ - { - name = "FLEET_S3_SECRET_ACCESS_KEY", - value_from = { - secret_key_ref = { - name = local.fleet.secret_name - key = local.fleet.carving.s3.secret_key - } - } - } - ] : [] - - content { - name = env.value.name - value_from { - secret_key_ref { - name = env.value.value_from.secret_key_ref.name - key = env.value.value_from.secret_key_ref.key - } - } - } - } - - dynamic "env" { - for_each = local.fleet.carving.s3.access_key_id == "" ? [ - { name = "FLEET_S3_STS_ASSUME_ROLE_ARN", value = local.fleet.carving.s3.secret_key } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.fleet.license.secret_name != "" ? [ - { - name = "FLEET_LICENSE_KEY", - value_from = { - secret_key_ref = { - name = local.fleet.license.secret_name - key = local.fleet.license.license_key - } - } - } - ] : [] - - content { - name = env.value.name - value_from { - secret_key_ref { - name = env.value.value_from.secret_key_ref.name - key = env.value.value_from.secret_key_ref.key - } - } - } - } - - dynamic "env" { - for_each = [ - { name = "FLEET_MYSQL_ADDRESS", value = local.database.address }, - { name = "FLEET_MYSQL_DATABASE", value = local.database.database }, - { name = "FLEET_MYSQL_USERNAME", value = local.database.username }, - { name = "FLEET_MYSQL_MAX_OPEN_CONNS", value = local.database.max_open_conns }, - { name = "FLEET_MYSQL_MAX_IDLE_CONNS", value = local.database.max_idle_conns }, - { name = "FLEET_MYSQL_CONN_MAX_LIFETIME", value = local.database.conn_max_lifetime } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - env { - name = "FLEET_MYSQL_PASSWORD" - value_from { - secret_key_ref { - name = local.database.secret_name - key = local.database.password_key - } - } - } - - dynamic "env" { - for_each = local.database.tls.enabled ? [ - { name = "FLEET_MYSQL_TLS_CA", value = "/secrets/mysql/${local.database.tls.ca_cert_key}" }, - { name = "FLEET_MYSQL_TLS_CERT", value = "/secrets/mysql/${local.database.tls.cert_secret_key}" }, - { name = "FLEET_MYSQL_TLS_KEY", value = "/secrets/mysql/${local.database.tls.key_key}" }, - { name = "FLEET_MYSQL_TLS_CONFIG", value = local.database.tls.config }, - { name = "FLEET_MYSQL_TLS_SERVER_NAME", value = local.database.tls.server_name } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = [ - { name = "FLEET_MYSQL_READ_REPLICA_ADDRESS", value = local.database_read_replica.address }, - { name = "FLEET_MYSQL_READ_REPLICA_DATABASE", value = local.database_read_replica.database }, - { name = "FLEET_MYSQL_READ_REPLICA_USERNAME", value = local.database_read_replica.username }, - { name = "FLEET_MYSQL_READ_REPLICA_PASSWORD_PATH", value = local.database_read_replica.password_path }, - { name = "FLEET_MYSQL_READ_REPLICA_MAX_OPEN_CONNS", value = local.database_read_replica.max_open_conns }, - { name = "FLEET_MYSQL_READ_REPLICA_MAX_IDLE_CONNS", value = local.database_read_replica.max_idle_conns }, - { name = "FLEET_MYSQL_READ_REPLICA_CONN_MAX_LIFETIME", value = local.database_read_replica.conn_max_lifetime } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - env { - name = "FLEET_MYSQL_READ_REPLICA_PASSWORD" - value_from { - secret_key_ref { - name = local.database_read_replica.secret_name - key = local.database_read_replica.password_key - } - } - } - - dynamic "env" { - for_each = local.database.tls.enabled ? [ - { name = "FLEET_MYSQL_READ_REPLICA_TLS_CA", value = "/secrets/mysql/${local.database_read_replica.tls.ca_cert_key}" }, - { name = "FLEET_MYSQL_READ_REPLICA_TLS_CERT", value = "/secrets/mysql/${local.database_read_replica.tls.cert_secret_key}" }, - { name = "FLEET_MYSQL_READ_REPLICA_TLS_KEY", value = "/secrets/mysql/${local.database_read_replica.tls.key_key}" }, - { name = "FLEET_MYSQL_READ_REPLICA_TLS_CONFIG", value = local.database_read_replica.tls.config }, - { name = "FLEET_MYSQL_READ_REPLICA_TLS_SERVER_NAME", value = local.database_read_replica.tls.server_name } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = [ - { name = "FLEET_REDIS_ADDRESS", value = local.cache.address }, - { name = "FLEET_REDIS_DATABASE", value = local.cache.database } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.cache.use_password ? [ - { - name = "FLEET_REDIS_PASSWORD", - value_from = { - secret_key_ref = { - name = local.cache.secret_name - key = local.cache.password_key - } - } - } - ] : [] - - content { - name = env.value.name - value_from { - secret_key_ref { - name = env.value.value_from.secret_key_ref.name - key = env.value.value_from.secret_key_ref.key - } - } - } - } - - dynamic "env" { - for_each = [ - { name = "FLEET_OSQUERY_NODE_KEY_SIZE", value = local.osquery.node_key_size }, - { name = "FLEET_OSQUERY_LABEL_UPDATE_INTERVAL", value = local.osquery.label_update_interval }, - { name = "FLEET_OSQUERY_DETAIL_UPDATE_INTERVAL", value = local.osquery.detail_update_interval }, - { name = "FLEET_OSQUERY_STATUS_LOG_PLUGIN", value = local.osquery.logging.status_plugin }, - { name = "FLEET_OSQUERY_RESULT_LOG_PLUGIN", value = local.osquery.logging.result_plugin } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "filesystem" ? [ - { name = "FLEET_FILESYSTEM_STATUS_LOG_FILE", value = "/logs/${local.osquery.logging.filesystem.status_log_file}" } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.result_plugin == "filesystem" ? [ - { name = "FLEET_FILESYSTEM_RESULT_LOG_FILE", value = "/logs/${local.osquery.logging.filesystem.result_log_file}" } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "filesystem" || local.osquery.logging.result_plugin == "filesystem" ? [ - { name = "FLEET_FILESYSTEM_ENABLE_LOG_ROTATION", value = local.osquery.logging.filesystem.enable_rotation }, - { name = "FLEET_FILESYSTEM_ENABLE_LOG_COMPRESSION", value = local.osquery.logging.filesystem.enable_compression } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "firehose" || local.osquery.logging.result_plugin == "firehose" ? [ - { name = "FLEET_FIREHOSE_REGION", value = local.osquery.logging.firehose.region } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "firehose" ? [ - { name = "FLEET_FIREHOSE_STATUS_STREAM", value = local.osquery.logging.firehose.status_stream } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.result_plugin == "firehose" ? [ - { name = "FLEET_FIREHOSE_RESULT_STREAM", value = local.osquery.logging.firehose.result_stream } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.firehose.access_key_id != "" ? [ - { - name = "FLEET_FIREHOSE_SECRET_ACCESS_KEY", - value_from = { - secret_key_ref = { - name = local.osquery.secret_name - key = local.osquery.logging.firehose.secret_key - } - } - } - ] : [] - - content { - name = env.value.name - value_from { - secret_key_ref { - name = env.value.value_from.secret_key_ref.name - key = env.value.value_from.secret_key_ref.key - } - } - } - } - - dynamic "env" { - for_each = local.osquery.logging.firehose.access_key_id == "" ? [ - { name = "FLEET_FIREHOSE_STS_ASSUME_ROLE_ARN", value = local.osquery.logging.firehose.sts_assume_role_arn } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "kinesis" || local.osquery.logging.result_plugin == "kinesis" ? [ - { name = "FLEET_KINESIS_REGION", value = local.osquery.logging.kinesis.region } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "kinesis" ? [ - { name = "FLEET_KINESIS_STATUS_STREAM", value = local.osquery.logging.kinesis.status_stream } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.result_plugin == "kinesis" ? [ - { name = "FLEET_KINESIS_RESULT_STREAM", value = local.osquery.logging.kinesis.result_stream } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.kinesis.access_key_id != "" ? [ - { name = "FLEET_KINESIS_ACCESS_KEY_ID", value = local.osquery.logging.kinesis.access_key_id } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.kinesis.access_key_id != "" ? [ - { - name = "FLEET_KINESIS_SECRET_ACCESS_KEY", - value_from = { - secret_key_ref = { - name = local.osquery.secret_name - key = local.osquery.logging.kinesis.secret_key - } - } - } - ] : [] - - content { - name = env.value.name - value_from { - secret_key_ref { - name = env.value.value_from.secret_key_ref.name - key = env.value.value_from.secret_key_ref.key - } - } - } - } - - dynamic "env" { - for_each = local.osquery.logging.kinesis.access_key_id == "" ? [ - { name = "FLEET_KINESIS_STS_ASSUME_ROLE_ARN", value = local.osquery.logging.kinesis.sts_assume_role_arn } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "lambda" || local.osquery.logging.result_plugin == "lambda" ? [ - { name = "FLEET_LAMBDA_REGION", value = local.osquery.logging.lambda.region } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "lambda" ? [ - { name = "FLEET_LAMBDA_STATUS_FUNCTION", value = local.osquery.logging.lambda.status_stream } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.result_plugin == "lambda" ? [ - { name = "FLEET_LAMBDA_RESULT_FUNCTION", value = local.osquery.logging.lambda.result_stream } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.lambda.access_key_id != "" ? [ - { name = "FLEET_LAMBDA_ACCESS_KEY_ID", value = local.osquery.logging.lambda.access_key_id } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.lambda.access_key_id != "" ? [ - { - name = "FLEET_LAMBDA_SECRET_ACCESS_KEY", - value_from = { - secret_key_ref = { - name = local.osquery.secret_name - key = local.osquery.logging.lambda.secret_key - } - } - } - ] : [] - - content { - name = env.value.name - value_from { - secret_key_ref { - name = env.value.value_from.secret_key_ref.name - key = env.value.value_from.secret_key_ref.key - } - } - } - } - - dynamic "env" { - for_each = local.osquery.logging.lambda.access_key_id == "" ? [ - { name = "FLEET_LAMBDA_STS_ASSUME_ROLE_ARN", value = local.osquery.logging.lambda.sts_assume_role_arn } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "pubsub" || local.osquery.logging.result_plugin == "pubsub" ? [ - { name = "FLEET_PUBSUB_PROJECT", value = local.osquery.logging.pubsub.project } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.status_plugin == "pubsub" ? [ - { name = "FLEET_PUBSUB_STATUS_TOPIC", value = local.osquery.logging.pubsub.status_topic } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.osquery.logging.result_plugin == "pubsub" ? [ - { name = "FLEET_PUBSUB_RESULT_TOPIC", value = local.osquery.logging.pubsub.result_topic } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.vuln_processing.dedicated ? [ - { name = "FLEET_VULNERABILITIES_DISABLE_SCHEDULE", value = local.vuln_processing.dedicated } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env"{ - for_each = local.environment_variables - - content { - name = env.value.name - value = env.value.value - } - } - - - dynamic "env_from" { - for_each = local.environment_from_config_maps - - content { - config_map_ref { - name = env_from.value.name - } - } - } - - dynamic "env_from" { - for_each = local.environment_from_secrets - - content { - secret_ref { - name = env_from.value.name - } - } - } - - security_context { - run_as_user = local.fleet.security_context.run_as_user - run_as_group = local.fleet.security_context.run_as_group - run_as_non_root = local.fleet.security_context.run_as_non_root - read_only_root_filesystem = "true" - privileged = "false" - allow_privilege_escalation = "false" - capabilities { - drop = ["ALL"] - } - } - - port { - name = "fleet" - container_port = local.fleet.listen_port - protocol = "TCP" - } - - liveness_probe { - http_get { - path = "healthz" - port = local.fleet.listen_port - scheme = local.fleet.tls.enabled ? "HTTPS" : "HTTP" - } - failure_threshold = "3" - period_seconds = "3" - success_threshold = "1" - timeout_seconds = "1" - } - - readiness_probe { - http_get { - path = "healthz" - port = local.fleet.listen_port - scheme = local.fleet.tls.enabled ? "HTTPS" : "HTTP" - } - failure_threshold = "3" - period_seconds = "10" - success_threshold = "1" - timeout_seconds = "1" - } - - resources { - limits = { - cpu = local.resources.limits.cpu - memory = local.resources.limits.memory - } - requests = { - cpu = local.resources.requests.cpu - memory = local.resources.requests.memory - } - } - - volume_mount { - name = "tmp" - mount_path = "/tmp" - } - - dynamic "volume_mount" { - for_each = local.fleet.tls.enabled ? [ - { name = "fleet-tls", read_only = true, mount_path = "/secrets/tls" } - ] : [] - - content { - name = volume_mount.value.name - read_only = volume_mount.value.read_only - mount_path = volume_mount.value.mount_path - } - } - - dynamic "volume_mount" { - for_each = local.database.tls.enabled ? [ - { name = "mysql-tls", read_only = true, mount_path = "/secrets/mysql" } - ] : [] - - content { - name = volume_mount.value.name - read_only = volume_mount.value.read_only - mount_path = volume_mount.value.mount_path - } - } - - dynamic "volume_mount" { - for_each = local.osquery.logging.status_plugin == "filesystem" || local.osquery.logging.result_plugin == "filesystem" ? [ - { name = "osquery-logs", mount_path = "/logs" } - ] : [] - - content { - name = volume_mount.value.name - mount_path = volume_mount.value.mount_path - } - } - } - - dynamic "container" { - for_each = local.gke.cloud_sql.enable_proxy ? [ - { - name = "cloudql-proxy", - image = "${local.gke.cloud_sql.image_repository}:${local.gke.cloud_sql.image_tag}", - command = ["/cloud_sql_proxy", "-verbose=${local.gke.cloud_sql.verbose}", "-instances=${local.gke.cloud_sql.instance_name}=tcp:3306"] - resources = { - limits = { - cpu = "0.1", - memory = "150Mi" - }, - requests = { - cpu = "0.1", - memory = "50Mi" - } - } - security_context = { - allow_privilege_escalation = false, - capabilities = { - drop = ["ALL"] - }, - privileged = false, - read_only_root_filesystem = true, - run_as_user = local.fleet.security_context.run_as_user, - run_as_group = local.fleet.security_context.run_as_group, - run_as_non_root = local.fleet.security_context.run_as_non_root - } - } - ] : [] - - content { - name = container.value.name - image = container.value.image - command = container.value.command - resources { - limits = { - cpu = container.value.resources.limits.cpu - memory = container.value.resources.limits.memory - } - requests = { - cpu = container.value.resources.requests.cpu - memory = container.value.resources.requests.memory - } - } - security_context { - allow_privilege_escalation = container.value.security_context.allow_privilege_escalation - capabilities { - drop = container.value.security_context.capabilities.drop - } - privileged = container.value.security_context.privileged - read_only_root_filesystem = container.value.security_context.read_only_root_filesystem - run_as_group = container.value.security_context.run_as_group - run_as_user = container.value.security_context.run_as_user - run_as_non_root = container.value.security_context.run_as_non_root - } - } - } - - host_pid = false - host_network = false - host_ipc = false - - volume { - name = "tmp" - empty_dir {} - } - - dynamic "volume" { - for_each = local.fleet.tls.enabled ? [ - { - name = "fleet-tls", - secret_name = local.fleet.tls.unique_tls_secret ? local.fleet.tls.secretName : local.fleet.secret_name - } - ] : [] - - content { - name = volume.value.name - secret { - secret_name = volume.value.secret_name - } - } - } - - dynamic "volume" { - for_each = local.database.tls.enabled ? [ - { - name = "mysql-tls", - secret_name = local.database.tls.secret_name - } - ] : [] - - content { - name = volume.value.name - secret { - secret_name = volume.value.secret_name - } - } - } - - dynamic "volume" { - for_each = local.osquery.logging.status_plugin == "filesystem" || local.osquery.logging.result_plugin == "filesystem" ? [ - { - name = "osquery-logs", - size_limit = local.osquery.logging.filesystem.volume_size - } - ] : [] - - content { - name = volume.value.name - empty_dir { - size_limit = volume.value.size_limit - } - } - } - - dynamic "affinity" { - for_each = local.affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null - - content { - pod_affinity { - required_during_scheduling_ignored_during_execution { - label_selector { - match_expressions { - key = affinity.value.label_selector.match_expressions[*].key - operator = affinity.value.label_selector.match_expressions[*].operator - values = affinity.value.label_selector.match_expressions[*].values - } - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "affinity" { - for_each = local.affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null - - content { - pod_affinity { - preferred_during_scheduling_ignored_during_execution { - pod_affinity_term { - preference = affinity.value.preference - } - topology_key = affinity.value.topology_key - } - } - } - } - - - dynamic "affinity" { - for_each = local.anti_affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null - - content { - pod_anti_affinity { - required_during_scheduling_ignored_during_execution { - label_selector { - match_expressions { - key = affinity.value.label_selector.match_expressions[*].key - operator = affinity.value.label_selector.match_expressions[*].operator - values = affinity.value.label_selector.match_expressions[*].values - } - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "affinity" { - for_each = local.anti_affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null - - content { - pod_anti_affinity { - preferred_during_scheduling_ignored_during_execution { - pod_affinity_term { - label_selector = affinity.value.label_selector.label_selector - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "image_pull_secrets" { - for_each = var.image_pull_secrets - - content { - name = image_pull_secrets.value["name"] - } - } - } - } - } - depends_on = [ - resource.kubernetes_job.migration // dependency should only be here if migration is enabled - ] + } + depends_on = [ + resource.kubernetes_job.migration // dependency should only be here if migration is enabled + ] } diff --git a/k8s/ingress.tf b/k8s/ingress.tf index 2c128e6..9494c22 100644 --- a/k8s/ingress.tf +++ b/k8s/ingress.tf @@ -1,23 +1,23 @@ -resource "kubernetes_ingress_v1" "fleet-ingress"{ +resource "kubernetes_ingress_v1" "fleet-ingress" { count = local.ingress.enabled ? 1 : 0 metadata { - name = "fleet" - namespace = data.kubernetes_namespace.fleet.metadata[0].name - labels = local.ingress.labels + name = "fleet" + namespace = data.kubernetes_namespace.fleet.metadata[0].name + labels = local.ingress.labels annotations = local.ingress.annotations } spec { ingress_class_name = local.ingress.class_name dynamic "tls" { - for_each = local.ingress.tls.hosts + for_each = local.ingress.tls.hosts - content { - hosts = [tls.value] - secret_name = local.ingress.tls.secret_name - } + content { + hosts = [tls.value] + secret_name = local.ingress.tls.secret_name + } } - + dynamic "rule" { for_each = local.ingress.hosts diff --git a/k8s/job.tf b/k8s/job.tf index da11bfc..ff743ff 100644 --- a/k8s/job.tf +++ b/k8s/job.tf @@ -1,334 +1,334 @@ resource "kubernetes_job" "migration" { - metadata{ + metadata { + name = "fleet-migration" + namespace = data.kubernetes_namespace.fleet.metadata[0].name + labels = { + app = "fleet" + } + annotations = local.pod_annotations + } + spec { + parallelism = local.fleet.migrations.parallelism + completions = local.fleet.migrations.completions + active_deadline_seconds = local.fleet.migrations.active_deadline_seconds + backoff_limit = local.fleet.migrations.backoff_limit + + manual_selector = local.fleet.migrations.manual_selector + + template { + metadata { name = "fleet-migration" - namespace = data.kubernetes_namespace.fleet.metadata[0].name labels = { - app = "fleet" + app = "fleet" } annotations = local.pod_annotations - } - spec { - parallelism = local.fleet.migrations.parallelism - completions = local.fleet.migrations.completions - active_deadline_seconds = local.fleet.migrations.active_deadline_seconds - backoff_limit = local.fleet.migrations.backoff_limit + } - manual_selector = local.fleet.migrations.manual_selector + spec { + service_account_name = resource.kubernetes_service_account.fleet-sa.metadata[0].name + share_process_namespace = "true" + restart_policy = local.fleet.migrations.restart_policy - template { - metadata { - name = "fleet-migration" - labels = { - app = "fleet" - } - annotations = local.pod_annotations + container { + name = "fleet-migration" + image = "${local.image_repository}:${local.image_tag}" + + command = ["/bin/sh", "-c"] + args = local.gke.cloud_sql.enable_proxy ? [ + "/usr/bin/fleet prepare db --no-prompt; sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;" + ] : [ + "/usr/bin/fleet prepare db --no-prompt;" + ] + + dynamic "env" { + for_each = [ + { name = "FLEET_SERVER_ADDRESS", value = "0.0.0.0:${local.fleet.listen_port}" }, + { name = "FLEET_AUTH_BCRYPT_COST", value = local.fleet.auth.b_crypto_cost }, + { name = "FLEET_AUTH_SALT_KEY_SIZE", value = local.fleet.auth.salt_key_size }, + { name = "FLEET_APP_TOKEN_KEY_SIZE", value = local.fleet.app.token_key_size }, + { name = "FLEET_APP_TOKEN_VALIDITY_PERIOD", value = local.fleet.app.invite_token_validity_period }, + { name = "FLEET_SESSION_KEY_SIZE", value = local.fleet.session.key_size }, + { name = "FLEET_SESSION_DURATION", value = local.fleet.session.duration }, + { name = "FLEET_LOGGING_DEBUG", value = local.fleet.logging.debug }, + { name = "FLEET_LOGGING_JSON", value = local.fleet.logging.json }, + { name = "FLEET_LOGGING_DISABLE_BANNER", value = local.fleet.logging.disable_banner }, + { name = "FLEET_SERVER_TLS", value = local.fleet.tls.enabled } + ] + + content { + name = env.value.name + value = env.value.value } + } - spec { - service_account_name = resource.kubernetes_service_account.fleet-sa.metadata[0].name - share_process_namespace = "true" - restart_policy = local.fleet.migrations.restart_policy + dynamic "env" { + for_each = local.fleet.tls.enabled ? [ + { name = "FLEET_SERVER_TLS_COMPATIBILITY", value = local.fleet.tls.compatibility }, + { name = "FLEET_SERVER_CERT", value = local.fleet.tls.cert_secret_key }, + { name = "FLEET_SERVER_KEY", value = local.fleet.tls.key_secret_key } + ] : [] - container { - name = "fleet-migration" - image = "${local.image_repository}:${local.image_tag}" - - command = ["/bin/sh", "-c"] - args = local.gke.cloud_sql.enable_proxy ? [ - "/usr/bin/fleet prepare db --no-prompt; sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;" - ] : [ - "/usr/bin/fleet prepare db --no-prompt;" - ] - - dynamic "env" { - for_each = [ - { name = "FLEET_SERVER_ADDRESS", value = "0.0.0.0:${local.fleet.listen_port}" }, - { name = "FLEET_AUTH_BCRYPT_COST", value = local.fleet.auth.b_crypto_cost }, - { name = "FLEET_AUTH_SALT_KEY_SIZE", value = local.fleet.auth.salt_key_size }, - { name = "FLEET_APP_TOKEN_KEY_SIZE", value = local.fleet.app.token_key_size }, - { name = "FLEET_APP_TOKEN_VALIDITY_PERIOD", value = local.fleet.app.invite_token_validity_period }, - { name = "FLEET_SESSION_KEY_SIZE", value = local.fleet.session.key_size }, - { name = "FLEET_SESSION_DURATION", value = local.fleet.session.duration }, - { name = "FLEET_LOGGING_DEBUG", value = local.fleet.logging.debug }, - { name = "FLEET_LOGGING_JSON", value = local.fleet.logging.json }, - { name = "FLEET_LOGGING_DISABLE_BANNER", value = local.fleet.logging.disable_banner }, - { name = "FLEET_SERVER_TLS", value = local.fleet.tls.enabled } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = local.fleet.tls.enabled ? [ - { name = "FLEET_SERVER_TLS_COMPATIBILITY", value = local.fleet.tls.compatibility }, - { name = "FLEET_SERVER_CERT", value = local.fleet.tls.cert_secret_key }, - { name = "FLEET_SERVER_KEY", value = local.fleet.tls.key_secret_key } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - dynamic "env" { - for_each = [ - { name = "FLEET_MYSQL_ADDRESS", value = local.database.address }, - { name = "FLEET_MYSQL_DATABASE", value = local.database.database }, - { name = "FLEET_MYSQL_USERNAME", value = local.database.username }, - { name = "FLEET_MYSQL_MAX_OPEN_CONNS", value = local.database.max_open_conns }, - { name = "FLEET_MYSQL_MAX_IDLE_CONNS", value = local.database.max_idle_conns }, - { name = "FLEET_MYSQL_CONN_MAX_LIFETIME", value = local.database.conn_max_lifetime } - ] - - content { - name = env.value.name - value = env.value.value - } - } - - env { - name = "FLEET_MYSQL_PASSWORD" - value_from { - secret_key_ref { - name = local.database.secret_name - key = local.database.password_key - } - } - } - - dynamic "env" { - for_each = local.database.tls.enabled ? [ - { name = "FLEET_MYSQL_TLS_CA", value = "/secrets/mysql/${local.database.tls.ca_cert_key}" }, - { name = "FLEET_MYSQL_TLS_CERT", value = "/secrets/mysql/${local.database.tls.cert_secret_key}" }, - { name = "FLEET_MYSQL_TLS_KEY", value = "/secrets/mysql/${local.database.tls.key_key}" }, - { name = "FLEET_MYSQL_TLS_CONFIG", value = local.database.tls.config }, - { name = "FLEET_MYSQL_TLS_SERVER_NAME", value = local.database.tls.server_name } - ] : [] - - content { - name = env.value.name - value = env.value.value - } - } - - security_context { - run_as_user = local.fleet.security_context.run_as_user - run_as_group = local.fleet.security_context.run_as_group - run_as_non_root = local.fleet.security_context.run_as_non_root - read_only_root_filesystem = "true" - privileged = "false" - allow_privilege_escalation = "false" - - dynamic "capabilities" { - for_each = local.gke.cloud_sql.enable_proxy ? [ - { name = "add", values = ["SYS_PTRACE"] } - ] : [ - { name = "drop", values = ["ALL"] } - ] - - content { - add = capabilities.value.name == "add" ? capabilities.value.values : [] - drop = capabilities.value.name == "drop" ? capabilities.value.values : [] - } - } - } - - resources { - limits = { - cpu = local.resources.limits.cpu - memory = local.resources.limits.memory - } - requests = { - cpu = local.resources.requests.cpu - memory = local.resources.requests.memory - } - } - - dynamic "volume_mount" { - for_each = local.database.tls.enabled ? [ - { name = "mysql-tls", read_only = true, mount_path = "/secrets/mysql" } - ] : [] - - content { - name = volume_mount.value.name - read_only = volume_mount.value.read_only - mount_path = volume_mount.value.mount_path - } - } - } - - dynamic "container" { - for_each = local.gke.cloud_sql.enable_proxy ? [ - { - name = "cloudql-proxy", - image = "${local.gke.cloud_sql.image_repository}:${local.gke.cloud_sql.image_tag}", - command = ["/cloud_sql_proxy", "-verbose=${local.gke.cloud_sql.verbose}", "-instances=${local.gke.cloud_sql.instance_name}=tcp:3306"] - resources = { - limits = { - cpu = "0.5", - memory = "150Mi" - }, - requests = { - cpu = "0.1", - memory = "50Mi" - } - } - security_context = { - allow_privilege_escalation = false, - capabilities = { - drop = ["ALL"] - }, - privileged = false, - read_only_root_filesystem = true, - run_as_user = local.fleet.security_context.run_as_user, - run_as_group = local.fleet.security_context.run_as_group, - run_as_non_root = local.fleet.security_context.run_as_non_root - } - } - ] : [] - - content { - name = container.value.name - image = container.value.image - command = container.value.command - resources { - limits = { - cpu = container.value.resources.limits.cpu - memory = container.value.resources.limits.memory - } - requests = { - cpu = container.value.resources.requests.cpu - memory = container.value.resources.requests.memory - } - } - security_context { - allow_privilege_escalation = container.value.security_context.allow_privilege_escalation - capabilities { - drop = container.value.security_context.capabilities.drop - } - privileged = container.value.security_context.privileged - read_only_root_filesystem = container.value.security_context.read_only_root_filesystem - run_as_group = container.value.security_context.run_as_group - run_as_user = container.value.security_context.run_as_user - run_as_non_root = container.value.security_context.run_as_non_root - } - } - } - - dynamic "volume" { - for_each = local.database.tls.enabled ? [ - { - name = "mysql-tls", - secret_name = local.database.tls.secret_name - } - ] : [] - - content { - name = volume.value.name - secret { - secret_name = volume.value.secret_name - } - } - } - - dynamic "affinity" { - for_each = local.affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null - - content { - pod_affinity { - required_during_scheduling_ignored_during_execution { - label_selector { - match_expressions { - key = affinity.value.label_selector.match_expressions[*].key - operator = affinity.value.label_selector.match_expressions[*].operator - values = affinity.value.label_selector.match_expressions[*].values - } - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "affinity" { - for_each = local.affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null - - content { - pod_affinity { - preferred_during_scheduling_ignored_during_execution { - pod_affinity_term { - preference = affinity.value.preference - } - topology_key = affinity.value.topology_key - } - } - } - } - - - dynamic "affinity" { - for_each = local.anti_affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null - - content { - pod_anti_affinity { - required_during_scheduling_ignored_during_execution { - label_selector { - match_expressions { - key = affinity.value.label_selector.match_expressions[*].key - operator = affinity.value.label_selector.match_expressions[*].operator - values = affinity.value.label_selector.match_expressions[*].values - } - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "affinity" { - for_each = local.anti_affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null - - content { - pod_anti_affinity { - preferred_during_scheduling_ignored_during_execution { - pod_affinity_term { - label_selector = affinity.value.label_selector.label_selector - } - topology_key = affinity.value.topology_key - } - } - } - } - - dynamic "toleration" { - for_each = local.tolerations - - content { - key = toleration.env.key - operator = toleration.env.operator - value = toleration.env.value - effect = toleration.env.effect - } - } - - node_selector = local.node_selector - - dynamic "image_pull_secrets" { - for_each = var.image_pull_secrets - - content { - name = image_pull_secrets.value["name"] - } - } + content { + name = env.value.name + value = env.value.value } + } + + dynamic "env" { + for_each = [ + { name = "FLEET_MYSQL_ADDRESS", value = local.database.address }, + { name = "FLEET_MYSQL_DATABASE", value = local.database.database }, + { name = "FLEET_MYSQL_USERNAME", value = local.database.username }, + { name = "FLEET_MYSQL_MAX_OPEN_CONNS", value = local.database.max_open_conns }, + { name = "FLEET_MYSQL_MAX_IDLE_CONNS", value = local.database.max_idle_conns }, + { name = "FLEET_MYSQL_CONN_MAX_LIFETIME", value = local.database.conn_max_lifetime } + ] + + content { + name = env.value.name + value = env.value.value + } + } + + env { + name = "FLEET_MYSQL_PASSWORD" + value_from { + secret_key_ref { + name = local.database.secret_name + key = local.database.password_key + } + } + } + + dynamic "env" { + for_each = local.database.tls.enabled ? [ + { name = "FLEET_MYSQL_TLS_CA", value = "/secrets/mysql/${local.database.tls.ca_cert_key}" }, + { name = "FLEET_MYSQL_TLS_CERT", value = "/secrets/mysql/${local.database.tls.cert_secret_key}" }, + { name = "FLEET_MYSQL_TLS_KEY", value = "/secrets/mysql/${local.database.tls.key_key}" }, + { name = "FLEET_MYSQL_TLS_CONFIG", value = local.database.tls.config }, + { name = "FLEET_MYSQL_TLS_SERVER_NAME", value = local.database.tls.server_name } + ] : [] + + content { + name = env.value.name + value = env.value.value + } + } + + security_context { + run_as_user = local.fleet.security_context.run_as_user + run_as_group = local.fleet.security_context.run_as_group + run_as_non_root = local.fleet.security_context.run_as_non_root + read_only_root_filesystem = "true" + privileged = "false" + allow_privilege_escalation = "false" + + dynamic "capabilities" { + for_each = local.gke.cloud_sql.enable_proxy ? [ + { name = "add", values = ["SYS_PTRACE"] } + ] : [ + { name = "drop", values = ["ALL"] } + ] + + content { + add = capabilities.value.name == "add" ? capabilities.value.values : [] + drop = capabilities.value.name == "drop" ? capabilities.value.values : [] + } + } + } + + resources { + limits = { + cpu = local.resources.limits.cpu + memory = local.resources.limits.memory + } + requests = { + cpu = local.resources.requests.cpu + memory = local.resources.requests.memory + } + } + + dynamic "volume_mount" { + for_each = local.database.tls.enabled ? [ + { name = "mysql-tls", read_only = true, mount_path = "/secrets/mysql" } + ] : [] + + content { + name = volume_mount.value.name + read_only = volume_mount.value.read_only + mount_path = volume_mount.value.mount_path + } + } } + + dynamic "container" { + for_each = local.gke.cloud_sql.enable_proxy ? [ + { + name = "cloudql-proxy", + image = "${local.gke.cloud_sql.image_repository}:${local.gke.cloud_sql.image_tag}", + command = ["/cloud_sql_proxy", "-verbose=${local.gke.cloud_sql.verbose}", "-instances=${local.gke.cloud_sql.instance_name}=tcp:3306"] + resources = { + limits = { + cpu = "0.5", + memory = "150Mi" + }, + requests = { + cpu = "0.1", + memory = "50Mi" + } + } + security_context = { + allow_privilege_escalation = false, + capabilities = { + drop = ["ALL"] + }, + privileged = false, + read_only_root_filesystem = true, + run_as_user = local.fleet.security_context.run_as_user, + run_as_group = local.fleet.security_context.run_as_group, + run_as_non_root = local.fleet.security_context.run_as_non_root + } + } + ] : [] + + content { + name = container.value.name + image = container.value.image + command = container.value.command + resources { + limits = { + cpu = container.value.resources.limits.cpu + memory = container.value.resources.limits.memory + } + requests = { + cpu = container.value.resources.requests.cpu + memory = container.value.resources.requests.memory + } + } + security_context { + allow_privilege_escalation = container.value.security_context.allow_privilege_escalation + capabilities { + drop = container.value.security_context.capabilities.drop + } + privileged = container.value.security_context.privileged + read_only_root_filesystem = container.value.security_context.read_only_root_filesystem + run_as_group = container.value.security_context.run_as_group + run_as_user = container.value.security_context.run_as_user + run_as_non_root = container.value.security_context.run_as_non_root + } + } + } + + dynamic "volume" { + for_each = local.database.tls.enabled ? [ + { + name = "mysql-tls", + secret_name = local.database.tls.secret_name + } + ] : [] + + content { + name = volume.value.name + secret { + secret_name = volume.value.secret_name + } + } + } + + dynamic "affinity" { + for_each = local.affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null + + content { + pod_affinity { + required_during_scheduling_ignored_during_execution { + label_selector { + match_expressions { + key = affinity.value.label_selector.match_expressions[*].key + operator = affinity.value.label_selector.match_expressions[*].operator + values = affinity.value.label_selector.match_expressions[*].values + } + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "affinity" { + for_each = local.affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null + + content { + pod_affinity { + preferred_during_scheduling_ignored_during_execution { + pod_affinity_term { + preference = affinity.value.preference + } + topology_key = affinity.value.topology_key + } + } + } + } + + + dynamic "affinity" { + for_each = local.anti_affinity_rules.required_during_scheduling_ignored_during_execution != null ? local.affinity_rules.required_during_scheduling_ignored_during_execution : null + + content { + pod_anti_affinity { + required_during_scheduling_ignored_during_execution { + label_selector { + match_expressions { + key = affinity.value.label_selector.match_expressions[*].key + operator = affinity.value.label_selector.match_expressions[*].operator + values = affinity.value.label_selector.match_expressions[*].values + } + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "affinity" { + for_each = local.anti_affinity_rules.preferred_during_scheduling_ignored_during_execution != null ? local.affinity_rules.preferred_during_scheduling_ignored_during_execution : null + + content { + pod_anti_affinity { + preferred_during_scheduling_ignored_during_execution { + pod_affinity_term { + label_selector = affinity.value.label_selector.label_selector + } + topology_key = affinity.value.topology_key + } + } + } + } + + dynamic "toleration" { + for_each = local.tolerations + + content { + key = toleration.env.key + operator = toleration.env.operator + value = toleration.env.value + effect = toleration.env.effect + } + } + + node_selector = local.node_selector + + dynamic "image_pull_secrets" { + for_each = var.image_pull_secrets + + content { + name = image_pull_secrets.value["name"] + } + } + } } - wait_for_completion = true - timeouts { - create = "30m" - } + } + wait_for_completion = true + timeouts { + create = "30m" + } } \ No newline at end of file diff --git a/k8s/locals.tf b/k8s/locals.tf index 96a0036..ba9777a 100644 --- a/k8s/locals.tf +++ b/k8s/locals.tf @@ -1,27 +1,27 @@ locals { - namespace = var.namespace - hostname = var.hostname - replicas = var.replicas - image_repository = var.image_repository - image_tag = var.image_tag - image_pull_secrets = var.image_pull_secrets - pod_annotations = var.pod_annotations - service_annotations = var.service_annotations - service_account_annotations = var.service_account_annotations - resources = var.resources - vuln_processing = var.vuln_processing - node_selector = var.node_selector - tolerations = var.tolerations - affinity_rules = var.affinity_rules - anti_affinity_rules = var.anti_affinity_rules - ingress = var.ingress - fleet = var.fleet - osquery = var.osquery - database = var.database - database_read_replica = var.database_read_replica - cache = var.cache - gke = var.gke - environment_variables = var.environment_variables - environment_from_config_maps = var.environment_from_config_maps - environment_from_secrets = var.environment_from_secrets + namespace = var.namespace + hostname = var.hostname + replicas = var.replicas + image_repository = var.image_repository + image_tag = var.image_tag + image_pull_secrets = var.image_pull_secrets + pod_annotations = var.pod_annotations + service_annotations = var.service_annotations + service_account_annotations = var.service_account_annotations + resources = var.resources + vuln_processing = var.vuln_processing + node_selector = var.node_selector + tolerations = var.tolerations + affinity_rules = var.affinity_rules + anti_affinity_rules = var.anti_affinity_rules + ingress = var.ingress + fleet = var.fleet + osquery = var.osquery + database = var.database + database_read_replica = var.database_read_replica + cache = var.cache + gke = var.gke + environment_variables = var.environment_variables + environment_from_config_maps = var.environment_from_config_maps + environment_from_secrets = var.environment_from_secrets } \ No newline at end of file diff --git a/k8s/ns.tf b/k8s/ns.tf index 9ff84ce..df848ff 100644 --- a/k8s/ns.tf +++ b/k8s/ns.tf @@ -1,5 +1,5 @@ data "kubernetes_namespace" "fleet" { - metadata { + metadata { name = local.namespace } } \ No newline at end of file diff --git a/k8s/sa.tf b/k8s/sa.tf index bc0ba75..9ee1486 100644 --- a/k8s/sa.tf +++ b/k8s/sa.tf @@ -1,55 +1,55 @@ resource "kubernetes_service_account" "fleet-sa" { - metadata { - name = "fleet" - namespace = data.kubernetes_namespace.fleet.metadata[0].name - - labels = { - app = "fleet" - } - annotations = local.gke.workload_identity_email != "" ? merge(local.service_account_annotations, { "iam.gke.io/gcp-service-account" = local.gke.workload_identity_email}) : local.service_account_annotations + metadata { + name = "fleet" + namespace = data.kubernetes_namespace.fleet.metadata[0].name + + labels = { + app = "fleet" } + annotations = local.gke.workload_identity_email != "" ? merge(local.service_account_annotations, { "iam.gke.io/gcp-service-account" = local.gke.workload_identity_email }) : local.service_account_annotations + } } resource "kubernetes_role" "fleet-role" { - metadata { - name = "fleet" - namespace = data.kubernetes_namespace.fleet.metadata[0].name - } + metadata { + name = "fleet" + namespace = data.kubernetes_namespace.fleet.metadata[0].name + } - rule { - api_groups = ["core"] - resources = ["secrets"] - resource_names = tolist([ - local.database.secret_name != "" ? local.database.secret_name : "", - local.cache.secret_name != "" ? local.cache.secret_name : "", - local.fleet.secret_name != "" ? local.fleet.secret_name : "", - local.osquery.secret_name != "" ? local.osquery.secret_name : "" - ]) - verbs = ["get"] - } - depends_on = [ - resource.kubernetes_service_account.fleet-sa - ] + rule { + api_groups = ["core"] + resources = ["secrets"] + resource_names = tolist([ + local.database.secret_name != "" ? local.database.secret_name : "", + local.cache.secret_name != "" ? local.cache.secret_name : "", + local.fleet.secret_name != "" ? local.fleet.secret_name : "", + local.osquery.secret_name != "" ? local.osquery.secret_name : "" + ]) + verbs = ["get"] + } + depends_on = [ + resource.kubernetes_service_account.fleet-sa + ] } resource "kubernetes_role_binding" "fleet-role-binding" { - metadata { - name = "fleet" - namespace = data.kubernetes_namespace.fleet.metadata[0].name - } + metadata { + name = "fleet" + namespace = data.kubernetes_namespace.fleet.metadata[0].name + } - role_ref { - api_group = "rbac.authorization.k8s.io" - kind = "Role" - name = resource.kubernetes_role.fleet-role.metadata[0].name - } + role_ref { + api_group = "rbac.authorization.k8s.io" + kind = "Role" + name = resource.kubernetes_role.fleet-role.metadata[0].name + } - subject { - kind = "ServiceAccount" - name = resource.kubernetes_service_account.fleet-sa.metadata[0].name - namespace = data.kubernetes_namespace.fleet.metadata[0].name - } - depends_on = [ - resource.kubernetes_role.fleet-role - ] + subject { + kind = "ServiceAccount" + name = resource.kubernetes_service_account.fleet-sa.metadata[0].name + namespace = data.kubernetes_namespace.fleet.metadata[0].name + } + depends_on = [ + resource.kubernetes_role.fleet-role + ] } \ No newline at end of file diff --git a/k8s/svc.tf b/k8s/svc.tf index dac8a6e..138826c 100644 --- a/k8s/svc.tf +++ b/k8s/svc.tf @@ -1,35 +1,35 @@ resource "kubernetes_service" "fleet-service" { - metadata { - name = "fleet" - namespace = data.kubernetes_namespace.fleet.metadata[0].name - annotations = local.service_annotations + metadata { + name = "fleet" + namespace = data.kubernetes_namespace.fleet.metadata[0].name + annotations = local.service_annotations + } + + spec { + selector = { + app = "fleet" + component = "fleet-server" } - spec { - selector = { - app = "fleet" - component = "fleet-server" - } + dynamic "port" { + for_each = local.gke.ingress.use_gke_ingress && local.gke.ingress.node_port != "" ? [ + { name = "fleet", port = local.fleet.listen_port, target_port = local.fleet.listen_port, protocol = "TCP", node_port = local.gke.ingress.node_port } + ] : [ + { name = "fleet", port = local.fleet.listen_port, target_port = local.fleet.listen_port, protocol = "TCP", node_port = null } + ] - dynamic "port" { - for_each = local.gke.ingress.use_gke_ingress && local.gke.ingress.node_port != "" ? [ - { name = "fleet", port = local.fleet.listen_port, target_port = local.fleet.listen_port, protocol = "TCP", node_port = local.gke.ingress.node_port } - ] : [ - { name = "fleet", port = local.fleet.listen_port, target_port = local.fleet.listen_port, protocol = "TCP", node_port = null } - ] + content { + name = port.value.name + port = port.value.port + protocol = port.value.protocol + target_port = port.value.target_port + node_port = port.value.node_port + } + } - content { - name = port.value.name - port = port.value.port - protocol = port.value.protocol - target_port = port.value.target_port - node_port = port.value.node_port - } - } - - type = local.gke.ingress.use_gke_ingress ? "NodePort" : "ClusterIP" - } - depends_on = [ - resource.kubernetes_deployment.fleet - ] + type = local.gke.ingress.use_gke_ingress ? "NodePort" : "ClusterIP" + } + depends_on = [ + resource.kubernetes_deployment.fleet + ] } diff --git a/k8s/variables.tf b/k8s/variables.tf index a59e653..bd0f40b 100644 --- a/k8s/variables.tf +++ b/k8s/variables.tf @@ -1,107 +1,107 @@ variable "namespace" { - type = string - default = "fleet" - description = "The value for this variable will be used as the name of the namespace that fleet will be deployed to." + type = string + default = "fleet" + description = "The value for this variable will be used as the name of the namespace that fleet will be deployed to." } variable "hostname" { - type = string - default = "fleet.localhost" - description = "Used as the hostname that you will access fleet on." + type = string + default = "fleet.localhost" + description = "Used as the hostname that you will access fleet on." } variable "replicas" { - type = number - default = 3 - description = "Used to drive the number of fleet deployment replicas." + type = number + default = 3 + description = "Used to drive the number of fleet deployment replicas." } variable "image_repository" { - type = string - default = "fleetdm/fleet" - description = "Used to populate the image repository for fleet." + type = string + default = "fleetdm/fleet" + description = "Used to populate the image repository for fleet." } variable "image_tag" { - type = string - default = "v4.66.0" - description = "Used to populate the fleet version that will be deployed." + type = string + default = "v4.66.0" + description = "Used to populate the fleet version that will be deployed." } variable "image_pull_secrets" { - type = list(object({ - name = string - })) - default = [] - description = "Used to inject image pull secrets for access to a private container registry." + type = list(object({ + name = string + })) + default = [] + description = "Used to inject image pull secrets for access to a private container registry." } variable "pod_annotations" { - type = map - default = {} - description = "Used to populate the annotations for pods." + type = map(any) + default = {} + description = "Used to populate the annotations for pods." } variable "service_annotations" { - type = map - default = {} - description = "Used to populate the annotations for the fleet service." + type = map(any) + default = {} + description = "Used to populate the annotations for the fleet service." } variable "service_account_annotations" { - type = map - default = {} - description = "Used to populate the annotations for the fleet service account." + type = map(any) + default = {} + description = "Used to populate the annotations for the fleet service account." } variable "resources" { - type = object({ - limits = optional(object({ - cpu = optional(string, "1") - memory = optional(string, "4Gi") - }),{ - cpu = "1" - memory = "4Gi" - }) - requests = optional(object({ - cpu = optional(string, "0.1") - memory = optional(string, "50Mi") - }),{ - cpu = "0.1" - memory = "50Mi" - }) + type = object({ + limits = optional(object({ + cpu = optional(string, "1") + memory = optional(string, "4Gi") + }), { + cpu = "1" + memory = "4Gi" }) - description = "Used to populate resource values for the fleet deployment and migration job." + requests = optional(object({ + cpu = optional(string, "0.1") + memory = optional(string, "50Mi") + }), { + cpu = "0.1" + memory = "50Mi" + }) + }) + description = "Used to populate resource values for the fleet deployment and migration job." } variable "node_selector" { - type = map - default = {} - description = "Used to populate node selector values." + type = map(any) + default = {} + description = "Used to populate node selector values." } variable "tolerations" { - type = list(any) - default = [] - description = "Used to configure tolerations." + type = list(any) + default = [] + description = "Used to configure tolerations." } variable "environment_variables" { - type = list(map(string)) - default = [] - description = "Used to configure additional environment variables for the fleet deployment and vuln-processing cron job." + type = list(map(string)) + default = [] + description = "Used to configure additional environment variables for the fleet deployment and vuln-processing cron job." } variable "environment_from_config_maps" { - type = list(map(string)) - default = [] - description = "Used to configure additional environment variables from a config map for the fleet deployment and vuln-processing cron job." + type = list(map(string)) + default = [] + description = "Used to configure additional environment variables from a config map for the fleet deployment and vuln-processing cron job." } variable "environment_from_secrets" { - type = list(map(string)) - default = [] - description = "Used to configure additional environment variables from a secret for the fleet deployment and vuln-processing cron job." + type = list(map(string)) + default = [] + description = "Used to configure additional environment variables from a secret for the fleet deployment and vuln-processing cron job." } /* @@ -110,273 +110,288 @@ variable "environment_from_secrets" { variable "affinity_rules" { - type = object({ - required_during_scheduling_ignored_during_execution = optional(list(any), []) - preferred_during_scheduling_ignored_during_execution = optional(list(any), []) - }) - description = "Used to configure affinity rules for the fleet deployment, migration job, and vuln-processing cron job." + type = object({ + required_during_scheduling_ignored_during_execution = optional(list(any), []) + preferred_during_scheduling_ignored_during_execution = optional(list(any), []) + }) + description = "Used to configure affinity rules for the fleet deployment, migration job, and vuln-processing cron job." } variable "anti_affinity_rules" { - type = object({ - required_during_scheduling_ignored_during_execution = optional(list(any), []) - preferred_during_scheduling_ignored_during_execution = optional(list(any), - [ - { - weight = 100 - label_selector = { - match_expressions = [ - { - key = "app" - operator = "In" - values = ["fleet"] - } - ] - } - topology_key = "kubernetes.io/hostname" - } - ]) - }) - description = "Used to configure anti-affinity rules for the fleet deployment, migration job, and vuln-processing cron job." + type = object({ + required_during_scheduling_ignored_during_execution = optional(list(any), []) + preferred_during_scheduling_ignored_during_execution = optional(list(any), + [ + { + weight = 100 + label_selector = { + match_expressions = [ + { + key = "app" + operator = "In" + values = ["fleet"] + } + ] + } + topology_key = "kubernetes.io/hostname" + } + ]) + }) + description = "Used to configure anti-affinity rules for the fleet deployment, migration job, and vuln-processing cron job." } /* vuln_processing */ variable "vuln_processing" { - type = object({ - ttl_seconds_after_finished = optional(number, 100) - restart_policy = optional(string, "Never") - dedicated = optional(bool, false) - schedule = optional(string, "0 * * * *") - resources = object({ - limits = optional(object({ - cpu = optional(string, "1") - memory = optional(string, "4Gi") - }),{ - cpu = "1" - memory = "4Gi" - }) - requests = optional(object({ - cpu = optional(string, "0.1") - memory = optional(string, "50Mi") - }),{ - cpu = "0.1" - memory = "50Mi" - }) - }) + type = object({ + ttl_seconds_after_finished = optional(number, 100) + restart_policy = optional(string, "Never") + dedicated = optional(bool, false) + schedule = optional(string, "0 * * * *") + resources = object({ + limits = optional(object({ + cpu = optional(string, "1") + memory = optional(string, "4Gi") + }), { + cpu = "1" + memory = "4Gi" + }) + requests = optional(object({ + cpu = optional(string, "0.1") + memory = optional(string, "50Mi") + }), { + cpu = "0.1" + memory = "50Mi" + }) }) - description = "Used to configure the values for the vuln-processing cron job." + }) + description = "Used to configure the values for the vuln-processing cron job." } /* ingress */ variable "ingress" { - type = object({ - enabled = optional(bool, false) - class_name = optional(string, "nginx") - labels = optional(map(string), {}) - annotations = optional(map(string), {}) - hosts = optional(list(any), []) - tls = object({ - secret_name = optional(string, "") - hosts = optional(list(string),[]) - }) + type = object({ + enabled = optional(bool, false) + class_name = optional(string, "nginx") + labels = optional(map(string), {}) + annotations = optional(map(string), {}) + hosts = optional(list(any), []) + tls = object({ + secret_name = optional(string, "") + hosts = optional(list(string), []) }) - description = "Used to configure values for ingress." + }) + description = "Used to configure values for ingress." } variable "fleet" { - type = object({ - listen_port = optional(number, 8080) - secret_name = optional(string, "fleet") - migrations = object({ - auto_apply_sql_migrations = optional(bool, true) - migration_job_annotations = optional(map(string), {}) - parallelism = optional(number, 1) - completions = optional(number, 1) - active_deadline_seconds = optional(number, 900) - backoff_limit = optional(number, 6) - manual_selector = optional(bool, false) - restart_policy = optional(string, "Never") - }) - tls = object({ - enabled = optional(bool, false) - unique_tls_secret = optional(bool, false) - secret_name = optional(string, "fleet-tls") - compatibility = optional(string, "modern") - cert_secret_key = optional(string, "server.cert") - key_secret_key = optional(string, "server.key") - }) - auth = object({ - b_crypto_cost = optional(number, 12) - salt_key_size = optional(number, 24) - }) - app = object({ - token_key_size = optional(number, 24) - invite_token_validity_period = optional(string, "120h") - }) - session = object({ - key_size = optional(number, 64) - duration = optional(string, "2160h") - }) - logging = object({ - debug = optional(bool, false) - json = optional(bool, false) - disable_banner = optional(bool, false) - }) - carving = object({ - s3 = object({ - bucket_name = optional(string, "") - prefix = optional(string, "") - access_key_id = optional(string, "") - secret_key = optional(string, "s3-bucket") - sts_assume_role_arn = optional(string, "") - }) - }) - license = object({ - secret_name = optional(string, "") - license_key = optional(string, "license-key") - }) - extra_volumes = optional(list(any), []) - extra_volume_mounts = optional(list(any), []) - security_context = object({ - run_as_user = optional(number, null) - run_as_group = optional(number, null) - run_as_non_root = optional(bool, true) - }) + type = object({ + listen_port = optional(number, 8080) + secret_name = optional(string, "fleet") + migrations = object({ + auto_apply_sql_migrations = optional(bool, true) + migration_job_annotations = optional(map(string), {}) + parallelism = optional(number, 1) + completions = optional(number, 1) + active_deadline_seconds = optional(number, 900) + backoff_limit = optional(number, 6) + manual_selector = optional(bool, false) + restart_policy = optional(string, "Never") }) - description = "Used to configure Fleet specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." + tls = object({ + enabled = optional(bool, false) + unique_tls_secret = optional(bool, false) + secret_name = optional(string, "fleet-tls") + compatibility = optional(string, "modern") + cert_secret_key = optional(string, "server.cert") + key_secret_key = optional(string, "server.key") + }) + auth = object({ + b_crypto_cost = optional(number, 12) + salt_key_size = optional(number, 24) + }) + app = object({ + token_key_size = optional(number, 24) + invite_token_validity_period = optional(string, "120h") + }) + session = object({ + key_size = optional(number, 64) + duration = optional(string, "2160h") + }) + logging = object({ + debug = optional(bool, false) + json = optional(bool, false) + disable_banner = optional(bool, false) + }) + software_installers = object({ + s3 = object({ + bucket_name = optional(string, "") + prefix = optional(string, "") + endpoint_url = optional(string, "") + force_s3_path_style = optional(bool, false) + region = optional(string, "") + access_key_id = optional(string, "") + secret_key = optional(string, "s3-software-installers") + sts_assume_role_arn = optional(string, "") + }) + }) + carving = object({ + s3 = object({ + bucket_name = optional(string, "") + prefix = optional(string, "") + endpoint_url = optional(string, "") + force_s3_path_style = optional(bool, false) + region = optional(string, "") + access_key_id = optional(string, "") + secret_key = optional(string, "s3-bucket") + sts_assume_role_arn = optional(string, "") + }) + }) + license = object({ + secret_name = optional(string, "") + license_key = optional(string, "license-key") + }) + extra_volumes = optional(list(any), []) + extra_volume_mounts = optional(list(any), []) + security_context = object({ + run_as_user = optional(number, null) + run_as_group = optional(number, null) + run_as_non_root = optional(bool, true) + }) + }) + description = "Used to configure Fleet specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." } variable "osquery" { - type = object({ - secret_name = optional(string, "osquery") - node_key_size = optional(number, 24) - label_update_interval = optional(string, "30m") - detail_update_interval = optional(string, "30m") - logging = object({ - status_plugin = optional(string, "filesystem") - result_plugin = optional(string, "filesystem") - filesystem = object({ - status_log_file = optional(string, "osquery_status") - result_log_file = optional(string, "osquery_result") - enable_rotation = optional(bool, false) - enable_compression = optional(bool, false) - volume_size = optional(string, "20Gi") - }) - firehose = object({ - region = optional(string, "") - access_key_id = optional(string, "") - secret_key = optional(string, "firehose") - sts_assume_role_arn = optional(string, "") - status_stream = optional(string, "") - result_stream = optional(string, "") - }) - kinesis = object({ - region = optional(string, "") - access_key_id = optional(string, "") - secret_key = optional(string, "kinesis") - sts_assume_role_arn = optional(string, "") - status_stream = optional(string, "") - result_stream = optional(string, "") - }) - lambda = object({ - region = optional(string, "") - access_key_id = optional(string, "") - secret_key = optional(string, "lambda") - sts_assume_role_arn = optional(string, "") - status_stream = optional(string, "") - result_stream = optional(string, "") - }) - pubsub = object({ - project = optional(string, "") - status_topic = optional(string, "") - result_topic = optional(string, "") - }) - }) + type = object({ + secret_name = optional(string, "osquery") + node_key_size = optional(number, 24) + label_update_interval = optional(string, "30m") + detail_update_interval = optional(string, "30m") + logging = object({ + status_plugin = optional(string, "filesystem") + result_plugin = optional(string, "filesystem") + filesystem = object({ + status_log_file = optional(string, "osquery_status") + result_log_file = optional(string, "osquery_result") + enable_rotation = optional(bool, false) + enable_compression = optional(bool, false) + volume_size = optional(string, "20Gi") + }) + firehose = object({ + region = optional(string, "") + access_key_id = optional(string, "") + secret_key = optional(string, "firehose") + sts_assume_role_arn = optional(string, "") + status_stream = optional(string, "") + result_stream = optional(string, "") + }) + kinesis = object({ + region = optional(string, "") + access_key_id = optional(string, "") + secret_key = optional(string, "kinesis") + sts_assume_role_arn = optional(string, "") + status_stream = optional(string, "") + result_stream = optional(string, "") + }) + lambda = object({ + region = optional(string, "") + access_key_id = optional(string, "") + secret_key = optional(string, "lambda") + sts_assume_role_arn = optional(string, "") + status_stream = optional(string, "") + result_stream = optional(string, "") + }) + pubsub = object({ + project = optional(string, "") + status_topic = optional(string, "") + result_topic = optional(string, "") + }) }) - description = "Used to configure osquery specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." + }) + description = "Used to configure osquery specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." } variable "database" { - type = object({ - enabled = optional(bool, false) - secret_name = optional(string, "mysql") - address = optional(string, "mysql:3306") - database = optional(string, "fleet") - username = optional(string, "fleet") - password_key = optional(string, "password") - max_open_conns = optional(number, 50) - max_idle_conns = optional(number, 50) - conn_max_lifetime = optional(number, 0) + type = object({ + enabled = optional(bool, false) + secret_name = optional(string, "mysql") + address = optional(string, "mysql:3306") + database = optional(string, "fleet") + username = optional(string, "fleet") + password_key = optional(string, "password") + max_open_conns = optional(number, 50) + max_idle_conns = optional(number, 50) + conn_max_lifetime = optional(number, 0) - tls = object({ - enabled = optional(bool, false) - config = optional(string, "") - server_name = optional(string, "") - ca_cert_key = optional(string, "") - cert_key = optional(string, "") - key_key = optional(string, "") - }) + tls = object({ + enabled = optional(bool, false) + config = optional(string, "") + server_name = optional(string, "") + ca_cert_key = optional(string, "") + cert_key = optional(string, "") + key_key = optional(string, "") }) - description = "Used to configure database specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." + }) + description = "Used to configure database specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." } variable "database_read_replica" { - type = object({ - enabled = optional(bool, false) - secret_name = optional(string, "mysql") - address = optional(string, "mysql-ro:3306") - database = optional(string, "fleet") - username = optional(string, "fleet-ro") - password_key = optional(string, "ro-password") - password_path = optional(string,"") - max_open_conns = optional(number, 50) - max_idle_conns = optional(number, 50) - conn_max_lifetime = optional(number, 0) + type = object({ + enabled = optional(bool, false) + secret_name = optional(string, "mysql") + address = optional(string, "mysql-ro:3306") + database = optional(string, "fleet") + username = optional(string, "fleet-ro") + password_key = optional(string, "ro-password") + password_path = optional(string, "") + max_open_conns = optional(number, 50) + max_idle_conns = optional(number, 50) + conn_max_lifetime = optional(number, 0) - tls = optional(object({ - enabled = optional(bool, false) - config = optional(string, "") - server_name = optional(string, "") - ca_cert_key = optional(string, "") - cert_key = optional(string, "") - key_key = optional(string, "") - })) - }) - description = "Used to configure database_read_replica specific values for use in the Fleet deployment and vuln-processing cron job." + tls = optional(object({ + enabled = optional(bool, false) + config = optional(string, "") + server_name = optional(string, "") + ca_cert_key = optional(string, "") + cert_key = optional(string, "") + key_key = optional(string, "") + })) + }) + description = "Used to configure database_read_replica specific values for use in the Fleet deployment and vuln-processing cron job." } variable "cache" { - type = object({ - enabled = optional(bool, false) - address = optional(string, "redis:6379") - database = optional(number, 0) - use_password = optional(bool, false) - secret_name = optional(string, "redis") - password_key = optional(string, "password") - }) - description = "Used to configure redis specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." + type = object({ + enabled = optional(bool, false) + address = optional(string, "redis:6379") + database = optional(number, 0) + use_password = optional(bool, false) + secret_name = optional(string, "redis") + password_key = optional(string, "password") + }) + description = "Used to configure redis specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." } variable "gke" { - type = object({ - workload_identity_email = optional(string, "") - cloud_sql = object({ - enable_proxy = optional(bool, false) - image_repository = optional(string, "gcr.io/cloudsql-docker/gce-proxy") - image_tag = optional(string, "1.17-alpine") - verbose = optional(bool, true) - instance_name = optional(string, "") - }) - ingress = object({ - use_managed_certificate = optional(bool, false) - use_gke_ingress = optional(bool, false) - node_port = optional(number, 0) - hostnames = optional(list(string), [""]) - }) + type = object({ + workload_identity_email = optional(string, "") + cloud_sql = object({ + enable_proxy = optional(bool, false) + image_repository = optional(string, "gcr.io/cloudsql-docker/gce-proxy") + image_tag = optional(string, "1.17-alpine") + verbose = optional(bool, true) + instance_name = optional(string, "") }) - description = "Used to configure gke specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." + ingress = object({ + use_managed_certificate = optional(bool, false) + use_gke_ingress = optional(bool, false) + node_port = optional(number, 0) + hostnames = optional(list(string), [""]) + }) + }) + description = "Used to configure gke specific values for use in the Fleet deployment, migration job, and vuln-processing cron job." }