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

breakfix: Error 404 Not Found when mounting the authentication portal on a path that is not / nor /auth #59

Open
em- opened this issue Dec 3, 2024 · 1 comment

Comments

@em-
Copy link

em- commented Dec 3, 2024

This works fine (quoting only the relevant bits):

authorization policy mypolicy {
  set auth url /auth/
}

localhost {
  handle /auth/* {
        authenticate with myportal
  }
  handle /* {
        authorize with mypolicy
  }
}

When accessing http://localhost, we get redirected to http://localhost/auth/?redirect_url=http://localhost, which in turn puts the redirect_url in a cookie and redirects to http://localhost/auth/login, which gives us the portal login ui.

However, replacing /auth/ with /foobar/ does not work: http://localhost/ redirects to http://localhost/foobar/ but instead of being redirected we get a HTTP 404 error.

Using set auth url /foobar/login instead of set auth url /foobar/ works around the issue at the price of keeping redirect_url in the login URL (not a big deal).

That's because https://github.com/greenpau/go-authcrunch/blob/a5596e855f924d62ea471b/pkg/authn/respond_http.go#L35 hardcodes the assumption that the portal is either at the root or under /auth:

	case r.URL.Path == "/" || r.URL.Path == "/auth" || r.URL.Path == "/auth/":
		p.injectRedirectURL(ctx, w, r, rr)
		return p.handleHTTPRedirect(ctx, w, r, rr, "/login")
@em-
Copy link
Author

em- commented Dec 3, 2024

An absolutely cursed workaround is to do something like:

authorization policy mypolicy {
  set auth url /foobar/
}

localhost {
  handle /foobar/ {
        rewrite * /auth
        request_header +X-Forwarded-Prefix /foobar/
        authenticate with myportal
  }
  handle /foobar/* {
        authenticate with myportal
  }
  handle /* {
        authorize with mypolicy
  }
}

The rewrite in the handle /foobar/ stanza persuades the portal to be where it expects to be, and the request_header overrides ensure that the redirect is based on the real prefix instead of /auth/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants