dockertraefikhsts

How to use STS headers with Traefik when using Docker


This is an issue I have been fighting with for days, but I could not find any help on stackoverflow, not even close to it. I hope to help people with similar issues in the future. Any elaboration on this question/answer is very much welcome.

I have been trying to set STS-headers to http-requests when using Traefik as a proxy in a Docker environment. Somehow, no matter how I try to set the headers, my browser (Google Chrome) ignores them. What am I doing wrong?


Solution

  • I have been fighting with HSTS headers in Traefik for multiple days, when I learned something important about HSTS:

    Your browser will ignore any STS headers when the certificate you are using is considered not trustworthy/safe by your browser. You can verify this (in Chrome) with the security tab in the developer tools.

    For HSTS (HTTP Strict Transport Security) to work, I had to solve the next few things in my particular scenario:

    Those two things were the things I missed, after solving those, my STS headers (used in docker-compose service labels) were working. The labels (Traefik v1.7) look as following:

    my_service:
        deploy:
          labels:
          - "traefik.frontend.headers.STSPreload=true"
          - "traefik.frontend.headers.STSSeconds=31536000"
    

    Hope it helps anybody.