terp-cli 0.41.0__tar.gz → 0.41.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.
- {terp_cli-0.41.0 → terp_cli-0.41.1}/PKG-INFO +9 -9
- {terp_cli-0.41.0 → terp_cli-0.41.1}/pyproject.toml +9 -9
- {terp_cli-0.41.0 → terp_cli-0.41.1}/signer/Dockerfile +2 -2
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/__init__.py +15 -111
- terp_cli-0.41.1/src/terp/cli/_cors_view.py +38 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/access.py +48 -29
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/authz_surface.py +9 -5
- terp_cli-0.41.1/src/terp/cli/guide_capability.py +100 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/guide_deployment.py +5 -3
- terp_cli-0.41.1/src/terp/cli/release/_npm_lock.py +115 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_plan.py +25 -35
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/promote.py +4 -2
- {terp_cli-0.41.0 → terp_cli-0.41.1}/.gitignore +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/signer/terp-arch-releases.json +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/_appref.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/_engine.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/_output.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/_subjects.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/api_contract.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/api_contract_bounds.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/api_contract_check.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/api_contract_schemas.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/api_contract_shapes.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/apidocs.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/authz_changes.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/capabilities.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/dependency_audit.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/deploy_safety.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/deployment_adopt.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/deployment_app.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/deployment_check.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/deployment_declare.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/deployment_render.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/dev.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/docker.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/docker_masks.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/envfile.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/envrequired.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/envschema.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/envseams.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/fmt.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/grants.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/guide_passwords.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/heartbeat.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/jobs.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/leases.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/locks.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/module_roles.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/npm_tree.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/openapi.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/outbox.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/ports.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/profiles.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/py.typed +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/__init__.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_common.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_compare.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_dockerfile.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_git.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_image.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_locks.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_registry.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_render.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/_sandbox.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/build.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/cli.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/dsse.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/gate.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/manifest.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/release/sign.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/reseal.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/reseal_report.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/routes.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/scaffold.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/schema.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/seed.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/service_accounts.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/smoke.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/users.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/verify.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/version.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/src/terp/cli/workbench.py +0 -0
- {terp_cli-0.41.0 → terp_cli-0.41.1}/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.41.
|
|
3
|
+
Version: 0.41.1
|
|
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.41.
|
|
11
|
-
Requires-Dist: terp-core==0.41.
|
|
12
|
-
Requires-Dist: terp-migrations==0.41.
|
|
10
|
+
Requires-Dist: terp-arch==0.41.1
|
|
11
|
+
Requires-Dist: terp-core==0.41.1
|
|
12
|
+
Requires-Dist: terp-migrations==0.41.1
|
|
13
13
|
Provides-Extra: jobs
|
|
14
|
-
Requires-Dist: terp-cap-outbox==0.41.
|
|
15
|
-
Requires-Dist: terp-cap-scheduler-apscheduler==0.41.
|
|
14
|
+
Requires-Dist: terp-cap-outbox==0.41.1; extra == 'jobs'
|
|
15
|
+
Requires-Dist: terp-cap-scheduler-apscheduler==0.41.1; 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.41.
|
|
19
|
+
Requires-Dist: terp-cap-egress==0.41.1; extra == 'release'
|
|
20
20
|
Provides-Extra: scheduler
|
|
21
|
-
Requires-Dist: terp-cap-scheduler-apscheduler==0.41.
|
|
21
|
+
Requires-Dist: terp-cap-scheduler-apscheduler==0.41.1; extra == 'scheduler'
|
|
22
22
|
Provides-Extra: worker
|
|
23
|
-
Requires-Dist: terp-cap-outbox==0.41.
|
|
23
|
+
Requires-Dist: terp-cap-outbox==0.41.1; extra == 'worker'
|
|
@@ -4,18 +4,18 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "terp-cli"
|
|
7
|
-
version = "0.41.
|
|
7
|
+
version = "0.41.1"
|
|
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.41.
|
|
12
|
+
"terp-core==0.41.1",
|
|
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.41.
|
|
15
|
+
"terp-migrations==0.41.1",
|
|
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.41.
|
|
18
|
+
"terp-arch==0.41.1",
|
|
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.41.
|
|
33
|
-
scheduler = ["terp-cap-scheduler-apscheduler==0.41.
|
|
32
|
+
worker = ["terp-cap-outbox==0.41.1"]
|
|
33
|
+
scheduler = ["terp-cap-scheduler-apscheduler==0.41.1"]
|
|
34
34
|
jobs = [
|
|
35
|
-
"terp-cap-outbox==0.41.
|
|
36
|
-
"terp-cap-scheduler-apscheduler==0.41.
|
|
35
|
+
"terp-cap-outbox==0.41.1",
|
|
36
|
+
"terp-cap-scheduler-apscheduler==0.41.1",
|
|
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.41.
|
|
45
|
+
"terp-cap-egress==0.41.1",
|
|
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
|
|
@@ -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)")
|
|
@@ -30,8 +30,8 @@ import json
|
|
|
30
30
|
from collections.abc import Sequence
|
|
31
31
|
|
|
32
32
|
from fastapi import FastAPI
|
|
33
|
-
from fastapi.routing import APIRoute
|
|
34
|
-
from starlette.routing import Mount, Route
|
|
33
|
+
from fastapi.routing import APIRoute, APIWebSocketRoute, iter_route_contexts
|
|
34
|
+
from starlette.routing import Mount, Route, WebSocketRoute
|
|
35
35
|
|
|
36
36
|
from terp.core import (
|
|
37
37
|
ActorStampedMixin,
|
|
@@ -49,13 +49,6 @@ from terp.core.scoping import registered_scope_predicates
|
|
|
49
49
|
# kernel / open route (e.g. health), not part of any module's policy surface.
|
|
50
50
|
_API_PREFIX = "/api/v1/"
|
|
51
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
52
|
def _mro_names(model: type) -> set[str]:
|
|
60
53
|
return {klass.__name__ for klass in model.__mro__}
|
|
61
54
|
|
|
@@ -201,25 +194,46 @@ def _undeclared_subscriber_alarms(specs: Sequence[ModuleSpec]) -> list[dict[str,
|
|
|
201
194
|
]
|
|
202
195
|
|
|
203
196
|
|
|
204
|
-
|
|
205
|
-
|
|
197
|
+
#: What a served WebSocket route is listed under: it has no HTTP method after the upgrade.
|
|
198
|
+
_WEBSOCKET = "WS"
|
|
199
|
+
|
|
206
200
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
201
|
+
def _served_routes(app: FastAPI) -> dict[str, frozenset[str]]:
|
|
202
|
+
"""Every path the composed app serves -> its HTTP methods, from the route table itself.
|
|
203
|
+
|
|
204
|
+
The table the router answers from, walked through every included router at the path
|
|
205
|
+
each route is really served under (``iter_route_contexts``, which FastAPI's own schema
|
|
206
|
+
generation walks). It used to be ``app.openapi()``, and a route declared with
|
|
207
|
+
``include_in_schema=False`` is not in that document: one on a router included inside
|
|
208
|
+
a module's router was served, was in no module's endpoints, and was reconciled
|
|
209
|
+
against a document that did not list it, so nothing reported it. A WebSocket route,
|
|
210
|
+
which the document never lists, is in the table too, under :data:`_WEBSOCKET`.
|
|
211
|
+
|
|
212
|
+
Outside ``/api/v1`` only an ``APIRoute`` is listed here: the plain routes and the
|
|
213
|
+
mounts there are :func:`_schema_hidden_routes`'s, reported with their own note.
|
|
211
214
|
"""
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
served: dict[str, set[str]] = {}
|
|
216
|
+
for context in iter_route_contexts(app.routes):
|
|
217
|
+
route = context.original_route
|
|
218
|
+
path = context.path or ""
|
|
219
|
+
if isinstance(route, APIRoute):
|
|
220
|
+
methods = set(context.methods or ())
|
|
221
|
+
elif not path.startswith(_API_PREFIX):
|
|
222
|
+
continue
|
|
223
|
+
elif isinstance(route, APIWebSocketRoute | WebSocketRoute):
|
|
224
|
+
methods = {_WEBSOCKET}
|
|
225
|
+
elif isinstance(route, Mount):
|
|
226
|
+
path, methods = f"{path}/*", {"*"}
|
|
227
|
+
else:
|
|
228
|
+
# A plain route, or a kind this walk does not know: served under the API
|
|
229
|
+
# prefix, so listed, with every method when it names none.
|
|
230
|
+
methods = set(getattr(route, "methods", None) or {"*"})
|
|
231
|
+
served.setdefault(path, set()).update(method.upper() for method in methods)
|
|
232
|
+
return {path: frozenset(methods) for path, methods in served.items()}
|
|
219
233
|
|
|
220
234
|
|
|
221
235
|
def _schema_hidden_routes(app: FastAPI) -> list[dict[str, object]]:
|
|
222
|
-
"""Reachable top-level routes
|
|
236
|
+
"""Reachable top-level routes that are no API route — still reported.
|
|
223
237
|
|
|
224
238
|
FastAPI's own docs/schema endpoints (``/openapi.json`` / ``/docs`` / ``/redoc``,
|
|
225
239
|
plain starlette ``Route``s with ``include_in_schema=False``) and any ``app.mount()``
|
|
@@ -229,7 +243,7 @@ def _schema_hidden_routes(app: FastAPI) -> list[dict[str, object]]:
|
|
|
229
243
|
hidden: list[dict[str, object]] = []
|
|
230
244
|
for route in app.routes:
|
|
231
245
|
if isinstance(route, APIRoute):
|
|
232
|
-
continue # schema
|
|
246
|
+
continue # an API route: listed by _served_routes, in the schema or not
|
|
233
247
|
if isinstance(route, Mount):
|
|
234
248
|
hidden.append(
|
|
235
249
|
{
|
|
@@ -256,7 +270,8 @@ def build_access_graph_for_app(app: FastAPI) -> dict[str, object]:
|
|
|
256
270
|
``create_app`` records the specs it mounted (client modules AND every discovered
|
|
257
271
|
capability router) and its control plane on ``app.state``; this reads them back so
|
|
258
272
|
the graph covers routes a hand-passed ``--module`` list would miss. It then
|
|
259
|
-
reconciles the graph against
|
|
273
|
+
reconciles the graph against the composed route table (the ground truth, which holds
|
|
274
|
+
a route the OpenAPI document was told to leave out): every served
|
|
260
275
|
``/api/v1`` method must map to a module endpoint — any that does not is reported
|
|
261
276
|
under ``omitted_routes`` (fail-visible, so a mounted route can never hide) — and the
|
|
262
277
|
served routes outside ``/api/v1`` (the unauthenticated kernel health routes), the
|
|
@@ -299,14 +314,18 @@ def build_access_graph_for_app(app: FastAPI) -> dict[str, object]:
|
|
|
299
314
|
modules: list = graph["modules"] # type: ignore[assignment]
|
|
300
315
|
for module in modules:
|
|
301
316
|
for endpoint in module["endpoints"]:
|
|
302
|
-
|
|
317
|
+
# A WebSocket endpoint carries no methods; it covers the served WebSocket.
|
|
318
|
+
covered.setdefault(endpoint["path"], set()).update(endpoint["methods"] or [_WEBSOCKET])
|
|
303
319
|
omitted: list[dict[str, object]] = []
|
|
304
320
|
for path, methods in sorted(served.items()):
|
|
305
321
|
if not path.startswith(_API_PREFIX):
|
|
306
322
|
continue
|
|
307
|
-
missing =
|
|
308
|
-
if missing:
|
|
309
|
-
omitted.append({"path": path, "methods": missing})
|
|
323
|
+
missing = methods - covered.get(path, set())
|
|
324
|
+
if missing - {_WEBSOCKET}:
|
|
325
|
+
omitted.append({"path": path, "methods": sorted(missing - {_WEBSOCKET})})
|
|
326
|
+
if _WEBSOCKET in missing:
|
|
327
|
+
# No methods, as a module's own WebSocket endpoint has none.
|
|
328
|
+
omitted.append({"path": path, "methods": []})
|
|
310
329
|
graph["omitted_routes"] = omitted
|
|
311
330
|
return graph
|
|
312
331
|
|
|
@@ -256,18 +256,22 @@ def verdict(project_root: pathlib.Path, app_ref: str, note_prefix: str) -> Verdi
|
|
|
256
256
|
push_app_root(project_root)
|
|
257
257
|
try:
|
|
258
258
|
app = load_app(app_ref)
|
|
259
|
-
|
|
259
|
+
graph = build_access_graph_for_app(app)
|
|
260
|
+
except (SystemExit, Exception) as exc:
|
|
260
261
|
# The tree pins its surface, so an app that cannot be composed is an unchecked
|
|
261
262
|
# surface, not an absent one. Skipping here passed every change for as long as
|
|
262
|
-
# the app failed to import, which is the one moment nobody is looking.
|
|
263
|
+
# the app failed to import, which is the one moment nobody is looking. Whatever
|
|
264
|
+
# stopped it is this answer: a factory that refuses to boot, or an app that
|
|
265
|
+
# create_app did not compose, is as unchecked as a module that does not import,
|
|
266
|
+
# and a traceback names no state a tool can read.
|
|
263
267
|
detail = (
|
|
264
268
|
f"{SURFACE_ARTIFACT} pins this app's authorization surface, but {app_ref} "
|
|
265
|
-
f"could not be composed ({exc}), so nothing was
|
|
266
|
-
"
|
|
269
|
+
f"could not be composed ({type(exc).__name__}: {exc}), so nothing was "
|
|
270
|
+
"checked. Fix what stops the app composing, or remove the baseline in a "
|
|
271
|
+
"change a reviewer sees."
|
|
267
272
|
)
|
|
268
273
|
unseen = [{"kind": "not_composed", "detail": detail}]
|
|
269
274
|
return Verdict(1, detail, _fields("unseen", unseen=unseen))
|
|
270
|
-
graph = build_access_graph_for_app(app)
|
|
271
275
|
current = authz_surface(graph)
|
|
272
276
|
# What the surface cannot see is refused before it is compared: a route the graph
|
|
273
277
|
# could not place (a router included inside a module's router, served under a path
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""The ``terp guide capability`` topic: using the opt-in capabilities, and composing an app."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
TOPIC = """\
|
|
6
|
+
Using capabilities
|
|
7
|
+
|
|
8
|
+
- Capabilities are opt-in packages (terp-cap-*). Every scaffolded app already has the
|
|
9
|
+
BASE PROFILE — auth, identity, users, groups, access, audit — so authentication,
|
|
10
|
+
accounts, group membership, permission checks and the audit trail are wired before you
|
|
11
|
+
write anything. Install the others you need.
|
|
12
|
+
- WHO IS CALLING, in words a person reads: take `caller: CallerDep` on the route.
|
|
13
|
+
from terp.capabilities.identity import CallerDep
|
|
14
|
+
def pause(name: str, caller: CallerDep, session: SessionDep) -> None:
|
|
15
|
+
service.pause(session, name, decided_by=caller.name)
|
|
16
|
+
`caller.name` is a user's email or a service account's name, read from the live row;
|
|
17
|
+
`caller.id` is the key to store when a record must point at who did it. Never take a
|
|
18
|
+
"decided by" from the request body (it is whatever the client says), and never build
|
|
19
|
+
an IdentityService inside a module to look the caller up.
|
|
20
|
+
- SEE WHAT EXISTS BEFORE YOU BUILD IT:
|
|
21
|
+
terp inspect capabilities
|
|
22
|
+
lists every maintained capability, whether this app already has it, the exact
|
|
23
|
+
`uv add` line and the composition-root wiring it expects. For a capability you
|
|
24
|
+
ALREADY have it also prints `not used here`: wiring points the package exports and
|
|
25
|
+
your source never mentions. That line exists because an installed capability looks
|
|
26
|
+
finished -- so a seam it grows in a later release is invisible from inside the
|
|
27
|
+
project, and at a release every day or two nobody reads the changelog delta. Most
|
|
28
|
+
of what it lists are alternatives you correctly did not take; it is information,
|
|
29
|
+
not a finding. Durable delivery, realtime
|
|
30
|
+
push, tenancy, files, webhooks, scheduling and shared multi-replica state are all
|
|
31
|
+
already solved — hand-rolling one of them is a defect, not a shortcut.
|
|
32
|
+
- A routed capability self-registers: create_app(specs, discover_capabilities=True)
|
|
33
|
+
mounts it at /api/v1/<name> via its entry point — no composition-root edit.
|
|
34
|
+
- A library capability (tenancy, eventbus) ships no router; you import and wire it
|
|
35
|
+
(a mixin/service, a dispatcher) where needed.
|
|
36
|
+
- Compose the app once:
|
|
37
|
+
create_app(specs, principal_provider=..., control_plane=...,
|
|
38
|
+
audit_sink=persist_audit, event_dispatcher=dispatch_in_process,
|
|
39
|
+
permission_enforcer=enforce_permission, discover_capabilities=True)
|
|
40
|
+
- You can always drop to native FastAPI/SQLModel — the same gate rules still apply.
|
|
41
|
+
- Outbound HTTP is a capability concern, never a module concern: importing httpx /
|
|
42
|
+
httpx2 / requests / urllib.request / urllib3 / aiohttp in a module is refused by the
|
|
43
|
+
no_raw_outbound_http rule — SSRF protection, egress allowlists and timeout policy
|
|
44
|
+
belong behind one declared capability, not scattered per call site. That capability
|
|
45
|
+
is `terp-cap-egress`, and it is a declaration rather than a client you configure at
|
|
46
|
+
the call site:
|
|
47
|
+
from terp.capabilities.egress import EgressClient, EgressPolicy
|
|
48
|
+
rates = EgressClient(EgressPolicy(
|
|
49
|
+
allowed_hosts=("api.exchange.example",), # EXACT hosts; empty permits nothing
|
|
50
|
+
timeout_seconds=5.0, # no per-call override, on purpose
|
|
51
|
+
))
|
|
52
|
+
body = rates.get("https://api.exchange.example/v1/rates").content
|
|
53
|
+
Every resolved address is checked against the SSRF denylist and the connection is
|
|
54
|
+
PINNED to the one that passed (so a rebind between the check and the connect cannot
|
|
55
|
+
land on a private address), redirects are never followed, and every attempt —
|
|
56
|
+
refusals included — reaches the optional `observer=` hook, which is where metering
|
|
57
|
+
and egress auditing attach. A sanctioned internal target is a declared
|
|
58
|
+
`allow_private_addresses=True`, visible in the composition root, never a quiet
|
|
59
|
+
exception inside the client.
|
|
60
|
+
- A vendor SDK builds its own HTTP client, so neither the rule (it reads YOUR imports)
|
|
61
|
+
nor EgressClient sees its traffic. Hold the whole process to the declaration at the
|
|
62
|
+
socket, in the composition root the web process and the worker both run:
|
|
63
|
+
install_egress_guard(EgressGuard.for_policies(
|
|
64
|
+
rates_policy, # every EgressPolicy you declared
|
|
65
|
+
hosts=("api.vendor.example",), # what an SDK calls, by exact name
|
|
66
|
+
infrastructure=("db", "redis", "smtp.relay.internal"), # names, IPs or CIDRs
|
|
67
|
+
))
|
|
68
|
+
It holds what goes through Python's socket module on IPv4/IPv6, whichever library
|
|
69
|
+
calls it: a lookup of an undeclared name (getaddrinfo, gethostbyname) is refused
|
|
70
|
+
before it is made, and a connect or datagram into a private / loopback / link-local /
|
|
71
|
+
metadata range is refused unless it is declared infrastructure; a peer given by name
|
|
72
|
+
(localhost too) is resolved and every address held. The refusal is EgressRefusedError
|
|
73
|
+
(502); under an async client it can arrive inside an ExceptionGroup. It cannot see
|
|
74
|
+
uvloop, so it refuses to install beside it and refuses `import uvloop` after it: run
|
|
75
|
+
uvicorn with --loop asyncio (uvicorn[standard] picks uvloop otherwise), and a worker
|
|
76
|
+
or scheduler with asyncio.run. Native drivers that open their own sockets (libpq,
|
|
77
|
+
gRPC's C core) are invisible to it and a public IP literal passes; the deployment's
|
|
78
|
+
network policy holds those. Built for Linux: on Windows asyncio's socketpair connects
|
|
79
|
+
to loopback, so a new event loop is refused unless loopback is declared.
|
|
80
|
+
- Credentials never live in module source: a credential-shaped assignment (password,
|
|
81
|
+
api_key, token, ...) to a string literal — or a recognizable secret-token literal
|
|
82
|
+
anywhere — is refused by the no_hardcoded_credentials rule. Wire secrets through
|
|
83
|
+
settings / sealed config (ADR 0055), never source.
|
|
84
|
+
- Sending e-mail is a capability too: `import smtplib` is refused by the same
|
|
85
|
+
no_raw_outbound_http rule, and terp-cap-mail is where it goes — `terp guide mail`.
|
|
86
|
+
- THE MODULES AN APP MOUNTS ARE THE SAME IN EVERY ENVIRONMENT (ADR 0211). Hand create_app
|
|
87
|
+
every module, always. A module added under a condition is mounted where the condition
|
|
88
|
+
holds and nowhere else, so the app serves routes the access check never saw where it ran:
|
|
89
|
+
# refused (module_list_is_unconditional)
|
|
90
|
+
modules = [login_module, me_module]
|
|
91
|
+
if os.environ.get("OIDC_ISSUER"):
|
|
92
|
+
modules.append(oidc_module)
|
|
93
|
+
# compliant: mounted always, and its routes refuse while nothing is configured
|
|
94
|
+
create_app([login_module, me_module, oidc_module], ...)
|
|
95
|
+
A capability whose configuration is per environment is built in every environment and
|
|
96
|
+
answers a typed refusal while it has none: build_oidc_module(providers, resolver,
|
|
97
|
+
allow_no_provider=True) mounts the SSO routes with an empty list, and each answers
|
|
98
|
+
503 sso_not_configured. The settings decide what a mounted route does, never whether
|
|
99
|
+
it exists.
|
|
100
|
+
"""
|
|
@@ -364,8 +364,9 @@ build container holds a credential or writes into what is built. Each takes the
|
|
|
364
364
|
alone, and is held to it), renders a generated app's files with the terp-arch the
|
|
365
365
|
commit pins (fetched by hash, run in a process of its own), reads the backend image from
|
|
366
366
|
the registry as data and holds it to the tree and the lock, describes each web image from
|
|
367
|
-
the npm lock it installs, the package-lock.json
|
|
368
|
-
of its build context
|
|
367
|
+
the npm lock it installs, the package-lock.json its Dockerfile copies (when it names
|
|
368
|
+
none, the one beside it or at the root of its build context, never a choice between two;
|
|
369
|
+
a static site's is site/package-lock.json), scans for known
|
|
369
370
|
vulnerabilities and for secrets in the history, and signs the manifest as a DSSE envelope
|
|
370
371
|
(release.dsse.json). --sign-key <file> is refused without --test-key. Run the image with
|
|
371
372
|
the checkout mounted read-only (/repo) and the engine's socket and its group
|
|
@@ -374,7 +375,8 @@ build container holds a credential or writes into what is built. Each takes the
|
|
|
374
375
|
|
|
375
376
|
Refused, by name, before anything is built or signed: an undeclared or unmanaged app, a
|
|
376
377
|
declaration that cannot be read or is untrue, a committed .terp-dist/ or submodule, a lock
|
|
377
|
-
naming a path, a web image
|
|
378
|
+
naming a path, a web image whose npm lock cannot be named (its Dockerfile copies two, or one
|
|
379
|
+
the commit does not hold, or names none where two stand or none does), an
|
|
378
380
|
image neither built here nor a datastore table digest, a datastore with no healthcheck, more
|
|
379
381
|
than one migration step or one with --revision/--sql, no step and other than one api unit, a
|
|
380
382
|
built image that does not read TERP_RELEASE_TAG, and a build with more than a context and a
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""The npm lock a web image installs, read from where the image is built.
|
|
2
|
+
|
|
3
|
+
A web image's SBOM is read from an npm lock, and ``sign`` vouches for that list, so the lock
|
|
4
|
+
has to be the one the image installs. The Dockerfile says which: the ``package-lock.json`` it
|
|
5
|
+
copies from its build context. Only when it names none (``COPY . .``) is the lock looked for
|
|
6
|
+
by position, beside the Dockerfile or at the root of the context, and then one of the two may
|
|
7
|
+
exist, never both: two locks and nothing to choose between them is refused, because choosing
|
|
8
|
+
by position signed the SBOM of whichever lock stood first.
|
|
9
|
+
|
|
10
|
+
Nothing is run here. The Dockerfile is text, read with the parser ``sign`` compares an
|
|
11
|
+
image's configuration with (:mod:`terp.cli.release._dockerfile`).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import fnmatch
|
|
17
|
+
import json
|
|
18
|
+
import posixpath
|
|
19
|
+
from typing import Protocol
|
|
20
|
+
|
|
21
|
+
from terp.cli.release import _dockerfile
|
|
22
|
+
from terp.cli.release._common import ReleaseError
|
|
23
|
+
|
|
24
|
+
#: The file a web image's npm lock is.
|
|
25
|
+
LOCK_FILE = "package-lock.json"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Files(Protocol):
|
|
29
|
+
"""What the plan asks a commit's tree, or the files on disk."""
|
|
30
|
+
|
|
31
|
+
def has(self, path: str) -> bool: ...
|
|
32
|
+
|
|
33
|
+
def read_text(self, path: str) -> str: ...
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def candidates(context: str, dockerfile: str) -> list[str]:
|
|
37
|
+
"""Where a lock the Dockerfile does not name may be, in the order looked for, each once."""
|
|
38
|
+
found: list[str] = []
|
|
39
|
+
for place in (posixpath.dirname(dockerfile), context):
|
|
40
|
+
candidate = posixpath.normpath(posixpath.join(place, LOCK_FILE))
|
|
41
|
+
if candidate not in found:
|
|
42
|
+
found.append(candidate)
|
|
43
|
+
return found
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _sources(rest: str) -> list[str]:
|
|
47
|
+
"""The sources of one ``COPY`` or ``ADD`` from the build context; none from elsewhere."""
|
|
48
|
+
if rest.lstrip().startswith("["):
|
|
49
|
+
try:
|
|
50
|
+
words = [str(word) for word in json.loads(rest)]
|
|
51
|
+
except ValueError:
|
|
52
|
+
return []
|
|
53
|
+
else:
|
|
54
|
+
words = [word.strip("\"'") for word in _dockerfile._words(rest)]
|
|
55
|
+
flags = [word for word in words if word.startswith("--")]
|
|
56
|
+
if any(flag.startswith("--from=") for flag in flags):
|
|
57
|
+
return [] # another stage's files, or another image's: not the context's lock
|
|
58
|
+
paths = [word for word in words if not word.startswith("--")]
|
|
59
|
+
return paths[:-1]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def copied(text: str, context: str, dockerfile: str) -> list[str]:
|
|
63
|
+
"""Every npm lock *dockerfile* copies from its build context by name, each once, sorted.
|
|
64
|
+
|
|
65
|
+
A source names the lock when its last step is ``package-lock.json`` or a pattern that
|
|
66
|
+
matches it (``package*.json``). A bare ``*``, a directory and a source holding a
|
|
67
|
+
variable name no file, so they name no lock.
|
|
68
|
+
"""
|
|
69
|
+
found: set[str] = set()
|
|
70
|
+
for keyword, rest in _dockerfile._instructions(text, dockerfile):
|
|
71
|
+
if keyword not in ("copy", "add"):
|
|
72
|
+
continue
|
|
73
|
+
for source in _sources(rest):
|
|
74
|
+
last = posixpath.basename(source)
|
|
75
|
+
if "$" in source or last == "*" or not fnmatch.fnmatchcase(LOCK_FILE, last):
|
|
76
|
+
continue
|
|
77
|
+
folder = posixpath.dirname(source).lstrip("/")
|
|
78
|
+
found.add(posixpath.normpath(posixpath.join(context, folder, LOCK_FILE)))
|
|
79
|
+
return sorted(found)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def choose(tree: Files, context: str, dockerfile: str) -> tuple[str | None, str | None]:
|
|
83
|
+
"""``(lock, None)`` for the lock the image installs, or ``(None, why)`` when none can be named."""
|
|
84
|
+
try:
|
|
85
|
+
named = copied(tree.read_text(dockerfile), context, dockerfile) if tree.has(dockerfile) else []
|
|
86
|
+
except (ReleaseError, UnicodeDecodeError) as exc:
|
|
87
|
+
return None, f"{dockerfile} cannot be read for the lock it copies ({exc})"
|
|
88
|
+
by_name = f"{dockerfile} copies a package-lock.json by name"
|
|
89
|
+
if len(named) > 1:
|
|
90
|
+
return None, (
|
|
91
|
+
f"{dockerfile} copies {len(named)} npm locks, {' and '.join(named)}, and a release "
|
|
92
|
+
f"reads a web image's packages from the one lock it installs (allowed: {dockerfile} "
|
|
93
|
+
"copies exactly one package-lock.json)"
|
|
94
|
+
)
|
|
95
|
+
if named:
|
|
96
|
+
if tree.has(named[0]):
|
|
97
|
+
return named[0], None
|
|
98
|
+
return None, (
|
|
99
|
+
f"{dockerfile} copies {named[0]}, which the commit does not hold (allowed: the "
|
|
100
|
+
"committed package-lock.json the Dockerfile copies)"
|
|
101
|
+
)
|
|
102
|
+
found = [path for path in candidates(context, dockerfile) if tree.has(path)]
|
|
103
|
+
if len(found) > 1:
|
|
104
|
+
return None, (
|
|
105
|
+
f"the commit holds {' and '.join(found)}, and {dockerfile} names neither: a release "
|
|
106
|
+
"reads a web image's packages from the lock it installs, and position does not say "
|
|
107
|
+
f"which that is (allowed: {by_name})"
|
|
108
|
+
)
|
|
109
|
+
if found:
|
|
110
|
+
return found[0], None
|
|
111
|
+
return None, (
|
|
112
|
+
f"the commit holds no {' and no '.join(candidates(context, dockerfile))}, and a release "
|
|
113
|
+
f"reads a web image's packages from the lock it installs (allowed: {by_name}, or a "
|
|
114
|
+
f"committed package-lock.json beside {dockerfile} or at the root of its build context)"
|
|
115
|
+
)
|
|
@@ -27,7 +27,6 @@ A service under a compose ``profiles:`` key is not part of the release: nothing
|
|
|
27
27
|
from __future__ import annotations
|
|
28
28
|
|
|
29
29
|
import pathlib
|
|
30
|
-
import posixpath
|
|
31
30
|
import re
|
|
32
31
|
import shlex
|
|
33
32
|
from dataclasses import dataclass
|
|
@@ -45,6 +44,7 @@ from terp.arch.deployment import (
|
|
|
45
44
|
)
|
|
46
45
|
from terp.arch.deployment.generator import RELEASE_TAG_VARIABLE
|
|
47
46
|
from terp.arch.deployment.profile import truth_findings
|
|
47
|
+
from terp.cli.release import _npm_lock
|
|
48
48
|
from terp.cli.release._common import ReleaseError
|
|
49
49
|
from terp.cli.release._git import Tree
|
|
50
50
|
from terp.cli.release._locks import (
|
|
@@ -69,9 +69,6 @@ _BUILD_KEYS = frozenset({"context", "dockerfile"})
|
|
|
69
69
|
|
|
70
70
|
_STEP = ("terp", "migrate", "upgrade")
|
|
71
71
|
|
|
72
|
-
#: The file a web image's npm lock is: beside its Dockerfile, or at the root of its context.
|
|
73
|
-
_NPM_LOCK_FILE = "package-lock.json"
|
|
74
|
-
|
|
75
72
|
|
|
76
73
|
@dataclass(frozen=True)
|
|
77
74
|
class Image:
|
|
@@ -83,9 +80,9 @@ class Image:
|
|
|
83
80
|
services: tuple[str, ...]
|
|
84
81
|
#: The web tier's image: its bundle cannot be compared with the tree (ADR 0187).
|
|
85
82
|
web: bool
|
|
86
|
-
#: The npm lock a web image
|
|
87
|
-
#:
|
|
88
|
-
#: for any other image.
|
|
83
|
+
#: The npm lock a web image installs, which its SBOM reads: the one its Dockerfile
|
|
84
|
+
#: copies, else the one beside it or at the root of its context (:func:`npm_lock_of`);
|
|
85
|
+
#: none for any other image.
|
|
89
86
|
npm_lock: str | None = None
|
|
90
87
|
|
|
91
88
|
|
|
@@ -135,16 +132,6 @@ def _relative(root: pathlib.Path, base: pathlib.Path, written: str) -> str | Non
|
|
|
135
132
|
return None
|
|
136
133
|
|
|
137
134
|
|
|
138
|
-
def _npm_lock_candidates(context: str, dockerfile: str) -> list[str]:
|
|
139
|
-
"""Where a web image's npm lock may be, in the order it is looked for, each once."""
|
|
140
|
-
found: list[str] = []
|
|
141
|
-
for place in (posixpath.dirname(dockerfile), context):
|
|
142
|
-
candidate = posixpath.normpath(posixpath.join(place, _NPM_LOCK_FILE))
|
|
143
|
-
if candidate not in found:
|
|
144
|
-
found.append(candidate)
|
|
145
|
-
return found
|
|
146
|
-
|
|
147
|
-
|
|
148
135
|
class _WorkingTree:
|
|
149
136
|
"""A project's files on disk, asked what the plan asks a commit's tree: whether a path is a file."""
|
|
150
137
|
|
|
@@ -154,17 +141,22 @@ class _WorkingTree:
|
|
|
154
141
|
def has(self, path: str) -> bool:
|
|
155
142
|
return (self.root / path).is_file()
|
|
156
143
|
|
|
144
|
+
def read_text(self, path: str) -> str:
|
|
145
|
+
return (self.root / path).read_text(encoding="utf-8")
|
|
157
146
|
|
|
158
|
-
def npm_lock_of(tree: Tree | _WorkingTree, context: str, dockerfile: str) -> str | None:
|
|
159
|
-
"""The npm lock a web image is built from: beside its Dockerfile, else in its build context.
|
|
160
147
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
148
|
+
def npm_lock_of(tree: Tree | _WorkingTree, context: str, dockerfile: str) -> str | None:
|
|
149
|
+
"""The npm lock a web image installs, or ``None`` when none can be named.
|
|
150
|
+
|
|
151
|
+
The one its Dockerfile copies from the build context; when the Dockerfile names none,
|
|
152
|
+
the one beside it or at the root of its context, and never a choice between two
|
|
153
|
+
(:func:`terp.cli.release._npm_lock.choose`). Read from where the image is built, never
|
|
154
|
+
from a recipe, which only the generated state declares: under ``"build": "own"`` an app
|
|
155
|
+
names none, and the image it builds a site from still installs a lock of its own. The
|
|
156
|
+
generator's two web Dockerfiles copy the locks beside them (``frontend/`` and ``site/``,
|
|
157
|
+
ADR 0198), so a generated app's images are planned with the locks they always were.
|
|
166
158
|
"""
|
|
167
|
-
return
|
|
159
|
+
return _npm_lock.choose(tree, context, dockerfile)[0]
|
|
168
160
|
|
|
169
161
|
|
|
170
162
|
def web_packages(tree: Tree, image: Image) -> list[tuple[str, str]]:
|
|
@@ -256,7 +248,11 @@ def _built(
|
|
|
256
248
|
return None
|
|
257
249
|
written = str(build.get("context", ".")), str(build.get("dockerfile", "Dockerfile"))
|
|
258
250
|
context = _relative(root, base, written[0])
|
|
259
|
-
|
|
251
|
+
# Against the context, as compose resolves it. *context* is already relative to the
|
|
252
|
+
# checkout, so it is joined to that and not to the profile's own directory again: for a
|
|
253
|
+
# profile in a subdirectory the two differ, and the plan named a Dockerfile compose would
|
|
254
|
+
# never build from.
|
|
255
|
+
dockerfile = _relative(root, root / context, written[1]) if context is not None else None
|
|
260
256
|
if context is None or dockerfile is None:
|
|
261
257
|
outside = "context" if context is None else "Dockerfile"
|
|
262
258
|
refused.append(
|
|
@@ -304,15 +300,9 @@ def _images(
|
|
|
304
300
|
for image, (_builder, context, dockerfile) in sorted(builds.items()):
|
|
305
301
|
run = runners.get(image, [])
|
|
306
302
|
web = bool(webs & set(run))
|
|
307
|
-
lock =
|
|
308
|
-
if
|
|
309
|
-
refused.append(
|
|
310
|
-
f"the web image {image} has no npm lock: the commit holds no "
|
|
311
|
-
f"{' and no '.join(_npm_lock_candidates(context, dockerfile))}, and a release "
|
|
312
|
-
f"reads a web image's packages from the lock it installs (allowed: a committed "
|
|
313
|
-
f"package-lock.json beside {dockerfile} or at the root of its build context "
|
|
314
|
-
"- run `npm install` there and commit the lock it writes)"
|
|
315
|
-
)
|
|
303
|
+
lock, why = _npm_lock.choose(tree, context, dockerfile) if web else (None, None)
|
|
304
|
+
if why is not None:
|
|
305
|
+
refused.append(f"the web image {image} has no npm lock a release can read: {why}")
|
|
316
306
|
images.append(Image(image, context, dockerfile, tuple(run), web, lock))
|
|
317
307
|
return tuple(images), datastores
|
|
318
308
|
|
|
@@ -54,7 +54,7 @@ from terp.arch.deployment import (
|
|
|
54
54
|
services_of,
|
|
55
55
|
)
|
|
56
56
|
from terp.arch.deployment.datastores import read_table
|
|
57
|
-
from terp.arch.deployment.generator import RELEASE_TAG_VARIABLE, escape_findings
|
|
57
|
+
from terp.arch.deployment.generator import RELEASE_TAG_VARIABLE, STATIC_SITE, escape_findings
|
|
58
58
|
from terp.arch.deployment.files import loads
|
|
59
59
|
from terp.arch.deployment.reader import SPEC_RELEASE
|
|
60
60
|
from terp.arch.deployment.standard import schema_sha256, words_newer_than
|
|
@@ -171,6 +171,8 @@ def load(envelope: bytes, public_keys: Sequence[bytes], *, require_generated: bo
|
|
|
171
171
|
if declared.build == "generated":
|
|
172
172
|
published = published_tables()
|
|
173
173
|
tables = Tables(table, published.base_images, published.system_packages, published.recipes)
|
|
174
|
+
# A site's port is taken only on the unit a static-site recipe builds (ADR 0198).
|
|
175
|
+
sites = [unit.id for unit in declared.units if declared.recipe(unit.id) == STATIC_SITE]
|
|
174
176
|
for path, content in carried.items():
|
|
175
177
|
try:
|
|
176
178
|
tagged, parsed = _tags(content), yaml.safe_load(content)
|
|
@@ -178,7 +180,7 @@ def load(envelope: bytes, public_keys: Sequence[bytes], *, require_generated: bo
|
|
|
178
180
|
raise ReleaseError(f"the carried {path} is not YAML", cause=str(exc)) from exc
|
|
179
181
|
if tagged:
|
|
180
182
|
raise ReleaseError(f"the carried {path} carries a YAML tag, which a generated profile never does")
|
|
181
|
-
escaping = escape_findings(parsed, tables)
|
|
183
|
+
escaping = escape_findings(parsed, tables, sites=sites)
|
|
182
184
|
if escaping:
|
|
183
185
|
raise ReleaseError(
|
|
184
186
|
f"the carried {path} interpolates outside the generator's fixed list:\n"
|
|
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
|
|
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
|
|
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
|