mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-03-25 15:50:21 -05:00
vaultwarden attempts postgresql connection with SLAAC address, not the websocket address #4928
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DerVerruckteFuchs on GitHub (May 29, 2022).
Subject of the issue
vaultwarden attempts potsgresql connection with SLAAC address, not the configured websocket address
Deployment environment
Your environment (Generated via diagnostics page)
Config (Generated via diagnostics page)
Show Running Config
Environment settings which are overridden:
Steps to reproduce
Expected behaviour
Vaultwarden starts and connects to postgresql database normally.
Actual behaviour
Vaultwarden fails to connect to postgresql database, since it is using the wrong IPv6 address.
Troubleshooting data
I'm using pfsense for my router. When I have my server subnet use "Unmanaged" RA mode (SLAAC, I think), then my vaultwarden server gets a SLAAC IP along with the static address I've configured. For whatever reason vaultwarden uses the SLAAC address, instead of the static websocket address, for the database connection. When setting the server subnet to "Router Only" RA mode (no SLAAC, just advertise router info), then my vaultwarden server only gets the static IP address I assigned it. The "Router Only" mode works as a workaround, but it would be preferable that the websocket IP is used for connecting to the database. Another option is a config option to set which IP to use when connecting to the database.
I've only permitted specific hosts to connect to my postgresql database, so that is why my vaultwarden server fails to connect with the SLAAC address. The behavior is rather unexpected, as I assumed it would connect with the configured websocket address. Nextcloud, among other services I self-host, connects with the IP I set in the relevant config files.
Edit: subdomain -> subnet
@BlackDex commented on GitHub (May 29, 2022):
I'm not sure what you mean here, web-sockets have nothing to do specifically with database connections.
Vaultwarden is running on the default interface of the host. If you want the application to only be accessible from/to a specific IP address i suggest to configure Vaultwarden to only listen on that specific address. You can configure Vaultwarden to use a specific address via
ROCKET_ADDRESS, the same goes for the web-sockets btw viaWEBSOCKET_ADDRESS.Vaultwarden as (most) any other application does not determine the route, interface or outgoing IP address it self, that is all done by the OS/Host. So I'm not sure what you would expect from us.
If you configure a a specific IP address (that may be v4 or v6) as your database IP address, then Vaultwarden will use that IP address to connect to it. Again, how that connection is established is not determined by Vaultwarden it self, it just uses the Host/OS Network Stack.
I would first check what happens if you try to connect to the database manually from the same LXC container you are running Vaultwarden on and if you are able to connect or not.
@DerVerruckteFuchs commented on GitHub (May 29, 2022):
I have set both
WEBSOCKET_ADDRESSandROCKET_ADDRESS. My setup has worked fine with IPv4 for months now. The issue came up when I tried IPv6 addresses recently. The static IPv6 address works fine with the websocket and rocket. The connection from vaultwarden to the database is wonky. Vaultwarden tries to connect to the database with the SLAAC address, then fails, and does not even try connecting with the static address. Both the SLAAC and static addresses are available to vaultwarden.Preventing the vaultwarden LXC container from getting a SLAAC address only leaves vaultwarden with a single static IPv6 address to use, then it works fine. I have applied it as a workaround on my subnet, and it works pretty well.
It just seems that vaultwarden is using whichever IP it feels like for the client side of the database connection if it has more than one to pick from. It does use the correct host IP for the database.
@BlackDex commented on GitHub (May 29, 2022):
Again, Vaultwarden or any library it's using isn't going to select an interface it self. The host will determine the best path on a number of metrics. Stuff like router position, subnet maybe even interface order.
You can check with
ip route getwhich path the os will take.It's all up to the os not per application (by default)