2026-03-2010 phút đọcVI
- 1.Tại sao cần Secret Manager? — Vượt ra ngoài .env files
- 2.Tổng quan Vaultwarden — Tương thích Bitwarden, chạy bằng Rust(bài này)
- 3.Cài đặt Docker với bảo mật nâng cao cho Vaultwarden
- 4.Cloudflare Tunnel và Zero Trust Access — Truy cập bảo mật không cần mở port
- 8.Backup và Disaster Recovery — Vault là sinh mệnh của bạn
Tổng quan Vaultwarden
Bitwarden là một trong những password manager mã nguồn mở phổ biến nhất thế giới. Ra đời năm 2016, Bitwarden cung cấp đầy đủ tính năng quản lý mật khẩu cho cá nhân và tổ chức — với tùy chọn self-host để kiểm soát hoàn toàn dữ liệu.
Tuy nhiên, phiên bản self-hosted chính thức của Bitwarden có yêu cầu tài nguyên khá cao — multiple containers, SQL Server, tối thiểu 2GB RAM. Đối với cá nhân hoặc team nhỏ chạy trên VPS 1-2GB, đây là rào cản đáng kể.
Vaultwarden (trước đây gọi là bitwarden_rs) ra đời để giải quyết vấn đề này — một implementation không chính thức (unofficial) của Bitwarden server API, viết bằng Rust, tiêu thụ tài nguyên cực kỳ thấp, nhưng tương thích hoàn toàn với hệ sinh thái Bitwarden clients.
Bài viết này phân tích chi tiết Vaultwarden — kiến trúc, tính năng, so sánh với các giải pháp khác, và khi nào nên (hoặc không nên) chọn Vaultwarden.
Bitwarden vs Vaultwarden — So sánh chi tiết
Bitwarden chính thức (Self-hosted)
Bitwarden official self-hosted deployment bao gồm nhiều containers chạy song song:
bitwarden-mssql # Microsoft SQL Server
bitwarden-web # Web vault (Angular)
bitwarden-api # API server (C#/.NET)
bitwarden-identity # Identity server (authentication)
bitwarden-admin # Admin portal
bitwarden-icons # Icon fetching service
bitwarden-notifications # WebSocket notifications
bitwarden-events # Event logging
bitwarden-attachments # File attachment handler
bitwarden-nginx # Reverse proxy
Yêu cầu tài nguyên:
- RAM: ~2GB minimum (SQL Server alone cần ~1GB)
- Disk: ~10GB cho Docker images + data
- CPU: 2 cores recommended
- OS: Linux (Docker) hoặc Windows Server
Vaultwarden
Vaultwarden thay thế toàn bộ stack trên bằng một binary duy nhất:
vaultwarden # Single Rust binary — bao gồm tất cả
Yêu cầu tài nguyên:
- RAM: ~50-128MB (tùy số users và workload)
- Disk: ~100MB cho Docker image + data
- CPU: 1 core đủ dùng
- OS: Linux, macOS, Windows, ARM (Raspberry Pi)
Tại sao nhẹ hơn nhiều?
Sự khác biệt đến từ technology stack:
| Thành phần | Bitwarden Official | Vaultwarden |
|---|---|---|
| Ngôn ngữ | C# / .NET | Rust |
| Web framework | ASP.NET Core | Rocket (Rust) |
| Database | Microsoft SQL Server | SQLite hoặc PostgreSQL hoặc MySQL |
| Web vault | Separate container | Embedded (static files) |
| Notifications | Separate service | Built-in WebSocket |
| Architecture | Microservices (10+ containers) | Monolith (1 binary) |
| Runtime | .NET CLR (managed memory) | Native binary (zero runtime overhead) |
Rust biên dịch sang native machine code, không cần runtime environment. SQLite là embedded database — một file duy nhất, không cần server process riêng. Kết hợp lại, Vaultwarden hoạt động hiệu quả trên cả các thiết bị ARM như Raspberry Pi.
API Compatibility
Đây là điểm mạnh quan trọng nhất của Vaultwarden: nó implement Bitwarden API specification, nên tất cả official Bitwarden clients đều hoạt động:
- Browser extensions: Chrome, Firefox, Safari, Edge, Brave
- Desktop apps: Windows, macOS, Linux
- Mobile apps: iOS, Android
- CLI tool:
bw(Bitwarden CLI) - Web vault: Embedded sẵn trong Vaultwarden
Người dùng cuối không nhận biết họ đang dùng Vaultwarden hay Bitwarden chính thức — giao diện, workflow, tính năng đều giống nhau.
Feature comparison chi tiết
| Tính năng | Bitwarden Official | Vaultwarden |
|---|---|---|
| Password vault | ✅ | ✅ |
| Secure notes | ✅ | ✅ |
| Credit cards & Identities | ✅ | ✅ |
| TOTP (2FA authenticator) | ✅ (Premium) | ✅ (miễn phí) |
| File attachments | ✅ | ✅ |
| Organizations | ✅ | ✅ |
| Collections | ✅ | ✅ |
| Send (secure sharing) | ✅ | ✅ |
| Emergency Access | ✅ (Premium) | ✅ (miễn phí) |
| Password health reports | ✅ (Premium) | ✅ (miễn phí) |
| Vault health reports | ✅ | ✅ |
| 2FA (TOTP, WebAuthn, Duo, Email) | ✅ | ✅ |
| Directory Connector (LDAP/AD) | ✅ (Enterprise) | Không hỗ trợ |
| SSO (SAML/OIDC) | ✅ (Enterprise) | Không hỗ trợ |
| Key Connector (SSO + keyless) | ✅ (Enterprise) | Không hỗ trợ |
| HSM integration | ✅ (Enterprise) | Không hỗ trợ |
| Custom roles (granular) | ✅ (Enterprise) | Hạn chế |
| Official support & SLA | ✅ | Community only |
| Compliance certifications | SOC 2, GDPR, HIPAA | Tự chịu trách nhiệm |
Điểm đáng chú ý: Nhiều tính năng mà Bitwarden yêu cầu Premium hoặc Enterprise license (TOTP, Emergency Access, vault reports) lại miễn phí trong Vaultwarden, vì Vaultwarden là community project không ràng buộc bởi mô hình kinh doanh.
Kiến trúc Vaultwarden
Tổng quan kiến trúc
┌─────────────────────────────────────────────────┐
│ Clients │
│ (Browser Extension, Desktop, Mobile, CLI, Web) │
└──────────────────────┬──────────────────────────┘
│ HTTPS (TLS)
▼
┌────────────────┐
│ Reverse Proxy │ (Caddy / Nginx / Traefik)
│ TLS Termination│
└───────┬────────┘
│ HTTP
▼
┌────────────────────────┐
│ Vaultwarden │
│ (Rocket Web Server) │
│ │
│ ┌──────────────────┐ │
│ │ REST API │ │ ← Bitwarden-compatible API
│ ├──────────────────┤ │
│ │ WebSocket │ │ ← Live sync notifications
│ ├──────────────────┤ │
│ │ Web Vault │ │ ← Static files (embedded)
│ ├──────────────────┤ │
│ │ Admin Panel │ │ ← /admin (token-protected)
│ └──────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────┐ │
│ │ Database │ │
│ │ SQLite / PgSQL │ │
│ └──────────────────┘ │
└────────────────────────┘
Rocket Web Server (Rust)
Vaultwarden được xây dựng trên Rocket — một web framework cho Rust, nổi tiếng với type safety và hiệu năng cao. Rocket xử lý:
- HTTP request routing
- JSON serialization/deserialization
- Static file serving (web vault)
- WebSocket connections
Rust đảm bảo memory safety mà không cần garbage collector — không có null pointer exceptions, không có buffer overflow, không có data race. Đây là lý do Vaultwarden ổn định với memory footprint rất thấp.
Database Backend
Vaultwarden hỗ trợ 3 database backends:
SQLite (mặc định)
data/
├── db.sqlite3 # Database file duy nhất
├── rsa_key.der # RSA private key
├── rsa_key.pub.der # RSA public key
├── icon_cache/ # Cached website icons
├── attachments/ # File attachments
└── sends/ # Send files
Ưu điểm SQLite:
- Zero configuration — không cần setup database server
- Single file backup —
cp db.sqlite3 backup.sqlite3 - Đủ hiệu năng cho dưới 50 users
- Không cần network connection (embedded)
Nhược điểm SQLite:
- Write concurrency hạn chế (1 writer tại 1 thời điểm)
- Không hỗ trợ replication native
- File-level locking có thể gây bottleneck khi nhiều users đồng thời
PostgreSQL
# Cấu hình qua environment variable
DATABASE_URL=postgresql://vaultwarden:password@localhost:5432/vaultwardenKhi nào dùng PostgreSQL:
- Team trên 20 users với hoạt động đồng thời cao
- Cần replication / high availability
- Đã có PostgreSQL infrastructure sẵn
- Cần advanced querying (admin/reporting)
MySQL/MariaDB
DATABASE_URL=mysql://vaultwarden:password@localhost:3306/vaultwardenCũng được hỗ trợ, nhưng PostgreSQL thường được recommend hơn cho production workloads.
Web Vault (Embedded)
Vaultwarden đóng gói Bitwarden Web Vault (giao diện Angular) dưới dạng static files phục vụ trực tiếp. Không cần deploy container riêng cho web UI.
Khi truy cập https://vault.example.com, Vaultwarden serve web vault từ thư mục /web-vault/ trong container. Giao diện này giống hệt Bitwarden official web vault — cùng design, cùng UX flow.
WebSocket Notifications
WebSocket cho phép live sync giữa các clients. Khi bạn thêm password trên browser extension, mobile app nhận được notification ngay lập tức thay vì chờ sync interval.
# WebSocket endpoint
wss://vault.example.com/notifications/hub
Reverse proxy cần được cấu hình để hỗ trợ WebSocket connections — đây là bước mà nhiều người bỏ qua khi setup.
Admin Panel
Truy cập tại https://vault.example.com/admin với admin token được cấu hình qua environment variable:
# Khuyến nghị dùng argon2 hash thay vì plaintext token
ADMIN_TOKEN='$argon2id$v=19$m=65540,t=3,p=4$...'Admin panel cho phép:
- Xem danh sách users và organizations
- Invite/disable/delete users
- Xem server configuration
- Backup database
- Manage global settings (disable registration, disable Send, v.v.)
Lưu ý bảo mật: Admin panel nên được giới hạn truy cập qua IP whitelist hoặc VPN. Bất kỳ ai có admin token đều có quyền quản lý toàn bộ vault.
Feature Map chi tiết
Password Vault (Personal + Organization)
Mỗi user có personal vault riêng — chỉ họ mới truy cập được. Ngoài ra, organizations cho phép chia sẻ credentials giữa các thành viên qua collections:
Organization: "DevOps Team"
├── Collection: "Production Servers"
│ ├── AWS Console Login
│ ├── Database Admin Password
│ └── Monitoring Dashboard
├── Collection: "Development"
│ ├── Staging API Keys
│ └── Test Database Credentials
└── Collection: "Shared Services"
├── Docker Hub Account
└── GitHub Organization Token
Mỗi collection có thể gán quyền riêng — ai được đọc, ai được sửa.
TOTP 2FA (Two-Factor Authentication)
Vaultwarden hỗ trợ lưu TOTP seeds và tự động generate mã 2FA. Thay vì dùng app riêng (Google Authenticator, Authy), bạn lưu TOTP key ngay trong vault entry:
Entry: "GitHub Account"
├── Username: user@example.com
├── Password: ********
└── TOTP: otpauth://totp/GitHub:user@example.com?secret=JBSWY3DPEHPK3PXP&issuer=GitHub
→ Current code: 482 719 (còn 18 giây)
Lưu ý: Lưu cả password lẫn TOTP trong cùng vault có nghĩa là nếu vault bị compromise, attacker có cả hai factor. Đây là trade-off giữa tiện lợi và defense in depth. Cho critical accounts (banking, admin), nên dùng hardware key (YubiKey) hoặc TOTP app riêng biệt.
Secure Notes, Credit Cards, Identities
Ngoài passwords, vault lưu trữ:
- Secure notes: Ghi chú mã hóa — dùng cho SSH keys, recovery codes, license keys
- Credit cards: Số thẻ, CVV, ngày hết hạn — auto-fill trên web
- Identities: Tên, địa chỉ, số điện thoại — auto-fill forms
Tất cả đều được mã hóa end-to-end — server (Vaultwarden) chỉ lưu ciphertext, không bao giờ thấy plaintext.
Organizations & Collections
Organization là đơn vị chia sẻ cao nhất. Trong mỗi organization, collections nhóm các items lại:
- Gán access control per collection (read-only hoặc read-write)
- Gán members vào collections cụ thể
- Hỗ trợ groups (nhóm users gán vào collections)
Mô hình phân quyền đủ linh hoạt cho team nhỏ đến vừa (2-50 người).
Send (Secure Sharing)
Bitwarden Send cho phép chia sẻ text hoặc file một cách an toàn:
Send properties:
├── Type: Text hoặc File
├── Expiration: 1 giờ / 1 ngày / 7 ngày / custom
├── Max access count: Giới hạn số lần truy cập
├── Password: Yêu cầu password để mở
├── Hide email: Ẩn danh người gửi
└── Deletion date: Tự động xóa sau thời gian
Mỗi Send tạo một unique URL — người nhận không cần tài khoản Bitwarden/Vaultwarden để truy cập.
Admin có thể disable Send nếu không muốn cho phép chia sẻ file qua vault:
SENDS_ALLOWED=falseEmergency Access
Cho phép chỉ định trusted contacts có thể truy cập vault trong trường hợp khẩn cấp:
- Chọn wait time (ví dụ: 7 ngày)
- Trusted contact request access, chờ hết wait time
- Nếu bạn không reject, họ được quyền view hoặc takeover vault
Tính năng này quan trọng cho business continuity — nếu admin duy nhất không thể truy cập, team vẫn có cách khôi phục.
API & CLI Access
Bitwarden CLI (bw) hoạt động hoàn toàn với Vaultwarden:
# Configure server URL
bw config server https://vault.example.com
# Login
bw login user@example.com
# Lấy password programmatically
bw get password "GitHub Account"
# List items trong organization
bw list items --organizationid <org-id>
# Tạo item mới
echo '{"type":1,"name":"New Secret","login":{"username":"user","password":"pass123"}}' \
| bw encode | bw create itemCLI cho phép automation — tích hợp vào scripts, CI/CD pipelines, hoặc các công cụ khác để lấy secrets khi cần.
Khi nào chọn Vaultwarden
Phù hợp
- Single user hoặc team nhỏ (dưới 50 users): Vaultwarden đủ hiệu năng, feature đầy đủ
- Self-hosted requirement: Data sovereignty — dữ liệu ở trên server của bạn, không gửi lên cloud
- Resource-constrained environment: VPS nhỏ (512MB-1GB RAM), Raspberry Pi, hoặc shared hosting
- Budget-conscious: Tất cả premium features miễn phí, chỉ tốn chi phí server
- Không cần enterprise features: Không cần SAML SSO, LDAP sync, HSM
- Muốn kiểm soát toàn bộ stack: Full control over updates, backups, security configuration
- Learning & experimentation: Tìm hiểu secret management, password manager internals
Không phù hợp
- Enterprise SSO requirement: Cần SAML/OIDC integration với corporate IdP (Azure AD, Okta) — dùng Bitwarden Enterprise
- Large organizations (trên 100 users): Cần Directory Connector, granular custom roles, HSM — dùng Bitwarden Enterprise
- Compliance certifications: Cần SOC 2 Type II, HIPAA BAA từ vendor — Bitwarden Cloud có certifications, Vaultwarden thì không
- Vendor support: Cần SLA, dedicated support, incident response from vendor — Bitwarden Teams/Enterprise
- Zero self-host expertise: Không có kinh nghiệm quản lý server, Docker, backups — dùng Bitwarden Cloud
So sánh với Alternatives
| Tiêu chí | Vaultwarden | HashiCorp Vault | AWS Secrets Manager | 1Password |
|---|---|---|---|---|
| Mục đích chính | Password manager (người dùng cuối) | Secret management (infrastructure) | Secret management (AWS workloads) | Password manager (người dùng cuối) |
| Self-hosted | Có (Docker) | Có (binary/Docker) | Managed only | Cloud only |
| Chi phí | Miễn phí | Miễn phí (OSS) / Enterprise trả phí | ~$0.40/secret/tháng | $2.99-7.99/user/tháng |
| Setup phức tạp | Thấp (1 container) | Cao (cần unseal, init, policies) | Thấp (managed) | Không cần (SaaS) |
| RAM | ~50-128MB | ~256MB-1GB | N/A (managed) | N/A (SaaS) |
| Database | SQLite / PgSQL | Consul / Raft / PgSQL | DynamoDB (managed) | Proprietary |
| UI cho end-users | Web vault, browser ext, apps | Admin UI only | AWS Console only | Apps, browser ext |
| API/CLI automation | Bitwarden CLI | Vault CLI (rất mạnh) | AWS CLI/SDK | 1Password CLI |
| Dynamic secrets | Không | Có (database creds, AWS tokens) | Có (rotation) | Không |
| PKI / Certificate mgmt | Không | Built-in CA | ACM | Không |
| Secret injection | Manual / CLI | Agent, K8s sidecar, CSI | Lambda, ECS, EKS | CLI injection |
| Best for | Cá nhân, team nhỏ, self-host | DevOps teams, microservices | AWS-native workloads | Teams muốn SaaS đơn giản |
Vaultwarden vs HashiCorp Vault
Đây là hai công cụ phục vụ mục đích khác nhau:
-
Vaultwarden: Password manager dành cho con người — giao diện thân thiện, browser extensions, mobile apps. Phù hợp lưu trữ credentials mà team members cần truy cập hàng ngày.
-
HashiCorp Vault: Secret management dành cho hệ thống/infrastructure — dynamic secrets, certificate management, encryption as a service. Phù hợp cho microservices cần inject secrets tự động lúc runtime.
Trong nhiều tổ chức, hai công cụ này bổ sung cho nhau: Vaultwarden cho human secrets (đăng nhập, API keys chia sẻ), HashiCorp Vault cho machine secrets (database credentials tự động rotate, TLS certificates).
Vaultwarden vs 1Password
- 1Password: SaaS thuần, không self-host. Ưu điểm: không cần quản lý server, support tốt, UI polish. Nhược điểm: data nằm trên cloud của 1Password, chi phí theo user.
- Vaultwarden: Self-hosted, data hoàn toàn do bạn kiểm soát. Ưu điểm: miễn phí, data sovereignty. Nhược điểm: bạn chịu trách nhiệm uptime, backup, security patching.
Tóm tắt
| Khía cạnh | Chi tiết |
|---|---|
| Bản chất | Unofficial Bitwarden server, viết bằng Rust, API-compatible |
| Tài nguyên | ~50-128MB RAM, 1 container, SQLite mặc định |
| Clients | Dùng chung toàn bộ Bitwarden ecosystem (browser, mobile, desktop, CLI) |
| Premium features | Tất cả miễn phí (TOTP, Emergency Access, Reports) |
| Giới hạn | Không có SAML SSO, LDAP sync, HSM, vendor support |
| Best for | Cá nhân, team nhỏ (dưới 50), self-hosted, resource-constrained |
| Không phù hợp | Enterprise SSO, trên 100 users, compliance-driven vendor requirements |
Vaultwarden là lựa chọn thực tế và hiệu quả cho phần lớn cá nhân và team nhỏ muốn tự quản lý secrets. Với chi phí setup thấp (1 Docker container, 15 phút), bạn có được một password/secret manager đầy đủ tính năng, mã hóa end-to-end, và hoàn toàn kiểm soát dữ liệu.