Guest User

Vaultwarden Docker on Raspberry Pi with Caddy and Fail2ban

a guest
Jun 14th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. ### docker-compose.yml ###
  2. services:
  3. vaultwarden:
  4. image: vaultwarden/server:latest
  5. container_name: vaultwarden
  6. restart: unless-stopped
  7. environment:
  8. DOMAIN: "https://vaultwarden.example.com" # change to you external facing domain, otherwise you can set it your local host name
  9. SIGNUPS_ALLOWED: "true" # deactivate this with "false" after creating all accounts
  10. ADMIN_TOKEN: SOME_RANDOM_PASSWORD # You should follow the instructions here to encrypt it. https://github.com/dani-garcia/vaultwarden/wiki/Enabling-admin-page#using-argon2
  11. LOG_FILE: "/data/vaultwarden.log"
  12. LOG_LEVEL: "warn"
  13. EXTENDED_LOGGING: "true"
  14. TZ: "America/Chicago" # Update to your time zone
  15. volumes:
  16. - /vw-data/:/data/ # update to your data folder, the first one is where it's on your local system
  17. # ports:
  18. # - 11005:80 # external:internal to docker
  19.  
  20. caddy:
  21. image: caddy:2
  22. container_name: caddy
  23. restart: always
  24. ports:
  25. - 80:80
  26. - 443:443
  27. - 443:443/udp # Needed for HTTP/3
  28. volumes:
  29. #- ./caddy:/usr/bin/caddy
  30. - ./Caddyfile:/etc/caddy/Caddyfile:ro
  31. - ./caddy-config:/config
  32. - ./caddy-data:/data
  33. environment:
  34. DOMAIN: "https://vaultwarden.example.com" # change to you external facing domain, otherwise you can set it your local host name
  35. LOG_FILE: "/data/access.log"
  36. TZ: "America/Chicago" # Update to your time zone
  37.  
  38. fail2ban:
  39. image: crazymax/fail2ban
  40. container_name: fail2ban
  41. restart: always
  42. environment:
  43. - TZ=America/Chicago # Update to your time zone
  44. - F2B_DB_PURGE_AGE=30d
  45. - F2B_LOG_TARGET=/data/fail2ban.log
  46. - F2B_LOG_LEVEL=INFO
  47. - F2B_IPTABLES_CHAIN=FORWARD
  48. volumes:
  49. - /fail2ban/:/data
  50. - /vw-data:/vaultwarden:ro # update both of these where you want the data for each of these to be stored on the host system
  51. network_mode: "host"
  52. privileged: true
  53. cap_add:
  54. - NET_ADMIN
  55. - NET_RAW
  56.  
  57.  
  58. ### Caddyfile ###
  59. {$DOMAIN} {
  60. log {
  61. level INFO
  62. output file {$LOG_FILE} {
  63. roll_size 10MB
  64. roll_keep 10
  65. }
  66. }
  67.  
  68. # Use the ACME HTTP-01 challenge to get a cert for the configured domain.
  69. tls {$EMAIL}
  70.  
  71. # This setting may have compatibility issues with some browsers
  72. # (e.g., attachment downloading on Firefox). Try disabling this
  73. # if you encounter issues.
  74. encode zstd gzip
  75.  
  76. # Uncomment to improve security (WARNING: only use if you understand the implications!)
  77. # If you want to use FIDO2 WebAuthn, set X-Frame-Options to "SAMEORIGIN" or the Browser will block those requests
  78. header / {
  79. # # Enable HTTP Strict Transport Security (HSTS)
  80. # Strict-Transport-Security "max-age=31536000;"
  81. # # Disable cross-site filter (XSS)
  82. # X-XSS-Protection "0"
  83. # # Disallow the site to be rendered within a frame (clickjacking protection)
  84. # X-Frame-Options "DENY"
  85. # Prevent search engines from indexing (optional)
  86. X-Robots-Tag "noindex, nofollow"
  87. # # Disallow sniffing of X-Content-Type-Options
  88. # X-Content-Type-Options "nosniff"
  89. # # Server name removing
  90. # -Server
  91. # # Remove X-Powered-By though this shouldn't be an issue, better opsec to remove
  92. # -X-Powered-By
  93. # # Remove Last-Modified because etag is the same and is as effective
  94. # -Last-Modified
  95. }
  96.  
  97. # Proxy everything Rocket
  98. reverse_proxy vaultwarden:80 {
  99. # Send the true remote IP to Rocket, so that vaultwarden can put this in the
  100. # log, so that fail2ban can ban the correct IP.
  101. header_up X-Real-IP {remote_host}
  102. }
  103. }
  104.  
  105.  
  106. ### /fail2ban/jail.d/vaultwarden.local ###
  107. [vaultwarden]
  108. enabled = true
  109. port = 80,443,8081
  110. filter = vaultwarden
  111. banaction = %(banaction_allports)s
  112. #banaction = iptables
  113. logpath = /vaultwarden/vaultwarden.log
  114. maxretry = 5
  115. bantime = 14400
  116. findtime = 14400
  117. chain = FORWARD
  118. actiontype = multiport
  119.  
  120. ### /fail2ban/jail.d/vaultwarden-admin.local ###
  121. [vaultwarden-admin]
  122. enabled = true
  123. port = 80,443
  124. filter = vaultwarden-admin
  125. banaction = %(banaction_allports)s
  126. logpath = /vaultwarden/vaultwarden.log
  127. maxretry = 3
  128. bantime = 14400
  129. findtime = 14400
  130. chain = FORWARD
  131. actiontype = multiport
  132.  
  133. ### /fail2ban/jail.d/vaultwarden-totp.local ###
  134. [vaultwarden-totp]
  135. enabled = true
  136. port = 80,443
  137. filter = vaultwarden-totp
  138. banaction = %(banaction_allports)s
  139. logpath = /vaultwarden/vaultwarden.log
  140. maxretry = 3
  141. bantime = 14400
  142. findtime = 14400
  143. chain = FORWARD
  144. actiontype = multiport
  145.  
  146. ### /fail2ban/action.d/iptables.local ###
  147. [Init]
  148. blocktype = DROP
  149. [Init?family=inet6]
  150. blocktype = DROP
  151.  
  152. [Definition]
  153. actionban = <iptables> -I <chain> 1 -s <ip> -j <blocktype>
  154. actionunban = <iptables> -D <chain> -s <ip> -j <blocktype>
  155.  
  156. ### /fail2ban/filter.d/vaultwarden.local ###
  157. [INCLUDES]
  158. before = common.conf
  159.  
  160. [Definition]
  161. failregex = ^.*?Username or password is incorrect\. Try again\. IP: <ADDR>\. Username:.*$
  162. ignoreregex =
  163.  
  164. ### /fail2ban/filter.d/vaultwarden-admin.local ###
  165. [INCLUDES]
  166. before = common.conf
  167.  
  168. [Definition]
  169. failregex = ^.*Invalid admin token\. IP: <ADDR>.*$
  170. ignoreregex =
  171.  
  172. ### /fail2ban/filter.d/vaultwarden-totp.local ###
  173. [INCLUDES]
  174. before = common.conf
  175.  
  176. [Definition]
  177. failregex = ^.*\[ERROR\] Invalid TOTP code! Server time: (.*) UTC IP: <ADDR>$
  178. ignoreregex =
Advertisement
Add Comment
Please, Sign In to add comment