Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make auth system more flexible & convenient and add "callbacks" (#1032)
This PR changes Tobira's auth system to be more flexible and hopefully easier to understand, rewriting the auth docs in the process. It also adds a new "callback" feature where Tobira can ask an HTTP endpoint for auth information, instead of only getting them from "auth headers". ## Callbacks The callback solution is preferred over auth headers now as HTTP headers are usually limited in size, which is a problem for users with many roles. It should also simplify setting up custom auth logic a lot. Further, Tobira only calls the callback when necessary, preventing auth logic to run uselessly, and allows you to remove special cases like `/~assets` from your reverse proxy config. Finally, Tobira can cache callback responses for some time to make everything even faster. There are login callbacks and auth callbacks. The former gets login credentials, the latter gets a forwarded HTTP request with headers. Both need to return a JSON describing the authorization outcome. See the docs for the details. ## Auth system changes These are some breaking changes in term of configuration file, but all previous "modes" are still supported. You just have to change your configuration slightly. See "Migration" section. Previously we had different "modes" in which Tobira could operate. These modes would determine what Tobira would do in a small number of different cases (e.g. when receiving login data, or an incoming request, ...). In a previous version, this PR added two more modes. But due to additional requirements, we rethought everything and figured that we can let admins configure the behavior in those cases individually. That way, they can mix & match. So instead of the `auth.mode` parameter, we have `auth.source` parameter which controls what Tobira does for any normal incoming request that needs authorization. Possible values are `none`, `tobira-session`, `trust-auth-headers` and `callback:...`. When using `tobira-session`, two additional behaviors can be configured, which control how Tobira's sessions are created: `auth.session.from_login_credentials` and `auth.session.from_session_endpoint`. With this change, a lot more systems can be configured. Like using Tobira session with Shibboleth. ### Migration (this will be copied to the changelog of the next release) You currently have `auth.mode = ...` #### `"opencast"` ```toml [auth] source = "tobira-session" session.from_login_credentials = "opencast" ``` #### `"login-proxy"` ```toml [auth] source = "tobira-session" session.from_session_endpoint = "trust-auth-headers" ``` #### `"full-auth-proxy"` ```toml [auth] source = "trust-auth-headers" ``` ## Other changes Some other auth-related changes are part of this PR. Some other breaking config changes were included: - All role related config was moved into the section `auth.roles`. - The configs to change the auth header names was removed. ----- ## How to review Good question. The commits are atomic and you should certainly read the commit messages. Reviewing commit by commit could be done: to understand the history and skip some of the very refactor/moving code around commits. But on the other hand, most of the code of the first commits has been moved and rewritten later again. It might make sense to read all the rendered auth docs first. And then look at the changed files in the `auth` module in their current form, and look at the remaining changes in diff view? --- ## Things that can be done in follow up PRs: - Does the callback need the ability to redirect the user? I.e. reply `{ "outcome": "redirect", "location": "..." }` and Tobira then answers with 302? - Make callbacks work with unix sockets - Add ability to update user data of a Tobira session regularly somehow - Always add `ROLE_ANONYMOUS` and `ROLE_USER` to users. - Maybe add some useful features to authkit? Though I really don't think it's necessary. At most we can add a type declaration for the output type. Closes #666
- Loading branch information