terp-cli 0.41.0__tar.gz → 0.42.0__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.
- {terp_cli-0.41.0 → terp_cli-0.42.0}/PKG-INFO +9 -9
- {terp_cli-0.41.0 → terp_cli-0.42.0}/pyproject.toml +9 -9
- {terp_cli-0.41.0 → terp_cli-0.42.0}/signer/Dockerfile +2 -2
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/__init__.py +19 -115
- terp_cli-0.42.0/src/terp/cli/_cors_view.py +38 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/access.py +17 -48
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/authz_surface.py +23 -113
- terp_cli-0.42.0/src/terp/cli/guide_capability.py +114 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/guide_deployment.py +5 -3
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_compare.py +38 -2
- terp_cli-0.42.0/src/terp/cli/release/_npm_lock.py +115 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_plan.py +25 -35
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/promote.py +4 -2
- terp_cli-0.41.0/src/terp/cli/authz_changes.py +0 -321
- {terp_cli-0.41.0 → terp_cli-0.42.0}/.gitignore +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/signer/terp-arch-releases.json +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/_appref.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/_engine.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/_output.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/_subjects.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/api_contract.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/api_contract_bounds.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/api_contract_check.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/api_contract_schemas.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/api_contract_shapes.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/apidocs.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/capabilities.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/dependency_audit.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/deploy_safety.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/deployment_adopt.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/deployment_app.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/deployment_check.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/deployment_declare.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/deployment_render.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/dev.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/docker.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/docker_masks.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/envfile.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/envrequired.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/envschema.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/envseams.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/fmt.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/grants.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/guide_passwords.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/heartbeat.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/jobs.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/leases.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/locks.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/module_roles.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/npm_tree.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/openapi.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/outbox.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/ports.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/profiles.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/py.typed +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/__init__.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_common.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_dockerfile.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_git.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_image.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_locks.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_registry.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_render.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/_sandbox.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/build.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/cli.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/dsse.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/gate.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/manifest.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/release/sign.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/reseal.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/reseal_report.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/routes.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/scaffold.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/schema.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/seed.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/service_accounts.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/smoke.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/users.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/verify.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/version.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/workbench.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.42.0}/src/terp/cli/workbench_adopt.py +0 -0
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: terp-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.42.0
|
|
4
4
|
Summary: Terp command-line tool — inspect, scaffolding, migrations, checks, api-docs.
|
|
5
5
|
Project-URL: Repository, https://github.com/AITT-NL/terp-framework
|
|
6
6
|
Project-URL: Changelog, https://github.com/AITT-NL/terp-framework/blob/main/CHANGELOG.md
|
|
7
7
|
License-Expression: Apache-2.0
|
|
8
8
|
Requires-Python: >=3.13
|
|
9
9
|
Requires-Dist: pyyaml>=6.0
|
|
10
|
-
Requires-Dist: terp-arch==0.
|
|
11
|
-
Requires-Dist: terp-core==0.
|
|
12
|
-
Requires-Dist: terp-migrations==0.
|
|
10
|
+
Requires-Dist: terp-arch==0.42.0
|
|
11
|
+
Requires-Dist: terp-core==0.42.0
|
|
12
|
+
Requires-Dist: terp-migrations==0.42.0
|
|
13
13
|
Provides-Extra: jobs
|
|
14
|
-
Requires-Dist: terp-cap-outbox==0.
|
|
15
|
-
Requires-Dist: terp-cap-scheduler-apscheduler==0.
|
|
14
|
+
Requires-Dist: terp-cap-outbox==0.42.0; extra == 'jobs'
|
|
15
|
+
Requires-Dist: terp-cap-scheduler-apscheduler==0.42.0; extra == 'jobs'
|
|
16
16
|
Provides-Extra: release
|
|
17
17
|
Requires-Dist: cryptography>=46; extra == 'release'
|
|
18
18
|
Requires-Dist: packaging>=24; extra == 'release'
|
|
19
|
-
Requires-Dist: terp-cap-egress==0.
|
|
19
|
+
Requires-Dist: terp-cap-egress==0.42.0; extra == 'release'
|
|
20
20
|
Provides-Extra: scheduler
|
|
21
|
-
Requires-Dist: terp-cap-scheduler-apscheduler==0.
|
|
21
|
+
Requires-Dist: terp-cap-scheduler-apscheduler==0.42.0; extra == 'scheduler'
|
|
22
22
|
Provides-Extra: worker
|
|
23
|
-
Requires-Dist: terp-cap-outbox==0.
|
|
23
|
+
Requires-Dist: terp-cap-outbox==0.42.0; extra == 'worker'
|
|
@@ -4,18 +4,18 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "terp-cli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.42.0"
|
|
8
8
|
description = "Terp command-line tool — inspect, scaffolding, migrations, checks, api-docs."
|
|
9
9
|
requires-python = ">=3.13"
|
|
10
10
|
license = "Apache-2.0"
|
|
11
11
|
dependencies = [
|
|
12
|
-
"terp-core==0.
|
|
12
|
+
"terp-core==0.42.0",
|
|
13
13
|
# `terp migrate` delegates to terp-migrations (lazily imported), keeping Alembic
|
|
14
14
|
# off the path for `terp inspect` / `terp guide` while making migrations work.
|
|
15
|
-
"terp-migrations==0.
|
|
15
|
+
"terp-migrations==0.42.0",
|
|
16
16
|
# `terp guide rules` projects the live rule registry; terp-arch is imported lazily
|
|
17
17
|
# (only when that topic is rendered), so it stays off the common `terp guide` path.
|
|
18
|
-
"terp-arch==0.
|
|
18
|
+
"terp-arch==0.42.0",
|
|
19
19
|
# `terp verify --only env-seams` and `terp smoke` read the compose profiles as data
|
|
20
20
|
# (anchors and `<<:` merge keys resolved), so both answer without a Docker daemon or
|
|
21
21
|
# even the `docker` binary. Declared explicitly rather than leant on: every app
|
|
@@ -29,11 +29,11 @@ dependencies = [
|
|
|
29
29
|
# or a scheduler engine into apps that only use inspect/check/migrate. Deployments can select
|
|
30
30
|
# one process role, while `jobs` is the convenient complete jobs-process bundle.
|
|
31
31
|
[project.optional-dependencies]
|
|
32
|
-
worker = ["terp-cap-outbox==0.
|
|
33
|
-
scheduler = ["terp-cap-scheduler-apscheduler==0.
|
|
32
|
+
worker = ["terp-cap-outbox==0.42.0"]
|
|
33
|
+
scheduler = ["terp-cap-scheduler-apscheduler==0.42.0"]
|
|
34
34
|
jobs = [
|
|
35
|
-
"terp-cap-outbox==0.
|
|
36
|
-
"terp-cap-scheduler-apscheduler==0.
|
|
35
|
+
"terp-cap-outbox==0.42.0",
|
|
36
|
+
"terp-cap-scheduler-apscheduler==0.42.0",
|
|
37
37
|
]
|
|
38
38
|
# `terp release` and `terp promote` (ADR 0187): the DSSE signature (cryptography), the lock's
|
|
39
39
|
# markers (packaging), and the one declared way to a registry, an index and the vulnerability
|
|
@@ -42,7 +42,7 @@ jobs = [
|
|
|
42
42
|
release = [
|
|
43
43
|
"cryptography>=46",
|
|
44
44
|
"packaging>=24",
|
|
45
|
-
"terp-cap-egress==0.
|
|
45
|
+
"terp-cap-egress==0.42.0",
|
|
46
46
|
]
|
|
47
47
|
|
|
48
48
|
[project.scripts]
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
# (tests/release_lane/).
|
|
27
27
|
|
|
28
28
|
# python:3.14-slim, the base-image table's interpreter (terp-arch's base-images.json).
|
|
29
|
-
FROM python@sha256:
|
|
29
|
+
FROM python@sha256:9aaa474097d094040649f2162a627c0049b408f52138d980916788d80f04802f AS install
|
|
30
30
|
COPY wheels/ /wheels/
|
|
31
31
|
COPY requirements.txt /requirements.txt
|
|
32
32
|
# Every distribution by its hash: the third-party ones as uv.lock pins them, the framework's as
|
|
@@ -41,7 +41,7 @@ FROM zricethezav/gitleaks@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9a
|
|
|
41
41
|
# The docker client 29.9.2, by digest (docker:29.9.2-cli, read 2026-10-22).
|
|
42
42
|
FROM docker@sha256:5e6baf67325a79f64ed3bed6863954d5e05d0f3d4e57cbdb14809346814bbfdb AS docker
|
|
43
43
|
|
|
44
|
-
FROM python@sha256:
|
|
44
|
+
FROM python@sha256:9aaa474097d094040649f2162a627c0049b408f52138d980916788d80f04802f
|
|
45
45
|
RUN apt-get update \
|
|
46
46
|
&& apt-get install -y --no-install-recommends git \
|
|
47
47
|
&& rm -rf /var/lib/apt/lists/* \
|
|
@@ -11,11 +11,12 @@ import sys
|
|
|
11
11
|
from collections.abc import Callable, Sequence
|
|
12
12
|
from typing import TYPE_CHECKING
|
|
13
13
|
|
|
14
|
-
from terp.core import ControlPlane,
|
|
14
|
+
from terp.core import ControlPlane, ModuleSpec
|
|
15
15
|
|
|
16
16
|
if TYPE_CHECKING: # terp-arch stays off the common `terp guide` / `terp inspect` path
|
|
17
17
|
from terp.arch import ScanRoot
|
|
18
18
|
|
|
19
|
+
from terp.cli._cors_view import cors_json, cors_label
|
|
19
20
|
from terp.cli._output import emit, use_utf8_output
|
|
20
21
|
from terp.cli.access import (
|
|
21
22
|
build_access_graph_for_app,
|
|
@@ -57,7 +58,7 @@ from terp.cli.module_roles import (
|
|
|
57
58
|
module_role_list_command,
|
|
58
59
|
module_role_revoke_command,
|
|
59
60
|
)
|
|
60
|
-
from terp.cli import guide_deployment, guide_passwords
|
|
61
|
+
from terp.cli import guide_capability, guide_deployment, guide_passwords
|
|
61
62
|
from terp.cli.grants import (
|
|
62
63
|
grant_add_command,
|
|
63
64
|
grant_list_command,
|
|
@@ -668,7 +669,7 @@ The access model (three layers) — profiles + the access graph
|
|
|
668
669
|
uv run terp inspect access --app app.main:build --app-root . --format json
|
|
669
670
|
The --app form reports the WHOLE composed surface — client modules AND every
|
|
670
671
|
discovered capability router (users / groups / audit / files / …) plus the kernel
|
|
671
|
-
health routes — reconciled against
|
|
672
|
+
health routes — reconciled against the composed route table so a served route can never hide
|
|
672
673
|
(any that is not covered is listed under omitted_routes, fail-visible). Use
|
|
673
674
|
--object/--module instead to inspect a focused, hand-passed subset.
|
|
674
675
|
One document: roles, permissions, every endpoint's method/path/requirement, each
|
|
@@ -909,16 +910,16 @@ Boundaries for a second top-level package (an ungated worker)
|
|
|
909
910
|
- WHAT THE COMPANION IS HELD TO, and what it is not. A companion root gets the rules whose
|
|
910
911
|
invariant holds for any Python that ships — `no_hardcoded_credentials`, `no_dynamic_sql`,
|
|
911
912
|
`no_raw_outbound_http`, `no_adhoc_config_decrypt`, `no_internal_imports`, `no_print`,
|
|
912
|
-
`no_naive_datetime`, `no_eval_or_exec`, `
|
|
913
|
-
`no_mutable_default_args`, `no_todo_fixme`, `
|
|
914
|
-
`
|
|
913
|
+
`no_naive_datetime`, `no_eval_or_exec`, `no_framework_patching`, `no_star_imports`,
|
|
914
|
+
`no_blocking_sleep`, `no_mutable_default_args`, `no_todo_fixme`, `no_empty_tests`,
|
|
915
|
+
`no_oversized_python_files`, `no_manual_table_schema`, `frozen_values_hold_no_mutable_collection`
|
|
915
916
|
and `request_timestamps_carry_their_offset`, since a worker that reads another system's
|
|
916
917
|
timestamps through a schema is held to their offset just as the app is.
|
|
917
918
|
It does NOT get the rules that are properties of being a mounted app: a route's response
|
|
918
919
|
model, a module's policy, a table's migration, the guarded session (ADR 0141). The check
|
|
919
920
|
report says which, per root, under `roots` — so a green over the companion names the
|
|
920
921
|
rules it is green about, and is a claim you can publish.
|
|
921
|
-
Expect the first declared run to be red.
|
|
922
|
+
Expect the first declared run to be red. Eighteen rules arriving at once over a package
|
|
922
923
|
nothing has ever scanned will find things; they were violations all along.
|
|
923
924
|
- WHAT A HAND-WRITTEN TEST IS STILL FOR. Not `no_dynamic_sql` or `no_print` — those now
|
|
924
925
|
reach the second package, and a bespoke AST scan beside them is a weaker copy that has
|
|
@@ -1178,12 +1179,17 @@ The security declaration (SecurityConfig, refused at production boot)
|
|
|
1178
1179
|
- FOUR of its states refuse a production boot (SecurityConfig.production_problems();
|
|
1179
1180
|
create_app raises BootError "insecure production security config"). Each has exactly
|
|
1180
1181
|
one declaration that answers it:
|
|
1181
|
-
1. CORS unset -> CorsPolicy.allow([...]) or
|
|
1182
|
+
1. CORS unset -> CorsPolicy.from_environment(), .allow([...]) or .disabled(reason=...)
|
|
1182
1183
|
2. CORS allowing '*' -> name the origins; a wildcard with credentials is no origin check
|
|
1183
1184
|
3. rate_limit disabled -> RateLimit(requests=..., window_seconds=...)
|
|
1184
1185
|
4. an override disabled -> an override may LOWER or RAISE a limit, never remove it
|
|
1185
1186
|
Declining is a full answer and must be said out loud: CorsPolicy.disabled(reason=...)
|
|
1186
1187
|
is the same-origin deployment's answer, and the reason is the point of it.
|
|
1188
|
+
Which browser origins may call the API is a fact of an environment, not of the source:
|
|
1189
|
+
CorsPolicy.from_environment() takes the allowlist from BACKEND_CORS_ORIGINS when the app
|
|
1190
|
+
is composed (ADR 0210). An environment that names none serves no cross-origin access; an
|
|
1191
|
+
entry that is not an origin (a path, a trailing slash, '*') refuses the boot. Without
|
|
1192
|
+
that declaration the variable opens nothing, and a boot that finds it set says so.
|
|
1187
1193
|
`terp verify --only production-readiness` asks these before you ship, so the refusal
|
|
1188
1194
|
arrives in the gate rather than at the deploy.
|
|
1189
1195
|
- rate_limit_overrides is a PER-PREFIX BUCKET, not a shared counter (ADR 0115):
|
|
@@ -1885,88 +1891,7 @@ File objects (files capability, ADR 0056/0057)
|
|
|
1885
1891
|
add it to the profile and to the volume's "mount": {"units": [...]}. A store behind
|
|
1886
1892
|
another adapter needs no volume. `terp guide deployment` has the rest.
|
|
1887
1893
|
""",
|
|
1888
|
-
"capability":
|
|
1889
|
-
Using capabilities
|
|
1890
|
-
|
|
1891
|
-
- Capabilities are opt-in packages (terp-cap-*). Every scaffolded app already has the
|
|
1892
|
-
BASE PROFILE — auth, identity, users, groups, access, audit — so authentication,
|
|
1893
|
-
accounts, group membership, permission checks and the audit trail are wired before you
|
|
1894
|
-
write anything. Install the others you need.
|
|
1895
|
-
- WHO IS CALLING, in words a person reads: take `caller: CallerDep` on the route.
|
|
1896
|
-
from terp.capabilities.identity import CallerDep
|
|
1897
|
-
def pause(name: str, caller: CallerDep, session: SessionDep) -> None:
|
|
1898
|
-
service.pause(session, name, decided_by=caller.name)
|
|
1899
|
-
`caller.name` is a user's email or a service account's name, read from the live row;
|
|
1900
|
-
`caller.id` is the key to store when a record must point at who did it. Never take a
|
|
1901
|
-
"decided by" from the request body (it is whatever the client says), and never build
|
|
1902
|
-
an IdentityService inside a module to look the caller up.
|
|
1903
|
-
- SEE WHAT EXISTS BEFORE YOU BUILD IT:
|
|
1904
|
-
terp inspect capabilities
|
|
1905
|
-
lists every maintained capability, whether this app already has it, the exact
|
|
1906
|
-
`uv add` line and the composition-root wiring it expects. For a capability you
|
|
1907
|
-
ALREADY have it also prints `not used here`: wiring points the package exports and
|
|
1908
|
-
your source never mentions. That line exists because an installed capability looks
|
|
1909
|
-
finished -- so a seam it grows in a later release is invisible from inside the
|
|
1910
|
-
project, and at a release every day or two nobody reads the changelog delta. Most
|
|
1911
|
-
of what it lists are alternatives you correctly did not take; it is information,
|
|
1912
|
-
not a finding. Durable delivery, realtime
|
|
1913
|
-
push, tenancy, files, webhooks, scheduling and shared multi-replica state are all
|
|
1914
|
-
already solved — hand-rolling one of them is a defect, not a shortcut.
|
|
1915
|
-
- A routed capability self-registers: create_app(specs, discover_capabilities=True)
|
|
1916
|
-
mounts it at /api/v1/<name> via its entry point — no composition-root edit.
|
|
1917
|
-
- A library capability (tenancy, eventbus) ships no router; you import and wire it
|
|
1918
|
-
(a mixin/service, a dispatcher) where needed.
|
|
1919
|
-
- Compose the app once:
|
|
1920
|
-
create_app(specs, principal_provider=..., control_plane=...,
|
|
1921
|
-
audit_sink=persist_audit, event_dispatcher=dispatch_in_process,
|
|
1922
|
-
permission_enforcer=enforce_permission, discover_capabilities=True)
|
|
1923
|
-
- You can always drop to native FastAPI/SQLModel — the same gate rules still apply.
|
|
1924
|
-
- Outbound HTTP is a capability concern, never a module concern: importing httpx /
|
|
1925
|
-
httpx2 / requests / urllib.request / urllib3 / aiohttp in a module is refused by the
|
|
1926
|
-
no_raw_outbound_http rule — SSRF protection, egress allowlists and timeout policy
|
|
1927
|
-
belong behind one declared capability, not scattered per call site. That capability
|
|
1928
|
-
is `terp-cap-egress`, and it is a declaration rather than a client you configure at
|
|
1929
|
-
the call site:
|
|
1930
|
-
from terp.capabilities.egress import EgressClient, EgressPolicy
|
|
1931
|
-
rates = EgressClient(EgressPolicy(
|
|
1932
|
-
allowed_hosts=("api.exchange.example",), # EXACT hosts; empty permits nothing
|
|
1933
|
-
timeout_seconds=5.0, # no per-call override, on purpose
|
|
1934
|
-
))
|
|
1935
|
-
body = rates.get("https://api.exchange.example/v1/rates").content
|
|
1936
|
-
Every resolved address is checked against the SSRF denylist and the connection is
|
|
1937
|
-
PINNED to the one that passed (so a rebind between the check and the connect cannot
|
|
1938
|
-
land on a private address), redirects are never followed, and every attempt —
|
|
1939
|
-
refusals included — reaches the optional `observer=` hook, which is where metering
|
|
1940
|
-
and egress auditing attach. A sanctioned internal target is a declared
|
|
1941
|
-
`allow_private_addresses=True`, visible in the composition root, never a quiet
|
|
1942
|
-
exception inside the client.
|
|
1943
|
-
- A vendor SDK builds its own HTTP client, so neither the rule (it reads YOUR imports)
|
|
1944
|
-
nor EgressClient sees its traffic. Hold the whole process to the declaration at the
|
|
1945
|
-
socket, in the composition root the web process and the worker both run:
|
|
1946
|
-
install_egress_guard(EgressGuard.for_policies(
|
|
1947
|
-
rates_policy, # every EgressPolicy you declared
|
|
1948
|
-
hosts=("api.vendor.example",), # what an SDK calls, by exact name
|
|
1949
|
-
infrastructure=("db", "redis", "smtp.relay.internal"), # names, IPs or CIDRs
|
|
1950
|
-
))
|
|
1951
|
-
It holds what goes through Python's socket module on IPv4/IPv6, whichever library
|
|
1952
|
-
calls it: a lookup of an undeclared name (getaddrinfo, gethostbyname) is refused
|
|
1953
|
-
before it is made, and a connect or datagram into a private / loopback / link-local /
|
|
1954
|
-
metadata range is refused unless it is declared infrastructure; a peer given by name
|
|
1955
|
-
(localhost too) is resolved and every address held. The refusal is EgressRefusedError
|
|
1956
|
-
(502); under an async client it can arrive inside an ExceptionGroup. It cannot see
|
|
1957
|
-
uvloop, so it refuses to install beside it and refuses `import uvloop` after it: run
|
|
1958
|
-
uvicorn with --loop asyncio (uvicorn[standard] picks uvloop otherwise), and a worker
|
|
1959
|
-
or scheduler with asyncio.run. Native drivers that open their own sockets (libpq,
|
|
1960
|
-
gRPC's C core) are invisible to it and a public IP literal passes; the deployment's
|
|
1961
|
-
network policy holds those. Built for Linux: on Windows asyncio's socketpair connects
|
|
1962
|
-
to loopback, so a new event loop is refused unless loopback is declared.
|
|
1963
|
-
- Credentials never live in module source: a credential-shaped assignment (password,
|
|
1964
|
-
api_key, token, ...) to a string literal — or a recognizable secret-token literal
|
|
1965
|
-
anywhere — is refused by the no_hardcoded_credentials rule. Wire secrets through
|
|
1966
|
-
settings / sealed config (ADR 0055), never source.
|
|
1967
|
-
- Sending e-mail is a capability too: `import smtplib` is refused by the same
|
|
1968
|
-
no_raw_outbound_http rule, and terp-cap-mail is where it goes — `terp guide mail`.
|
|
1969
|
-
""",
|
|
1894
|
+
"capability": guide_capability.TOPIC,
|
|
1970
1895
|
"mail": """\
|
|
1971
1896
|
Sending e-mail (terp-cap-mail)
|
|
1972
1897
|
|
|
@@ -3460,7 +3385,7 @@ def inspect_access(
|
|
|
3460
3385
|
|
|
3461
3386
|
With ``app`` (a FastAPI instance or zero-arg factory, e.g. ``app.main:build``) the
|
|
3462
3387
|
graph covers the WHOLE composed surface — every discovered capability router and the
|
|
3463
|
-
kernel routes — reconciled against
|
|
3388
|
+
kernel routes — reconciled against the composed route table so no served route can hide.
|
|
3464
3389
|
Without it, the focused form reports just the hand-passed ``modules``.
|
|
3465
3390
|
|
|
3466
3391
|
The three-layer view — module policy, per-endpoint requirement, and the data
|
|
@@ -3570,7 +3495,7 @@ def _render_json(plane: ControlPlane, specs: Sequence[ModuleSpec]) -> str:
|
|
|
3570
3495
|
"relaxed_reason": plane.passwords.relaxed_reason,
|
|
3571
3496
|
},
|
|
3572
3497
|
"security": {
|
|
3573
|
-
"cors":
|
|
3498
|
+
"cors": cors_json(plane.security.cors),
|
|
3574
3499
|
"rate_limit": {
|
|
3575
3500
|
"enabled": plane.security.rate_limit.enabled,
|
|
3576
3501
|
"requests": plane.security.rate_limit.requests,
|
|
@@ -3596,19 +3521,6 @@ def _render_json(plane: ControlPlane, specs: Sequence[ModuleSpec]) -> str:
|
|
|
3596
3521
|
return json.dumps(payload, indent=2)
|
|
3597
3522
|
|
|
3598
3523
|
|
|
3599
|
-
def _cors_json(cors: CorsPolicy) -> dict[str, object]:
|
|
3600
|
-
"""The CORS declaration as one of three explicit modes (never raw fields)."""
|
|
3601
|
-
if cors.disabled_reason is not None:
|
|
3602
|
-
return {"mode": "disabled", "reason": cors.disabled_reason}
|
|
3603
|
-
if cors.allow_origins:
|
|
3604
|
-
return {
|
|
3605
|
-
"mode": "allow",
|
|
3606
|
-
"origins": list(cors.allow_origins),
|
|
3607
|
-
"allow_credentials": cors.allow_credentials,
|
|
3608
|
-
}
|
|
3609
|
-
return {"mode": "deny-all", "configured": cors.configured}
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
3524
|
def _module_json(spec: ModuleSpec) -> dict[str, object]:
|
|
3613
3525
|
policy: dict[str, object] | None = None
|
|
3614
3526
|
if spec.policy is not None:
|
|
@@ -3674,7 +3586,7 @@ def _render_text(plane: ControlPlane, specs: Sequence[ModuleSpec]) -> str:
|
|
|
3674
3586
|
lines.append(password_line)
|
|
3675
3587
|
lines.append("")
|
|
3676
3588
|
lines.append("Security")
|
|
3677
|
-
lines.append(f" cors {
|
|
3589
|
+
lines.append(f" cors {cors_label(plane.security.cors)}")
|
|
3678
3590
|
rate_limit = plane.security.rate_limit
|
|
3679
3591
|
lines.append(
|
|
3680
3592
|
" rate_limit "
|
|
@@ -3700,14 +3612,6 @@ def _render_text(plane: ControlPlane, specs: Sequence[ModuleSpec]) -> str:
|
|
|
3700
3612
|
return "\n".join(lines)
|
|
3701
3613
|
|
|
3702
3614
|
|
|
3703
|
-
def _cors_label(cors: CorsPolicy) -> str:
|
|
3704
|
-
if cors.disabled_reason is not None:
|
|
3705
|
-
return f"disabled ({cors.disabled_reason})"
|
|
3706
|
-
if cors.allow_origins:
|
|
3707
|
-
return "allow " + ", ".join(cors.allow_origins)
|
|
3708
|
-
return "deny-all" + ("" if cors.configured else " (unconfigured)")
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
3615
|
def _policy_label(spec: ModuleSpec) -> str:
|
|
3712
3616
|
if spec.policy is None:
|
|
3713
3617
|
return "policy=<missing>"
|
|
@@ -3842,7 +3746,7 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
3842
3746
|
"--app",
|
|
3843
3747
|
default=None,
|
|
3844
3748
|
help="Composed FastAPI app or factory (e.g. app.main:build): report the WHOLE "
|
|
3845
|
-
"mounted surface incl. discovered capabilities, reconciled against
|
|
3749
|
+
"mounted surface incl. discovered capabilities, reconciled against the route table",
|
|
3846
3750
|
)
|
|
3847
3751
|
access_parser.add_argument(
|
|
3848
3752
|
"--app-root",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""The CORS declaration as ``terp inspect control-plane`` shows it: one explicit mode."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from terp.core import CorsPolicy
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def cors_json(cors: CorsPolicy) -> dict[str, object]:
|
|
9
|
+
"""The CORS declaration as one of four explicit modes (never raw fields)."""
|
|
10
|
+
if cors.disabled_reason is not None:
|
|
11
|
+
return {"mode": "disabled", "reason": cors.disabled_reason}
|
|
12
|
+
if cors.origins_from_environment:
|
|
13
|
+
# The origins are each environment's own: what is listed is what this process
|
|
14
|
+
# was composed with, so a plane inspected before create_app lists none.
|
|
15
|
+
return {
|
|
16
|
+
"mode": "from-environment",
|
|
17
|
+
"variable": "BACKEND_CORS_ORIGINS",
|
|
18
|
+
"origins": list(cors.allow_origins),
|
|
19
|
+
"allow_credentials": cors.allow_credentials,
|
|
20
|
+
}
|
|
21
|
+
if cors.allow_origins:
|
|
22
|
+
return {
|
|
23
|
+
"mode": "allow",
|
|
24
|
+
"origins": list(cors.allow_origins),
|
|
25
|
+
"allow_credentials": cors.allow_credentials,
|
|
26
|
+
}
|
|
27
|
+
return {"mode": "deny-all", "configured": cors.configured}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def cors_label(cors: CorsPolicy) -> str:
|
|
31
|
+
if cors.disabled_reason is not None:
|
|
32
|
+
return f"disabled ({cors.disabled_reason})"
|
|
33
|
+
if cors.origins_from_environment:
|
|
34
|
+
named = ", ".join(cors.allow_origins) or "none named here"
|
|
35
|
+
return f"from BACKEND_CORS_ORIGINS ({named})"
|
|
36
|
+
if cors.allow_origins:
|
|
37
|
+
return "allow " + ", ".join(cors.allow_origins)
|
|
38
|
+
return "deny-all" + ("" if cors.configured else " (unconfigured)")
|
|
@@ -41,21 +41,16 @@ from terp.core import (
|
|
|
41
41
|
SoftDeleteMixin,
|
|
42
42
|
)
|
|
43
43
|
from terp.core.authz import build_access_model
|
|
44
|
+
from terp.core.authz_surface import (
|
|
45
|
+
API_PREFIX,
|
|
46
|
+
render_authz_surface,
|
|
47
|
+
served_routes,
|
|
48
|
+
unplaced_routes,
|
|
49
|
+
)
|
|
44
50
|
from terp.core.object_authz import registered_object_authz_predicates
|
|
45
51
|
from terp.core.scoping import registered_scope_predicates
|
|
46
52
|
|
|
47
53
|
|
|
48
|
-
# Every module mounts under this prefix (``create_app``); a served path outside it is a
|
|
49
|
-
# kernel / open route (e.g. health), not part of any module's policy surface.
|
|
50
|
-
_API_PREFIX = "/api/v1/"
|
|
51
|
-
|
|
52
|
-
# OpenAPI path-item keys that are HTTP operations (the rest are metadata such as
|
|
53
|
-
# ``parameters`` / ``summary``) — used to read the served methods for each path.
|
|
54
|
-
_HTTP_METHODS = frozenset(
|
|
55
|
-
{"get", "put", "post", "delete", "options", "head", "patch", "trace"}
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
|
|
59
54
|
def _mro_names(model: type) -> set[str]:
|
|
60
55
|
return {klass.__name__ for klass in model.__mro__}
|
|
61
56
|
|
|
@@ -201,25 +196,8 @@ def _undeclared_subscriber_alarms(specs: Sequence[ModuleSpec]) -> list[dict[str,
|
|
|
201
196
|
]
|
|
202
197
|
|
|
203
198
|
|
|
204
|
-
def _served_routes(app: FastAPI) -> dict[str, frozenset[str]]:
|
|
205
|
-
"""Every path the composed app serves -> its HTTP methods, from ``app.openapi()``.
|
|
206
|
-
|
|
207
|
-
``app.openapi()`` is the same document ``terp openapi`` exports and FastAPI serves,
|
|
208
|
-
so it is the authoritative, full-path route table — client module routers, every
|
|
209
|
-
discovered capability router, and the kernel health routes — the ground truth the
|
|
210
|
-
access graph is reconciled against.
|
|
211
|
-
"""
|
|
212
|
-
paths: dict[str, object] = app.openapi().get("paths", {})
|
|
213
|
-
return {
|
|
214
|
-
path: frozenset(
|
|
215
|
-
method.upper() for method in item if method.lower() in _HTTP_METHODS
|
|
216
|
-
)
|
|
217
|
-
for path, item in paths.items()
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
199
|
def _schema_hidden_routes(app: FastAPI) -> list[dict[str, object]]:
|
|
222
|
-
"""Reachable top-level routes
|
|
200
|
+
"""Reachable top-level routes that are no API route — still reported.
|
|
223
201
|
|
|
224
202
|
FastAPI's own docs/schema endpoints (``/openapi.json`` / ``/docs`` / ``/redoc``,
|
|
225
203
|
plain starlette ``Route``s with ``include_in_schema=False``) and any ``app.mount()``
|
|
@@ -229,7 +207,7 @@ def _schema_hidden_routes(app: FastAPI) -> list[dict[str, object]]:
|
|
|
229
207
|
hidden: list[dict[str, object]] = []
|
|
230
208
|
for route in app.routes:
|
|
231
209
|
if isinstance(route, APIRoute):
|
|
232
|
-
continue # schema
|
|
210
|
+
continue # an API route: listed by served_routes, in the schema or not
|
|
233
211
|
if isinstance(route, Mount):
|
|
234
212
|
hidden.append(
|
|
235
213
|
{
|
|
@@ -256,7 +234,8 @@ def build_access_graph_for_app(app: FastAPI) -> dict[str, object]:
|
|
|
256
234
|
``create_app`` records the specs it mounted (client modules AND every discovered
|
|
257
235
|
capability router) and its control plane on ``app.state``; this reads them back so
|
|
258
236
|
the graph covers routes a hand-passed ``--module`` list would miss. It then
|
|
259
|
-
reconciles the graph against
|
|
237
|
+
reconciles the graph against the composed route table (the ground truth, which holds
|
|
238
|
+
a route the OpenAPI document was told to leave out): every served
|
|
260
239
|
``/api/v1`` method must map to a module endpoint — any that does not is reported
|
|
261
240
|
under ``omitted_routes`` (fail-visible, so a mounted route can never hide) — and the
|
|
262
241
|
served routes outside ``/api/v1`` (the unauthenticated kernel health routes), the
|
|
@@ -270,7 +249,7 @@ def build_access_graph_for_app(app: FastAPI) -> dict[str, object]:
|
|
|
270
249
|
"app was not composed by terp.core.create_app (no access-graph state on "
|
|
271
250
|
"app.state) — pass a terp app factory, e.g. --app app.main:build"
|
|
272
251
|
)
|
|
273
|
-
served =
|
|
252
|
+
served = served_routes(app)
|
|
274
253
|
kernel_routes: list[dict[str, object]] = [
|
|
275
254
|
{
|
|
276
255
|
"path": path,
|
|
@@ -286,7 +265,7 @@ def build_access_graph_for_app(app: FastAPI) -> dict[str, object]:
|
|
|
286
265
|
"note": "unauthenticated kernel route (no module policy, no operation)",
|
|
287
266
|
}
|
|
288
267
|
for path, methods in sorted(served.items())
|
|
289
|
-
if not path.startswith(
|
|
268
|
+
if not path.startswith(API_PREFIX)
|
|
290
269
|
]
|
|
291
270
|
kernel_routes.extend(_schema_hidden_routes(app))
|
|
292
271
|
graph = build_access_graph(
|
|
@@ -295,19 +274,11 @@ def build_access_graph_for_app(app: FastAPI) -> dict[str, object]:
|
|
|
295
274
|
kernel_routes=kernel_routes,
|
|
296
275
|
undeclared_subscribers=_undeclared_subscriber_alarms(specs),
|
|
297
276
|
)
|
|
298
|
-
|
|
277
|
+
# Every served ``/api/v1`` method must map to a module endpoint; one that does not is
|
|
278
|
+
# a route the record cannot hold, which the surface check and the app's own startup
|
|
279
|
+
# check both refuse (:func:`terp.core.authz_surface.unplaced_routes`).
|
|
299
280
|
modules: list = graph["modules"] # type: ignore[assignment]
|
|
300
|
-
|
|
301
|
-
for endpoint in module["endpoints"]:
|
|
302
|
-
covered.setdefault(endpoint["path"], set()).update(endpoint["methods"])
|
|
303
|
-
omitted: list[dict[str, object]] = []
|
|
304
|
-
for path, methods in sorted(served.items()):
|
|
305
|
-
if not path.startswith(_API_PREFIX):
|
|
306
|
-
continue
|
|
307
|
-
missing = sorted(methods - covered.get(path, set()))
|
|
308
|
-
if missing:
|
|
309
|
-
omitted.append({"path": path, "methods": missing})
|
|
310
|
-
graph["omitted_routes"] = omitted
|
|
281
|
+
graph["omitted_routes"] = unplaced_routes(served, modules)
|
|
311
282
|
return graph
|
|
312
283
|
|
|
313
284
|
|
|
@@ -405,12 +376,10 @@ def render_access_graph(graph: dict[str, object], fmt: str = "text") -> str:
|
|
|
405
376
|
"""Render a prebuilt access *graph* as ``text``, ``json`` or ``surface``.
|
|
406
377
|
|
|
407
378
|
``surface`` is the authority baseline the ``authz-surface`` verify check pins
|
|
408
|
-
(:mod:`terp.
|
|
379
|
+
(:mod:`terp.core.authz_surface`): the same projection reduced to what is an
|
|
409
380
|
authority claim, sorted at every level so the committed file is diffable.
|
|
410
381
|
"""
|
|
411
382
|
if fmt == "surface":
|
|
412
|
-
from terp.cli.authz_surface import render_authz_surface
|
|
413
|
-
|
|
414
383
|
return render_authz_surface(graph)
|
|
415
384
|
if fmt == "json":
|
|
416
385
|
return json.dumps(graph, indent=2)
|