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

Consider using "expose:" vs. "ports" in the docker compose yaml. #116

Open
sudoshi opened this issue Nov 28, 2023 · 6 comments
Open

Consider using "expose:" vs. "ports" in the docker compose yaml. #116

sudoshi opened this issue Nov 28, 2023 · 6 comments

Comments

@sudoshi
Copy link

sudoshi commented Nov 28, 2023

Consider using the expose parameter for all ports that do not need to be bound to the docker host external environment. This will reduce conflicts between application stacks running on the same docker host (ie Perseus and Broadsea). It also increases security by ensuring that key services are only available within the docker network.

In the case of Traefik, this will allow one instance of the container to serve as reverse proxy across multiple networks and manage SSL for all stacks. Explained here: (https://ioflood.com/blog/docker-compose-ports-vs-expose-explained/#:~:text='Expose'%20is%20used%20for%20inter,the%20host%20machine%20and%20beyond.)

@alondhe
Copy link
Collaborator

alondhe commented Jan 4, 2024

Which ports do you think we shouldn't have open to the external environment?

@sudoshi
Copy link
Author

sudoshi commented Jan 4, 2024

Any/all ports that belong to a db or API. I had a hell of a time with cryptominers and other malware invading my docker environment on GCP. Specifically kdevtmpfsi (kinsing) and a hotfuzz variant.

@alondhe
Copy link
Collaborator

alondhe commented Jan 4, 2024

Understood. I think we can shift to expose for all services but these:

  1. traefik - needed
  2. atlasdb - it is helpful to have remote access for DBA activities. However, we need to address the password secret issue in the docker image, this is likely where you had the malware issue. For now, I think we need to advise changing the PG password after building.
  3. openldap - if we position this as for debugging only, then sure, we could keep this internal only. The challenge is that there's not a lot of good ldap user management we can do via Docker, just user names and passwords.

Others exist in the experimental Perseus services and have just been adopted from that repo. But we could try limiting those.

@sudoshi
Copy link
Author

sudoshi commented Jan 5, 2024

Agreed. I think we should either enforce or strongly urge users to use strong passwords and non-standard ports if the ports are bound vs. exposed. For example, instead of postgres/mypass on port 5432 as the default, perhaps we should change those default parameters?

@alondhe
Copy link
Collaborator

alondhe commented Jan 5, 2024

I just pushed some changes to develop to really scale back the number of external ports:

  1. traefik
  2. atlasdb
  3. openldap

Let's examine the last 2, but thanks @sudoshi for the push towards fewer external ports!

@sudoshi
Copy link
Author

sudoshi commented Jan 5, 2024

@alondhe - this is the part of docker-compose.yml that I modified from the original Broadsea docker compose yaml:

  traefik:
    image: docker.io/library/traefik:v2.10.5
    container_name: traefik
    restart: unless-stopped
    ipc: none
    read_only: true
    environment:
      BROADSEA_HOST: ${BROADSEA_HOST}
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./traefik/traefik-${HTTP_TYPE}.yml:/etc/traefik/traefik.yml:ro
      - ./traefik/config.yml:/etc/traefik/config.yml:ro
      - ${BROADSEA_CERTS_FOLDER}:/etc/certs:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    command:
      - "--api.dashboard=true"
      - "--api.insecure=false"
      - "--log.level=INFO"
      - "--providers.docker=true"
      - "--providers.docker.network=traefik-proxy"
      - "--providers.docker.exposedByDefault=false"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mydashboard.rule=Host(`sandbox.acumenus.net`) && PathPrefix(`/api`, `/dashboard`)"
      - "traefik.http.routers.mydashboard.service=api@internal"
      - "traefik.http.routers.mydashboard.middlewares=myauth"
      - "traefik.http.middlewares.myauth.basicauth.users=acumenus:$$apr1$$aw2RYnxA$$RXTcLZ8KipPUcyeoLGziu0". # <-- change me using htpasswd to create an encrypted user/password combo
    networks:
      - traefik-proxy

This enables the traefik dashboard where you can see ALL the ports being managed by the reverse proxy and the routes and middleware specified in the traefik.yml configuration file. It took me a few days to get it to work, and I don't know how to create a pull request (I'll learn this weekend - now that I have a reason to!), so if you want to incorporate it, please do.

https://sandbox.acumenus.net/dashboard/

results in:

Screenshot 2024-01-05 at 3 58 02 PM

https://www.web2generators.com/apache-tools/htpasswd-generator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants