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

Set file permissions for created files #1842

Closed
wants to merge 2 commits into from
Closed

Set file permissions for created files #1842

wants to merge 2 commits into from

Conversation

RealOrangeOne
Copy link
Contributor

Fixes #1784

This isn't a full audit of all places files are created, but it covers most. Intentionally not set them on the image cache, as they're not sensitive.

It only works on unix, because that's the only place permissions like this work. It should work fine under docker even if docker isn't run on unix.

This also reuses the existing write_file util in a few places which custom implemented it.

Removed creating icon cache dir as it's done on startup
This isn't a full audit of all places files are created, but it covers most. Intentionally not set them on the image cache, as they're not sensitive.
@williamdes
Copy link
Contributor

Does it run only when the file is created so it could not break read only file system mounts ?

@RealOrangeOne
Copy link
Contributor Author

It always happens after files are written, so the write would fail before this would.

@jjlin
Copy link
Contributor

jjlin commented Jul 10, 2021

This doesn't cover the SQLite DB file. It would probably be much simpler to just chmod 700 the data directory.

@BlackDex
Copy link
Collaborator

Maybe better to set an umask in the entry file? Since this is only a concern for docker run instances.

@RealOrangeOne
Copy link
Contributor Author

I'd say this is still a concern to non docker users, it's general file permissions.

Setting a umask would probably work too, and default everything to 600, without having to remember to set it everywhere. Unfortunately there's nothing in the rust stdlib to set a umask, so it'd involve dropping down to a shell, which feels like a bit of a hack. Would also want to manually chmod everything on startup anyway, to make sure the permissions are updated for existing users.

What I don't know is whether umask works on macOS / windows, or if there are alternatives for those platforms we should be using.

@BlackDex
Copy link
Collaborator

BlackDex commented Jul 10, 2021

It will only work within a docker layer.
I can also think that a group could maybe need read rights for say, backups or other stuff maybe.

Also, if someone runs it outside of docker, then the application would use the umask of the system or the init/systemd part, same goes for MacOS.

And, what if i do not want it to have 600, but 664 or 644 or whatever.
I'm not certain what to do here actually.

@BlackDex
Copy link
Collaborator

I'm not inclined to merge this PR. I still think adding a umask would be the best option here, and this will only add extra overhead.
It also is not touching every file created by Vaultwarden, and it would make maintaining this harder if someone is adding a new file to be saved somewhere. Therefor a umask would be better, because that would count for every file created.

@septatrix
Copy link

This approach is likely to miss some points in the code where files are created and the way the mode is set is inherently racy which is also very bad if this is really meant as a protection against attacks...

This doesn't cover the SQLite DB file. It would probably be much simpler to just chmod 700 the data directory.

Maybe better to set an umask in the entry file? Since this is only a concern for docker run instances.

Both of these feel like cleaner solutions and I think the former would be the "usual" approach to this and how most linux packages are set up when storing some secrets.

@BlackDex
Copy link
Collaborator

I'm going to close this stale PR.
There isn't a good clean solution for everything. Maybe adding the umask is a good one by default.
If so, please create a new PR for this.

Also, calling the the permissions setting during every storage is an other IO call, which only slows down, and i like to prevent that.

@BlackDex BlackDex closed this May 30, 2022
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

Successfully merging this pull request may close these issues.

5 participants