dani-garcia / vaultwarden

Unofficial Bitwarden compatible server written in Rust, formerly known as bitwarden_rs
GNU Affero General Public License v3.0
39k stars 1.89k forks source link

Some variables from .env file being ignored i.e. ROCKET_PORT #4496

Closed RT-Tap closed 7 months ago

RT-Tap commented 7 months ago

Subject of the issue

ROCKET_PORT inside .env file is ignored possibly others - i know there was an announcement about getting rid of websockets but I did notice that the default variable mentioned in the .env.template file ENABLE_WEBSOCKET=true does not work but WEBSOCKET_ENABLE=true does work. Because it's depreciated it shouldnt matter but I figured I would mention it as well. Others that I have changed (in the env file) and can confirm worked fine:

Steps to reproduce

docker-compose.yml

services:
  vaultwarden:
    image: vaultwarden/server:latest
    container_name: vaultwardentest
    user: "4400:4400"
    security_opt:
      - no-new-privileges:true
    volumes:
      - "./logs/vaultwarden/:/logs/"
      - "./vaultwardendata/:/data/"
    restart: always
    secrets:
      - vaultwardenconfig
    environment:
      - ENV_FILE=/run/secrets/vaultwardenconfig
      #- ROCKET_PORT=4084   # only works when set here
    hostname: vaultwarden

secrets:
  vaultwardenconfig:
    file: ./envfile

.envfile

ROCKET_PORT=4084

Expected behaviour

Rocket server start on port 4084 when using ROCKET_PORT=4084 in env file

Actual behaviour

Rocket server still starts on port 80 unless environment variable explicitly set through docker-compose

Troubleshooting data

docker logs vaultwardentest When set in envfile

[2024-04-12 01:38:07.039][start][INFO] Rocket has launched from http://0.0.0.0:80

when set in docker-compose environment directive

[2024-04-12 01:44:20.367][start][INFO] Rocket has launched from http://0.0.0.0:4084
BlackDex commented 7 months ago

I do not think we can fix this. The env's are loaded in a order, and the one which is last will probably override the previously set items.

The problem here is that the env of the container it self is not overridden when loading the .env file. It currently checks if there already is an env value assigned, if so, it will not re-assign. The reason a -e or custom environment setting works is that it will override the default container environment.

The only way we could solve this is by changing from_path to from_path_override, but that probably would be a breaking change as it might cause issues for other users.

So, it's not really an issue, as this is how it is designed.