modelsign 1.3.0__tar.gz → 1.4.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.
Files changed (83) hide show
  1. {modelsign-1.3.0 → modelsign-1.4.0}/CHANGELOG.md +10 -0
  2. {modelsign-1.3.0 → modelsign-1.4.0}/PKG-INFO +13 -1
  3. {modelsign-1.3.0 → modelsign-1.4.0}/README.md +12 -0
  4. modelsign-1.4.0/docs/outreach/demo-verification.md +26 -0
  5. modelsign-1.4.0/docs/outreach/modelsign-1.3-engineering-packet.md +113 -0
  6. modelsign-1.4.0/docs/reviews/2026-12-03-v1.4-development.md +53 -0
  7. modelsign-1.4.0/docs/superpowers/plans/2026-12-03-trust-rollback.md +64 -0
  8. modelsign-1.4.0/docs/superpowers/specs/2026-12-03-trust-rollback-design.md +258 -0
  9. modelsign-1.4.0/docs/trust-policy.md +138 -0
  10. modelsign-1.4.0/examples/security_review_demo.py +73 -0
  11. modelsign-1.4.0/examples/trust_policy_demo.py +119 -0
  12. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/__init__.py +4 -1
  13. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/api.py +24 -6
  14. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/cli.py +90 -21
  15. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/guard.py +11 -1
  16. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/identity/card.py +13 -0
  17. modelsign-1.4.0/src/modelsign/policy.py +275 -0
  18. modelsign-1.4.0/src/modelsign/policy_state.py +228 -0
  19. modelsign-1.4.0/src/modelsign/trust_bundle.py +234 -0
  20. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign.egg-info/PKG-INFO +13 -1
  21. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign.egg-info/SOURCES.txt +16 -1
  22. modelsign-1.4.0/tests/test_policy.py +348 -0
  23. modelsign-1.4.0/tests/test_policy_cli.py +186 -0
  24. modelsign-1.4.0/tests/test_policy_state.py +155 -0
  25. modelsign-1.4.0/tests/test_trust_bundle.py +147 -0
  26. {modelsign-1.3.0 → modelsign-1.4.0}/.github/FUNDING.yml +0 -0
  27. {modelsign-1.3.0 → modelsign-1.4.0}/.github/workflows/ci.yml +0 -0
  28. {modelsign-1.3.0 → modelsign-1.4.0}/.gitignore +0 -0
  29. {modelsign-1.3.0 → modelsign-1.4.0}/LICENSE +0 -0
  30. {modelsign-1.3.0 → modelsign-1.4.0}/action.yml +0 -0
  31. {modelsign-1.3.0 → modelsign-1.4.0}/docs/attestation.md +0 -0
  32. {modelsign-1.3.0 → modelsign-1.4.0}/docs/aws-kms.md +0 -0
  33. {modelsign-1.3.0 → modelsign-1.4.0}/docs/reviews/2026-12-03-v1.3.0.md +0 -0
  34. {modelsign-1.3.0 → modelsign-1.4.0}/docs/security-policy-follow-ons.md +0 -0
  35. {modelsign-1.3.0 → modelsign-1.4.0}/docs/superpowers/plans/2026-12-03-kms.md +0 -0
  36. {modelsign-1.3.0 → modelsign-1.4.0}/docs/superpowers/plans/2026-12-03-rfc3161.md +0 -0
  37. {modelsign-1.3.0 → modelsign-1.4.0}/docs/superpowers/specs/2026-12-03-kms-design.md +0 -0
  38. {modelsign-1.3.0 → modelsign-1.4.0}/docs/superpowers/specs/2026-12-03-rfc3161-design.md +0 -0
  39. {modelsign-1.3.0 → modelsign-1.4.0}/docs/timestamps.md +0 -0
  40. {modelsign-1.3.0 → modelsign-1.4.0}/pyproject.toml +0 -0
  41. {modelsign-1.3.0 → modelsign-1.4.0}/setup.cfg +0 -0
  42. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/approvals.py +0 -0
  43. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/attest.py +0 -0
  44. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/crypto/__init__.py +0 -0
  45. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/crypto/aws_kms.py +0 -0
  46. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/crypto/keys.py +0 -0
  47. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/crypto/sign.py +0 -0
  48. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/crypto/signers.py +0 -0
  49. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/crypto/verify.py +0 -0
  50. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/formats/__init__.py +0 -0
  51. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/formats/directory.py +0 -0
  52. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/formats/single.py +0 -0
  53. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/identity/__init__.py +0 -0
  54. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/identity/canonical.py +0 -0
  55. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/lineage.py +0 -0
  56. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/middleware/__init__.py +0 -0
  57. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/middleware/response.py +0 -0
  58. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/oms.py +0 -0
  59. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/sig.py +0 -0
  60. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign/timestamps.py +0 -0
  61. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign.egg-info/dependency_links.txt +0 -0
  62. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign.egg-info/entry_points.txt +0 -0
  63. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign.egg-info/requires.txt +0 -0
  64. {modelsign-1.3.0 → modelsign-1.4.0}/src/modelsign.egg-info/top_level.txt +0 -0
  65. {modelsign-1.3.0 → modelsign-1.4.0}/tests/conftest.py +0 -0
  66. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_api.py +0 -0
  67. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_approvals.py +0 -0
  68. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_attest.py +0 -0
  69. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_canonical.py +0 -0
  70. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_card.py +0 -0
  71. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_cli.py +0 -0
  72. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_digest_binding_review.py +0 -0
  73. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_formats.py +0 -0
  74. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_guard.py +0 -0
  75. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_integration.py +0 -0
  76. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_keys.py +0 -0
  77. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_kms.py +0 -0
  78. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_lineage.py +0 -0
  79. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_middleware.py +0 -0
  80. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_oms.py +0 -0
  81. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_sig.py +0 -0
  82. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_sign_verify.py +0 -0
  83. {modelsign-1.3.0 → modelsign-1.4.0}/tests/test_timestamps.py +0 -0
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.4.0 (2026-12-03)
4
+
5
+ - Optional signed trust bundles with pinned roots, exact model grants and current-key revocation policy.
6
+ - Signed model IDs/security versions and deployment floors.
7
+ - Explicitly initialized POSIX rollback state with locking, atomic updates and cross-model trust sequence memory.
8
+ - Shared API/CLI/guard policy enforcement, including approvals before model-state commits.
9
+ - Offline bundle issuance and explicit state initialization/reset with audit backup.
10
+ - Identity-only policies do not require a security version; version floors and state still do.
11
+ - Preserve operational verification errors (CLI exit 2) and explicit embedded-key verification for approval-only checks.
12
+
3
13
  ## v1.3.0 (2026-12-03)
