aspendigital / docker-octobercms

Dockerized October CMS: PHP, Composer, October core and dependencies
MIT License
150 stars 55 forks source link

Invalid security token #19

Closed atlekbai closed 5 years ago

atlekbai commented 5 years ago

Hello! I am using traefik as my reverse-proxy and set its config as traefik.frontend.passHostHeader=true. Although, I am always getting Invalid security token error while logging into the backend. Any suggestion to fix this?

petehalverson commented 5 years ago

Hmm. I'm unable to recreate your issue. Can you offer some more specifics? E.g. your traefik.toml, October CMS container settings...

atlekbai commented 5 years ago

I followed this tutorial on how to setup docker swarm cluster using traefic: https://dockerswarm.rocks

This is the configuration for october cms:

version: '3.3'

volumes:
    web_data: {}

networks:
  net:
    driver: overlay
    attachable: true
  traefik-public:
    external: true

services:
  web:
    image: aspendigital/octobercms:latest
    networks:
      - net
      - default
      - traefik-public
    environment:
      - DB_TYPE=mysql
      - DB_HOST=mysql
      - DB_DATABASE=****
      - DB_USERNAME=****
      - DB_PASSWORD=****
      - CMS_LINK_POLICY=secure
    container_name: october
    volumes:
      - web_data:/var/www/html/storage/app
    deploy:
      mode: replicated
      replicas: 3
      labels:
        - traefik.frontend.rule=Host:example.com
        - traefik.enable=true
        - traefik.port=80
        - traefik.tags=${TRAEFIK_PUBLIC_TAG:-traefik-public}
        - traefik.docker.network=traefik-public
        # Traefik service that listens to HTTP
        - traefik.redirectorservice.frontend.entryPoints=http
        - traefik.redirectorservice.frontend.redirect.entryPoint=https
        # Traefik service that listens to HTTPS
        - traefik.webservice.frontend.entryPoints=https

Configuration for traefic:

version: '3.3'

services:
  ...
  # consul images
  ...
  traefik:
    image: traefik:v1.7
    ports:
      - 80:80
      - 443:443
    deploy:
      replicas: 3
      placement:
        constraints:
          - node.role == manager
        preferences:
          - spread: node.id
      labels:
        - traefik.frontend.rule=Host:traefik.${DOMAIN}
        - traefik.enable=true
        - traefik.port=8080
        - traefik.tags=traefik-public
        - traefik.docker.network=traefik-public
        # Traefik service that listens to HTTP
        - traefik.redirectorservice.frontend.entryPoints=http
        - traefik.redirectorservice.frontend.redirect.entryPoint=https
        # Traefik service that listens to HTTPS
        - traefik.webservice.frontend.entryPoints=https
        - traefik.frontend.auth.basic.users=${USERNAME}:${HASHED_PASSWORD}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command:
      --docker
      --docker.swarmmode
      --docker.watch
      --docker.exposedbydefault=false
      --constraints=tag==traefik-public
      --entrypoints='Name:http Address::80'
      --entrypoints='Name:https Address::443 TLS'
      --consul
      --consul.endpoint="consul-leader:8500"
      --acme
      --acme.email=${EMAIL}
      --acme.storage="traefik/acme/account"
      --acme.entryPoint=https
      --acme.httpChallenge.entryPoint=http
      --acme.onhostrule=true
      --acme.acmelogging=true
      --logLevel=INFO
      --accessLog
      --api
    networks:
      - default
      - traefik-public
    depends_on:
      - consul-leader

volumes:
  consul-data-leader:
  consul-data-replica:

networks:
  traefik-public:
    external: true
petehalverson commented 5 years ago

It looks like your problem is related to your October CMS stack config. You aren't defining a shared cache or session driver, which is required when using the admin across replicas. Try this example:


version: '3.3'
services:
  web:
    image: aspendigital/octobercms:latest
    ports:
      - 80:80
    environment:
      - CACHE_STORE=redis
      - DB_DATABASE=octobercms
      - DB_HOST=mysql
      - DB_PASSWORD=root
      - DB_TYPE=mysql
      - DB_USERNAME=root
      - INIT_OCTOBER=true
      - SESSION_DRIVER=redis
    deploy:
      replicas: 3

  mysql:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=octobercms

  redis:
    image: redis:5

I should also point out your web_data volume may not function as you are expecting. When using Swarm across multiple nodes, a volume will be created on each host. The data from each won't be synced across hosts.

You can overcome this by leveraging introducing cloud storage for October CMS Filesystem.

atlekbai commented 5 years ago

Thanks!