File size: 2,672 Bytes
8e2791b
 
 
 
 
 
 
 
 
 
e00400b
 
 
 
 
 
 
068a29f
 
 
e00400b
 
 
 
 
 
068a29f
 
 
 
 
 
 
 
 
 
e00400b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
068a29f
e00400b
 
 
 
 
 
 
 
 
 
 
 
068a29f
f019318
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: Prolog Gateway
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.