pl_ai_gateway / README.md
fraudTech's picture
Update README.md
8ce712a verified
|
Raw History Blame Contribute Delete
2.68 kB
---
title: Prolog AI Gateway - Basic
emoji: 📊
colorFrom: blue
colorTo: pink
sdk: docker
pinned: false
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
## Authentication
The gateway uses JWT for authenticated access to proxy endpoints.
### Multi-user login
User credentials are stored and managed in the **private backend**. The public gateway proxies login/registration requests to the backend and issues JWTs to the frontend.
Configure one or more initial users via environment variables on the **backend Space**:
- `APP_USERS_JSON`: JSON object mapping `username -> plaintext_password` (recommended for demos; store as secrets)
- `APP_USERS_HASHED_JSON`: JSON object mapping `username -> werkzeug_password_hash` (recommended for production)
- `APP_USER` / `APP_PASSWORD`: legacy single-user plaintext credentials (still supported)
- `TEST_USER_PASSWORD`: if set, enables a `test_user` account with this password
Persistence:
- The backend stores users in a **SQLite database** (passwords are hashed).
- Configure the DB file path on the backend with `USER_DB_PATH` (use a persistent mount such as `/data/users.db` if available).
Seeding behavior (backend):
- On startup, the backend **seeds** users from `APP_USERS_JSON`, `APP_USERS_HASHED_JSON`, `APP_USER/APP_PASSWORD`, and `TEST_USER_PASSWORD`.
- Seeding **does not overwrite existing passwords**; it only adds missing users and updates admin flags.
Examples:
- `APP_USERS_JSON={"alice":"pw1","bob":"pw2","test_user":"pw3"}`
- `TEST_USER_PASSWORD=changeme` (creates user `test_user`)
Notes:
- Do not hardcode passwords in the repo. Use Hugging Face Space secrets or your deployment secret store.
- The JWT identity is set to the username.
### Admin-only user registration
The gateway can create users at runtime via `POST /register`.
- Requires a valid JWT (`Authorization: Bearer ...`).
- Only allowed if the JWT identity (username) is in `ADMIN_USERS`.
Env vars (backend):
- `ADMIN_USERS`: comma-separated usernames who can call `/register` (e.g. `ADMIN_USERS=alice,bob`)
- If `ADMIN_USERS` is not set but `APP_USER` is set, `APP_USER` is treated as the admin for convenience.
Request body:
```json
{ "username": "new_user", "password": "pw", "overwrite": false }
```
Notes:
- Users created via `/register` are stored in the backend SQLite DB at `USER_DB_PATH` (persist across restarts).
### Current user info
`GET /me` (JWT required) returns the current username and whether the user is an admin:
```json
{ "ok": true, "username": "alice", "is_admin": true }
```
- Used by the frontend to show the “Register User” panel only for admins.