From 2f8e37a17ee19ad636f9ce68db02a0d8d137dfca Mon Sep 17 00:00:00 2001 From: sekulicd Date: Tue, 24 Oct 2023 22:07:44 +0200 Subject: [PATCH 1/2] api key auth --- app/core/config.py | 6 ++++++ app/core/services.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/core/config.py b/app/core/config.py index ca3aed6..64faa60 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -17,6 +17,7 @@ PROXY_ENABLED: bool = os.getenv("PROXY_ENABLED", "False").lower() in ("true", "1") DNSD_URL: str = os.getenv("DNSD_URL", "http://dnsd:8080") DOCKER_NETWORK: str = os.getenv("DOCKER_NETWORK", "bridge") +AUTHD_URL: str = os.getenv("DNSD_URL", "http://authd:8080") # APIs # ------------------------------------------------------------------------------ @@ -42,6 +43,7 @@ # ------------------------------------------------------------------------------ DNSD_DNS_EXIST_PATH = "/dns/existing" DNSD_IP = "/dns/ip" +AUTHD_VERIFY = "/auth/verify" def dns_exists_url() -> str: @@ -50,3 +52,7 @@ def dns_exists_url() -> str: def dns_ip() -> str: return f"{DNSD_URL}{DNSD_IP}" + + +def auth_verify_url() -> str: + return f"{AUTHD_URL}{AUTHD_VERIFY}" diff --git a/app/core/services.py b/app/core/services.py index 52fe516..3025679 100644 --- a/app/core/services.py +++ b/app/core/services.py @@ -189,6 +189,7 @@ def run_container_with_retries(service_object): if config.PROXY_ENABLED: dns = utils.check_dns_exists() default_port = service_object["defaultPort"] + auth = config.auth_verify_url() if dns: labels = { "traefik.enable": "true", @@ -204,13 +205,16 @@ def run_container_with_retries(service_object): "traefik.http.middlewares.http-to-https.redirectscheme.scheme": "https", f"traefik.http.routers.{service_id}-http.middlewares": "http-to-https", f"traefik.http.services.{service_id}.loadbalancer.server.port": f"{default_port}", + f"traefik.http.routers.{service_id}-https.middlewares": "auth", + "traefik.http.middlewares.auth.forwardauth.address": f"{auth}", } else: labels = { "traefik.enable": "true", f"traefik.http.routers.{service_id}.rule": f"PathPrefix(`/{service_id}`)", f"traefik.http.middlewares.{service_id}-strip-prefix.stripprefix.prefixes": f"/{service_id}", - f"traefik.http.routers.{service_id}.middlewares": f"{service_id}-strip-prefix", + f"traefik.http.routers.{service_id}.middlewares": f"{service_id}-strip-prefix,auth", + "traefik.http.middlewares.auth.forwardauth.address": f"{auth}", } container = client.containers.run( From c2c168ee51f593c13016a00158c45a0dce84a656 Mon Sep 17 00:00:00 2001 From: sekulicd Date: Wed, 25 Oct 2023 11:10:48 +0200 Subject: [PATCH 2/2] fix --- app/core/services.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/services.py b/app/core/services.py index 3025679..1703bb2 100644 --- a/app/core/services.py +++ b/app/core/services.py @@ -213,7 +213,7 @@ def run_container_with_retries(service_object): "traefik.enable": "true", f"traefik.http.routers.{service_id}.rule": f"PathPrefix(`/{service_id}`)", f"traefik.http.middlewares.{service_id}-strip-prefix.stripprefix.prefixes": f"/{service_id}", - f"traefik.http.routers.{service_id}.middlewares": f"{service_id}-strip-prefix,auth", + f"traefik.http.routers.{service_id}.middlewares": f"auth,{service_id}-strip-prefix", "traefik.http.middlewares.auth.forwardauth.address": f"{auth}", }