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

Replace custom nginx / certbot config with BunkerWeb #1695

Merged
merged 22 commits into from
Mar 3, 2025

Conversation

spwoodcock
Copy link
Member

@spwoodcock spwoodcock commented Jul 23, 2024

What type of PR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation
  • πŸ§‘β€πŸ’» Refactor
  • βœ… Test
  • πŸ€– Build or CI
  • ❓ Other (please specify)

Related Issue

Fixes #1686
Also fixes #1479

Related to: #1650, but does not fix it.
(the FastAPI middleware is probably required after all)

Describe this PR

Bunkerweb repo: https://github.com/bunkerity/bunkerweb/

  • Replaces the nginx configuration on this repo entirely with BunkerWeb, which has a lot of nice security defaults (see original issue).
    • I was able to remove the entire nginx directory and related code / configs / scripts.
    • This also manages all certs for us, rather than our custom certbot config.
  • @dakotabenjamin this is a pretty neat all-in-one web proxy that I would recommend to put all our services behind! It has rate limiting, brotli compression, optional antibot, good ModSecurity defaults, 'bad behaviour' checking and banning.
  • I added the config for local development. Still todo development and main compose configs.
  • It's a bit of a pain that the architecture of this system relies on a scheduler and docker socket binding service. Thankfully I managed to get this to work as initialisation only, rather than running continuously.
    • Using timeout 120 for each service allows the configs to generated and copied to the nginx webserver, then the scheduler and docker socket service shut down.

Alternative Approaches Considered

  • Adding modsecurity etc to our existing nginx config.
  • But why bother maintaining our own nginx module building (e.g. brotli, modsecurity) and configuration, when we an outsource this to a well adopted upstream service.
  • Resource usage is no more than the standard nginx server we were using, about 100-200mb memory usage at idle.

https://github.com/hotosm/fmtm/blob/development/docs/decisions/0006-web-app-firewall.md

Notes

  • Once merged, we can remove the proxy images from the repo.
  • The NGINX_IMG_TAG var can also be removed from Github environment vars.
  • Local projects will no longer work as the ODK_CENTRAL_URL was updated from https://proxy --> https://odkcentral
    • Existing projects for local development should be removed docker compose down -v

Review Guide

Notes for the reviewer. How to test this change?

Checklist before requesting a review

[optional] What gif best describes this PR or how it makes you feel?

@github-actions github-actions bot added backend Related to backend code devops Related to deployment or configuration contrib labels Jul 23, 2024
@spwoodcock spwoodcock self-assigned this Jul 23, 2024
@spwoodcock spwoodcock changed the title Build/bunkerweb Replace custom nginx / certbot config with BunkerWeb Jul 23, 2024
@spwoodcock spwoodcock added docs Improvements or additions to documentation and removed documentation labels Aug 1, 2024
@dakotabenjamin
Copy link
Member

I've used a turnkey-like server solution Caddy before, but this seems like it's got even more and its security focused. Looks good to me.

@spwoodcock
Copy link
Member Author

Thanks!

I like that it reduces the maintenance burden for building nginx images with brotli and maintaining configs πŸ˜„

Hoping to finish this at some point & also roll it out for DroneTM eventually too πŸ‘

@github-actions github-actions bot added the contrib External contributions, or not related to core functionality label Mar 3, 2025
@spwoodcock
Copy link
Member Author

Tests failing I presume because the CI image doesn't have the correct dev cert for ODK Central.

Merging pre-emptively in the hope that a new CI image build will fix this πŸ˜„

@spwoodcock spwoodcock merged commit 1ff50dc into development Mar 3, 2025
9 of 10 checks passed
@spwoodcock spwoodcock deleted the build/bunkerweb branch March 3, 2025 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Related to backend code contrib External contributions, or not related to core functionality devops Related to deployment or configuration docs Improvements or additions to documentation frontend Related to frontend code
Projects
Development

Successfully merging this pull request may close these issues.

Assess usage of BunkerWeb to replace custom Nginx & certbot containers Add rate limiting to API calls
3 participants