soliplex 0.90__tar.gz → 0.91__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.
- {soliplex-0.90/src/soliplex.egg-info → soliplex-0.91}/PKG-INFO +2 -2
- {soliplex-0.90 → soliplex-0.91}/example/skills/bare-bones/SKILL.md +1 -0
- {soliplex-0.90 → soliplex-0.91}/pyproject.toml +2 -2
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/authz/__init__.py +215 -6
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/authz/schema.py +52 -5
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/admin_users.py +39 -22
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/admin_users.py +33 -94
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/room_authz.py +39 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/room_authz.py +40 -24
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/installation.py +0 -111
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/loggers.py +2 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/models.py +9 -7
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/skills/bwrap_sandbox/__init__.py +26 -14
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/tui/main.py +5 -3
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/util.py +41 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/room_file_uploads.py +13 -15
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/sandbox_workdirs.py +14 -13
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/thread_file_uploads.py +14 -16
- {soliplex-0.90 → soliplex-0.91/src/soliplex.egg-info}/PKG-INFO +2 -2
- {soliplex-0.90 → soliplex-0.91}/src/soliplex.egg-info/requires.txt +1 -1
- {soliplex-0.90 → soliplex-0.91}/LICENSE +0 -0
- {soliplex-0.90 → soliplex-0.91}/MANIFEST.in +0 -0
- {soliplex-0.90 → soliplex-0.91}/README.md +0 -0
- {soliplex-0.90 → soliplex-0.91}/example/skills/stanzas/SKILL.md +0 -0
- {soliplex-0.90 → soliplex-0.91}/setup.cfg +0 -0
- {soliplex-0.90 → soliplex-0.91}/skills/soliplex-docs/SKILL.md +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/agents.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/agui/__init__.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/agui/parser.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/agui/persistence.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/agui/schema.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/agui/sse_delivery.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/agui/util.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/__init__.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/env.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/versions/216d48e1e2e5_soliplex_v0_53.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/versions/4b63e5f3f39e_soliplex_v0_51_1.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/versions/63edaa5987f6_soliplex_v0_67.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/versions/a1c7d3e90b42_soliplex_v0_80.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/versions/b7e2f41c9d05_soliplex_v0_82.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/versions/d5009d4f9874_soliplex_v0_44.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/alembic_migrations/versions/f13fea6c1953_soliplex_v0_86.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/authn.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/authz/persistence.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/capabilities/filesystem.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/capabilities/rag_audit.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/ask.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/__init__.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/_common.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/completions.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/databases.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/environment.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/installation.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/interpolation.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/logfire.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/logging.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/oidc.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/ollama.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/quizzes.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/rooms.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/secrets.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/audit/skills.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/cli_util.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/database.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/main.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/ollama.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/serve.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/service_token.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/cli/types.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/completions.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/__init__.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/_utils.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/agents.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/agui.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/authsystem.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/completions.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/exceptions.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/interpolation.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/logfire.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/meta.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/middleware.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/quizzes.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/rag.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/rooms.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/routing.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/secrets.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/skills.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/sse_delivery.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/config/tools.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/examples.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/installation.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/log_ingest.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/main.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/mcp_auth.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/mcp_client.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/mcp_server.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/ollama.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/quizzes.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/rag_audit.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/sandbox_audit.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/secrets.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/skills/bwrap_sandbox/SKILL.md +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/titles.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/token_mint.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/tools/__init__.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/tools/agui_run_feedback.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/tools/file_uploads.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/tools/rag.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/tui/cli.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/tui/rest_api.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/tui/serve.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/__init__.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/agui.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/authn.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/authz.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/completions.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/installation.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/log_ingest.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/quizzes.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/rooms.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/stats.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/streaming.py +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/templates/consent.html.mako +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex/views/templates/cookie-too-large.html.mako +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex.egg-info/SOURCES.txt +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex.egg-info/dependency_links.txt +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex.egg-info/entry_points.txt +0 -0
- {soliplex-0.90 → soliplex-0.91}/src/soliplex.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: soliplex
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.91
|
|
4
4
|
Summary: An AI-powered Retrieval-Augmented Generation (RAG) system with a modern web interface.
|
|
5
5
|
Author-email: Enfold <info@enfoldsystems.net>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -20,7 +20,7 @@ Requires-Dist: fakeredis!=2.35.0
|
|
|
20
20
|
Requires-Dist: fastapi
|
|
21
21
|
Requires-Dist: fastmcp<5.0,>=4.1.2
|
|
22
22
|
Requires-Dist: greenlet
|
|
23
|
-
Requires-Dist: haiku.rag-slim<0.
|
|
23
|
+
Requires-Dist: haiku.rag-slim<0.109,>=0.108.0
|
|
24
24
|
Requires-Dist: idna>=3.15
|
|
25
25
|
Requires-Dist: itsdangerous
|
|
26
26
|
Requires-Dist: joserfc<1.8,>=1.7.5
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "soliplex"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.91"
|
|
8
8
|
description = "An AI-powered Retrieval-Augmented Generation (RAG) system with a modern web interface."
|
|
9
9
|
authors = [{ name = "Enfold", email = "info@enfoldsystems.net" }]
|
|
10
10
|
readme = "README.md"
|
|
@@ -26,7 +26,7 @@ dependencies = [
|
|
|
26
26
|
"fastapi",
|
|
27
27
|
"fastmcp >= 4.1.2, < 5.0",
|
|
28
28
|
"greenlet",
|
|
29
|
-
"haiku.rag-slim >= 0.
|
|
29
|
+
"haiku.rag-slim >= 0.108.0, < 0.109",
|
|
30
30
|
"idna >= 3.15",
|
|
31
31
|
"itsdangerous",
|
|
32
32
|
"joserfc >= 1.7.5, < 1.8", # CVE-2026-11928{3,4}
|
|
@@ -2,11 +2,13 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import abc
|
|
4
4
|
import enum
|
|
5
|
+
import functools
|
|
5
6
|
import json
|
|
6
7
|
import re
|
|
7
8
|
import typing
|
|
8
9
|
|
|
9
10
|
import jsonpath
|
|
11
|
+
from jsonpath import filter as jp_filter
|
|
10
12
|
|
|
11
13
|
# Avoid circular import when only used for typing
|
|
12
14
|
|
|
@@ -19,6 +21,10 @@ UserToken = dict[str, typing.Any]
|
|
|
19
21
|
# filter functions in one place.
|
|
20
22
|
the_jsonpath_environment = jsonpath.JSONPathEnvironment()
|
|
21
23
|
|
|
24
|
+
# Set on the wrapper installed by 'register_jsonpath_function', so that
|
|
25
|
+
# re-registering a wrapper replaces rather than re-wraps it.
|
|
26
|
+
_WRAPPED_FILTER_MARKER = "__soliplex_wrapped_filter__"
|
|
27
|
+
|
|
22
28
|
# Names of the RFC 9535 built-in filter functions, captured before any
|
|
23
29
|
# metaconfig registration. Anything added to the environment beyond these
|
|
24
30
|
# was supplied by config, so the metaconfig can round-trip just those.
|
|
@@ -37,6 +43,25 @@ class ReservedJSONPathFunctionName(ValueError):
|
|
|
37
43
|
)
|
|
38
44
|
|
|
39
45
|
|
|
46
|
+
class InvalidPredicateResult(ValueError):
|
|
47
|
+
"""Raised when a registered JSONPath filter function returns None.
|
|
48
|
+
|
|
49
|
+
python-jsonpath counts ``None`` (JSON ``null``) as an extant, truthy
|
|
50
|
+
value inside a filter expression ('JSONPathEnvironment.is_truthy'),
|
|
51
|
+
so a predicate returning it on miss would match every token with at
|
|
52
|
+
least one claim. The wrapper installed by
|
|
53
|
+
'register_jsonpath_function' fails closed by raising this error when
|
|
54
|
+
the query runs instead.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def __init__(self, name: str):
|
|
58
|
+
self.name = name
|
|
59
|
+
super().__init__(
|
|
60
|
+
f"Filter function {name!r} returned None; authz predicates"
|
|
61
|
+
f" must not return None."
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
40
65
|
def register_jsonpath_function(name: str, func: typing.Any) -> None:
|
|
41
66
|
"""Register a named filter function into the shared environment.
|
|
42
67
|
|
|
@@ -45,19 +70,44 @@ def register_jsonpath_function(name: str, func: typing.Any) -> None:
|
|
|
45
70
|
RFC 9535 well-typedness checks). It becomes usable inside JSONPath
|
|
46
71
|
filter expressions as 'name(...)'.
|
|
47
72
|
|
|
73
|
+
The stored callable is wrapped: a call returning 'None' raises
|
|
74
|
+
'InvalidPredicateResult' when the query runs; any other result
|
|
75
|
+
passes through unchanged, with the engine's usual truthiness rules
|
|
76
|
+
deciding the match. 'functools.wraps' carries 'func's identity, so
|
|
77
|
+
metaconfig round-tripping via 'registered_jsonpath_functions' still
|
|
78
|
+
resolves the original dotted name.
|
|
79
|
+
|
|
48
80
|
Raises 'ReservedJSONPathFunctionName' if 'name' collides with one of
|
|
49
81
|
the RFC 9535 built-ins.
|
|
50
82
|
"""
|
|
83
|
+
while getattr(func, _WRAPPED_FILTER_MARKER, False):
|
|
84
|
+
func = func.__wrapped__
|
|
85
|
+
|
|
51
86
|
if name in BUILTIN_JSONPATH_FUNCTION_NAMES:
|
|
52
87
|
raise ReservedJSONPathFunctionName(name)
|
|
53
|
-
|
|
88
|
+
|
|
89
|
+
@functools.wraps(func)
|
|
90
|
+
def wrapped_filter_function(*args, **kwargs):
|
|
91
|
+
result = func(*args, **kwargs)
|
|
92
|
+
|
|
93
|
+
if result is None:
|
|
94
|
+
raise InvalidPredicateResult(name)
|
|
95
|
+
|
|
96
|
+
return result
|
|
97
|
+
|
|
98
|
+
setattr(wrapped_filter_function, _WRAPPED_FILTER_MARKER, True)
|
|
99
|
+
the_jsonpath_environment.function_extensions[name] = (
|
|
100
|
+
wrapped_filter_function
|
|
101
|
+
)
|
|
54
102
|
|
|
55
103
|
|
|
56
104
|
def registered_jsonpath_functions() -> dict[str, typing.Any]:
|
|
57
105
|
"""Filter functions added via 'register_jsonpath_function'.
|
|
58
106
|
|
|
59
107
|
Excludes the RFC 9535 built-ins, leaving only the config-supplied
|
|
60
|
-
functions (e.g. for metaconfig round-tripping)
|
|
108
|
+
functions (e.g. for metaconfig round-tripping): each entry is the
|
|
109
|
+
wrapper installed by 'register_jsonpath_function', whose
|
|
110
|
+
'__module__' / '__name__' still name the registered function.
|
|
61
111
|
"""
|
|
62
112
|
return {
|
|
63
113
|
name: func
|
|
@@ -74,6 +124,14 @@ class InvalidJSONPath(ValueError):
|
|
|
74
124
|
super().__init__(f"Invalid JSONPath: {value!r}")
|
|
75
125
|
|
|
76
126
|
|
|
127
|
+
class JSONPathMatchesNull(ValueError):
|
|
128
|
+
"""Raised when a JSONPath query string can return 'null' values"""
|
|
129
|
+
|
|
130
|
+
def __init__(self, value: str):
|
|
131
|
+
self.value = value
|
|
132
|
+
super().__init__(f"JSONPath matches null: {value!r}")
|
|
133
|
+
|
|
134
|
+
|
|
77
135
|
class ExactlyOneDiscriminator(ValueError):
|
|
78
136
|
"""Raised when an ACL entry does not set exactly one discriminator."""
|
|
79
137
|
|
|
@@ -123,13 +181,17 @@ def validate_json_path(value: str | None) -> str | None:
|
|
|
123
181
|
"""Validate a JSONPath query string.
|
|
124
182
|
|
|
125
183
|
Returns ``value`` unchanged for ``None`` or a syntactically valid
|
|
126
|
-
RFC 9535 query. Raises ``InvalidJSONPath`` for malformed queries
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
184
|
+
RFC 9535 query. Raises ``InvalidJSONPath`` for malformed queries,
|
|
185
|
+
and for blank queries (all whitespace), which compile but match
|
|
186
|
+
every token: a blank 'ALLOW' entry would grant everyone. Callers
|
|
187
|
+
(pydantic field validators, SQLAlchemy ``@validates`` hooks) can
|
|
188
|
+
reject bad values at write time rather than failing later inside
|
|
189
|
+
``check_token``.
|
|
130
190
|
"""
|
|
131
191
|
if value is None:
|
|
132
192
|
return value
|
|
193
|
+
if not value.strip():
|
|
194
|
+
raise InvalidJSONPath(value)
|
|
133
195
|
try:
|
|
134
196
|
the_jsonpath_environment.compile(value)
|
|
135
197
|
except jsonpath.JSONPathError as exc:
|
|
@@ -173,6 +235,153 @@ def parse_token_field_json_path(value: str) -> tuple[str, str] | None:
|
|
|
173
235
|
return match.group("field"), decoded
|
|
174
236
|
|
|
175
237
|
|
|
238
|
+
def discriminator_claim_names(json_path: str) -> list[str]:
|
|
239
|
+
"""Extract the claim names referenced by a stored json_path.
|
|
240
|
+
|
|
241
|
+
Returns the (sorted) distinct claim names a query can reference
|
|
242
|
+
from the token root: for each chain of names reachable from '$',
|
|
243
|
+
or from an '@'-relative query under '$' or under one of those
|
|
244
|
+
chains, the chain's first name (so '$.realm_access.roles[0]'
|
|
245
|
+
yields 'realm_access', matching how the authn cookie carries
|
|
246
|
+
claims).
|
|
247
|
+
|
|
248
|
+
Parsing uses this environment's own JSONPath compiler, not pattern
|
|
249
|
+
matching: quoted values, slices, wildcards, unions, recursive
|
|
250
|
+
descent, nested filters and JSONPath function extensions are all
|
|
251
|
+
understood, though claims read only *inside* a function extension
|
|
252
|
+
remain invisible to the audit.
|
|
253
|
+
|
|
254
|
+
An unparseable query (e.g. authored under a metaconfig whose filter
|
|
255
|
+
function no longer exists) contributes no claim names: such rows
|
|
256
|
+
are reported separately, in the invalid JSONPath block.
|
|
257
|
+
"""
|
|
258
|
+
try:
|
|
259
|
+
parsed = the_jsonpath_environment.compile(json_path)
|
|
260
|
+
except jsonpath.JSONPathError:
|
|
261
|
+
return []
|
|
262
|
+
|
|
263
|
+
claims: set[str] = set()
|
|
264
|
+
_collect_from_segments(parsed.segments, (), claims)
|
|
265
|
+
return sorted(claims)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _collect_from_segments(
|
|
269
|
+
segments,
|
|
270
|
+
chain: tuple[str, ...],
|
|
271
|
+
claims: set[str],
|
|
272
|
+
) -> None:
|
|
273
|
+
"""Fold a segment sequence into the claim set, threading 'chain'.
|
|
274
|
+
|
|
275
|
+
Each chain's first name is a referenced claim. Within one segment,
|
|
276
|
+
union selectors each fork from the incoming chain, and the first
|
|
277
|
+
fork's chain continues into later segments. Wildcard, index and
|
|
278
|
+
slice segments pass the chain through unchanged.
|
|
279
|
+
"""
|
|
280
|
+
for segment in segments:
|
|
281
|
+
grown: tuple[str, ...] | None = None
|
|
282
|
+
|
|
283
|
+
for selector in segment.selectors:
|
|
284
|
+
name = getattr(selector, "name", None)
|
|
285
|
+
|
|
286
|
+
if name is None:
|
|
287
|
+
sub_path = getattr(selector, "query", None)
|
|
288
|
+
if sub_path is not None:
|
|
289
|
+
_collect_from_segments(sub_path.segments, (), claims)
|
|
290
|
+
continue
|
|
291
|
+
|
|
292
|
+
expression = getattr(selector, "expression", None)
|
|
293
|
+
if expression is not None:
|
|
294
|
+
_collect_from_expression(expression, chain, claims)
|
|
295
|
+
continue
|
|
296
|
+
|
|
297
|
+
forked = (*chain, str(name))
|
|
298
|
+
claims.add(forked[0])
|
|
299
|
+
if grown is None:
|
|
300
|
+
grown = forked
|
|
301
|
+
|
|
302
|
+
if grown is not None:
|
|
303
|
+
chain = grown
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def _collect_from_expression(
|
|
307
|
+
expression,
|
|
308
|
+
chain: tuple[str, ...],
|
|
309
|
+
claims: set[str],
|
|
310
|
+
) -> tuple[str, ...]:
|
|
311
|
+
"""Fold a filter expression's claim references into 'claims'.
|
|
312
|
+
|
|
313
|
+
Embedded JSONPaths are folded per their kind: a '$'-anchored query
|
|
314
|
+
re-roots at '$'; an '@'-relative query continues the enclosing
|
|
315
|
+
chain. Other expressions (infix operators, literals, function
|
|
316
|
+
calls) contribute only their children.
|
|
317
|
+
"""
|
|
318
|
+
if isinstance(expression, jp_filter.FilterQuery):
|
|
319
|
+
sub_chain: tuple[str, ...] = chain
|
|
320
|
+
if not isinstance(expression, jp_filter.RelativeFilterQuery):
|
|
321
|
+
sub_chain = ()
|
|
322
|
+
|
|
323
|
+
_collect_from_segments(expression.path.segments, sub_chain, claims)
|
|
324
|
+
return chain
|
|
325
|
+
|
|
326
|
+
for child in expression.children():
|
|
327
|
+
_collect_from_expression(child, chain, claims)
|
|
328
|
+
|
|
329
|
+
return chain
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def null_probe_tokens(claim_names: list[str]) -> list[dict]:
|
|
333
|
+
"""Build the synthetic tokens null-probing a stored json_path.
|
|
334
|
+
|
|
335
|
+
One token seeds every claim name the expression references with
|
|
336
|
+
JSON 'null', plus one token with no claims at all -- the shapes a
|
|
337
|
+
miswritten expression is most likely to match by surprise: bare
|
|
338
|
+
selectors and presence tests count 'null' as matching,
|
|
339
|
+
'$'-root or constant filters match an empty token outright.
|
|
340
|
+
|
|
341
|
+
Claims read only inside a function extension are invisible here;
|
|
342
|
+
matching that depends on nested claim structure cannot be reached
|
|
343
|
+
from the first-name chains either.
|
|
344
|
+
"""
|
|
345
|
+
tokens: list[dict] = [{name: None for name in claim_names}]
|
|
346
|
+
if claim_names:
|
|
347
|
+
tokens.append({})
|
|
348
|
+
return tokens
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def null_claims_match(json_path: str) -> dict | None:
|
|
352
|
+
"""Return the first null-probe token 'json_path' matches, if any.
|
|
353
|
+
|
|
354
|
+
Runs the expression against the 'null_probe_tokens' shapes; the
|
|
355
|
+
first match is returned as the evidence for an audit report.
|
|
356
|
+
|
|
357
|
+
Queries failing 'validate_json_path' (already reported in the
|
|
358
|
+
invalid block) and queries whose function extensions choke on the
|
|
359
|
+
synthetic claims contribute no flags: predicate behavior is
|
|
360
|
+
software, audited only insofar as it runs here without complaint.
|
|
361
|
+
"""
|
|
362
|
+
try:
|
|
363
|
+
validate_json_path(json_path)
|
|
364
|
+
except InvalidJSONPath:
|
|
365
|
+
return None
|
|
366
|
+
|
|
367
|
+
for probe_token in null_probe_tokens(
|
|
368
|
+
discriminator_claim_names(json_path),
|
|
369
|
+
):
|
|
370
|
+
try:
|
|
371
|
+
if (
|
|
372
|
+
the_jsonpath_environment.match(
|
|
373
|
+
json_path,
|
|
374
|
+
probe_token,
|
|
375
|
+
)
|
|
376
|
+
is not None
|
|
377
|
+
):
|
|
378
|
+
return probe_token
|
|
379
|
+
except Exception:
|
|
380
|
+
continue
|
|
381
|
+
|
|
382
|
+
return None
|
|
383
|
+
|
|
384
|
+
|
|
176
385
|
class AllowDeny(enum.Enum):
|
|
177
386
|
ALLOW = "allow"
|
|
178
387
|
DENY = "deny"
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import datetime
|
|
4
|
+
import logging
|
|
4
5
|
import typing
|
|
5
6
|
|
|
7
|
+
import jsonpath
|
|
6
8
|
import sqlalchemy
|
|
7
9
|
from sqlalchemy import orm as sqla_orm
|
|
8
10
|
from sqlalchemy import schema as sqla_schema
|
|
@@ -10,6 +12,7 @@ from sqlalchemy.ext import asyncio as sqla_asyncio
|
|
|
10
12
|
from sqlalchemy.sql import sqltypes as sqla_sqltypes
|
|
11
13
|
|
|
12
14
|
from soliplex import authz
|
|
15
|
+
from soliplex import loggers
|
|
13
16
|
from soliplex import models
|
|
14
17
|
from soliplex import util
|
|
15
18
|
from soliplex.config import installation as config_installation
|
|
@@ -21,6 +24,8 @@ Mapped = sqla_orm.Mapped
|
|
|
21
24
|
mapped_column = sqla_orm.mapped_column
|
|
22
25
|
relationship = sqla_orm.relationship
|
|
23
26
|
|
|
27
|
+
_authz_logger = logging.getLogger(loggers.AUTHZ_LOGGER_NAME)
|
|
28
|
+
|
|
24
29
|
|
|
25
30
|
def _timestamp() -> datetime.datetime:
|
|
26
31
|
return datetime.datetime.now(datetime.UTC)
|
|
@@ -72,15 +77,32 @@ class AdminUser(Base):
|
|
|
72
77
|
|
|
73
78
|
@sqla_orm.validates("json_path")
|
|
74
79
|
def _check_json_path(self, _key, value):
|
|
80
|
+
probe = authz.null_claims_match(value)
|
|
81
|
+
|
|
82
|
+
if probe is not None:
|
|
83
|
+
raise authz.JSONPathMatchesNull(value)
|
|
84
|
+
|
|
75
85
|
return authz.validate_json_path(value)
|
|
76
86
|
|
|
77
87
|
def check_token(
|
|
78
88
|
self,
|
|
79
89
|
user_token: authz.UserToken | None,
|
|
80
90
|
) -> bool:
|
|
81
|
-
"""Does 'user_token' match our JSONPath query?
|
|
91
|
+
"""Does 'user_token' match our JSONPath query?
|
|
92
|
+
|
|
93
|
+
A stored 'json_path' which no longer compiles (e.g., it references
|
|
94
|
+
a meta-config filter function which is no longer registered)
|
|
95
|
+
never matches: log it as a warning and return False.
|
|
96
|
+
"""
|
|
82
97
|
token = user_token or {}
|
|
83
|
-
|
|
98
|
+
try:
|
|
99
|
+
match = authz.the_jsonpath_environment.match(self.json_path, token)
|
|
100
|
+
except jsonpath.JSONPathError as exc:
|
|
101
|
+
_authz_logger.warning(
|
|
102
|
+
loggers.AUTHZ_STALE_ADMIN_ENTRY,
|
|
103
|
+
extra={"json_path": self.json_path, "reason": str(exc)},
|
|
104
|
+
)
|
|
105
|
+
return False
|
|
84
106
|
return match is not None
|
|
85
107
|
|
|
86
108
|
|
|
@@ -213,6 +235,12 @@ class ACLEntry(Base):
|
|
|
213
235
|
|
|
214
236
|
@sqla_orm.validates("json_path")
|
|
215
237
|
def _check_json_path(self, _key, value):
|
|
238
|
+
if value is not None:
|
|
239
|
+
probe = authz.null_claims_match(value)
|
|
240
|
+
|
|
241
|
+
if probe is not None:
|
|
242
|
+
raise authz.JSONPathMatchesNull(value)
|
|
243
|
+
|
|
216
244
|
return authz.validate_json_path(value)
|
|
217
245
|
|
|
218
246
|
@classmethod
|
|
@@ -290,6 +318,12 @@ class ACLEntry(Base):
|
|
|
290
318
|
return our 'allow_deny'.
|
|
291
319
|
|
|
292
320
|
Otherwise, return None.
|
|
321
|
+
|
|
322
|
+
A stored 'json_path' which no longer compiles (e.g., it references
|
|
323
|
+
a meta-config filter function which is no longer registered) is
|
|
324
|
+
logged as a warning, and then treated as matching if our
|
|
325
|
+
'allow_deny' is DENY, else as not matching: so a stale entry can
|
|
326
|
+
never grant access.
|
|
293
327
|
"""
|
|
294
328
|
# Column defaults (Python 'default' / the migration's
|
|
295
329
|
# 'server_default', which backfills existing rows) are applied
|
|
@@ -308,9 +342,22 @@ class ACLEntry(Base):
|
|
|
308
342
|
token = user_token or {}
|
|
309
343
|
|
|
310
344
|
if self.json_path is not None:
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
345
|
+
try:
|
|
346
|
+
jp_match = authz.the_jsonpath_environment.match(
|
|
347
|
+
self.json_path, token
|
|
348
|
+
)
|
|
349
|
+
except jsonpath.JSONPathError as exc:
|
|
350
|
+
_authz_logger.warning(
|
|
351
|
+
loggers.AUTHZ_STALE_ACL_ENTRY,
|
|
352
|
+
extra={
|
|
353
|
+
"json_path": self.json_path,
|
|
354
|
+
"allow_deny": self.allow_deny.name,
|
|
355
|
+
"reason": str(exc),
|
|
356
|
+
},
|
|
357
|
+
)
|
|
358
|
+
if self.allow_deny is authz.AllowDeny.DENY:
|
|
359
|
+
return authz.AllowDeny.DENY
|
|
360
|
+
return None
|
|
314
361
|
if jp_match is not None:
|
|
315
362
|
return self.allow_deny
|
|
316
363
|
|
|
@@ -6,7 +6,6 @@ import pathlib
|
|
|
6
6
|
import sys
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
|
-
import jsonpath
|
|
10
9
|
import typer
|
|
11
10
|
import yaml
|
|
12
11
|
|
|
@@ -155,9 +154,11 @@ def _admin_user_from_jsonable(entry: dict) -> str:
|
|
|
155
154
|
|
|
156
155
|
Each entry must specify exactly one of 'email',
|
|
157
156
|
'preferred_username', or 'json_path'. Raises 'typer.Exit(1)' on a
|
|
158
|
-
malformed entry.
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
malformed entry.
|
|
158
|
+
|
|
159
|
+
The validity of a literal 'json_path' is not checked here;
|
|
160
|
+
the caller checks, falling back to the storage layer's '@validates'
|
|
161
|
+
hook enforcement on insert.
|
|
161
162
|
"""
|
|
162
163
|
email = entry.get("email")
|
|
163
164
|
preferred_username = entry.get("preferred_username")
|
|
@@ -179,18 +180,38 @@ def _admin_user_from_jsonable(entry: dict) -> str:
|
|
|
179
180
|
return json_path
|
|
180
181
|
|
|
181
182
|
|
|
182
|
-
def _admin_users_from_jsonable(data) -> list[str]:
|
|
183
|
+
def _admin_users_from_jsonable(data, the_console) -> list[str]:
|
|
183
184
|
"""Translate the JSON-serializable shape back to a list of json_paths.
|
|
184
185
|
|
|
185
186
|
Returns an empty list for a 'null' document or one with no entries.
|
|
186
187
|
"""
|
|
187
188
|
if data is None:
|
|
188
189
|
return []
|
|
189
|
-
|
|
190
|
+
json_paths = [
|
|
190
191
|
_admin_user_from_jsonable(entry)
|
|
191
192
|
for entry in data.get("admin_users", ())
|
|
192
193
|
]
|
|
193
194
|
|
|
195
|
+
bad_entries = []
|
|
196
|
+
for i_entry, json_path in enumerate(json_paths):
|
|
197
|
+
try:
|
|
198
|
+
authz.validate_json_path(json_path)
|
|
199
|
+
except authz.InvalidJSONPath:
|
|
200
|
+
bad_entries.append((i_entry, "invalid", json_path))
|
|
201
|
+
continue
|
|
202
|
+
else:
|
|
203
|
+
probe = authz.null_claims_match(json_path)
|
|
204
|
+
if probe is not None:
|
|
205
|
+
bad_entries.append((i_entry, "matches null", json_path))
|
|
206
|
+
|
|
207
|
+
if bad_entries:
|
|
208
|
+
the_console.rule("Invalid JSONPaths")
|
|
209
|
+
for i_entry, reason, entry in bad_entries:
|
|
210
|
+
the_console.print(f"entry {i_entry}: {reason} {entry}")
|
|
211
|
+
raise typer.Exit(1)
|
|
212
|
+
|
|
213
|
+
return json_paths
|
|
214
|
+
|
|
194
215
|
|
|
195
216
|
def _check_admin_user_args(
|
|
196
217
|
installation_path: pathlib.Path,
|
|
@@ -268,6 +289,9 @@ def _human_dump_check_result(result): # pragma NO COVER UI ONLY
|
|
|
268
289
|
the_console.rule(verdict)
|
|
269
290
|
the_console.print(f"Subject: {result['sub']}")
|
|
270
291
|
|
|
292
|
+
if not result["is_admin"]:
|
|
293
|
+
the_console.print("Perhaps run 'soliplex-cli audit admin-users'?")
|
|
294
|
+
|
|
271
295
|
|
|
272
296
|
def _dump_check_result(result): # pragma NO COVER UI ONLY
|
|
273
297
|
print(json.dumps(result))
|
|
@@ -349,26 +373,16 @@ def check_admin_user(
|
|
|
349
373
|
):
|
|
350
374
|
"""Check whether a service token's user is an admin user.
|
|
351
375
|
|
|
352
|
-
Exits 0 if the user is an admin user, else 1
|
|
353
|
-
|
|
376
|
+
Exits 0 if the user is an admin user, else 1. An admin entry whose
|
|
377
|
+
'json_path' no longer compiles never matches.
|
|
354
378
|
"""
|
|
355
379
|
the_installation = cli_util.get_installation(installation_path)
|
|
356
380
|
|
|
357
381
|
claims = service_token.load_token_claims(the_installation, input_path)
|
|
358
382
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
)
|
|
363
|
-
except jsonpath.JSONPathError as exc:
|
|
364
|
-
the_console.rule("Stale admin entry")
|
|
365
|
-
the_console.print(
|
|
366
|
-
f"An admin entry's 'json_path' no longer compiles ({exc}): "
|
|
367
|
-
"find it with 'soliplex-cli audit admin-users', and remove it "
|
|
368
|
-
"with 'soliplex-cli admin-users delete "
|
|
369
|
-
"--allow-invalid-json-path'."
|
|
370
|
-
)
|
|
371
|
-
raise typer.Exit(1) from None
|
|
383
|
+
is_admin = asyncio.run(
|
|
384
|
+
_is_admin(the_installation, "admin-users check", claims)
|
|
385
|
+
)
|
|
372
386
|
_dump_check(ctx, _check_result_as_jsonable(claims, is_admin))
|
|
373
387
|
|
|
374
388
|
if not is_admin:
|
|
@@ -587,7 +601,10 @@ def admin_users_from_yaml(
|
|
|
587
601
|
else:
|
|
588
602
|
yaml_text = sys.stdin.read()
|
|
589
603
|
|
|
590
|
-
json_paths = _admin_users_from_jsonable(
|
|
604
|
+
json_paths = _admin_users_from_jsonable(
|
|
605
|
+
yaml.safe_load(yaml_text),
|
|
606
|
+
the_console,
|
|
607
|
+
)
|
|
591
608
|
|
|
592
609
|
asyncio.run(
|
|
593
610
|
_replace_discriminators(
|