Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix: Traefik www redirect #893

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/admin-panels/jupyter_server_config.py.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.port = 8888
c.ServerApp.open_browser = False
Expand Down
2 changes: 1 addition & 1 deletion services/traefik/docker-compose.letsencrypt.dns.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
traefik:
deploy:
labels:
- traefik.http.routers.wwwsecure-catchall.tls.certresolver=myresolver
- traefik.http.routers.www-catchall.tls.certresolver=myresolver
- traefik.http.routers.api.tls.certresolver=myresolver
- traefik.http.middlewares.ops_whitelist_ips.ipallowlist.sourcerange=${TRAEFIK_IPWHITELIST_SOURCERANGE}
# What follows is a tested workaround to ensure letsencrypt certificates for products' domains are generated
Expand Down
40 changes: 26 additions & 14 deletions services/traefik/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ services:
command:
- "--api=true"
- "--api.dashboard=true"
- "--accesslog=true"
- "--accesslog.format=json"
- "--accesslog.fields.defaultmode=keep"
- "--accesslog.fields.names.ClientUsername=keep"
- "--accesslog.fields.headers.defaultmode=keep"
- "--accesslog.fields.headers.names.User-Agent=keep"
- "--accesslog.fields.headers.names.Authorization=drop"
- "--accesslog.fields.headers.names.Content-Type=keep"
- "--log.level=${OPS_TRAEFIK_LOGLEVEL}"
- "--accesslog=false"
- "--metrics.prometheus=true"
- "--metrics.prometheus.addEntryPointsLabels=true"
- "--metrics.prometheus.addServicesLabels=true"
Expand All @@ -18,9 +25,9 @@ services:
- "--entryPoints.http.transport.respondingTimeouts.idleTimeout=21600s" #6h, for https://github.com/traefik/traefik/issues/10805
- "--entryPoints.http.transport.respondingTimeouts.writeTimeout=21600s" #6h, for https://github.com/traefik/traefik/issues/10805
- "--entryPoints.http.transport.respondingTimeouts.readTimeout=21600s" #6h, for https://github.com/traefik/traefik/issues/10805
- --entrypoints.http.http.redirections.entrypoint.to=https
- --entrypoints.http.http.redirections.entrypoint.scheme=https
- --entrypoints.http.http.redirections.entrypoint.permanent=true
- "--entrypoints.http.http.redirections.entrypoint.to=https"
- "--entrypoints.http.http.redirections.entrypoint.scheme=https"
- "--entrypoints.http.http.redirections.entrypoint.permanent=true"
- '--entryPoints.postgres.address=:5432'
- '--entryPoints.postgres2.address=:5433'
- "--entryPoints.https.address=:443"
Expand Down Expand Up @@ -90,16 +97,15 @@ services:
# via https://community.traefik.io/t/v2-2-8-global-redirect-www-to-non-www-with-http-to-https/7428
# see also: https://community.traefik.io/t/get-a-valid-ssl-certificate-for-www-domains-via-traefik-and-lets-encrypt/2023
# Global redirection: https (www.) to https
- traefik.http.routers.wwwsecure-catchall.rule=HostRegexp(`(?P<host>(www\.).+)`)
- traefik.http.routers.wwwsecure-catchall.entrypoints=https
- traefik.http.routers.wwwsecure-catchall.tls=true
- traefik.http.routers.wwwsecure-catchall.middlewares=wwwtohttps
# middleware: http(s)://(www.) to https://
- traefik.http.middlewares.wwwtohttps.redirectregex.regex=^https?://(?:www\.)?(.+)
- traefik.http.middlewares.wwwtohttps.redirectregex.replacement=https://$${1}
- traefik.http.middlewares.wwwtohttps.redirectregex.permanent=true
- traefik.http.routers.www-catchall.rule=Host(`www.osparc.local`)
- traefik.http.routers.www-catchall.priority=100000
- traefik.http.routers.www-catchall.entrypoints=https,http
- traefik.http.routers.www-catchall.tls=true
- traefik.http.routers.www-catchall.middlewares=strip-www

# Explicit www domain certificate
- traefik.http.routers.wwwsecure-catchall.tls.domains[0].main=www.${MACHINE_FQDN}
- traefik.http.routers.www-catchall.tls.domains[0].main=www.${MACHINE_FQDN} # Shouldnt this be all domains?>>
mrnicegyu11 marked this conversation as resolved.
Show resolved Hide resolved

###########################
# basic authentication
# Note: all dollar signs in the hash need to be doubled for escaping.
Expand Down Expand Up @@ -137,6 +143,12 @@ services:
- traefik.http.middlewares.authenticated_platform_user.forwardauth.address=http://${WEBSERVER_HOST}:${WEBSERVER_PORT}/v0/auth:check
- traefik.http.middlewares.authenticated_platform_user.forwardauth.trustForwardHeader=true
- traefik.http.middlewares.authenticated_platform_user.forwardauth.authResponseHeaders=Set-Cookie,osparc-sc2
#
# middleware: http(s)://(www.) to https://
mrnicegyu11 marked this conversation as resolved.
Show resolved Hide resolved
- traefik.http.middlewares.strip-www.redirectregex.regex=^(.*)www\.(.+)
mrnicegyu11 marked this conversation as resolved.
Show resolved Hide resolved
- traefik.http.middlewares.strip-www.redirectregex.replacement=$${1}$${2}
- traefik.http.middlewares.strip-www.redirectregex.permanent=true

networks:
public: null
monitored: null
Expand All @@ -145,7 +157,7 @@ services:
deploy:
placement:
constraints:
- node.labels.ops==true
- node.labels.traefik==true
labels:
- traefik.enable=true
- traefik.docker.network=${PUBLIC_NETWORK}
Expand Down
Loading