4
14
 
5
15
  - Optional AWS KMS Ed25519 signing for models and approvals; pinned key/algorithm,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modelsign
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Summary: Sign AI models with identity. Verify anywhere. Part of the AURE Provenance stack by Constant Systems.
5
5
  Author-email: James Kerr <qj@constantqj.com>
6
6
  License: Apache-2.0
@@ -380,3 +380,15 @@ keeping verification offline. See [the KMS guide](docs/aws-kms.md) for the signe
380
380
  interface, optional SDK extra, IAM requirements and 4,096-byte signing-message
381
381
  limit. This backend has SDK-contract tests, not live AWS validation, and is
382
382
  available through `pip install "modelsign[aws-kms]==1.3.0"`.
383
+
384
+ ## Deployment trust and rollback policy (v1.4)
385
+
386
+ Version 1.4 adds optional root-signed trust bundles and signed model
387
+ security versions. See [the policy guide](docs/trust-policy.md) for offline bundle
388
+ issuance, API/CLI/guard enforcement, explicit state initialization, shared sequence
389
+ tracking and administrative recovery. Persistent state requires POSIX flock
390
+ and local atomic writes.
391
+
392
+ Run `python examples/trust_policy_demo.py` from a checkout with modelsign 1.4 installed
393
+ to see valid loading, version rollback rejection, publisher revocation and old
394
+ bundle replay rejection using disposable keys and files.
@@ -346,3 +346,15 @@ keeping verification offline. See [the KMS guide](docs/aws-kms.md) for the signe
346
346
  interface, optional SDK extra, IAM requirements and 4,096-byte signing-message
347
347
  limit. This backend has SDK-contract tests, not live AWS validation, and is
348
348
  available through `pip install "modelsign[aws-kms]==1.3.0"`.
