[GH-ISSUE #1060] .env file seems to be ignored? #749

Closed
opened 2026-03-03 02:02:49 +03:00 by kerem · 13 comments
Owner

Originally created by @pdarcos on GitHub (Jul 20, 2020).
Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/1060

Hi everyone,

I recently recompiled bitwarden_rs after a fresh git clone and for some reason (likely a stupid mistake on my part) it seems the .env file isn't being parsed when I run ./bitwarden_rs from the target/release/ directory after it compiled.

I can see the .env file is in the same directory but bitwarden_rs doesn't seem to be reading it when it starts since it complains about the "missing" mysql configuration (which is there).

If I start bitwarden_rs with that config explicitly set in the command line it runs as expected which leaves me confused as to why it's not picking up the environment variables from it.
Do I need to run any command or any special permissions for bitwarden_rs to use the .env file that I placed in the release directory?

Thanks

~/bitwarden_rs/target/release# ls -la
total 24164
drwxr-xr-x 8 root root 4096 Jul 20 18:58 .
drwxr-xr-x 3 root root 4096 Jul 20 17:15 ..
-rwxr-xr-x 2 root root 24591112 Jul 20 17:15 bitwarden_rs
-rw-r--r-- 1 root root 5847 Jul 20 17:15 bitwarden_rs.d
drwxr-xr-x 102 root root 4096 Jul 20 17:03 build
-rw-r--r-- 1 root root 0 Jul 20 17:03 .cargo-lock
drwxr-xr-x 3 root root 4096 Jul 20 18:47 data
drwxr-xr-x 2 root root 69632 Jul 20 17:15 deps
-rw-r--r-- 1 root root 8507 Jul 20 18:58 .env
-rw-r--r-- 1 root root 8507 Jul 20 18:58 .env.template
drwxr-xr-x 2 root root 4096 Jul 20 17:03 examples
drwxr-xr-x 392 root root 20480 Jul 20 17:03 .fingerprint
drwxr-xr-x 2 root root 4096 Jul 20 17:03 incremental

Originally created by @pdarcos on GitHub (Jul 20, 2020). Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/1060 Hi everyone, I recently recompiled bitwarden_rs after a fresh git clone and for some reason (likely a stupid mistake on my part) it seems the .env file isn't being parsed when I run ./bitwarden_rs from the target/release/ directory after it compiled. I can see the .env file is in the same directory but bitwarden_rs doesn't seem to be reading it when it starts since it complains about the "missing" mysql configuration (which is there). If I start bitwarden_rs with that config explicitly set in the command line it runs as expected which leaves me confused as to why it's not picking up the environment variables from it. Do I need to run any command or any special permissions for bitwarden_rs to use the .env file that I placed in the release directory? Thanks ~/bitwarden_rs/target/release# ls -la total 24164 drwxr-xr-x 8 root root 4096 Jul 20 18:58 . drwxr-xr-x 3 root root 4096 Jul 20 17:15 .. -rwxr-xr-x 2 root root 24591112 Jul 20 17:15 bitwarden_rs -rw-r--r-- 1 root root 5847 Jul 20 17:15 bitwarden_rs.d drwxr-xr-x 102 root root 4096 Jul 20 17:03 build -rw-r--r-- 1 root root 0 Jul 20 17:03 .cargo-lock drwxr-xr-x 3 root root 4096 Jul 20 18:47 data drwxr-xr-x 2 root root 69632 Jul 20 17:15 deps -rw-r--r-- 1 root root 8507 Jul 20 18:58 .env -rw-r--r-- 1 root root 8507 Jul 20 18:58 .env.template drwxr-xr-x 2 root root 4096 Jul 20 17:03 examples drwxr-xr-x 392 root root 20480 Jul 20 17:03 .fingerprint drwxr-xr-x 2 root root 4096 Jul 20 17:03 incremental
kerem 2026-03-03 02:02:49 +03:00
Author
Owner

@jjlin commented on GitHub (Jul 21, 2020):

It should work as long as .env is in your current working directory. Run strace -e trace=file ./bitwarden_rs and see whether .env is being read and what the result is.

<!-- gh-comment-id:661632517 --> @jjlin commented on GitHub (Jul 21, 2020): It should work as long as `.env` is in your current working directory. Run `strace -e trace=file ./bitwarden_rs` and see whether `.env` is being read and what the result is.
Author
Owner

@pdarcos commented on GitHub (Jul 21, 2020):

Thanks @jjlin

I tried as you suggested but it doesn't seem to recognize the settings in the .env file even though it appears to open it without problems:

strace -e trace=file ./bitwarden_rs

openat(AT_FDCWD, ".env", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "data/config.json", O_RDONLY|O_CLOEXEC) = 3
Error loading config:
DATABASE_URL should start with mysql: when using the MySQL server

+++ exited with 12 +++
root@vault:~/bitwarden_rs/target/release#

cat .env

DATABASE_URL=mysql://bitwarden_rs:mysecretpassword@localhost:3306/bitwarden_rs

The DATABASE_URL is set to the correct format in the .env file as you can see above. But for some reason bitwarden_rs doesn't seem to recognize it.

Any ideas?

Thanks

<!-- gh-comment-id:661825914 --> @pdarcos commented on GitHub (Jul 21, 2020): Thanks @jjlin I tried as you suggested but it doesn't seem to recognize the settings in the .env file even though it appears to open it without problems: `strace -e trace=file ./bitwarden_rs` openat(AT_FDCWD, ".env", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "data/config.json", O_RDONLY|O_CLOEXEC) = 3 Error loading config: `DATABASE_URL` should start with mysql: when using the MySQL server +++ exited with 12 +++ root@vault:~/bitwarden_rs/target/release# `cat .env` DATABASE_URL=mysql://bitwarden_rs:mysecretpassword@localhost:3306/bitwarden_rs The DATABASE_URL is set to the correct format in the .env file as you can see above. But for some reason bitwarden_rs doesn't seem to recognize it. Any ideas? Thanks
Author
Owner

@pdarcos commented on GitHub (Jul 22, 2020):

Anyone have any ideas? Is this just happening to me?

Do I have to recompile bitwarden_rs with the .env file in the source directory? That doesn't make sense to me but it's the only thing I can think of.

<!-- gh-comment-id:662410086 --> @pdarcos commented on GitHub (Jul 22, 2020): Anyone have any ideas? Is this just happening to me? Do I have to recompile bitwarden_rs with the .env file in the source directory? That doesn't make sense to me but it's the only thing I can think of.
Author
Owner

@mqus commented on GitHub (Jul 22, 2020):

No, the .env file only matters at runtime. In my case, I let other programs take care of reading the .env file and transmit them as env variables to bitwarden_rs, e.g. through systemds EnvironmentFile. I'll try on my machine (with the 1.16 release) and get back to you.

<!-- gh-comment-id:662467233 --> @mqus commented on GitHub (Jul 22, 2020): No, the .env file only matters at runtime. In my case, I let other programs take care of reading the .env file and transmit them as env variables to bitwarden_rs, e.g. through systemds `EnvironmentFile`. I'll try on my machine (with the 1.16 release) and get back to you.
Author
Owner

@mqus commented on GitHub (Jul 22, 2020):

I tried to manipulate the .env file by only changing the port and then put the .env file and the binary in the same folder (in my case /tmp/sometest) and then cded into it and ran

$ ./bitwarden_rs

The first output showed the changed port so it seemed to work. (CAVEAT: I am running the sqlite version). I'm assuming that you also compiled with the right feature flags. I'll try the mysql version now, but I'll have to compile it first.

<!-- gh-comment-id:662473209 --> @mqus commented on GitHub (Jul 22, 2020): I tried to manipulate the .env file by only changing the port and then put the .env file and the binary in the same folder (in my case `/tmp/sometest`) and then `cd`ed into it and ran ``` $ ./bitwarden_rs ``` The first output showed the changed port so it seemed to work. (CAVEAT: I am running the sqlite version). I'm assuming that you also compiled with the right feature flags. I'll try the mysql version now, but I'll have to compile it first.
Author
Owner

@pdarcos commented on GitHub (Jul 22, 2020):

Thanks @mqus

Yeah I compiled with mysql support and it works when I use DATABASE_URL=mysql://bitwarden_rs:mysecretpassword@localhost:3306/bitwarden_rs directly on the command line.

<!-- gh-comment-id:662485445 --> @pdarcos commented on GitHub (Jul 22, 2020): Thanks @mqus Yeah I compiled with mysql support and it works when I use DATABASE_URL=mysql://bitwarden_rs:mysecretpassword@localhost:3306/bitwarden_rs directly on the command line.
Author
Owner

@mqus commented on GitHub (Jul 22, 2020):

So I also compiled with mysql just now and had the following setup and output (no mysql server is actually running, so starting bitwarden_rs will fail), but it doesn't say anything about the URL not being correct:

mqus@mypc /tmp/sometest $ tree -a
.
├── bitwarden_rs
└── .env

0 directories, 2 files
mqus@mypc /tmp/sometest $ grep URL .env
## Database URL
## When using MySQL, this it is the URL to the DB, including username and password:
# DATABASE_URL=data/db.sqlite3
DATABASE_URL=mysql://admin:admin@localhost/bwrsdb
mqus@mypc /tmp/sometest $ ./bitwarden_rs 
/--------------------------------------------------------------------\
|                       Starting Bitwarden_RS                        |
|--------------------------------------------------------------------|
| This is an *unofficial* Bitwarden implementation, DO NOT use the   |
| official channels to report bugs/features, regardless of client.   |
| Send usage/configuration questions or feature requests to:         |
|   https://bitwardenrs.discourse.group/                             |
| Report suspected bugs/issues in the software itself at:            |
|   https://github.com/dani-garcia/bitwarden_rs/issues/new           |
\--------------------------------------------------------------------/

[2020-07-22 16:35:53][panic][ERROR] thread 'main' panicked at 'Can't connect to DB: BadConnection("Can\'t connect to local MySQL server through socket \'/run/mysqld/mysqld.sock\' (2)")': src/main.rs:235
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: __libc_start_main
  10: <unknown>

I'm not sure why it tries to connect through a socket (and not via tcp to localhost with the default port). But this can be my lack of knowledge.

<!-- gh-comment-id:662493687 --> @mqus commented on GitHub (Jul 22, 2020): So I also compiled with mysql just now and had the following setup and output (no mysql server is actually running, so starting bitwarden_rs will fail), but it doesn't say anything about the URL not being correct: ``` mqus@mypc /tmp/sometest $ tree -a . ├── bitwarden_rs └── .env 0 directories, 2 files ``` ``` mqus@mypc /tmp/sometest $ grep URL .env ## Database URL ## When using MySQL, this it is the URL to the DB, including username and password: # DATABASE_URL=data/db.sqlite3 DATABASE_URL=mysql://admin:admin@localhost/bwrsdb ``` ``` mqus@mypc /tmp/sometest $ ./bitwarden_rs /--------------------------------------------------------------------\ | Starting Bitwarden_RS | |--------------------------------------------------------------------| | This is an *unofficial* Bitwarden implementation, DO NOT use the | | official channels to report bugs/features, regardless of client. | | Send usage/configuration questions or feature requests to: | | https://bitwardenrs.discourse.group/ | | Report suspected bugs/issues in the software itself at: | | https://github.com/dani-garcia/bitwarden_rs/issues/new | \--------------------------------------------------------------------/ [2020-07-22 16:35:53][panic][ERROR] thread 'main' panicked at 'Can't connect to DB: BadConnection("Can\'t connect to local MySQL server through socket \'/run/mysqld/mysqld.sock\' (2)")': src/main.rs:235 0: <unknown> 1: <unknown> 2: <unknown> 3: <unknown> 4: <unknown> 5: <unknown> 6: <unknown> 7: <unknown> 8: <unknown> 9: __libc_start_main 10: <unknown> ``` I'm not sure why it tries to connect through a socket (and not via tcp to localhost with the default port). But this can be my lack of knowledge.
Author
Owner

@pdarcos commented on GitHub (Jul 22, 2020):

Thanks again @mqus

Must be something wrong on my end then.

I'll recompile and start again from scratch.
I'm going to go ahead and close this ticket since it's obviously something I've done wrong and not a bug in bitwarden_rs.

Cheers

<!-- gh-comment-id:662495774 --> @pdarcos commented on GitHub (Jul 22, 2020): Thanks again @mqus Must be something wrong on my end then. I'll recompile and start again from scratch. I'm going to go ahead and close this ticket since it's obviously something I've done wrong and not a bug in bitwarden_rs. Cheers
Author
Owner

@mqus commented on GitHub (Jul 22, 2020):

I think the socket thing is still suspicous and It would be better to close this once you have actually figured out what the issue was. I didn't see anything wrong from your side.

EDIT: Could it be that it tries to read your (old) database configuration from data/config.json?

<!-- gh-comment-id:662505377 --> @mqus commented on GitHub (Jul 22, 2020): I think the socket thing is still suspicous and It would be better to close this once you have actually figured out what the issue was. I didn't see anything wrong from your side. EDIT: Could it be that it tries to read your (old) database configuration from `data/config.json`?
Author
Owner

@pdarcos commented on GitHub (Aug 2, 2020):

Opening this issue again since it seems the strange behavior continues.

I made sure that it isn't reading data/config.json since I changed its name to config.json.backup and it still seems to ignore my .env file completely even though it's in the same directory and is properly configured:

root@vault:~/bitwarden_rs/target/release# grep URL .env
## Database URL
## When using MySQL, this it is the URL to the DB, including username and password:
# DATABASE_URL=data/db.sqlite3
DATABASE_URL='mysql://bitwarden_rs:supersecretpassword@localhost:3306/bitwarden_rs'
root@vault:~/bitwarden_rs/target/release#

And then

root@vault:~/bitwarden_rs/target/release# ./bitwarden_rs 
/--------------------------------------------------------------------\
|                       Starting Bitwarden_RS                        |
|                      Version 1.15.1-0b04caab                       |
|--------------------------------------------------------------------|
| This is an *unofficial* Bitwarden implementation, DO NOT use the   |
| official channels to report bugs/features, regardless of client.   |
| Send usage/configuration questions or feature requests to:         |
|   https://bitwardenrs.discourse.group/                             |
| Report suspected bugs/issues in the software itself at:            |
|   https://github.com/dani-garcia/bitwarden_rs/issues/new           |
\--------------------------------------------------------------------/

Error loading config:
        `DATABASE_URL` should start with mysql: when using the MySQL server

root@vault:~/bitwarden_rs/target/release# 

I don't know why it seems to ignore my .env file when it is there in the same directory:

root@vault:~/bitwarden_rs/target/release# ls -la .env 
-rw-r--r-- 1 root root 8503 Aug  2 16:30 .env

Any ideas?

<!-- gh-comment-id:667689945 --> @pdarcos commented on GitHub (Aug 2, 2020): Opening this issue again since it seems the strange behavior continues. I made sure that it isn't reading` data/config.json` since I changed its name to config.json.backup and it still seems to ignore my `.env` file completely even though it's in the same directory and is properly configured: ``` root@vault:~/bitwarden_rs/target/release# grep URL .env ## Database URL ## When using MySQL, this it is the URL to the DB, including username and password: # DATABASE_URL=data/db.sqlite3 DATABASE_URL='mysql://bitwarden_rs:supersecretpassword@localhost:3306/bitwarden_rs' root@vault:~/bitwarden_rs/target/release# ``` And then ``` root@vault:~/bitwarden_rs/target/release# ./bitwarden_rs /--------------------------------------------------------------------\ | Starting Bitwarden_RS | | Version 1.15.1-0b04caab | |--------------------------------------------------------------------| | This is an *unofficial* Bitwarden implementation, DO NOT use the | | official channels to report bugs/features, regardless of client. | | Send usage/configuration questions or feature requests to: | | https://bitwardenrs.discourse.group/ | | Report suspected bugs/issues in the software itself at: | | https://github.com/dani-garcia/bitwarden_rs/issues/new | \--------------------------------------------------------------------/ Error loading config: `DATABASE_URL` should start with mysql: when using the MySQL server root@vault:~/bitwarden_rs/target/release# ``` I don't know why it seems to ignore my .env file when it is there in the same directory: ``` root@vault:~/bitwarden_rs/target/release# ls -la .env -rw-r--r-- 1 root root 8503 Aug 2 16:30 .env ``` Any ideas?
Author
Owner

@jjlin commented on GitHub (Aug 2, 2020):

Try adding something like println!("DATABASE_URL = {}", db_url); to

github.com/dani-garcia/bitwarden_rs@f724addf9a/src/config.rs (L427-L429)

Rebuild and see what it's getting for that value.

<!-- gh-comment-id:667734672 --> @jjlin commented on GitHub (Aug 2, 2020): Try adding something like `println!("DATABASE_URL = {}", db_url);` to https://github.com/dani-garcia/bitwarden_rs/blob/f724addf9ac972a04f536262ed21a7e6c1da0660/src/config.rs#L427-L429 Rebuild and see what it's getting for that value.
Author
Owner

@pdarcos commented on GitHub (Aug 3, 2020):

Thanks @jjlin

I'll try that and report back.

Cheers

<!-- gh-comment-id:667980970 --> @pdarcos commented on GitHub (Aug 3, 2020): Thanks @jjlin I'll try that and report back. Cheers
Author
Owner

@pdarcos commented on GitHub (Aug 3, 2020):

Update. I did a fresh git clone and added the println as @jjlin described above.
I just compiled and now when I start up bitwarden_rs it no longer complains about the missing mysql and connects as expected.

Not sure what the error was but it seems to have gone away after rebuilding.

Thanks to everyone that helped.

Going to go ahead and close.

<!-- gh-comment-id:668069151 --> @pdarcos commented on GitHub (Aug 3, 2020): Update. I did a fresh git clone and added the println as @jjlin described above. I just compiled and now when I start up bitwarden_rs it no longer complains about the missing mysql and connects as expected. Not sure what the error was but it seems to have gone away after rebuilding. Thanks to everyone that helped. Going to go ahead and close.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vaultwarden#749
No description provided.