PHACDataHub / cloudrun-deployment-example

Working towards deploying Django apps to Google Cloud Run, using a Cloud SQL Postgres database and a Cloud Build GitHub Trigger.
0 stars 0 forks source link

Static file Solution #20

Closed LilaKelland closed 1 year ago

LilaKelland commented 1 year ago

Seeing both whitenoise and for using Google Cloud Storage being used for static files. @KingBain figured out the work around for current GCP "policy disabling fine grained bucket level access and are forcing all storage accounts to use "uniform bucket-level access"". Is there a preferred option?

LilaKelland commented 1 year ago

realized not quite a douplicate

Stephen-ONeil commented 1 year ago

Whitenoise is nice for keeping things very simple, and more consistent between dev and prod, that's a plus!

In prod, it does mean all the static content requests are going to the Django app instances instead of cloud storage, which is less great. More burden on the app, which is (I believe) going to be less optimized for serving static content than google cloud on top of that. Possibly not significant.

Those downsides could in turn be addressed with a CDN. Back to a more complicated prod architecture, but maybe we would have ended up considering a CDN even if we went with google cloud storage for static assets. The added complexity of configuring a CDN in prod would at least be more invisible than having to have different static content configurations for local and cloud builds. :thinking:

Final trade off I can think of is security. Whitenoise means more surface area on the app instances. Is it going to introduce path traversal vulnerabilities? Malicious users could bypass the CDN caching intentionally to put pressure on the server too, which means there's still a (D)DOS risk here for us to consider. With google cloud storage at least, the risk of some sort of attempted DDOS against file content would be a) google's problem (billing aside, but I think they often waive costs caused by attacks) and b) will not necessarily take out 100% of the app (users might still have enough in their local caches, some routes might not need JS/CSS to be usable, etc). Of course, the day-to-day benefits of simpler configuration and more dev/prod parity might outweigh some vague security concerns, ha.

Stephen-ONeil commented 1 year ago

Settled on Whitenoise and have it working well on the CPHO repo. Cloud Armor should mitigate DDOS, but might still consider adding a CDN as well.