Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

amazon alb and basic auth

I have a simple site in fargate and an alb. I want to throw a simple basic auth on top of it - just a single hardwired username and password. Is there an easy way to do this?

I tried going to cognito - creating a user pool, and attaching it to the site, but there were questions like "callback url" - which i just set to the same url and "signout url" that I wasn't sure about and when I managed to click a set of things that allowed me to add it, and add a listener to my https endpoint - it just gives a "redirect_mismatch" when I try to get in.

Is there any way to do what I want without editing the underlying system in any way?

like image 458
Darren Oakey Avatar asked May 18 '26 21:05

Darren Oakey


1 Answers

I did the following tests using ALB and CloudFront - HTTPS for Browsers only

  1. Encode credentials user=user and password=password

    echo -n 'user:password' | base64
    
    dXNlcjpwYXNzd29yZA==
    
  2. Create ALB with the listener rule HTTP header Authorization is Basic dXNlcjpwYXNzd29yZA== AWS ALB Listener rules

  1. Place ALB behind CloudFront and forward Authorization header

  2. Test result using curl

    # Authentication option
    curl -u 'user:password' https://d3anlpzrykthss.cloudfront.net
    Hello from f86c5f9e0395
    
    # In-url password
    curl https://user:[email protected]
    Hello from f86c5f9e0395
    
    # Headers
    curl -H 'Authorization: Basic dXNlcjpwYXNzd29yZA==' https://d3anlpzrykthss.cloudfront.net
    Hello from f86c5f9e0395
    
    # Wrong password
    curl -u 'user:wrong' https://d3anlpzrykthss.cloudfront.net
    Not authorized
    
  3. Not clear how to make it to work in Browsers - Can I use HTTP Basic Auth in URLs?

    # Firefox / Chrome / Safari
    https://user:[email protected]
    Not authorized
    
like image 104
Veaceslav Doina Avatar answered May 21 '26 23:05

Veaceslav Doina



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!