Matrix room gatekeeper bot for the unofficial Unimore space
Project description
Loki Bot
Gatekeeper bot for the Unimore Informatica unofficial Matrix space
TIP: You may be looking for its predecessor, Thor Bot.
Functionality
This bot monitors a pre-configured public Matrix space for join events, sending a welcome message to every new joiner.
The welcome message contains a link, which when clicked starts the user verification process:
- a page describing the bot is opened, and it allows users to login with a pre-configured OpenID Connect Identity Provider;
- the claims of the OIDC IdP are verified, and the user's email address is checked to verify that its domain matches a pre-configured RegEx with specific email requirements;
- if the email address fullfils all the requirements, an invitation to a different, pre-configured private Matrix space is sent to the user.
Additionally, the bot monitors for leave events from both spaces, deleting user data if no longer needed to protect the user's privacy.
Setting up a development environment
Dependencies
This project uses Poetry to manage the dependencies.
To install all dependencies in a venv, run:
$ poetry install
TIP: For easier venv management, you may want to set:
$ poetry config virtualenvs.in-project true
To activate the venv, run:
$ poetry shell
To run something in the venv without activating it, run:
$ poetry run <COMMAND>
Environment
Loki requires a lot of environment variables to be set, therefore it makes use of cfig to simplify the setup.
To view the current configuration, followed by a description of each variable, run:
$ poetry run python -m lokiunimore.config
Deploying in production
Use the pre-built Docker image, or build it from the provided Dockerfile.
Run the image without any command to view and validate the current configuration.
Run the image with the gunicorn -b 0.0.0.0:80 lokiunimore.web.app:rp_app
command to launch the production web server on local port 80, expecting to be behind a reverse proxy.
Run the image with the lokiunimore.matrix
command to launch the Matrix bot.
Using Docker Compose
Create a docker-compose.yml
file which starts three services:
- a
postgres
instance - a
ghcr.io/steffo99/lokiunimore
instance running the webserver via the commandgunicorn -b 0.0.0.0:80 lokiunimore.web.app:rp_app
- a
ghcr.io/steffo99/lokiunimore
instance running the Matrix bot via the commandlokiunimore.matrix
Ensure you're configuring all the required environment variables, as Loki Bot will not work otherwise.
Example docker-compose.yml
version: "3.9"
services:
# The database Loki uses to store its files
lokidb:
image: "postgres:14"
restart: unless-stopped
environment:
PGUSER: "loki"
PGPASSWORD: "loki"
PGDATABASE: "loki"
POSTGRES_USER: "loki"
POSTGRES_PASSWORD: "loki"
POSTGRES_DB: "loki"
POSTGRES_INITDB_ARGS: '--encoding=UTF-8 --lc-collate=C --lc-ctype=C'
LANG: "C"
LC_COLLATE: "C"
LC_CTYPE: "C"
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
volumes:
- "./data/lokidb:/var/lib/postgresql/data"
# The web server that Loki uses for authentication
lokiweb:
image: "ghcr.io/steffo99/lokiunimore:latest"
command: "gunicorn -b 0.0.0.0:80 lokiunimore.web.app:rp_app"
restart: unless-stopped
ports:
- "80:30035" # Choose your preferred port
env_file:
- "./secrets/loki.env"
depends_on:
lokidb:
condition: service_healthy
# The Matrix bot that Loki uses for user interactions
lokibot:
image: "ghcr.io/steffo99/lokiunimore:latest"
command: "lokiunimore.matrix"
restart: unless-stopped
env_file:
- "./secrets/loki.env"
depends_on:
lokidb:
condition: service_healthy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lokiunimore-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5df0eae7eb71a71bbc37ce24c71f426a6edf1d2a7a20b777e813ae7ad031f444 |
|
MD5 | 2a5ec030ff105aaea36ba7c43fdedb98 |
|
BLAKE2b-256 | 935da99ede2fbca4e5e0613d099429c4c006e1483e2b1095b111e312880acb39 |