nacho-python 0.1.0__tar.gz → 0.1.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.
- {nacho_python-0.1.0/nacho_python.egg-info → nacho_python-0.1.1}/PKG-INFO +38 -1
- {nacho_python-0.1.0 → nacho_python-0.1.1}/README.md +37 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/_version.py +1 -1
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/server/app.py +6 -1
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/server/auth.py +18 -3
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/server/ui/index.html +12 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1/nacho_python.egg-info}/PKG-INFO +38 -1
- {nacho_python-0.1.0 → nacho_python-0.1.1}/pyproject.toml +1 -1
- {nacho_python-0.1.0 → nacho_python-0.1.1}/LICENSE +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/MANIFEST.in +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/__init__.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/cli/__init__.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/cli/main.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/client.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/config.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/env.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/event.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/schema.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/server/__init__.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/server/models.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/server/runtime.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/storage/__init__.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/storage/base.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/storage/file.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/storage/remote.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/utils/__init__.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/utils/io.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho/utils/path.py +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho_python.egg-info/SOURCES.txt +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho_python.egg-info/dependency_links.txt +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho_python.egg-info/entry_points.txt +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho_python.egg-info/requires.txt +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/nacho_python.egg-info/top_level.txt +0 -0
- {nacho_python-0.1.0 → nacho_python-0.1.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nacho-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Nacho - Lightweight, schema-first dynamic configuration service
|
|
5
5
|
Author-email: "Nya Foundation Team (k3scat)" <k3scat@github.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -246,6 +246,43 @@ When the server runs with `--api-key`, the UI prompts for the key on first
|
|
|
246
246
|
load. The `/ui` page itself is public so the sign-in screen can load; every
|
|
247
247
|
API call behind it requires authentication.
|
|
248
248
|
|
|
249
|
+
#### Pre-authenticating an embedded UI
|
|
250
|
+
|
|
251
|
+
When the orchestrator is mounted inside a host application that already has
|
|
252
|
+
its own session auth, users should not face a second login. The UI reads its
|
|
253
|
+
credential from two same-origin browser stores, and **these two names are a
|
|
254
|
+
stable contract** — seed them before navigating to `/ui` and the UI comes up
|
|
255
|
+
already signed in:
|
|
256
|
+
|
|
257
|
+
| Store | Name | Used for |
|
|
258
|
+
|---|---|---|
|
|
259
|
+
| `localStorage` | `nacho_api_key` | `Authorization: Bearer` header on REST calls |
|
|
260
|
+
| Cookie | `NACHO_api_key` | The WebSocket handshake, which cannot send headers |
|
|
261
|
+
|
|
262
|
+
The cookie value must be URL-encoded, and its path must match the mount
|
|
263
|
+
point — the UI derives it as `location.pathname` with a trailing `/ui`
|
|
264
|
+
removed (so `/config/ui` yields a cookie path of `/config`, and a top-level
|
|
265
|
+
mount yields `/`):
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
// Run on your own login page, same origin as the mounted UI.
|
|
269
|
+
function preauthenticateNacho(key, mountPath = "") {
|
|
270
|
+
localStorage.setItem("nacho_api_key", key);
|
|
271
|
+
const secure = location.protocol === "https:" ? "; Secure" : "";
|
|
272
|
+
document.cookie =
|
|
273
|
+
"NACHO_api_key=" + encodeURIComponent(key) +
|
|
274
|
+
"; path=" + (mountPath || "/") + "; SameSite=Strict" + secure;
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Seed only a credential the signed-in user is entitled to. A user who may
|
|
279
|
+
read configuration but not change it should be given the
|
|
280
|
+
`--read-only-api-key`, not the admin key — the UI surfaces the server's
|
|
281
|
+
`403` responses on write attempts.
|
|
282
|
+
|
|
283
|
+
Do not pass the key in the URL (`?token=`): query strings leak through
|
|
284
|
+
browser history, `Referer` headers, and proxy logs.
|
|
285
|
+
|
|
249
286
|
### Authentication
|
|
250
287
|
|
|
251
288
|
Passing `--api-key` (or `api_key=` to `NachoOrchestrator`) enables bearer
|
|
@@ -199,6 +199,43 @@ When the server runs with `--api-key`, the UI prompts for the key on first
|
|
|
199
199
|
load. The `/ui` page itself is public so the sign-in screen can load; every
|
|
200
200
|
API call behind it requires authentication.
|
|
201
201
|
|
|
202
|
+
#### Pre-authenticating an embedded UI
|
|
203
|
+
|
|
204
|
+
When the orchestrator is mounted inside a host application that already has
|
|
205
|
+
its own session auth, users should not face a second login. The UI reads its
|
|
206
|
+
credential from two same-origin browser stores, and **these two names are a
|
|
207
|
+
stable contract** — seed them before navigating to `/ui` and the UI comes up
|
|
208
|
+
already signed in:
|
|
209
|
+
|
|
210
|
+
| Store | Name | Used for |
|
|
211
|
+
|---|---|---|
|
|
212
|
+
| `localStorage` | `nacho_api_key` | `Authorization: Bearer` header on REST calls |
|
|
213
|
+
| Cookie | `NACHO_api_key` | The WebSocket handshake, which cannot send headers |
|
|
214
|
+
|
|
215
|
+
The cookie value must be URL-encoded, and its path must match the mount
|
|
216
|
+
point — the UI derives it as `location.pathname` with a trailing `/ui`
|
|
217
|
+
removed (so `/config/ui` yields a cookie path of `/config`, and a top-level
|
|
218
|
+
mount yields `/`):
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
// Run on your own login page, same origin as the mounted UI.
|
|
222
|
+
function preauthenticateNacho(key, mountPath = "") {
|
|
223
|
+
localStorage.setItem("nacho_api_key", key);
|
|
224
|
+
const secure = location.protocol === "https:" ? "; Secure" : "";
|
|
225
|
+
document.cookie =
|
|
226
|
+
"NACHO_api_key=" + encodeURIComponent(key) +
|
|
227
|
+
"; path=" + (mountPath || "/") + "; SameSite=Strict" + secure;
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Seed only a credential the signed-in user is entitled to. A user who may
|
|
232
|
+
read configuration but not change it should be given the
|
|
233
|
+
`--read-only-api-key`, not the admin key — the UI surfaces the server's
|
|
234
|
+
`403` responses on write attempts.
|
|
235
|
+
|
|
236
|
+
Do not pass the key in the URL (`?token=`): query strings leak through
|
|
237
|
+
browser history, `Referer` headers, and proxy logs.
|
|
238
|
+
|
|
202
239
|
### Authentication
|
|
203
240
|
|
|
204
241
|
Passing `--api-key` (or `api_key=` to `NachoOrchestrator`) enables bearer
|
|
@@ -24,7 +24,7 @@ from fastapi.responses import FileResponse, JSONResponse
|
|
|
24
24
|
from nacho._version import __version__
|
|
25
25
|
from nacho.config import Nacho
|
|
26
26
|
from nacho.schema import ValidationError
|
|
27
|
-
from nacho.server.auth import AuthGuard, AuthMiddleware
|
|
27
|
+
from nacho.server.auth import AuthGuard, AuthMiddleware, validate_api_key
|
|
28
28
|
from nacho.utils.io import dump_string, load_string
|
|
29
29
|
from nacho.utils.path import get_nested_value
|
|
30
30
|
|
|
@@ -74,6 +74,11 @@ class NachoOrchestrator:
|
|
|
74
74
|
# clients are not browsers, so cross-origin access is opt-in.
|
|
75
75
|
self.cors_origins = list(cors_origins) if cors_origins is not None else []
|
|
76
76
|
self.logger = logger or LOGGER
|
|
77
|
+
# Validate before the truthiness check below: a falsy non-str key
|
|
78
|
+
# (e.g. an empty list from a caller's own config) would otherwise
|
|
79
|
+
# skip AuthGuard entirely and leave the server unauthenticated.
|
|
80
|
+
api_key = validate_api_key("api_key", api_key)
|
|
81
|
+
read_only_api_key = validate_api_key("read_only_api_key", read_only_api_key)
|
|
77
82
|
self.auth = (
|
|
78
83
|
AuthGuard(api_key=api_key, read_only_api_key=read_only_api_key)
|
|
79
84
|
if (api_key or read_only_api_key)
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import hmac
|
|
6
6
|
import logging
|
|
7
|
-
from typing import Optional, Sequence
|
|
7
|
+
from typing import Any, Optional, Sequence
|
|
8
8
|
from urllib.parse import unquote
|
|
9
9
|
|
|
10
10
|
from fastapi import Request, WebSocket
|
|
@@ -25,6 +25,21 @@ ROLE_ADMIN = "admin" # full read/write access
|
|
|
25
25
|
ROLE_READ = "read" # safe HTTP methods and WebSocket subscriptions only
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
def validate_api_key(name: str, value: Any) -> Optional[str]:
|
|
29
|
+
"""Return *value* if it is a usable API key, raising TypeError otherwise.
|
|
30
|
+
|
|
31
|
+
Keys are compared as UTF-8 bytes, so a non-str key would only fail when
|
|
32
|
+
someone first presents a *valid* credential — an opaque 500 long after
|
|
33
|
+
the misconfiguration. Worse, a falsy non-str (``[]``, ``0``) would leave
|
|
34
|
+
the server silently unauthenticated. Both are caught here instead.
|
|
35
|
+
"""
|
|
36
|
+
if value is None:
|
|
37
|
+
return None
|
|
38
|
+
if not isinstance(value, str):
|
|
39
|
+
raise TypeError(f"{name} must be a str or None, got {type(value).__name__}")
|
|
40
|
+
return value
|
|
41
|
+
|
|
42
|
+
|
|
28
43
|
class AuthGuard:
|
|
29
44
|
"""Verifies API keys from headers, cookies, and WebSocket handshakes.
|
|
30
45
|
|
|
@@ -39,8 +54,8 @@ class AuthGuard:
|
|
|
39
54
|
api_key: Optional[str] = None,
|
|
40
55
|
read_only_api_key: Optional[str] = None,
|
|
41
56
|
) -> None:
|
|
42
|
-
self.api_key = api_key
|
|
43
|
-
self.read_only_api_key = read_only_api_key
|
|
57
|
+
self.api_key = validate_api_key("api_key", api_key)
|
|
58
|
+
self.read_only_api_key = validate_api_key("read_only_api_key", read_only_api_key)
|
|
44
59
|
|
|
45
60
|
@property
|
|
46
61
|
def enabled(self) -> bool:
|
|
@@ -580,6 +580,18 @@ h1, h2, h3 { margin: 0; }
|
|
|
580
580
|
const BASE = location.pathname.replace(/\/ui\/?$/, "");
|
|
581
581
|
const COOKIE_PATH = BASE || "/";
|
|
582
582
|
|
|
583
|
+
/* ===================================================================== */
|
|
584
|
+
/* PUBLIC EMBEDDING CONTRACT — do not rename without a major release. */
|
|
585
|
+
/* Host applications that mount this UI behind their own session auth */
|
|
586
|
+
/* pre-authenticate it by seeding these two same-origin stores before */
|
|
587
|
+
/* navigating here, so their users are not asked to log in twice: */
|
|
588
|
+
/* localStorage["nacho_api_key"] → REST Authorization: Bearer header */
|
|
589
|
+
/* cookie "NACHO_api_key" (URL-encoded, path=COOKIE_PATH above) */
|
|
590
|
+
/* → WebSocket handshake, which cannot */
|
|
591
|
+
/* carry headers */
|
|
592
|
+
/* Documented in README.md, "Pre-authenticating an embedded UI". */
|
|
593
|
+
/* ===================================================================== */
|
|
594
|
+
|
|
583
595
|
/* ===================================================================== */
|
|
584
596
|
/* State */
|
|
585
597
|
/* ===================================================================== */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nacho-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Nacho - Lightweight, schema-first dynamic configuration service
|
|
5
5
|
Author-email: "Nya Foundation Team (k3scat)" <k3scat@github.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -246,6 +246,43 @@ When the server runs with `--api-key`, the UI prompts for the key on first
|
|
|
246
246
|
load. The `/ui` page itself is public so the sign-in screen can load; every
|
|
247
247
|
API call behind it requires authentication.
|
|
248
248
|
|
|
249
|
+
#### Pre-authenticating an embedded UI
|
|
250
|
+
|
|
251
|
+
When the orchestrator is mounted inside a host application that already has
|
|
252
|
+
its own session auth, users should not face a second login. The UI reads its
|
|
253
|
+
credential from two same-origin browser stores, and **these two names are a
|
|
254
|
+
stable contract** — seed them before navigating to `/ui` and the UI comes up
|
|
255
|
+
already signed in:
|
|
256
|
+
|
|
257
|
+
| Store | Name | Used for |
|
|
258
|
+
|---|---|---|
|
|
259
|
+
| `localStorage` | `nacho_api_key` | `Authorization: Bearer` header on REST calls |
|
|
260
|
+
| Cookie | `NACHO_api_key` | The WebSocket handshake, which cannot send headers |
|
|
261
|
+
|
|
262
|
+
The cookie value must be URL-encoded, and its path must match the mount
|
|
263
|
+
point — the UI derives it as `location.pathname` with a trailing `/ui`
|
|
264
|
+
removed (so `/config/ui` yields a cookie path of `/config`, and a top-level
|
|
265
|
+
mount yields `/`):
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
// Run on your own login page, same origin as the mounted UI.
|
|
269
|
+
function preauthenticateNacho(key, mountPath = "") {
|
|
270
|
+
localStorage.setItem("nacho_api_key", key);
|
|
271
|
+
const secure = location.protocol === "https:" ? "; Secure" : "";
|
|
272
|
+
document.cookie =
|
|
273
|
+
"NACHO_api_key=" + encodeURIComponent(key) +
|
|
274
|
+
"; path=" + (mountPath || "/") + "; SameSite=Strict" + secure;
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Seed only a credential the signed-in user is entitled to. A user who may
|
|
279
|
+
read configuration but not change it should be given the
|
|
280
|
+
`--read-only-api-key`, not the admin key — the UI surfaces the server's
|
|
281
|
+
`403` responses on write attempts.
|
|
282
|
+
|
|
283
|
+
Do not pass the key in the URL (`?token=`): query strings leak through
|
|
284
|
+
browser history, `Referer` headers, and proxy logs.
|
|
285
|
+
|
|
249
286
|
### Authentication
|
|
250
287
|
|
|
251
288
|
Passing `--api-key` (or `api_key=` to `NachoOrchestrator`) enables bearer
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|