Terraform k8s deployments - Handle runAsUser/runAsGroup/run_as_non_root when not defined for (#53)
Handling use-case where kubernetes platform is openshift and runAsUser/runAsGroup is not defined by a user; Openshift automatically assigns runAsUser/runAsGroup.
This commit is contained in:
1 parent
770afe9cd3
commit
2b8b75199a
6 files changed
+52
-18
No files matched your search
+2
-2
@@ -292,7 +292,7 @@ No requirements.
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.36.0 |
|
||||
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.37.1 |
|
||||
|
||||
## Modules
|
||||
|
||||
@@ -323,7 +323,7 @@ No modules.
|
||||
| <a name="input_environment_from_config_maps"></a> [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 |
|
||||
| <a name="input_environment_from_secrets"></a> [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 |
|
||||
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | Used to configure additional environment variables for the fleet deployment and vuln-processing cron job. | `list(map(string))` | `[]` | no |
|
||||
| <a name="input_fleet"></a> [fleet](#input\_fleet) | Used to configure Fleet specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. | <pre>object({<br/> listen_port = optional(number, 8080)<br/> secret_name = optional(string, "fleet")<br/> migrations = object({<br/> auto_apply_sql_migrations = optional(bool, true)<br/> migration_job_annotations = optional(map(string), {})<br/> parallelism = optional(number, 1)<br/> completions = optional(number, 1)<br/> active_deadline_seconds = optional(number, 900)<br/> backoff_limit = optional(number, 6)<br/> manual_selector = optional(bool, false)<br/> restart_policy = optional(string, "Never")<br/> })<br/> tls = object({<br/> enabled = optional(bool, false)<br/> unique_tls_secret = optional(bool, false)<br/> secret_name = optional(string, "fleet-tls")<br/> compatibility = optional(string, "modern")<br/> cert_secret_key = optional(string, "server.cert")<br/> key_secret_key = optional(string, "server.key")<br/> })<br/> auth = object({<br/> b_crypto_cost = optional(number, 12)<br/> salt_key_size = optional(number, 24)<br/> })<br/> app = object({<br/> token_key_size = optional(number, 24)<br/> invite_token_validity_period = optional(string, "120h")<br/> })<br/> session = object({<br/> key_size = optional(number, 64)<br/> duration = optional(string, "2160h")<br/> })<br/> logging = object({<br/> debug = optional(bool, false)<br/> json = optional(bool, false)<br/> disable_banner = optional(bool, false)<br/> })<br/> carving = object({<br/> s3 = object({<br/> bucket_name = optional(string, "")<br/> prefix = optional(string, "")<br/> access_key_id = optional(string, "")<br/> secret_key = optional(string, "s3-bucket")<br/> sts_assume_role_arn = optional(string, "")<br/> })<br/> })<br/> license = object({<br/> secret_name = optional(string, "")<br/> license_key = optional(string, "license-key")<br/> })<br/> extra_volumes = optional(list(any), [])<br/> extra_volume_mounts = optional(list(any), [])<br/> security_context = object({<br/> run_as_user = optional(number, 3333)<br/> run_as_group = optional(number, 3333)<br/> })<br/> })</pre> | n/a | yes |
|
||||
| <a name="input_fleet"></a> [fleet](#input\_fleet) | Used to configure Fleet specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. | <pre>object({<br/> listen_port = optional(number, 8080)<br/> secret_name = optional(string, "fleet")<br/> migrations = object({<br/> auto_apply_sql_migrations = optional(bool, true)<br/> migration_job_annotations = optional(map(string), {})<br/> parallelism = optional(number, 1)<br/> completions = optional(number, 1)<br/> active_deadline_seconds = optional(number, 900)<br/> backoff_limit = optional(number, 6)<br/> manual_selector = optional(bool, false)<br/> restart_policy = optional(string, "Never")<br/> })<br/> tls = object({<br/> enabled = optional(bool, false)<br/> unique_tls_secret = optional(bool, false)<br/> secret_name = optional(string, "fleet-tls")<br/> compatibility = optional(string, "modern")<br/> cert_secret_key = optional(string, "server.cert")<br/> key_secret_key = optional(string, "server.key")<br/> })<br/> auth = object({<br/> b_crypto_cost = optional(number, 12)<br/> salt_key_size = optional(number, 24)<br/> })<br/> app = object({<br/> token_key_size = optional(number, 24)<br/> invite_token_validity_period = optional(string, "120h")<br/> })<br/> session = object({<br/> key_size = optional(number, 64)<br/> duration = optional(string, "2160h")<br/> })<br/> logging = object({<br/> debug = optional(bool, false)<br/> json = optional(bool, false)<br/> disable_banner = optional(bool, false)<br/> })<br/> carving = object({<br/> s3 = object({<br/> bucket_name = optional(string, "")<br/> prefix = optional(string, "")<br/> access_key_id = optional(string, "")<br/> secret_key = optional(string, "s3-bucket")<br/> sts_assume_role_arn = optional(string, "")<br/> })<br/> })<br/> license = object({<br/> secret_name = optional(string, "")<br/> license_key = optional(string, "license-key")<br/> })<br/> extra_volumes = optional(list(any), [])<br/> extra_volume_mounts = optional(list(any), [])<br/> security_context = object({<br/> run_as_user = optional(number, null)<br/> run_as_group = optional(number, null)<br/> run_as_non_root = optional(bool, true)<br/> })<br/> })</pre> | n/a | yes |
|
||||
| <a name="input_gke"></a> [gke](#input\_gke) | Used to configure gke specific values for use in the Fleet deployment, migration job, and vuln-processing cron job. | <pre>object({<br/> workload_identity_email = optional(string, "")<br/> cloud_sql = object({<br/> enable_proxy = optional(bool, false)<br/> image_repository = optional(string, "gcr.io/cloudsql-docker/gce-proxy")<br/> image_tag = optional(string, "1.17-alpine")<br/> verbose = optional(bool, true)<br/> instance_name = optional(string, "")<br/> })<br/> ingress = object({<br/> use_managed_certificate = optional(bool, false)<br/> use_gke_ingress = optional(bool, false)<br/> node_port = optional(number, 0)<br/> hostnames = optional(list(string), [""])<br/> })<br/> })</pre> | n/a | yes |
|
||||
| <a name="input_hostname"></a> [hostname](#input\_hostname) | Used as the hostname that you will access fleet on. | `string` | `"fleet.localhost"` | no |
|
||||
| <a name="input_image_pull_secrets"></a> [image\_pull\_secrets](#input\_image\_pull\_secrets) | Used to inject image pull secrets for access to a private container registry. | <pre>list(object({<br/> name = string<br/> }))</pre> | `[]` | no |
|
||||
|
||||
+5
-5
@@ -171,7 +171,7 @@ resource "kubernetes_cron_job_v1" "fleet_vuln_processing_cron_job" {
|
||||
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 = "true"
|
||||
run_as_non_root = local.fleet.security_context.run_as_non_root
|
||||
read_only_root_filesystem = "true"
|
||||
privileged = "false"
|
||||
allow_privilege_escalation = "false"
|
||||
@@ -231,10 +231,10 @@ resource "kubernetes_cron_job_v1" "fleet_vuln_processing_cron_job" {
|
||||
drop = ["ALL"]
|
||||
},
|
||||
privileged = false,
|
||||
read_only_root_filesystem = true,
|
||||
run_as_group = local.fleet.security_context.run_as_group,
|
||||
read_only_root_filesystem = true,
|
||||
run_as_user = local.fleet.security_context.run_as_user,
|
||||
run_as_non_root = true
|
||||
run_as_group = local.fleet.security_context.run_as_group,
|
||||
run_as_non_root = local.fleet.security_context.run_as_non_root
|
||||
}
|
||||
}
|
||||
] : []
|
||||
@@ -260,8 +260,8 @@ resource "kubernetes_cron_job_v1" "fleet_vuln_processing_cron_job" {
|
||||
}
|
||||
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_group = container.value.security_context.run_as_group
|
||||
run_as_non_root = container.value.security_context.run_as_non_root
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -582,7 +582,7 @@ resource "kubernetes_deployment" "fleet" {
|
||||
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 = "true"
|
||||
run_as_non_root = local.fleet.security_context.run_as_non_root
|
||||
read_only_root_filesystem = "true"
|
||||
privileged = "false"
|
||||
allow_privilege_escalation = "false"
|
||||
@@ -696,9 +696,9 @@ resource "kubernetes_deployment" "fleet" {
|
||||
},
|
||||
privileged = false,
|
||||
read_only_root_filesystem = true,
|
||||
run_as_group = local.fleet.security_context.run_as_group,
|
||||
run_as_user = local.fleet.security_context.run_as_user,
|
||||
run_as_non_root = true
|
||||
run_as_group = local.fleet.security_context.run_as_group,
|
||||
run_as_non_root = local.fleet.security_context.run_as_non_root
|
||||
}
|
||||
}
|
||||
] : []
|
||||
@@ -870,4 +870,4 @@ resource "kubernetes_deployment" "fleet" {
|
||||
depends_on = [
|
||||
resource.kubernetes_job.migration // dependency should only be here if migration is enabled
|
||||
]
|
||||
}
|
||||
}
|
||||
+34
-1
@@ -1,5 +1,5 @@
|
||||
module "fleet" {
|
||||
source = "git::https://github.com/fleetdm/fleet-terraform//k8s?depth=1&ref=tf-mod-k8s-v1.1.0"
|
||||
source = "git::https://github.com/fleetdm/fleet-terraform//k8s?depth=1&ref=tf-mod-k8s-v1.1.1"
|
||||
|
||||
namespace = "fleet"
|
||||
hostname = "fleet.localhost.local"
|
||||
@@ -196,9 +196,42 @@ module "fleet" {
|
||||
}
|
||||
extra_volumes = []
|
||||
extra_volume_mounts = []
|
||||
/*
|
||||
If you're not providing an id for run_as_user or run_as_group,
|
||||
and you're not running on Openshift (Openshift will set the userid/groupid, if left blank),
|
||||
you might encounter an issue with Fleet pods starting up, where
|
||||
k8s is not able to determine whether the fleet user, in the
|
||||
Fleet container image, is running as root.
|
||||
|
||||
Examples:
|
||||
1. Openshift example (without id's):
|
||||
security_context = {
|
||||
run_as_non_root = true
|
||||
}
|
||||
|
||||
2. Openshift example (with id's):
|
||||
security_context = {
|
||||
run_as_user = 1000653333
|
||||
run_as_group = 1000653333
|
||||
run_as_non_root = true
|
||||
}
|
||||
|
||||
3. Non-Openshift (without id's):
|
||||
security_context = {
|
||||
run_as_non_root = false
|
||||
}
|
||||
|
||||
4. Non-Openshift (with id's):
|
||||
security_context = {
|
||||
run_as_user = 3333
|
||||
run_as_group = 3333
|
||||
run_as_non_root = true
|
||||
}
|
||||
*/
|
||||
security_context = {
|
||||
run_as_user = 3333
|
||||
run_as_group = 3333
|
||||
run_as_non_root = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -118,7 +118,7 @@ resource "kubernetes_job" "migration" {
|
||||
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 = "true"
|
||||
run_as_non_root = local.fleet.security_context.run_as_non_root
|
||||
read_only_root_filesystem = "true"
|
||||
privileged = "false"
|
||||
allow_privilege_escalation = "false"
|
||||
@@ -184,9 +184,9 @@ resource "kubernetes_job" "migration" {
|
||||
},
|
||||
privileged = false,
|
||||
read_only_root_filesystem = true,
|
||||
run_as_group = local.fleet.security_context.run_as_group,
|
||||
run_as_user = local.fleet.security_context.run_as_user,
|
||||
run_as_non_root = true
|
||||
run_as_group = local.fleet.security_context.run_as_group,
|
||||
run_as_non_root = local.fleet.security_context.run_as_non_root
|
||||
}
|
||||
}
|
||||
] : []
|
||||
|
||||
+4
-3
@@ -242,8 +242,9 @@ variable "fleet" {
|
||||
extra_volumes = optional(list(any), [])
|
||||
extra_volume_mounts = optional(list(any), [])
|
||||
security_context = object({
|
||||
run_as_user = optional(number, 3333)
|
||||
run_as_group = optional(number, 3333)
|
||||
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."
|
||||
@@ -353,4 +354,4 @@ variable "gke" {
|
||||
})
|
||||
})
|
||||
description = "Used to configure gke specific values for use in the Fleet deployment, migration job, and vuln-processing cron job."
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user