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

Proof of concept for reverse-proxy auth #95

Merged
merged 3 commits into from
Mar 22, 2024

Conversation

weaversam8
Copy link
Contributor

  • This commit adds a new auth manager class for authorizing via proxy headers ProxyHeaderAuth which can be selected by setting the AUTH_METHOD env var to PROXY_HEADER

    • This auth manager looks for the following headers in order to
      create a "pseudo-user" on each request. No users are committed to
      the SQLite database when using this auth manager.

      • X-OtterWiki-Name - the name of the user to include on the Git commit when editing a page
      • X-OtterWiki-Email - the email of the user to include on the Git commit when editing a page
      • X-OtterWiki-Permissions - a comma separated list of permissions to grant to the user
    • The Docker entrypoint.sh script has been updated to pass the AUTH_METHOD config option thru if set in the environment.

  • has_permission(permission, user) is now a method specific to each auth manager

  • auth managers now implement a supported_features() method to detail which features they support (like whether an auth manager allows a user to change their name or password, or logout)

    • the features object this method returns is present in all Jinja
      templates as the variable auth_supported_features

    • the settings page was updated to prevent a user from editing their
      password and name if it is not supported by the current auth
      manager.

    • the dropdown menu present on all page was updated to hide the
      "logout" button if it is not supported by the current auth manager

  • The test_settings.py test was updated to tolerate extra whitespace

CC @redimp. I didn't make the headers configurable for now, and I'm sure this is a bit hacky, so interested to hear what you think.

@weaversam8 weaversam8 changed the title Closes #90. Proof of concept for reverse-proxy auth. Proof of concept for reverse-proxy auth Mar 6, 2024
@redimp
Copy link
Owner

redimp commented Mar 6, 2024

That looks very good. I don't have time to set up a test environment until the weekend. I will then test and merge or let you know if I run into problems.

Awesome work @weaversam8 !

@redimp
Copy link
Owner

redimp commented Mar 10, 2024

First test went fine!

I have added the commits in the branch feature/proxy-header-auth. This branch includes a minimal test example. A more serious example would be useful.

Some thoughts:

  • I like the implementation of ProxyHeaderAuth, minimal but sufficient.
  • Something like supported_features()/auth_supported_features() was necessary.
  • Having the header names fixed is in my opinion okay, all services that I know are able to define the headers they set. The comma seperated list of permissions should also be easy to implement.

@redimp redimp closed this Mar 10, 2024
@redimp redimp reopened this Mar 10, 2024
@weaversam8 weaversam8 force-pushed the feature/proxy-header-auth branch from 3ed05d5 to cf202ad Compare March 20, 2024 19:36
weaversam8 and others added 2 commits March 20, 2024 15:46
- This commit adds a new auth manager class for authorizing via proxy
  headers `ProxyHeaderAuth` which can be selected by setting the
  `AUTH_METHOD` env var to `PROXY_HEADER`

    - This auth manager looks for the following headers in order to
      create a "pseudo-user" on each request. No users are committed to
      the SQLite database when using this auth manager.

        - `X-OtterWiki-Name` - the name of the user to include on the
          Git commit when editing a page
        - `X-OtterWiki-Email` - the email of the user to include on the
          Git commit when editing a page
        - `X-OtterWiki-Permissions` - a comma separated list of
          permissions to grant to the user

    - The Docker `entrypoint.sh` script has been updated to pass the
      `AUTH_METHOD` config option thru if set in the environment.

- `has_permission(permission, user)` is now a method specific to each
  auth manager

- auth managers now implement a `supported_features()` method to detail
  which features they support (like whether an auth manager allows a
  user to change their name or password, or logout)

    - the features object this method returns is present in all Jinja
      templates as the variable `auth_supported_features`

    - the settings page was updated to prevent a user from editing their
      password and name if it is not supported by the current auth
      manager.

    - the dropdown menu present on all page was updated to hide the
      "logout" button if it is not supported by the current auth manager

- The `test_settings.py` test was updated to tolerate extra whitespace
- deny unauthenticated user, in case the proxy has been skipped
- mini example with Caddy as proxy adding pseudo authenticated headers
@weaversam8 weaversam8 force-pushed the feature/proxy-header-auth branch from cf202ad to 7203ae0 Compare March 20, 2024 19:46
@weaversam8
Copy link
Contributor Author

I just pulled and tested these changes. Fixed one tiny bug in 7b3098c but otherwise this looks great! I think this example is plenty sufficient to show how this is used, thanks for putting that together!

I rebased my branch off of main and pushed, so this PR should be good to merge (since it now contains your changes.)

@redimp redimp merged commit 7b3098c into redimp:main Mar 22, 2024
@redimp
Copy link
Owner

redimp commented Mar 22, 2024

Merged. Thank you for the work.

Will do a new release including this feature within the next two days.

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

Successfully merging this pull request may close these issues.

2 participants