terp-cli 0.40.0__tar.gz → 0.41.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.40.0 → terp_cli-0.41.0}/PKG-INFO +9 -9
- {terp_cli-0.40.0 → terp_cli-0.41.0}/pyproject.toml +9 -9
- terp_cli-0.41.0/src/terp/cli/authz_changes.py +321 -0
- terp_cli-0.41.0/src/terp/cli/authz_surface.py +321 -0
- terp_cli-0.41.0/src/terp/cli/dependency_audit.py +69 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/guide_deployment.py +42 -25
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/locks.py +48 -20
- terp_cli-0.41.0/src/terp/cli/npm_tree.py +159 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_locks.py +28 -3
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_plan.py +133 -25
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/manifest.py +6 -5
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/promote.py +32 -5
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/sign.py +6 -5
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/verify.py +24 -207
- terp_cli-0.40.0/src/terp/cli/authz_surface.py +0 -169
- {terp_cli-0.40.0 → terp_cli-0.41.0}/.gitignore +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/signer/Dockerfile +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/signer/terp-arch-releases.json +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/__init__.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/_appref.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/_engine.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/_output.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/_subjects.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/access.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/api_contract.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/api_contract_bounds.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/api_contract_check.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/api_contract_schemas.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/api_contract_shapes.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/apidocs.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/capabilities.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/deploy_safety.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/deployment_adopt.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/deployment_app.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/deployment_check.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/deployment_declare.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/deployment_render.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/dev.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/docker.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/docker_masks.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/envfile.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/envrequired.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/envschema.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/envseams.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/fmt.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/grants.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/guide_passwords.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/heartbeat.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/jobs.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/leases.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/module_roles.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/openapi.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/outbox.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/ports.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/profiles.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/py.typed +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/__init__.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_common.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_compare.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_dockerfile.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_git.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_image.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_registry.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_render.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/_sandbox.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/build.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/cli.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/dsse.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/release/gate.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/reseal.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/reseal_report.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/routes.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/scaffold.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/schema.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/seed.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/service_accounts.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/smoke.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/users.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/version.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.0}/src/terp/cli/workbench.py +0 -0
- {terp_cli-0.40.0 → terp_cli-0.41.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.41.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.41.0
|
|
11
|
+
Requires-Dist: terp-core==0.41.0
|
|
12
|
+
Requires-Dist: terp-migrations==0.41.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.41.0; extra == 'jobs'
|
|
15
|
+
Requires-Dist: terp-cap-scheduler-apscheduler==0.41.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.41.0; extra == 'release'
|
|
20
20
|
Provides-Extra: scheduler
|
|
21
|
-
Requires-Dist: terp-cap-scheduler-apscheduler==0.
|
|
21
|
+
Requires-Dist: terp-cap-scheduler-apscheduler==0.41.0; extra == 'scheduler'
|
|
22
22
|
Provides-Extra: worker
|
|
23
|
-
Requires-Dist: terp-cap-outbox==0.
|
|
23
|
+
Requires-Dist: terp-cap-outbox==0.41.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.41.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.41.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.41.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.41.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.41.0"]
|
|
33
|
+
scheduler = ["terp-cap-scheduler-apscheduler==0.41.0"]
|
|
34
34
|
jobs = [
|
|
35
|
-
"terp-cap-outbox==0.
|
|
36
|
-
"terp-cap-scheduler-apscheduler==0.
|
|
35
|
+
"terp-cap-outbox==0.41.0",
|
|
36
|
+
"terp-cap-scheduler-apscheduler==0.41.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.41.0",
|
|
46
46
|
]
|
|
47
47
|
|
|
48
48
|
[project.scripts]
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"""Each change to who can reach what, labelled a widening or a narrowing (ADR 0209).
|
|
2
|
+
|
|
3
|
+
The ``authz-surface`` check compares an app's composed surface with its committed baseline
|
|
4
|
+
(ADR 0139). This module says what each difference is: one entry per changed endpoint,
|
|
5
|
+
module, role ladder or permission set, each carrying ``widens``.
|
|
6
|
+
|
|
7
|
+
A change is a narrowing only when the guard's own replayed answers prove that nobody gains
|
|
8
|
+
reach; everything else is a widening, including a difference this module cannot itemise.
|
|
9
|
+
It is set inclusion over the answers ``decide`` already gives, never a judgement of which
|
|
10
|
+
change is dangerous: that would be a second authorization model, which ADR 0121 exists to
|
|
11
|
+
prevent. A tool can then put the widenings, and only those, in front of a person.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
#: How far one rung's answer reaches. A ``grant`` reaches whoever holds the permission. Every
|
|
19
|
+
#: answer not named here (``rank``, ``no_policy``, ``unknown_permission``,
|
|
20
|
+
#: ``unauthenticated``, ``unregistered_role``) refuses, and reaches nobody.
|
|
21
|
+
_REACH = {"public": 3, "allowed": 2, "allowed_in_module": 2, "grant": 1}
|
|
22
|
+
|
|
23
|
+
Key = tuple[str, str]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _reach(answer: object) -> int:
|
|
27
|
+
return _REACH.get(answer, 0) if isinstance(answer, str) else 0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def endpoint_key(endpoint: dict[str, Any]) -> Key:
|
|
31
|
+
"""``(path, methods)``: the identity a baseline and a surface compare endpoints on."""
|
|
32
|
+
return endpoint["path"], ",".join(endpoint.get("methods", ())) or "WS"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _endpoints(surface: dict[str, Any]) -> dict[Key, tuple[str, dict[str, Any]]]:
|
|
36
|
+
return {
|
|
37
|
+
endpoint_key(endpoint): (module["name"], endpoint)
|
|
38
|
+
for module in surface.get("modules", ())
|
|
39
|
+
for endpoint in module.get("endpoints", ())
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _labels(graph: dict[str, Any] | None) -> tuple[dict[Key, Any], dict[str, Any]]:
|
|
44
|
+
"""Each endpoint's declared operation, and each permission's label, from the graph."""
|
|
45
|
+
operations: dict[Key, Any] = {}
|
|
46
|
+
permissions: dict[str, Any] = {}
|
|
47
|
+
for module in (graph or {}).get("modules", ()):
|
|
48
|
+
for endpoint in module.get("endpoints", ()):
|
|
49
|
+
operations[endpoint_key(endpoint)] = endpoint.get("operation")
|
|
50
|
+
for permission in (graph or {}).get("permissions", ()):
|
|
51
|
+
permissions[permission["name"]] = permission.get("label")
|
|
52
|
+
return operations, permissions
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _entry(subject: str, change: str, widens: bool, **detail: Any) -> dict[str, Any]:
|
|
56
|
+
methods = detail.get("methods")
|
|
57
|
+
return {
|
|
58
|
+
"subject": subject,
|
|
59
|
+
"module": detail.get("module"),
|
|
60
|
+
"methods": methods.split(",") if methods else [],
|
|
61
|
+
"path": detail.get("path"),
|
|
62
|
+
"operation": detail.get("operation"),
|
|
63
|
+
"gains": sorted(detail.get("gains", ())),
|
|
64
|
+
"loses": sorted(detail.get("loses", ())),
|
|
65
|
+
"anonymous": bool(detail.get("anonymous")),
|
|
66
|
+
"permissions": detail.get("permissions", []),
|
|
67
|
+
"change": change,
|
|
68
|
+
"widens": widens,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _permissions_involved(
|
|
73
|
+
names: set[str], permission_labels: dict[str, Any]
|
|
74
|
+
) -> list[dict[str, Any]]:
|
|
75
|
+
return [{"name": name, "label": permission_labels.get(name)} for name in sorted(names)]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _named_permissions(*endpoints: dict[str, Any]) -> set[str]:
|
|
79
|
+
names: set[str] = set()
|
|
80
|
+
for endpoint in endpoints:
|
|
81
|
+
kind, _, name = str(endpoint.get("requirement", "")).partition(":")
|
|
82
|
+
if kind == "permission":
|
|
83
|
+
names.add(name)
|
|
84
|
+
names.update(endpoint.get("extra_permissions") or ())
|
|
85
|
+
return names
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _endpoint_change(
|
|
89
|
+
key: Key,
|
|
90
|
+
module: str,
|
|
91
|
+
was: dict[str, Any],
|
|
92
|
+
now: dict[str, Any],
|
|
93
|
+
operation: Any,
|
|
94
|
+
permission_labels: dict[str, Any],
|
|
95
|
+
) -> dict[str, Any] | None:
|
|
96
|
+
path, methods = key
|
|
97
|
+
before, after = was.get("by_role", {}), now.get("by_role", {})
|
|
98
|
+
rungs = sorted(set(before) | set(after))
|
|
99
|
+
gains = [rung for rung in rungs if _reach(after.get(rung)) > _reach(before.get(rung))]
|
|
100
|
+
loses = [rung for rung in rungs if _reach(after.get(rung)) < _reach(before.get(rung))]
|
|
101
|
+
was_grants = list(was.get("extra_permissions") or ())
|
|
102
|
+
now_grants = list(now.get("extra_permissions") or ())
|
|
103
|
+
parts: list[str] = []
|
|
104
|
+
if was["requirement"] != now["requirement"]:
|
|
105
|
+
parts.append(f"requirement {was['requirement']!r} -> {now['requirement']!r}")
|
|
106
|
+
if was_grants != now_grants:
|
|
107
|
+
parts.append(f"required grants {was_grants} -> {now_grants}")
|
|
108
|
+
newly = [rung for rung in gains if _reach(before.get(rung)) == 0]
|
|
109
|
+
if newly:
|
|
110
|
+
parts.append(f"now reachable by {newly} (it was not before)")
|
|
111
|
+
if wider := [rung for rung in gains if rung not in newly]:
|
|
112
|
+
parts.append(f"reachable more widely by {wider}")
|
|
113
|
+
if loses:
|
|
114
|
+
parts.append(f"reachable less widely by {loses}")
|
|
115
|
+
if not parts:
|
|
116
|
+
if before == after:
|
|
117
|
+
return None
|
|
118
|
+
parts.append(f"the answers per rung changed: {before} -> {after}")
|
|
119
|
+
# A grant on both sides of a changed requirement names another permission, so the
|
|
120
|
+
# people who hold it may differ; fewer required grants admit more of them.
|
|
121
|
+
regranted = was["requirement"] != now["requirement"] and any(
|
|
122
|
+
before.get(rung) == "grant" and after.get(rung) == "grant" for rung in rungs
|
|
123
|
+
)
|
|
124
|
+
widens = bool(gains) or regranted or not set(was_grants) <= set(now_grants)
|
|
125
|
+
return _entry(
|
|
126
|
+
"endpoint",
|
|
127
|
+
f"{methods} {path}: " + "; ".join(parts),
|
|
128
|
+
widens,
|
|
129
|
+
module=module,
|
|
130
|
+
methods=methods,
|
|
131
|
+
path=path,
|
|
132
|
+
operation=operation,
|
|
133
|
+
gains=gains,
|
|
134
|
+
loses=loses,
|
|
135
|
+
anonymous=any(answer == "public" for answer in after.values()),
|
|
136
|
+
permissions=_permissions_involved(_named_permissions(was, now), permission_labels),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _floor(requirement: object, surface: dict[str, Any]) -> tuple[int, bool] | None:
|
|
141
|
+
"""``(rank, needs a grant)`` for a ``role:`` or ``permission:`` requirement, or ``None``."""
|
|
142
|
+
kind, _, name = str(requirement).partition(":")
|
|
143
|
+
ranks = {role["name"]: role["rank"] for role in surface.get("roles", ())}
|
|
144
|
+
if kind == "role":
|
|
145
|
+
return (ranks[name], False) if name in ranks else None
|
|
146
|
+
if kind == "permission":
|
|
147
|
+
floors = {item["name"]: item["min_role"] for item in surface.get("permissions", ())}
|
|
148
|
+
floor = floors.get(name)
|
|
149
|
+
return (ranks[floor], True) if floor in ranks else None
|
|
150
|
+
return None
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _requirement_narrows(
|
|
154
|
+
was: object, now: object, baseline: dict[str, Any], current: dict[str, Any]
|
|
155
|
+
) -> bool:
|
|
156
|
+
if was == now:
|
|
157
|
+
return True
|
|
158
|
+
old, new = _floor(was, baseline), _floor(now, current)
|
|
159
|
+
if old is None or new is None:
|
|
160
|
+
return False
|
|
161
|
+
(old_rank, old_grant), new_rank = old, new[0]
|
|
162
|
+
# A permission moved to another permission, or to a role, admits people who were not
|
|
163
|
+
# admitted before: a role admits its whole rung, a different permission other holders.
|
|
164
|
+
if old_grant:
|
|
165
|
+
return False
|
|
166
|
+
return new_rank >= old_rank
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _policy_narrows(
|
|
170
|
+
was: Any, now: Any, baseline: dict[str, Any], current: dict[str, Any]
|
|
171
|
+
) -> bool:
|
|
172
|
+
if was == now or now is None:
|
|
173
|
+
return True # no policy refuses every caller
|
|
174
|
+
if was is None:
|
|
175
|
+
return False
|
|
176
|
+
if now.get("public"):
|
|
177
|
+
return bool(was.get("public")) and not (
|
|
178
|
+
now.get("allows_public_writes") and not was.get("allows_public_writes")
|
|
179
|
+
)
|
|
180
|
+
if was.get("public"):
|
|
181
|
+
return True
|
|
182
|
+
if was.get("authenticated") and not now.get("authenticated"):
|
|
183
|
+
return False
|
|
184
|
+
return all(
|
|
185
|
+
_requirement_narrows(was.get(tier), now.get(tier), baseline, current)
|
|
186
|
+
for tier in ("read", "write")
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _module_changes(baseline: dict[str, Any], current: dict[str, Any]) -> list[dict[str, Any]]:
|
|
191
|
+
"""A module's own policy and access, compared on their own.
|
|
192
|
+
|
|
193
|
+
The endpoint entries test one method per route, so a route serving GET and POST can have
|
|
194
|
+
its read tier lowered with no endpoint entry moving; and a module that starts taking
|
|
195
|
+
per-module roles lets an assignment lift a caller over a floor (ADR 0121) without any
|
|
196
|
+
rung's answer changing in this view.
|
|
197
|
+
"""
|
|
198
|
+
before = {module["name"]: module for module in baseline.get("modules", ())}
|
|
199
|
+
after = {module["name"]: module for module in current.get("modules", ())}
|
|
200
|
+
entries: list[dict[str, Any]] = []
|
|
201
|
+
for name in sorted(before.keys() & after.keys()):
|
|
202
|
+
was, now = before[name], after[name]
|
|
203
|
+
if was.get("policy") != now.get("policy"):
|
|
204
|
+
entries.append(
|
|
205
|
+
_entry(
|
|
206
|
+
"module",
|
|
207
|
+
f"module {name}: policy {was.get('policy')!r} -> {now.get('policy')!r}",
|
|
208
|
+
not _policy_narrows(was.get("policy"), now.get("policy"), baseline, current),
|
|
209
|
+
module=name,
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
if was.get("access") != now.get("access"):
|
|
213
|
+
assignable = bool((now.get("access") or {}).get("assignable"))
|
|
214
|
+
entries.append(
|
|
215
|
+
_entry(
|
|
216
|
+
"module",
|
|
217
|
+
f"module {name}: access {was.get('access')!r} -> {now.get('access')!r}",
|
|
218
|
+
assignable and not bool((was.get("access") or {}).get("assignable")),
|
|
219
|
+
module=name,
|
|
220
|
+
)
|
|
221
|
+
)
|
|
222
|
+
return entries
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _floors_fell(baseline: dict[str, Any], current: dict[str, Any]) -> bool:
|
|
226
|
+
"""Whether a permission declared on both sides now has a lower floor (or one unknown)."""
|
|
227
|
+
before = {item["name"]: item["min_role"] for item in baseline.get("permissions", ())}
|
|
228
|
+
after = {item["name"]: item["min_role"] for item in current.get("permissions", ())}
|
|
229
|
+
old_ranks = {role["name"]: role["rank"] for role in baseline.get("roles", ())}
|
|
230
|
+
new_ranks = {role["name"]: role["rank"] for role in current.get("roles", ())}
|
|
231
|
+
for name in before.keys() & after.keys():
|
|
232
|
+
old, new = old_ranks.get(before[name]), new_ranks.get(after[name])
|
|
233
|
+
if old is None or new is None or new < old:
|
|
234
|
+
return True
|
|
235
|
+
return False
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def authority_changes(
|
|
239
|
+
baseline: dict[str, Any],
|
|
240
|
+
current: dict[str, Any],
|
|
241
|
+
graph: dict[str, Any] | None = None,
|
|
242
|
+
) -> list[dict[str, Any]]:
|
|
243
|
+
"""Every authority difference, each labelled with whether it widens who can reach what.
|
|
244
|
+
|
|
245
|
+
*graph* (the access graph *current* was reduced from) supplies the labels a person reads
|
|
246
|
+
a change by: each endpoint's declared operation and each permission's label. The
|
|
247
|
+
baseline has neither, so an endpoint that is gone carries no operation.
|
|
248
|
+
"""
|
|
249
|
+
operations, permission_labels = _labels(graph)
|
|
250
|
+
entries: list[dict[str, Any]] = []
|
|
251
|
+
before, after = _endpoints(baseline), _endpoints(current)
|
|
252
|
+
for key in sorted(before.keys() & after.keys()):
|
|
253
|
+
module, now = after[key]
|
|
254
|
+
changed = _endpoint_change(
|
|
255
|
+
key, module, before[key][1], now, operations.get(key), permission_labels
|
|
256
|
+
)
|
|
257
|
+
if changed is not None:
|
|
258
|
+
entries.append(changed)
|
|
259
|
+
for key in sorted(after.keys() - before.keys()):
|
|
260
|
+
module, now = after[key]
|
|
261
|
+
reaches = [rung for rung, answer in now.get("by_role", {}).items() if _reach(answer)]
|
|
262
|
+
entries.append(
|
|
263
|
+
_entry(
|
|
264
|
+
"endpoint",
|
|
265
|
+
f"{key[1]} {key[0]}: NEW endpoint, requirement {now['requirement']!r} - "
|
|
266
|
+
"nothing has reviewed what it requires",
|
|
267
|
+
bool(reaches),
|
|
268
|
+
module=module,
|
|
269
|
+
methods=key[1],
|
|
270
|
+
path=key[0],
|
|
271
|
+
operation=operations.get(key),
|
|
272
|
+
gains=reaches,
|
|
273
|
+
anonymous=any(answer == "public" for answer in now.get("by_role", {}).values()),
|
|
274
|
+
permissions=_permissions_involved(_named_permissions(now), permission_labels),
|
|
275
|
+
)
|
|
276
|
+
)
|
|
277
|
+
for key in sorted(before.keys() - after.keys()):
|
|
278
|
+
module, was = before[key]
|
|
279
|
+
entries.append(
|
|
280
|
+
_entry(
|
|
281
|
+
"endpoint",
|
|
282
|
+
f"{key[1]} {key[0]}: gone from the surface",
|
|
283
|
+
False,
|
|
284
|
+
module=module,
|
|
285
|
+
methods=key[1],
|
|
286
|
+
path=key[0],
|
|
287
|
+
loses=[rung for rung, answer in was.get("by_role", {}).items() if _reach(answer)],
|
|
288
|
+
)
|
|
289
|
+
)
|
|
290
|
+
entries.extend(_module_changes(baseline, current))
|
|
291
|
+
# The ladder itself, last: a changed rank silently re-scores every floor above it, so it
|
|
292
|
+
# is a widening however it moved.
|
|
293
|
+
if baseline.get("roles") != current.get("roles"):
|
|
294
|
+
entries.append(
|
|
295
|
+
_entry(
|
|
296
|
+
"roles",
|
|
297
|
+
f"the role ladder changed: {baseline.get('roles')} -> {current.get('roles')}",
|
|
298
|
+
True,
|
|
299
|
+
)
|
|
300
|
+
)
|
|
301
|
+
if baseline.get("permissions") != current.get("permissions"):
|
|
302
|
+
entries.append(
|
|
303
|
+
_entry(
|
|
304
|
+
"permissions",
|
|
305
|
+
"the declared permissions or their floors changed",
|
|
306
|
+
_floors_fell(baseline, current),
|
|
307
|
+
)
|
|
308
|
+
)
|
|
309
|
+
# Anything the entries above do not name is still a change to who can reach what, or to
|
|
310
|
+
# the record of it. Passing it as "no difference" is the one answer this check must never
|
|
311
|
+
# give, so it is reported whole, and as a widening.
|
|
312
|
+
if not entries and baseline != current:
|
|
313
|
+
entries.append(
|
|
314
|
+
_entry(
|
|
315
|
+
"surface",
|
|
316
|
+
"the authorization surface changed in a way this check does not itemise; "
|
|
317
|
+
"read the diff of authz-surface.json line by line",
|
|
318
|
+
True,
|
|
319
|
+
)
|
|
320
|
+
)
|
|
321
|
+
return entries
|