vlambda 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vlambda-0.2.0 → vlambda-0.2.1}/PKG-INFO +34 -10
- {vlambda-0.2.0 → vlambda-0.2.1}/README.md +33 -9
- {vlambda-0.2.0 → vlambda-0.2.1}/pyproject.toml +1 -1
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/__main__.py +17 -14
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/assets.py +1 -1
- vlambda-0.2.1/python/vlambda/pool.py +518 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/runner.py +13 -1
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/sandbox.py +6 -3
- {vlambda-0.2.0 → vlambda-0.2.1}/src/vlambda_native.v +72 -11
- {vlambda-0.2.0 → vlambda-0.2.1}/tests/test_unit.py +29 -4
- {vlambda-0.2.0 → vlambda-0.2.1}/tests/test_vlambda.py +109 -2
- {vlambda-0.2.0 → vlambda-0.2.1}/vcraft.toml +1 -1
- vlambda-0.2.0/python/vlambda/pool.py +0 -285
- {vlambda-0.2.0 → vlambda-0.2.1}/LICENSE +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/__init__.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/auth.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/cache.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/dbpool.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/metrics.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/packages.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/project.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/py.typed +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/request.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/reset.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/shared_cache.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/tasks.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/python/vlambda/transfer.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/tests/conftest.py +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/v.mod +0 -0
- {vlambda-0.2.0 → vlambda-0.2.1}/vcraft_build.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vlambda
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: An ASGI-like server for Python lambdas, written in V.
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.14
|
|
@@ -33,7 +33,7 @@ POST that code to `/vlambda` and it becomes `GET /f/<slug>` instantly.
|
|
|
33
33
|
- **Auth** — JWT-based authentication with per-user ownership
|
|
34
34
|
- **Web UI** — Dashboard for managing lambdas, code editor, metrics
|
|
35
35
|
- **Async invocation** — Fire-and-forget with task tracking
|
|
36
|
-
- **Sandbox** —
|
|
36
|
+
- **Sandbox** — nsjail namespaces in Docker, plus restricted Python builtins and blocked modules
|
|
37
37
|
- **Metrics** — Prometheus-compatible + Chart.js dashboard
|
|
38
38
|
- **Per-lambda method** — GET, POST, PUT, PATCH, DELETE
|
|
39
39
|
- **Naming** — Human-readable names for lambdas
|
|
@@ -102,8 +102,14 @@ token with `DELETE /tokens/<id>`. Tokens do not expire.
|
|
|
102
102
|
## Docker + Dokploy
|
|
103
103
|
|
|
104
104
|
The repository includes a production image (`Dockerfile`, installs from PyPI) and
|
|
105
|
-
a development image (`Dockerfile.dev`, builds the local wheel). Both
|
|
106
|
-
|
|
105
|
+
a development image (`Dockerfile.dev`, builds the local wheel). Both use a
|
|
106
|
+
free-threaded Python 3.14 venv, run each invocation in nsjail and expose plain
|
|
107
|
+
HTTP on port `8080`; Dokploy (or another proxy) handles TLS and the public
|
|
108
|
+
domain.
|
|
109
|
+
|
|
110
|
+
nsjail needs unprivileged user namespaces, so the container must run with
|
|
111
|
+
`--security-opt seccomp=unconfined` (nsjail applies its own seccomp policy to
|
|
112
|
+
the sandbox) or an equivalent custom profile. The compose files already set it.
|
|
107
113
|
|
|
108
114
|
```bash
|
|
109
115
|
export VLAMBDA_SECRET="$(openssl rand -hex 32)"
|
|
@@ -115,7 +121,7 @@ With Dokploy, create an application from the image, map the domain to container
|
|
|
115
121
|
port `8080`, and set `VLAMBDA_SECRET` and `VLAMBDA_ADMIN_TOKEN`. Dokploy terminates
|
|
116
122
|
TLS, so the container does not manage certificates.
|
|
117
123
|
|
|
118
|
-
See `docker/README.md` for details, limits and the
|
|
124
|
+
See `docker/README.md` for details, limits and the reset command.
|
|
119
125
|
|
|
120
126
|
## CLI Options
|
|
121
127
|
|
|
@@ -131,12 +137,15 @@ See `docker/README.md` for details, limits and the weekly reset command.
|
|
|
131
137
|
| `--cors_origin` | `VLAMBDA_CORS` | * | CORS allowed origin |
|
|
132
138
|
| `--cert` | `VLAMBDA_CERT` | | TLS certificate path |
|
|
133
139
|
| `--key` | `VLAMBDA_KEY` | | TLS key path |
|
|
140
|
+
| | `VLAMBDA_REGISTRATION` | 1 | Allow public registration (`0` disables it) |
|
|
134
141
|
|
|
135
142
|
## API
|
|
136
143
|
|
|
137
144
|
### Authentication
|
|
138
|
-
- `
|
|
145
|
+
- `GET /config` — Public runtime flags (whether registration is open)
|
|
146
|
+
- `POST /register` — Register user (body: `username:password`); returns `403` when registration is disabled
|
|
139
147
|
- `POST /login` — Login (body: `username:password`) → JWT token
|
|
148
|
+
- `POST /admin/users` — Create a user with `X-Admin-Token` and body `username:password` (for closed registration)
|
|
140
149
|
|
|
141
150
|
### Lambdas (requires auth)
|
|
142
151
|
- `POST /vlambda?method=GET&name=my-lambda` — Create lambda (body: Python code)
|
|
@@ -238,10 +247,25 @@ The `request` object has: `method`, `path`, `query_string`, `headers`, `body`.
|
|
|
238
247
|
|
|
239
248
|
Safe builtins: `abs`, `all`, `any`, `bool`, `dict`, `enumerate`, `filter`, `float`, `int`, `len`, `list`, `map`, `max`, `min`, `range`, `reversed`, `round`, `set`, `sorted`, `str`, `sum`, `tuple`, `zip`, `print`, etc.
|
|
240
249
|
|
|
241
|
-
Blocked modules: `os`, `subprocess`, `sys`, `importlib`, `ctypes`, `socket`, `urllib`, `http`, `shutil`, `pathlib`, `io`, `pickle`, `marshal`, etc.
|
|
250
|
+
Blocked modules: `os`, `posix`, `subprocess`, `sys`, `importlib`, `ctypes`, `socket`, `_socket`, `urllib`, `http`, `shutil`, `pathlib`, `io`, `pickle`, `marshal`, `resource`, `fcntl`, `mmap`, `sqlite3`, etc.
|
|
242
251
|
|
|
243
252
|
Safe modules: `json`, `math`, `re`, `datetime`, `collections`, `itertools`, `functools`, `hashlib`, `base64`, `string`, `random`, `statistics`, etc.
|
|
244
253
|
|
|
254
|
+
### Security
|
|
255
|
+
|
|
256
|
+
User code runs inside nsjail with a separate user, PID, mount and network
|
|
257
|
+
namespace. The sandbox sees only `/opt` and the current project/vendor (read-only),
|
|
258
|
+
has no access to `/data`, cannot read the server's `/proc`, and has no network.
|
|
259
|
+
Resource limits and a seccomp deny-list are also applied. The server process and
|
|
260
|
+
the database stay outside the sandbox.
|
|
261
|
+
|
|
262
|
+
The Docker image keeps public registration open by default for toy deployments.
|
|
263
|
+
Set `VLAMBDA_REGISTRATION=0` to close it and create users with
|
|
264
|
+
`POST /admin/users` instead. A daily data reset removes state, but it does not
|
|
265
|
+
undo a kernel-level escape. Keep this deployment disposable and do not store
|
|
266
|
+
valuable secrets in it; for stronger isolation use gVisor, Firecracker or one
|
|
267
|
+
container per tenant.
|
|
268
|
+
|
|
245
269
|
## Web UI
|
|
246
270
|
|
|
247
271
|
Open http://localhost:8080/ in your browser for the dashboard:
|
|
@@ -261,13 +285,13 @@ Open http://localhost:8080/ in your browser for the dashboard:
|
|
|
261
285
|
The demo can be wiped with:
|
|
262
286
|
|
|
263
287
|
```bash
|
|
264
|
-
python -m vlambda reset --yes --url http://127.0.0.1:
|
|
288
|
+
python -m vlambda reset --yes --url http://127.0.0.1:8080 --token "$VLAMBDA_ADMIN_TOKEN"
|
|
265
289
|
```
|
|
266
290
|
|
|
267
|
-
For
|
|
291
|
+
For a disposable demo, run it from cron every day:
|
|
268
292
|
|
|
269
293
|
```cron
|
|
270
|
-
0
|
|
294
|
+
0 3 * * * docker exec -e VLAMBDA_ADMIN_TOKEN="..." <container> /opt/venv/bin/python -m vlambda reset --yes --url http://127.0.0.1:8080
|
|
271
295
|
```
|
|
272
296
|
|
|
273
297
|
## Performance
|
|
@@ -22,7 +22,7 @@ POST that code to `/vlambda` and it becomes `GET /f/<slug>` instantly.
|
|
|
22
22
|
- **Auth** — JWT-based authentication with per-user ownership
|
|
23
23
|
- **Web UI** — Dashboard for managing lambdas, code editor, metrics
|
|
24
24
|
- **Async invocation** — Fire-and-forget with task tracking
|
|
25
|
-
- **Sandbox** —
|
|
25
|
+
- **Sandbox** — nsjail namespaces in Docker, plus restricted Python builtins and blocked modules
|
|
26
26
|
- **Metrics** — Prometheus-compatible + Chart.js dashboard
|
|
27
27
|
- **Per-lambda method** — GET, POST, PUT, PATCH, DELETE
|
|
28
28
|
- **Naming** — Human-readable names for lambdas
|
|
@@ -91,8 +91,14 @@ token with `DELETE /tokens/<id>`. Tokens do not expire.
|
|
|
91
91
|
## Docker + Dokploy
|
|
92
92
|
|
|
93
93
|
The repository includes a production image (`Dockerfile`, installs from PyPI) and
|
|
94
|
-
a development image (`Dockerfile.dev`, builds the local wheel). Both
|
|
95
|
-
|
|
94
|
+
a development image (`Dockerfile.dev`, builds the local wheel). Both use a
|
|
95
|
+
free-threaded Python 3.14 venv, run each invocation in nsjail and expose plain
|
|
96
|
+
HTTP on port `8080`; Dokploy (or another proxy) handles TLS and the public
|
|
97
|
+
domain.
|
|
98
|
+
|
|
99
|
+
nsjail needs unprivileged user namespaces, so the container must run with
|
|
100
|
+
`--security-opt seccomp=unconfined` (nsjail applies its own seccomp policy to
|
|
101
|
+
the sandbox) or an equivalent custom profile. The compose files already set it.
|
|
96
102
|
|
|
97
103
|
```bash
|
|
98
104
|
export VLAMBDA_SECRET="$(openssl rand -hex 32)"
|
|
@@ -104,7 +110,7 @@ With Dokploy, create an application from the image, map the domain to container
|
|
|
104
110
|
port `8080`, and set `VLAMBDA_SECRET` and `VLAMBDA_ADMIN_TOKEN`. Dokploy terminates
|
|
105
111
|
TLS, so the container does not manage certificates.
|
|
106
112
|
|
|
107
|
-
See `docker/README.md` for details, limits and the
|
|
113
|
+
See `docker/README.md` for details, limits and the reset command.
|
|
108
114
|
|
|
109
115
|
## CLI Options
|
|
110
116
|
|
|
@@ -120,12 +126,15 @@ See `docker/README.md` for details, limits and the weekly reset command.
|
|
|
120
126
|
| `--cors_origin` | `VLAMBDA_CORS` | * | CORS allowed origin |
|
|
121
127
|
| `--cert` | `VLAMBDA_CERT` | | TLS certificate path |
|
|
122
128
|
| `--key` | `VLAMBDA_KEY` | | TLS key path |
|
|
129
|
+
| | `VLAMBDA_REGISTRATION` | 1 | Allow public registration (`0` disables it) |
|
|
123
130
|
|
|
124
131
|
## API
|
|
125
132
|
|
|
126
133
|
### Authentication
|
|
127
|
-
- `
|
|
134
|
+
- `GET /config` — Public runtime flags (whether registration is open)
|
|
135
|
+
- `POST /register` — Register user (body: `username:password`); returns `403` when registration is disabled
|
|
128
136
|
- `POST /login` — Login (body: `username:password`) → JWT token
|
|
137
|
+
- `POST /admin/users` — Create a user with `X-Admin-Token` and body `username:password` (for closed registration)
|
|
129
138
|
|
|
130
139
|
### Lambdas (requires auth)
|
|
131
140
|
- `POST /vlambda?method=GET&name=my-lambda` — Create lambda (body: Python code)
|
|
@@ -227,10 +236,25 @@ The `request` object has: `method`, `path`, `query_string`, `headers`, `body`.
|
|
|
227
236
|
|
|
228
237
|
Safe builtins: `abs`, `all`, `any`, `bool`, `dict`, `enumerate`, `filter`, `float`, `int`, `len`, `list`, `map`, `max`, `min`, `range`, `reversed`, `round`, `set`, `sorted`, `str`, `sum`, `tuple`, `zip`, `print`, etc.
|
|
229
238
|
|
|
230
|
-
Blocked modules: `os`, `subprocess`, `sys`, `importlib`, `ctypes`, `socket`, `urllib`, `http`, `shutil`, `pathlib`, `io`, `pickle`, `marshal`, etc.
|
|
239
|
+
Blocked modules: `os`, `posix`, `subprocess`, `sys`, `importlib`, `ctypes`, `socket`, `_socket`, `urllib`, `http`, `shutil`, `pathlib`, `io`, `pickle`, `marshal`, `resource`, `fcntl`, `mmap`, `sqlite3`, etc.
|
|
231
240
|
|
|
232
241
|
Safe modules: `json`, `math`, `re`, `datetime`, `collections`, `itertools`, `functools`, `hashlib`, `base64`, `string`, `random`, `statistics`, etc.
|
|
233
242
|
|
|
243
|
+
### Security
|
|
244
|
+
|
|
245
|
+
User code runs inside nsjail with a separate user, PID, mount and network
|
|
246
|
+
namespace. The sandbox sees only `/opt` and the current project/vendor (read-only),
|
|
247
|
+
has no access to `/data`, cannot read the server's `/proc`, and has no network.
|
|
248
|
+
Resource limits and a seccomp deny-list are also applied. The server process and
|
|
249
|
+
the database stay outside the sandbox.
|
|
250
|
+
|
|
251
|
+
The Docker image keeps public registration open by default for toy deployments.
|
|
252
|
+
Set `VLAMBDA_REGISTRATION=0` to close it and create users with
|
|
253
|
+
`POST /admin/users` instead. A daily data reset removes state, but it does not
|
|
254
|
+
undo a kernel-level escape. Keep this deployment disposable and do not store
|
|
255
|
+
valuable secrets in it; for stronger isolation use gVisor, Firecracker or one
|
|
256
|
+
container per tenant.
|
|
257
|
+
|
|
234
258
|
## Web UI
|
|
235
259
|
|
|
236
260
|
Open http://localhost:8080/ in your browser for the dashboard:
|
|
@@ -250,13 +274,13 @@ Open http://localhost:8080/ in your browser for the dashboard:
|
|
|
250
274
|
The demo can be wiped with:
|
|
251
275
|
|
|
252
276
|
```bash
|
|
253
|
-
python -m vlambda reset --yes --url http://127.0.0.1:
|
|
277
|
+
python -m vlambda reset --yes --url http://127.0.0.1:8080 --token "$VLAMBDA_ADMIN_TOKEN"
|
|
254
278
|
```
|
|
255
279
|
|
|
256
|
-
For
|
|
280
|
+
For a disposable demo, run it from cron every day:
|
|
257
281
|
|
|
258
282
|
```cron
|
|
259
|
-
0
|
|
283
|
+
0 3 * * * docker exec -e VLAMBDA_ADMIN_TOKEN="..." <container> /opt/venv/bin/python -m vlambda reset --yes --url http://127.0.0.1:8080
|
|
260
284
|
```
|
|
261
285
|
|
|
262
286
|
## Performance
|
|
@@ -54,7 +54,7 @@ def main() -> None:
|
|
|
54
54
|
from vlambda.auth import verify_token, create_token, hash_password, check_password
|
|
55
55
|
import sqlite3
|
|
56
56
|
from vlambda.request import Request
|
|
57
|
-
from vlambda_native import start_server, db_init, register_pool, register_auth_verifier, register_auth_register, register_auth_login, configure, register_validate_code, register_ui_html, register_get_asset, register_get_project_json, register_save_project_json, register_list_versions, register_list_aliases, register_admin_reset, register_list_packages, register_install_packages, register_create_task, register_get_task, register_record_metric, register_query_metrics, register_query_stats, register_query_summary, register_query_aggregate, register_query_logs, register_delete_metrics, register_delete_logs, register_export_metrics, register_pool_stats, register_run_project, register_create_project, register_delete_project, register_schedule_delete, register_get_dlq, register_export_lambda, register_import_lambda, register_duplicate_lambda, set_overloaded
|
|
57
|
+
from vlambda_native import start_server, db_init, register_pool, register_auth_verifier, register_auth_register, register_auth_login, configure, register_validate_code, register_ui_html, register_get_asset, register_get_project_json, register_save_project_json, register_list_versions, register_list_aliases, register_admin_reset, register_admin_create_user, register_list_packages, register_install_packages, register_create_task, register_get_task, register_record_metric, register_query_metrics, register_query_stats, register_query_summary, register_query_aggregate, register_query_logs, register_delete_metrics, register_delete_logs, register_export_metrics, register_pool_stats, register_run_project, register_create_project, register_delete_project, register_schedule_delete, register_get_dlq, register_export_lambda, register_import_lambda, register_duplicate_lambda, set_overloaded
|
|
58
58
|
|
|
59
59
|
if not db_init(args.sqlite_path):
|
|
60
60
|
print("Failed to initialize database", file=sys.stderr)
|
|
@@ -69,11 +69,12 @@ def main() -> None:
|
|
|
69
69
|
|
|
70
70
|
metrics_enabled = os.environ.get("VLAMBDA_METRICS_ENABLED", "1") == "1"
|
|
71
71
|
metrics_sample = int(os.environ.get("VLAMBDA_METRICS_SAMPLE", "1"))
|
|
72
|
+
registration_enabled = os.environ.get("VLAMBDA_REGISTRATION", "1") == "1"
|
|
72
73
|
|
|
73
74
|
configure(
|
|
74
75
|
args.max_body_size, args.rate_limit, args.invoke_timeout,
|
|
75
76
|
args.max_memory_mb, args.cors_origin, args.cert, args.key,
|
|
76
|
-
metrics_enabled, metrics_sample,
|
|
77
|
+
metrics_enabled, metrics_sample, registration_enabled,
|
|
77
78
|
)
|
|
78
79
|
|
|
79
80
|
metrics_db = os.environ.get("VLAMBDA_METRICS_DB", args.sqlite_path.replace(".db", "_metrics.db"))
|
|
@@ -237,6 +238,16 @@ def main() -> None:
|
|
|
237
238
|
|
|
238
239
|
register_admin_reset(_admin_reset)
|
|
239
240
|
|
|
241
|
+
def _admin_create_user(token, username, password):
|
|
242
|
+
if not _admin_token_ok(token):
|
|
243
|
+
return json.dumps({"error": "forbidden"})
|
|
244
|
+
uid = _auth_register(username, password)
|
|
245
|
+
if uid < 0:
|
|
246
|
+
return json.dumps({"error": "user already exists"})
|
|
247
|
+
return json.dumps({"user_id": uid})
|
|
248
|
+
|
|
249
|
+
register_admin_create_user(_admin_create_user)
|
|
250
|
+
|
|
240
251
|
from vlambda.packages import list_for as _list_packages, install_for as _install_packages
|
|
241
252
|
|
|
242
253
|
def _list_packages_cb(slug, kind, project_dir):
|
|
@@ -369,25 +380,17 @@ def main() -> None:
|
|
|
369
380
|
|
|
370
381
|
from vlambda.project import create_project as _create_project, execute_project as _execute_project, delete_project as _delete_project_impl, schedule_delete as _schedule_delete_impl
|
|
371
382
|
|
|
372
|
-
def _run_project(project_dir, entrypoint,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
method=request_dict.get("method", "GET"),
|
|
376
|
-
path=request_dict.get("path", "/"),
|
|
377
|
-
query_string=request_dict.get("query_string", ""),
|
|
378
|
-
headers={},
|
|
379
|
-
body=request_dict.get("body", b""),
|
|
380
|
-
)
|
|
383
|
+
def _run_project(project_dir, entrypoint, method, path, query, body):
|
|
384
|
+
import json
|
|
385
|
+
timeout = int(os.environ.get("VLAMBDA_INVOKE_TIMEOUT", "30"))
|
|
381
386
|
try:
|
|
382
|
-
result =
|
|
383
|
-
import json
|
|
387
|
+
result = pool.execute_project(project_dir, entrypoint, method, path, query, body, timeout=timeout)
|
|
384
388
|
if isinstance(result, str):
|
|
385
389
|
return result
|
|
386
390
|
if isinstance(result, (dict, list)):
|
|
387
391
|
return json.dumps(result)
|
|
388
392
|
return str(result)
|
|
389
393
|
except Exception as e:
|
|
390
|
-
import json
|
|
391
394
|
return json.dumps({"error": f"{type(e).__name__}: {e}"})
|
|
392
395
|
|
|
393
396
|
def _delete_project(project_dir):
|