How to secure S3 bucket with username and password

How to secure S3 bucket with username and password

When you start looking for a solution, you will find answers like using Cloudfront, lambda, and middleware 3rd party services. And basically, you don’t have any other choice. There is no simple solution to your problem. But – as long as you use Caddy Server solution is super easy.

All we need is to have basicauth , and then proxy server to redirect queries. The only problem is a matter of Authorization header. If you pass it “as is as” to S3 – it will cause a problem because expects valid header when data is protected. But if you pass “empty” header it will pass. 

example.com.au {
	basicauth / username password
	proxy / http://s3-ap-southeast-2.amazonaws.com/example.com.au/ {
		header_upstream Authorization " "
	}
}