349
+
350
+ ## Deployment trust and rollback policy (v1.4)
351
+
352
+ Version 1.4 adds optional root-signed trust bundles and signed model
353
+ security versions. See [the policy guide](docs/trust-policy.md) for offline bundle
354
+ issuance, API/CLI/guard enforcement, explicit state initialization, shared sequence
355
+ tracking and administrative recovery. Persistent state requires POSIX flock
356
+ and local atomic writes.
357
+
358
+ Run `python examples/trust_policy_demo.py` from a checkout with modelsign 1.4 installed
359
+ to see valid loading, version rollback rejection, publisher revocation and old
360
+ bundle replay rejection using disposable keys and files.
@@ -0,0 +1,26 @@
1
+ # Sharing demo verification
2
+
3
+ Executed on 2026-12-03 with Python 3.12 in a virtual environment containing the
4
+ published PyPI ModelSign 1.3.0 package (not an editable source installation).
5
+
6
+ Command: `python examples/security_review_demo.py`
7
+
8
+ Result: exit status 0. All eight checks returned true:
9
+
10
+ - Valid model and trusted approval accepted.
11
+ - Output, request, model and signer comparisons all performed.
12
+ - Changed output rejected.
13
+ - Changed request rejected.
14
+ - Wrong attestor key rejected.
15
+ - Wrong model signer rejected.
16
+ - Changed model blocked by the pre-load guard.
17
+ - Restored original model still verifies.
18
+
19
+ The script uses disposable synthetic model bytes and a synthetic response. It does
20
+ not run inference or call AWS/TSA/network services. The separate FinSense artifact
21
+ compatibility check was completed during the v1.3.0 release verification.
22
+
23
+ The v1.4 design received a builder review. Its two findings—approval checks before
24
+ model-state commit and shared bundle-sequence state across model IDs—were resolved;
25
+ the follow-up review reported no important unanswered planning questions. This is
26
+ not implementation verification or a security audit of code that does not yet exist.
@@ -0,0 +1,113 @@
1
+ # ModelSign 1.3.0: engineering review packet
2
+
3
+ Status: draft for sharing. No outreach has been sent by preparing this packet.
4
+ Audience: engineers responsible for model artifact verification, ML deployment
5
+ pipelines, inference services, or software supply-chain security.
6
+
7
+ ## Short message
8
+
9
+ I released ModelSign 1.3.0, an Apache-2.0 Python library/CLI for signing model
10
+ artifacts and enforcing verification before loading them. It supports timestamped
11
+ approval chains and serving-key attestations that bind response/request hashes to
12
+ the verified model's content, identity card and signer.
13
+
14
+ I've published a FinSense v5 example with a timestamped signature and a pre-load
15
+ verification gate. There is also a small offline demo that rejects changed model
16
+ bytes, changed outputs/requests and incorrect keys. The offline demo uses synthetic
17
+ bytes and does not run inference.
18
+
19
+ I'd value a technical review: can you reproduce the failure cases, find a trust or
20
+ policy bypass, or identify friction in putting this into an MLOps pipeline?
21
+
22
+ Runtime attestations are signed claims by a serving key, not proof of execution.
23
+ AWS KMS support is experimental and tested at the SDK boundary, not with a live
24
+ AWS key. Revocation feeds and rollback floors are design work for v1.4, not shipped
25
+ features.
26
+
27
+ - Release: https://pypi.org/project/modelsign/1.3.0/
28
+ - Source and notes: https://github.com/QuantQJ/modelsign/releases/tag/v1.3.0
29
+ - FinSense: https://huggingface.co/ConstantQJ/finsense-v5
30
+ - Review scope: https://github.com/QuantQJ/modelsign/blob/v1.3.0/docs/reviews/2026-12-03-v1.3.0.md
31
+
32
+ James Kerr / Constant Systems
33
+
34
+ ## Reproduce the offline demonstration
35
+
36
+ Use a fresh environment with Python 3.9 or later. This demo requires neither
37
+ OpenSSL, an external TSA, AWS, nor ML frameworks:
38
+
39
+ ```bash
40
+ python3 -m venv .venv-modelsign-review
41
+ .venv-modelsign-review/bin/python -m pip install 'modelsign==1.3.0'
42
+ .venv-modelsign-review/bin/python examples/security_review_demo.py
43
+ ```
44
+
45
+ The script accompanies this packet in the repository branch/PR containing the
46
+ packet; it was added after the v1.3.0 tag, so do not expect it in that tag's tree.
47
+ Run the commands from a checkout containing it. It uses temporary keys and files,
48
+ cleans them up, and exits nonzero if an expected security check fails. On Windows
49
+ use the environment's Scripts/python.exe instead of bin/python.
50
+
51
+ Expected: modelsign_version is 1.3.0, synthetic_demo is true, and all eight checks
52
+ are true. This shows integrity/policy behavior with known fixtures; it is not an
53
+ independent security audit or an ML accuracy benchmark.
54
+
55
+ ## Reproduce the real FinSense artifact gate
56
+
57
+ Use the pinned public revision:
58
+ https://huggingface.co/ConstantQJ/finsense-v5/tree/822405c196aa16b6c3cb2030f8e231fc88a31ca1
59
+
60
+ Follow that revision's SIGNING.md snapshot download instructions. Fetch all actual
61
+ LFS objects, not just Git pointer files. Download into a clean directory, keep
62
+ keys/CA outside the snapshot, and do not add files before verifying its manifest.
63
+ The signed guide pins ModelSign 1.2.0; v1.3.0 was separately tested against this
64
+ unchanged artifact. Install the timestamp extra when evaluating v1.3.0:
65
+
66
+ ```bash
67
+ python -m pip install 'modelsign[timestamp]==1.3.0'
68
+ modelsign verify /path/to/clean-snapshot \
69
+ --sig /path/to/clean-snapshot/modelsign.sig \
70
+ --pubkey /path/to/independently-trusted-publisher.pem \
71
+ --require-timestamp --tsa-ca /path/to/independently-trusted-tsa-ca.pem --json
72
+ ```
73
+
74
+ OpenSSL 3 must be available; on macOS with Homebrew set MODELSIGN_OPENSSL to the
75
+ installed OpenSSL 3 executable if the system command is LibreSSL.
76
+
77
+ Confirm the publisher key independently. Its full SHA-256 fingerprint of the raw
78
+ 32-byte public key is:
79
+ `fac28faad5cb425998539313db2ba0e26ea42320c3ca620c39e11be22eaed1d5`.
80
+ This packet is a reference, not an independent trust channel for someone obtaining
81
+ all their files from one untrusted source. Do not use the short display fingerprint
82
+ as an authorization identifier. The TSA CA also requires independent trust.
83
+
84
+ For the changed-file case, run TAMPER_DEMO.md from the pinned revision using this
85
+ v1.3 environment. It modifies only a temporary copy. Model verification does not
86
+ validate sentiment accuracy or the provenance of training data. Review the model
87
+ card's evaluation limitations separately. FinSense does not automatically publish
88
+ per-response runtime attestations; those are demonstrated by the separate script.
89
+
90
+ ## Reviewer questions
91
+
92
+ 1. Can altered bytes, identity fields, approvals or serving statements be accepted
93
+ under pinned keys and the explicitly required policy?
94
+ 2. Are the actual checked properties clear in API and CLI results? Can a caller
95
+ confuse signature-only verification with output/model/signer verification?
96
+ 3. Does the pre-load gate fit artifact caching, container builds and inference
97
+ startup? What concrete integration would remove the most friction?
98
+ 4. For the proposed v1.4 policy, are bundle scope, revocation behavior and state
99
+ transitions sufficiently explicit? The design is separate from this release.
100
+
101
+ ## How to share without overstating it
102
+
103
+ Send the short message and demo to a small number of engineers who own the relevant
104
+ pipeline, or use a community's designated project/showcase channel after checking
105
+ its current rules. Ask for reproducible findings rather than endorsements. A useful
106
+ bug report contains version, OS/Python version, command, expected/actual outcome and
107
+ minimal non-sensitive fixture. Never ask reviewers to share private keys or cloud
108
+ credentials. Do not describe ModelSign as proof of AI execution, regulatory
109
+ compliance, prevention of every supply-chain attack, or validation of FinSense's
110
+ financial performance.
111
+
112
+ Recipient selection and sending remain separate actions; this packet is ready for
113
+ review and has not been emailed, posted, or sent as a direct message.
@@ -0,0 +1,53 @@
1
+ # v1.4 development review
2
+
3
+ Implemented the accepted trust-bundle/rollback design on a separate feature branch.
4
+ Runtime version is 1.4.0.dev0, deliberately not a published v1.4.0 release.
5
+
6
+ ## Implementation
7
+
8
+ - Strict bounded bundle/policy JSON, domain-separated Ed25519 root signatures,
9
+ exact issuer/audience/model grants, current key authorization and revocation.
10
+ - Explicit optional signed model_id/security_version fields; legacy positional
11
+ ModelCard construction retained, reserved-field shadowing rejected.
12
+ - Frozen VerificationPolicy shared by verify_model, CLI and direct/installed guards.
13
+ Required approvals and timestamps precede the model-state commit. A single loaded
14
+ signature snapshot supplies all model, approval and timestamp checks.
15
+ - Shared per-authority bundle state accepted before model checks; model high-water
16
+ marks committed only after all required checks. POSIX flock, atomic replacement,
17
+ fsync, commit-time concurrency recheck and equal-version equivocation checks.
18
+ - Explicit initialization and administrative reset with exclusive audit backup and
19
+ reason. No state auto-reset, unsigned/OMS bypass, or hidden network fetching.
20
+ - Offline root-signing and policy-state CLI commands; relative deployment paths.
21
+
22
+ ## Independent review and fixes
23
+
24
+ The reviewer found positional ModelCard compatibility and weak stored-digest
25
+ validation. Both were reproduced and fixed. The same positional safeguard was
26
+ applied to VerifyResult. Additional findings concerning idempotent verification
27
+ against unwritable state and structured CLI JSON errors were also fixed.
28
+
29
+ The scoped follow-up reported no remaining important findings in these fixes.
30
+ It independently ran 50 policy/trust/state tests and the four-outcome CLI demo.
31
+
32
+ ## Acceptance coverage
33
+
34
+ Tests cover invalid bundle signatures/scope/schema/time, duplicate JSON/keys,
35
+ explicit floors, shared revocation memory across model IDs, unauthorized model
36
+ identities and keys, rotation without resetting floors, failed approvals and
37
+ missing timestamps without model-state advancement, valid old TSA tokens followed
38
+ by revocation, actual multi-process model races, bundle updates during full API
39
+ verification, corrupt/missing/unwritable state, pre/post-replacement fsync errors,
40
+ reset audit backups, installed Hub policy and legacy constructor compatibility.
41
+
42
+ The CLI demo shows authorized version 12 accepted, version 11 rejected, a revoked
43
+ publisher rejected, and replay of the earlier trust bundle rejected. Its data and
44
+ keys are disposable, and it makes no network or AWS requests.
45
+
46
+ ## Limits
47
+
48
+ Persistent state is for cooperating POSIX processes on suitable local filesystems,
49
+ not a distributed consensus/anti-snapshot mechanism. A trusted clock and deployed
50
+ initial floors are operational prerequisites. Current revocation rejects even
51
+ historical timestamped artifacts; historical authorization is not implemented.
52
+ Already loaded models are not retroactively unloaded. Administrative reset lowers
53
+ the entire shared scope explicitly and is not a cryptographically signed audit.
@@ -0,0 +1,64 @@
1
+ # Trust and rollback implementation plan
2
+
3
+ > **For agentic workers:** Use superpowers:executing-plans to implement task-by-task.
4
+
5
+ Goal: implement the reviewed v1.4 policy without changing legacy verification defaults.
6
+ Architecture: strict signed-bundle module; locked state store; one shared policy
7
+ wrapper around existing verification; CLI and guards delegate to that wrapper.
8
+ Tech stack: Python >=3.9, existing Ed25519/JCS, stdlib filesystem locks.
9
+ Spec: ../specs/2026-12-03-trust-rollback-design.md
10
+
11
+ ## Global constraints
12
+
13
+ - Offline verification; independently pinned root; full key bytes for authorization.
14
+ - Safe integer range 0..2^53-1 (not bool/float); exact model/scope matching.
15
+ - Bundles <=1 MiB, <=1024 keys and model IDs per key; identifiers <=256 ASCII chars.
16
+ - Current authorization only; all revocations reject; expired bundles/keys reject.
17
+ - Accept trust state before model checks; commit model state after all required checks.
18
+ - Legacy no-policy verification remains compatible. No silent state initialization/reset.
19
+
20
+ ## Review focus
21
+
22
+ - Invalid JSON types/duplicates must fail closed: bundle tests.
23
+ - A revoked model must not permit an older bundle next: policy integration tests.
24
+ - High versions with missing approvals must not poison state: policy tests.
25
+ - Racing verifiers must recheck bundle and model versions under one lock: state tests.
26
+ - Installed loader unsigned/OMS fallback must not escape policy: guard tests.
27
+
28
+ ### Task 1: signed bundle and identity
29
+ Files: trust_bundle.py, identity/card.py, tests/test_trust_bundle.py.
30
+ Interface: issue_bundle(payload,key)->dict; verify_bundle(document,root,issuer,audience,now,min_sequence,max_age)->dict;
31
+ strict_load(path)->dict; key_id(raw)->str; PolicyError.
32
+ - [x] Write failing tests for signature/scope/revocation schema, time bounds, duplicate JSON and identity collisions.
33
+ - [x] Implement bounded strict parser, payload validation and domain-separated signing.
34
+ - [x] Run tests and commit.
35
+
36
+ ### Task 2: persistent state
37
+ Files: policy_state.py, tests/test_policy_state.py.
38
+ Interface: initialize_state(path,scope,model_floors,bundle_floor); accept_bundle(path,scope,sequence,digest);
39
+ commit_model(path,scope,model_id,version,binding,bundle)->None.
40
+ - [x] Write failures for missing/corrupt state, rollback/equivocation and cross-model bundle memory.
41
+ - [x] Implement POSIX interprocess lock, atomic/fsynced state writes; fail closed on unsupported platforms.
42
+ - [x] Test process races, failure before replacement, equal-version identity binding and commit-time bundle recheck; commit.
43
+
44
+ ### Task 3: shared policy API
45
+ Files: policy.py, api.py, guard.py, tests/test_policy.py.
46
+ Interface: frozen VerificationPolicy; load_policy(path); verify_model(...,policy=); policy enforcement accepts
47
+ trusted bundle keys, current authorization, version floors, approvals and state in documented order.
48
+ - [x] Write failing integration tests including revoked key/old replay, failed approval and timestamp, unsigned/OMS guard paths.
49
+ - [x] Add a policy wrapper around legacy verifier; preserve exact successful verification key/content results.
50
+ - [x] Thread policy through direct and installed guard; test and commit.
51
+
52
+ ### Task 4: CLI and docs
53
+ Files: cli.py, docs/trust-policy.md, examples/trust_policy_demo.py, tests/test_policy_cli.py.
54
+ Commands: verify --policy/--model-id/--min-security-version; trust-bundle sign; policy-state init.
55
+ - [x] Test CLI floor and revocation failures, relative policy paths and option conflicts before implementation.
56
+ - [x] Translate approval requirements into shared policy before state commit; implement issuance/state initialization commands.
57
+ - [x] Run a reproducible offline demo and full test/mypy/build suite. Independent whole-branch review; fix findings.
58
+ - [x] Push reviewable branch/PR. No release claim until checks finish.
59
+
60
+ ## Ledger
61
+
62
+ Execution authorized by user “implement”; no repeated planning confirmation needed.
63
+
64
+ Tasks 1–4 implemented. Independent whole-branch review completed; all important findings fixed and scoped re-review clear. Full validation and branch publication are recorded in the v1.4 development review.
@@ -0,0 +1,258 @@
1
+ # ModelSign v1.4.0: signed trust bundles and rollback policy
2
+
3
+ Status: implemented for v1.4.0. Design baseline: v1.3.0.
4
+ This document records the accepted direction and implementation choices proposed
5
+ by Codex. It is not a claim that v1.3.0 provides these protections.
6
+
7
+ ## Purpose and scope
8
+
9
+ A deployment should reject an otherwise valid model signature when its publisher
10
+ is no longer authorized, its trust metadata is stale, or its signed security
11
+ version is below deployment policy. Keep verification offline and backwards
12
+ compatible unless the caller explicitly enables the new policy.
13
+
14
+ Deliver v1.4 in two increments: signed bundles plus explicit version/sequence
15
+ floors first; optional persistent rollback state second. Both must use the same
16
+ policy evaluator in the API, CLI, direct guard and installed loader guard.
17
+ No separate policy interpretation in each entry point.
18
+
19
+ ## Approaches
20
+
21
+ 1. Explicit floors and a root-signed local bundle: auditable, reproducible and
22
+ stateless, but operators must advance floors and refresh metadata.
23
+ 2. The same policy plus local high-water marks: catches rollback after observation,
24
+ but introduces locking, persistence, recovery and first-use limitations.
25
+ 3. A complete secure update client such as TUF: broader role separation and update
26
+ distribution, with substantially more integration scope.
27
+
28
+ Use (1), then optional (2). This is not a TUF implementation or replacement.
29
+ Do not add a custom online transparency service, KMS provisioning, C2PA, or a
30
+ commercial hosting promise. v2 is reserved for intentional compatibility changes,
31
+ not for renaming optional functionality.
32
+
33
+ ## Existing code and integration points
34
+
35
+ - `identity/card.py`: ModelCard preserves unknown fields in `extra`, flattened by
36
+ to_dict. Add explicit optional model_id/security_version fields and reject extra
37
+ collisions with reserved fields; do not silently reinterpret conflicting values.
38
+ - `api.py`: verify_model returns the actual verified signer_key and content hash.
39
+ Evaluate policy against those values, never the embedded key or display fingerprint.
40
+ - `guard.py`: require_verified and installed guards must accept the same policy.
41
+ Required policy must not be bypassed by allow_unsigned, OMS fallback, or exceptions.
42
+ - `timestamps.py`: RFC 3161 authenticates an envelope existence bound, not the
43
+ model-signing key's authorization. v1.4 current-authorization policy is independent.
44
+ - `attest.py`: statements remain serving-key claims; no implicit policy proof is
45
+ added to them. Callers obtain the VerifyResult through the policy-enforcing path.
46
+
47
+ ## Trust anchors and wire format
48
+
49
+ Deployments provision one Ed25519 root public key, expected issuer and audience
50
+ out of band. Never accept an embedded root as authority. Root rotation is an
51
+ explicit deployment change in v1.4; it must preserve or deliberately migrate state.
52
+
53
+ `trust-bundle.json` is a strict JSON object with `signed` and `signature` fields:
54
+
55
+ ```json
56
+ {
57
+ "signed": {
58
+ "type": "modelsign-trust-bundle",
59
+ "schema_version": 1,
60
+ "issuer": "example.org/model-security",
61
+ "audience": "production",
62
+ "sequence": 12,
63
+ "issued_at": "2026-12-03T00:00:00Z",
64
+ "expires_at": "2026-12-04T00:00:00Z",
65
+ "keys": [{
66
+ "key_id": "sha256:<64 lowercase hex of raw public key>",
67
+ "public_key": "<canonical base64 of 32-byte Ed25519 key>",
68
+ "valid_from": "2026-12-01T00:00:00Z",
69
+ "valid_until": "2027-01-01T00:00:00Z",
70
+ "revoked_at": null,
71
+ "revocation_reason": null,
72
+ "model_ids": ["example.org/finsense-v5"],
73
+ "roles": ["model_signer"]
74
+ }]
75
+ },
76
+ "signature": "<canonical base64 of 64-byte Ed25519 signature>"
77
+ }
78
+ ```
79
+
80
+ Sign `b"modelsign-trust-bundle-v1\x00" + canonical_json(signed)` with the pinned
81
+ root. The signature field is outside its signed payload. Key IDs are lookup
82
+ identifiers; authorization uses full decoded key bytes and validates the key ID.
83
+ Model IDs are exact matches: no wildcard, prefix, or case-fold matching in v1.4.
84
+ A key may authorize multiple exact model IDs; key rotation does not reset a
85
+ model's floor. A missing key or missing model authorization means reject.
86
+
87
+ Parsing rejects duplicate JSON keys, unknown schema fields, invalid Unicode,
88
+ NaN/infinities, malformed base64, duplicate key IDs and contradictory records.
89
+ Optional revocation fields must both be null or both present. Allowed reasons:
90
+ key_compromise, superseded, administrative. Unknown reasons fail closed.
91
+ Only model_signer is defined in v1.4; approval and TSA trust remain separately
92
+ configured and must not be inferred from these grants.
93
+
94
+ Proposed limits: bundle <=1 MiB; <=1024 key entries; <=1024 model IDs per entry;
95
+ identifiers <=256 ASCII characters, nonempty; safe integers in [0, 2^53-1], bool
96
+ and float rejected. Timestamps are real UTC calendar instants in YYYY-MM-DDTHH:MM:SSZ.
97
+ These limits are implementation choices, not upstream protocol requirements.
98
+
99
+ ## Signed model fields
100
+
101
+ ```json
102
+ {"name":"FinSense v5","model_id":"example.org/finsense-v5","security_version":12}
103
+ ```
104
+
105
+ These fields are inside the signed identity. `security_version` is an integer,
106
+ not SemVer or a date; never order using signed_at. Validate on signing when
107
+ present, and independently after signature verification under required policy.
108
+ Legacy cards continue to work without new policy; required rollback policy rejects
109
+ missing model_id/version. The deployment supplies expected_model_id; the artifact
110
+ cannot select a different identity to escape an existing floor.
111
+
112
+ ## v1.4 authorization semantics
113
+
114
+ Capture one trusted wall-clock instant `now` for the verification attempt.
115
+ Require issued_at <= now < expires_at, issued_at < expires_at, and optional
116
+ max_trust_age with now-issued_at <= configured age. No implicit grace period.
117
+ The root signer and verifier must use synchronized clocks; wrong local time can
118
+ invalidate these guarantees. Validate key intervals valid_from < valid_until.
119
+
120
+ Require key.valid_from <= now < key.valid_until. Any non-null revoked_at rejects
121
+ the key immediately for model acceptance, regardless of timestamp or reason.
122
+ Future scheduled revocations are not represented as revoked records; use
123
+ valid_until for planned cessation. A revoked_at after bundle issued_at is invalid.
124
+
125
+ This is deliberately CURRENT authorization, not historical acceptance. It rejects
126
+ artifacts signed by expired, retired or compromised keys even if their timestamps
127
+ predate retirement. An RFC 3161 timestamp cannot prove the actual signing instant
128
+ or that signing occurred after valid_from. Do not market this policy as proof
129
+ that the key was valid at signing. Historical policy is deferred and would need
130
+ separate semantics, TSA accuracy handling and explicit opt-in.
131
+
132
+ ## Proposed API and commands (not available in v1.3.0)
133
+
134
+ Create an immutable VerificationPolicy holding trust_bundle path, root_pubkey,
135
+ issuer, audience, expected_model_id, optional min_security_version,
136
+ min_bundle_sequence, max_trust_age_seconds and optional state_path. Include explicit
137
+ required_approval_roles, min_approvals, approver_pubkeys and approver_keyring_dir;
138
+ approver identities are full key bytes resolved through these separate trusted
139
+ inputs, not inferred from a bundle model_signer grant.
140
+ Pass `policy=` to verify_model, require_verified and install. Policy does not
141
+ replace required timestamp, trusted approval or name-binding checks.
142
+ Move required-approval enforcement into the shared verification pipeline before
143
+ its state commit. Today the CLI calls require_approval after verify_model returns;
144
+ that ordering must change. Translate existing CLI approval flags into the shared
145
+ verification request, preserving their current role/quorum semantics. API and
146
+ guards use the same request. No path may commit a high-water mark and then perform
147
+ required approval checks outside the verifier. Read/display-only approval reporting
148
+ may remain outside. Test the approval-rejected high-version artifact explicitly.
149
+
150
+ A CLI policy file supplies these settings; paths resolve relative to the policy
151
+ file, never relative to an untrusted model directory. Explicit CLI overrides must
152
+ be documented; conflicting values reject rather than silently weaken policy.
153
+
154
+ Proposed flags: --policy FILE, --min-security-version INT. Standalone version-floor
155
+ use requires --model-id ID and a trusted pubkey/keyring. A bundle can supply the
156
+ trusted signing key after authenticating the root and model grant; if --pubkey is
157
+ also supplied, both constraints must agree. An enabled policy never falls back to
158
+ an embedded-only key. Reject model-signer policy on OMS-only verification until an
159
+ explicit adapter exists. CLI errors and failed JSON results identify the policy
160
+ stage without exposing credentials.
161
+
162
+ Bundle issuance is a separate offline command that validates the payload before
163
+ root-signing it. Verification never fetches artifact-supplied URLs. Operators
164
+ refresh a local bundle independently (HTTPS may transport bytes; the signature is
165
+ the authority). Keep signing-root private keys off serving machines.
166
+
167
+ ## Floors, state and transaction ordering
168
+
169
+ Effective model floor = max(configured floor, persisted high-water mark).
170
+ Scope model state by (pinned root fingerprint or explicit publisher-key identity,
171
+ issuer, audience, expected_model_id). For bundle-authorized rotations use the stable
172
+ root scope, not the rotating leaf key. State from a different scope cannot apply.
173
+
174
+ Bundle state is scoped ONLY by (root fingerprint, issuer, audience), never by
175
+ model ID. One configured state file holds that scope's bundle record plus a map of
176
+ model IDs to model-state records. All processes and all model policies that share
177
+ this trust scope must use that same state path and lock. Initialization pins the
178
+ scope in the file header; a scope mismatch rejects. A model-specific state file is
179
+ not a supported layout. Separate hosts/files do not share observations: operators
180
+ must distribute configured sequence floors or use a future coordinated service.
181
+ There is no claim of cross-machine revocation memory.
182
+
183
+ Bundle state stores highest accepted sequence plus canonical signed-payload digest.
184
+ Reject lower sequences. At an equal sequence, reject a different signed payload;
185
+ accept an identical payload without needlessly rewriting state. Model state stores
186
+ highest security_version and authenticated content/identity binding. For an equal
187
+ version, require the same content and canonical identity digest; a re-signing or
188
+ publisher rotation may be allowed if that binding is unchanged and current policy
189
+ accepts the key. Different artifact content requires a higher version.
190
+
191
+ Two distinct transactions are necessary:
192
+ 1. After validating root signature, scope, schema, freshness and sequence, atomically
193
+ record acceptance of the bundle BEFORE checking the candidate model. This ensures
194
+ a freshly learned revocation is not forgotten just because that model is rejected.
195
+ 2. Only after ALL model signature, identity, trust, timestamp, approval and rollback
196
+ checks succeed, atomically commit the model high-water mark, then return success.
197
+
198
+ Do not advance model state for rejected signatures or unauthorized high-version
199
+ artifacts. Do not roll back accepted trust state on model failure. No signed_at
200
+ value participates in either version ordering.
201
+
202
+ Use an interprocess lock and read/check/write transaction for each state file;
203
+ write a mode-0600 temporary file, flush/fsync, atomically replace, and sync its
204
+ parent directory where supported. Re-read while locked before comparing values.
205
+ If a newer bundle was committed concurrently, fail with a retryable policy error
206
+ and refresh/reverify; never return success under superseded bundle state. If model
207
+ state advanced concurrently, reapply its floor and equal-version binding check.
208
+
209
+ An explicitly enabled state path fails closed on missing, corrupted, wrong-scope,
210
+ unwritable or unsupported-lock state. An explicit initialization command creates
211
+ it without overwriting existing state and records deployment floors. No silent
212
+ TOFU bootstrap or automatic reset on read errors. Provide migration/reset as an
213
+ explicit administrative operation with a backup and recorded reason, not a
214
+ per-load --force bypass. Crash recovery must not lower accepted state.
215
+
216
+ The guarantee is monotonic policy acceptance among cooperating processes using
217
+ this state. It cannot stop a privileged actor deleting/replacing state, a restored
218
+ VM snapshot, or a model already in memory. First deployment needs externally
219
+ provisioned floors; an old but unexpired bundle remains replayable on a fresh
220
+ machine without a sequence floor. This is not remote transparency or consensus.
221
+
222
+ ## Acceptance tests and release gates
223
+
224
+ | Test | Required outcome |
225
+ |---|---|
226
+ | Altered bundle, wrong root, issuer or audience | Reject |
227
+ | Duplicate JSON keys/records, float/bool sequence, unknown schema/reason | Reject |
228
+ | Expired/future bundle, excessive age, clock boundary | Reject deterministically |
229
+ | Unknown/expired/revoked key, wrong model grant | Reject |
230
+ | Compromised key with old valid TSA token | Reject |
231
+ | Missing signed identity fields under required policy | Reject |
232
+ | Artifact chooses another model ID or huge unauthorized epoch | Reject; model state unchanged |
233
+ | Version 12 then 11, sequence 12 then 11 | Reject regression |
234
+ | Equal sequence with changed bundle payload | Reject |
235
+ | Equal model version with changed content or identity | Reject |
236
+ | Authorized key rotation, same model identity | Preserve floor |
237
+ | Fresh valid revocation bundle rejects model A; old bundle replay for model B in the same state scope follows | Reject old bundle |
238
+ | Bad bundle/model signature | Never advance the corresponding state |
239
+ | Concurrent writers accepting different epochs | Atomic monotonic state |
240
+ | Crash around replace/fsync; corrupt/missing/unwritable state | No silent reset or successful load |
241
+ | Timestamp/approval failure after bundle acceptance | Keep bundle state; do not advance model state |
242
+ | Guard unsigned/OMS fallback with policy enabled | Reject bypass |
243
+ | Existing v1.3 signatures without new policy | Still verify |
244
+ | Actual revoked-key and rollback CLI demo | Deterministic rejection, documented exit statuses |
245
+
246
+ Release requires supported-Python CI, independent review of policy/state ordering,
247
+ reproducible adversarial tests, and a runnable example. Do not ship local-state
248
+ claims until filesystem/process-race tests pass. This design does not establish
249
+ that these features have been built or audited.
250
+
251
+ ## References
252
+
253
+ TUF's signed versions, expirations and persistent client state are relevant prior
254
+ art for rollback/freeze defenses; the small format here does not implement its
255
+ role structure or claim compatibility: https://theupdateframework.github.io/specification/latest/
256
+
257
+ RFC 3161 defines timestamp tokens and accuracy: https://www.rfc-editor.org/rfc/rfc3161
258
+ RFC 8785 defines the canonical JSON already used by ModelSign: https://www.rfc-editor.org/rfc/rfc8785