From c2355507107a961d9f0b5637c089daac94728e0e Mon Sep 17 00:00:00 2001 From: VURU Date: Tue, 22 Oct 2024 09:17:13 +0200 Subject: [PATCH] Delete consul connect from deployment. See https://github.com/suikast42/nomadder/issues/164 --- .../setup/stack_core/templates/security.j2 | 87 +--- .../stack_core/templates/security_with_cc.j2 | 480 ++++++++++++++++++ 2 files changed, 499 insertions(+), 68 deletions(-) create mode 100644 ansible/setup/stack_core/templates/security_with_cc.j2 diff --git a/ansible/setup/stack_core/templates/security.j2 b/ansible/setup/stack_core/templates/security.j2 index 468e7ff..098152a 100644 --- a/ansible/setup/stack_core/templates/security.j2 +++ b/ansible/setup/stack_core/templates/security.j2 @@ -55,31 +55,13 @@ job "security" { mode = "bridge" port "db" { to = 5432 - host_network = "local" } } service { name = "keycloak-postgres" - port = "5432" - address_mode = "alloc" - connect { - sidecar_service {} - sidecar_task{ - config{ - {% if set_cpu_hard_limit %} - cpu_hard_limit = "true" - {% endif %} - labels = { - "com.github.logunifier.application.name" = "envoy-proxy-keycloak-postgres" - "com.github.logunifier.application.version" = "{{version_envoy}}" - "com.github.logunifier.application.org" = "${var.org}" - "com.github.logunifier.application.env" = "${var.env}" - "com.github.logunifier.application.pattern.key" = "envoy" - } - } - } - } + port = "db" + check { name = "keycloak_postgres_ping" type = "script" @@ -87,7 +69,6 @@ job "security" { task = "keycloak_postgres" interval = "10s" timeout = "2s" - address_mode = "alloc" check_restart { limit = 3 grace = "30s" @@ -176,13 +157,11 @@ job "security" { mode = "bridge" port "auth" { to = 4181 - host_network = "local" } } service { name = "forwardauth" port = "auth" - address_mode = "alloc" tags = [ "traefik.enable=true", "traefik.http.routers.forwardauth.entrypoints=https", @@ -296,10 +275,8 @@ job "security" { mode = "bridge" port "ui" { to = 8080 - host_network = "local" } port "health_check" { - host_network = "local" to = 9000 } } @@ -307,7 +284,6 @@ job "security" { service { name = "keycloak-health" port = "health_check" - address_mode = "alloc" check { name = "health" type = "http" @@ -315,7 +291,6 @@ job "security" { path="/health" interval = "10s" timeout = "2s" - address_mode = "alloc" check_restart { limit = 3 grace = "60s" @@ -329,7 +304,6 @@ job "security" { path="/health/live" interval = "10s" timeout = "2s" - address_mode = "alloc" } check { name = "started" @@ -338,7 +312,6 @@ job "security" { path="/health/started" interval = "10s" timeout = "2s" - address_mode = "alloc" } check { name = "ready" @@ -347,7 +320,6 @@ job "security" { path="/health/ready" interval = "10s" timeout = "2s" - address_mode = "alloc" check_restart { limit = 3 grace = "60s" @@ -357,38 +329,11 @@ job "security" { } service { name = "keycloak" -# port = "ui" - port = "8080" - address_mode = "alloc" - connect { - sidecar_service { - proxy { - upstreams { - destination_name = "keycloak-postgres" - local_bind_port = 5432 - } - } - } - sidecar_task{ - + port = "ui" + # port = "8080" - config{ - {% if set_cpu_hard_limit %} - cpu_hard_limit = "true" - {% endif %} - labels = { - "com.github.logunifier.application.name" = "envoy-proxy-keycloak" - "com.github.logunifier.application.pattern.key" = "envoy" - "com.github.logunifier.application.version" = "{{version_envoy}}" - "com.github.logunifier.application.org" = "${var.org}" - "com.github.logunifier.application.env" = "${var.env}" - } - } - } - } tags = [ "traefik.enable=true", - "traefik.consulcatalog.connect=true", "traefik.http.routers.keycloak.tls=true", "traefik.http.routers.keycloak.rule=Host(`{{security_dns}}`)", ] @@ -437,8 +382,6 @@ job "security" { KC_DB = "postgres" KC_DB_SCHEMA = "keycloak" KC_DB_USERNAME = "keycloak" - KC_DB_URL_HOST = "${NOMAD_UPSTREAM_IP_keycloak_postgres}" - KC_DB_URL_PORT = "${NOMAD_UPSTREAM_PORT_keycloak_postgres}" } config { image = "{{registry_dns}}/{{stack_name}}/keycloak:{{version_keycloak_nomadder}}" @@ -466,15 +409,23 @@ job "security" { destination = "${NOMAD_SECRETS_DIR}/env.vars" env = true change_mode = "restart" + right_delimiter = "++" + left_delimiter = "++" data = <&1 >/dev/null; do echo '.'; sleep 2; done"] + #network_mode = "host" + } + + resources { + cpu = 200 + memory = 128 + memory_max = 1024 + } + + lifecycle { + hook = "prestart" + sidecar = false + } + } + task "forwardauth" { + driver = "docker" + env { + # https://brianturchyn.net/traefik-forwardauth-support-with-keycloak/ + # https://github.com/mesosphere/traefik-forward-auth/issues/36 + # INSECURE_COOKIE = "1" + ENCRYPTION_KEY = "45659373957778734945638459467936" #32 character encryption key + # SCOPE = "profile email openid" # scope openid is necessary for keycloak... + SECRET = "9e7d7b0776f032e3a1996272c2fe22d2" + PROVIDER_URI = "https://security.{{tls_san}}/realms/nomadder" + # OIDC_ISSUER = "https://security.{{tls_san}}/realms/nomadder" + CLIENT_ID = "ingress" + LOG_LEVEL = "debug" + # Lifetime of cookie 60s + LIFETIME = "60" + + } + volume_mount { + volume = "ca_cert" + destination = "/etc/ssl/certs/" + } + config { + image = "{{registry_dns}}/mesosphere/traefik-forward-auth:{{version_mesosphere}}" + {% if set_cpu_hard_limit %} + cpu_hard_limit = "true" + {% endif %} + labels = { + "com.github.logunifier.application.name" = "mesosphere" + "com.github.logunifier.application.version" = "{{version_mesosphere}}" + "com.github.logunifier.application.pattern.key" = "logfmt" + "com.github.logunifier.application.org" = "${var.org}" + "com.github.logunifier.application.env" = "${var.env}" + } + ports = ["auth"] + } + resources { + cpu = 500 + memory = 256 + memory_max = 32768 + } + template { + destination = "${NOMAD_SECRETS_DIR}/env.vars" + env = true + change_mode = "restart" + data = <&1 >/dev/null; do echo '.'; sleep 2; done"] + #network_mode = "host" + } + + resources { + cpu = 200 + memory = 128 + memory_max = 1024 + } + + lifecycle { + hook = "prestart" + sidecar = false + } + } + task "keycloak" { + driver = "docker" + env { + KEYCLOAK_ADMIN = "admin" + KC_HTTP_ENABLED= "true" + KC_HOSTNAME="https://{{security_dns}}" + KC_HEALTH_ENABLED= "true" + KC_METRICS_ENABLED= "true" + KC_DB = "postgres" + KC_DB_SCHEMA = "keycloak" + KC_DB_USERNAME = "keycloak" + KC_DB_URL_HOST = "${NOMAD_UPSTREAM_IP_keycloak_postgres}" + KC_DB_URL_PORT = "${NOMAD_UPSTREAM_PORT_keycloak_postgres}" + } + config { + image = "{{registry_dns}}/{{stack_name}}/keycloak:{{version_keycloak_nomadder}}" + {% if set_cpu_hard_limit %} + cpu_hard_limit = "true" + {% endif %} + labels = { + "com.github.logunifier.application.name" = "keycloak" + "com.github.logunifier.application.version" = "{{version_keycloak_nomadder}}" + "com.github.logunifier.application.pattern.key" = "tslevelmsg" + "com.github.logunifier.application.org" = "${var.org}" + "com.github.logunifier.application.env" = "${var.env}" + } + ports = ["ui"] + args = [ + "start", "--import-realm" , "--optimized" + ] + } + resources { + cpu = 500 + memory = 2048 + memory_max = 32768 + } + template { + destination = "${NOMAD_SECRETS_DIR}/env.vars" + env = true + change_mode = "restart" + data = <