0

I'm using Caddy as a reverse proxy, feeding a web app on CherryPy. Caddy is handling basic-auth, and I would like to pass the username to the CherryPy app.

I've modified my Caddyfile like this:

my.example.com {
  redir /data_tools /data_tools/
  handle_path /data_tools/* {
    import basic-auth
    reverse_proxy data_tools:1234 {
      header_down +X-WEBAUTH-USER={http.auth.user.id}
    }
  }
}

When I go to my.example.com/data_tools/ I see my header populated correctly. If I go to my.example.com/data_tools/index.html, the header is there, but it's empty.

I've tried to intercept the headers with different hooks in CherryPy, but my header doesn't show up there at all.

def show_headers():
    print("Request")
    print(json.dumps(cherrypy.request.headers, indent="\t"))
    print("Response")
    print(json.dumps(cherrypy.response.headers, indent="\t"))

cherrypy.tools.get_user = cherrypy.Tool('on_start_resource', show_headers)

^^^ Shows expected headers, but not my custom one.

Any suggestions?

user1209675
  • 296
  • 7
  • 18
  • The caddy syntax to configure the header does not use the equal sign: `header_down [+|-] [ []]`. How about `header_down +X-WEBAUTH-USER {http.auth.user.id}`? – cyraxjoe Aug 03 '22 at 00:49
  • @cyraxjoe - Thanks, but no difference. Still shows if I go to .../data_tools/ but doesn't show for .../data_tools/index.html and doesn't show in CherryPy. – user1209675 Aug 03 '22 at 01:38

1 Answers1

0

I got help from the Caddy Forum.

In my caddyfile, this is what I had for the basic-auth section.

(basic-auth) {
  basicauth / {
    my-name XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  }
}

The / here makes it so that basicauth only applies to requests to exactly / and nothing else. Remove that to make it match all requests.

Once I did that, I could see the headers through CherryPy, although they didn't show in the developer tools of the browser.

user1209675
  • 296
  • 7
  • 18