Fix admin groups parsing

This commit is contained in:
Andrea Mistrali 2024-07-26 16:40:36 +02:00
parent 50097ce5b3
commit 07ac2edb53
Signed by: andre
SSH Key Fingerprint: SHA256:/D780pZnuHMQ8xFII5lAtXWy8zdowtBhgWjwi88p+lI
4 changed files with 32 additions and 14 deletions

View File

@ -16,17 +16,17 @@ You can run the Flask application as any other Flask app, using `flask run` insi
There are some settings that must/can be provided to the application: There are some settings that must/can be provided to the application:
| Variable | Usage | Default | | Variable | Usage | Default |
| -------------------------- | ---------------------------------------- | :-----: | | -------------------------- | -------------------------------------------------------------- | :-----: |
| `APPLICATION_ROOT` | Base URI path for the app | `/` | | `APPLICATION_ROOT` | Base URI path for the app | `/` |
| `HSMAN_SECRET_KEY` | Flask app secret key | | | `HSMAN_SECRET_KEY` | Flask app secret key | |
| `HSMAN_ADMIN_GROUPS` | User groups that are considered admins | | | `HSMAN_ADMIN_GROUPS` | Comma separated list of user groups that are considered admins | |
| `HSMAN_OIDC_CLIENT_ID` | OIDC client ID | | | `HSMAN_OIDC_CLIENT_ID` | OIDC client ID | |
| `HSMAN_OIDC_CLIENT_SECRET` | OIDC clietn secret | | | `HSMAN_OIDC_CLIENT_SECRET` | OIDC clietn secret | |
| `HSMAN_OIDC_URL` | OIDC server URL | | | `HSMAN_OIDC_URL` | OIDC server URL | |
| `HSMAN_OIDC_REDIRECT_URI` | OIDC redirect URI | | | `HSMAN_OIDC_REDIRECT_URI` | OIDC redirect URI | |
| `HSAPI_SERVER` | Headscale server URL | | | `HSAPI_SERVER` | Headscale server URL | |
| `HSAPI_API_TOKEN` | API token/key to access headscale server | | | `HSAPI_API_TOKEN` | API token/key to access headscale server | |
The last two variables are then fed to `hsapi-client`, the module that we use to interact with Headscale APIs. The last two variables are then fed to `hsapi-client`, the module that we use to interact with Headscale APIs.

View File

@ -29,6 +29,9 @@ def create_app(environment='development'):
app.config.from_prefixed_env(prefix="HSMAN") app.config.from_prefixed_env(prefix="HSMAN")
config[env].configure(app) config[env].configure(app)
app.config['APP_TZ'] = os.environ.get('TZ', 'UTC') app.config['APP_TZ'] = os.environ.get('TZ', 'UTC')
app.config['ADMIN_GROUPS'] = list(
map(str.strip, app.config['ADMIN_GROUPS'].split(',')))
app.logger.debug(f"admin groups: {app.config['ADMIN_GROUPS']}")
app.logger.info("middleware init: mobility") app.logger.info("middleware init: mobility")
mobility.init_app(app) mobility.init_app(app)

View File

@ -1,7 +1,9 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<h3>Welcome, {{ session.userinfo.name }}</h3> <h3>
Welcome, {{ session.userinfo.name }}
</h3>
<hr> <hr>
<h4>authentication info</h4> <h4>authentication info</h4>
<div class="row data"> <div class="row data">
@ -27,7 +29,13 @@
</div> </div>
<div class="col col-6"> <div class="col col-6">
<i class="fas fa-angle-right"></i> <i class="fas fa-angle-right"></i>
{% if session.userinfo.groups[0] in config['ADMIN_GROUPS'] %}
<span class="badge badge-pill badge-warning">
{% else %}
<span class="badge badge-pill badge-dark">
{% endif %}
{{ session.userinfo.groups[0]}} {{ session.userinfo.groups[0]}}
</span>
</div> </div>
</div> </div>
{% for group in session.userinfo.groups[1:] |sort %} {% for group in session.userinfo.groups[1:] |sort %}
@ -36,7 +44,14 @@
&nbsp; &nbsp;
</div> </div>
<div class="col col-6"> <div class="col col-6">
<i class="fas fa-angle-right"></i> {{ group }} <i class="fas fa-angle-right"></i>
{% if group in config['ADMIN_GROUPS'] %}
<span class="badge badge-pill badge-warning">
{% else %}
<span class="badge badge-pill badge-dark">
{% endif %}
{{ group }}
</span>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "hsman" name = "hsman"
version = "0.9.6" version = "0.9.7"
description = "Flask Admin webui for Headscale" description = "Flask Admin webui for Headscale"
authors = ["Andrea Mistrali <andrea@mistrali.pw>"] authors = ["Andrea Mistrali <andrea@mistrali.pw>"]
license = "BSD" license = "BSD"