mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-03-12 01:45:56 -05:00
[PR #5626] [MERGED] Abstract persistent files through Apache OpenDAL #7279
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?
📋 Pull Request Information
Original PR: https://github.com/dani-garcia/vaultwarden/pull/5626
Author: @txase
Created: 2/21/2025
Status: ✅ Merged
Merged: 5/29/2025
Merged by: @dani-garcia
Base:
main← Head:opendal📝 Commits (5)
0044a6cAbstract file access through Apache OpenDAL4a5d547Add AWS S3 support via OpenDAL for data files05f5993PR improvementsd47e245Additional PR improvementse27965dConfig setting comments for local/remote data locations📊 Changes
19 files changed (+1467 additions, -198 deletions)
View changed files
📝
.env.template(+16 -3)📝
Cargo.lock(+1080 -4)📝
Cargo.toml(+11 -0)📝
build.rs(+3 -0)📝
src/api/admin.rs(+4 -4)📝
src/api/core/ciphers.rs(+23 -33)📝
src/api/core/emergency_access.rs(+1 -1)📝
src/api/core/organizations.rs(+10 -5)📝
src/api/core/sends.rs(+22 -24)📝
src/api/core/two_factor/duo.rs(+1 -1)📝
src/api/icons.rs(+28 -26)📝
src/auth.rs(+35 -41)📝
src/config.rs(+140 -18)📝
src/db/models/attachment.rs(+32 -26)📝
src/db/models/cipher.rs(+14 -4)📝
src/db/models/send.rs(+3 -2)📝
src/error.rs(+3 -0)📝
src/main.rs(+20 -5)📝
src/util.rs(+21 -1)📄 Description
This PR represents the first set of attempting to incorporate the changes from the AWS Serverless POC in #5591 and contains two commits:
s3feature flagThe first commit looks quite large at first glance, but many changes simply make all file accesses asynchronous and fallible by returning
Resulttypes. I think the key changes worth reviewing are:initialize_keys()as needed for OpenDAL access of private key fileCONFIGis still a synchronousLazytype, but we have to calculate it from async methods. I shoehorned a tiny tokio async thread that runs to completion to calculate the value. The alternative of patching every use ofCONFIGto be async, for no runtime benefit, seemed not worth doing.opendal_operator_for_path()and the abstractedCONFIG.opendal_operator_for_path_type()methods for the core of how operators are managed for various paths.save_temp_file()that abstracts the saving of TempFiles that Rocket creates when files are uploadedThe second commit is much smaller and more straightforward. The only thing worth pointing out is that OpenDAL uses reqsign under the covers to configure AWS credentials. However, AWS SDK configs have repeatedly been extended for better credential generation. For example, I use AWS Identity Center (aka AWS SSO) to generate temporary access tokens in my dev environment. reqsign doesn't support AWS SSO configs, but it has an escape hatch I utilized to load credentials. In the escape hatch I load the official AWS SDK config and credential generation crates to generate credentials. The one annoying part of the escape hatch is that reqsign's AwsCredentialLoad trait uses
anyhow::Result, so we have to pull in anyhow just for this escape hatch :(.Trying it out
These changes should be a behavioral no-op for existing use cases. The one minor change is the attachments, icon_cache, and sends folders aren't created at startup as OpenDAL FS service creates them when the first Operator is instantiated for each.
To try out the new S3 changes:
s3feature turned onAWS_PROFILEandAWS_REGIONalong with standard AWS configs like~/.aws/config)DATA_FOLDER->s3://<bucket in the matching AWS region>[/<optional path prefix>]ALLOWED_CONNECT_SRC->https://<bucket>.s3.<region>.amazonaws.com(required if using web-vault)TMP_FOLDER->data/tmp(or your preference, but must be set to a local path)TEMPLATES_FOLDER->data/templates(or your preference, but must be set to a local path)DATABASE_URL->data/db.sqlite3(or your preference, but must be set to a valid value)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.