goauthentik / goauthentik/authentik
Allow role based access control + Hostname pattern matching for domain level forward auth
- Dominant language
- Python
- Stars
- 25.6k
- Forks
- 2k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 644
Description
It's pretty much in the title - https://www.authelia.com/docs/configuration/access-control.html authelia provides a good reference
I tried to roll my own, but i couldn't figure out how to access the original host - Also i think this use case is common enough to warrant a feature
Here was my attempt at an expression policy that achieved this
```python
dest_host_key = 'X-Forwarded-Host-Original'
protected_subdomains = ['movies']
headers = request.http_request.headers
dest_host = headers[dest_host_key] if dest_host_key in headers else ""
ak_logger.info(f"Destination Host: {dest_host}")
if not dest_host:
ak_message(f"No value found for {dest_host_key}")
return False
ak_message(f"Let's try to auth to {dest_host}")
ak_message(f"Headers: {headers}")
host_components = dest_host.split('.')
# Determine if subdomain should be protected
require_admin = False
for host_component in host_components:
if regex_match(host_component, r"^([:alpha:]+-)?admin$"):
require_admin = True
# Or if last domain component is a protected app
for subdomain in protected_subdomains:
if subdomain == host_components[0]:
require_admin = True
if not require_admin:
ak_message(f"{dest_host} does not require admin.")
return True
is_admin = ak_is_group_member(request.user, name = "authentik Admins")
if not is_admin:
ak_message(f"{request.user} is not an admin but {dest_host} requires admin!")
return False
ak_message(f"{request.user} is an admin and {dest_host} requires admin, granting acess!")
return True
```
apologies for the above devolving into debug spam
For now, I'm just going to make a separate google oauth app for admin forward auth
Contributor guide
Assessment
This issue has not been assessed yet.