Skip to content

feat: authenticate tool gate deployments - #35

Merged
Deathcharge merged 2 commits into
mainfrom
codex/authenticated-deployments
Aug 2, 2026
Merged

feat: authenticate tool gate deployments#35
Deathcharge merged 2 commits into
mainfrom
codex/authenticated-deployments

Conversation

@Deathcharge

@Deathcharge Deathcharge commented Aug 2, 2026

Copy link
Copy Markdown
Owner

What

  • add versioned HMAC-SHA-256 authentication envelopes for complete tool-gate deployments
  • verify audience, key identifier, monotonic sequence floor, validity window, deployment fingerprint, and authenticated content before binding callbacks
  • add strict bounded JSON I/O, JSON Schema, CLI workflows, public APIs, and an end-to-end example
  • document key custody, replay, clock, rotation, and asymmetric-identity boundaries

Why

Tool-gate artifacts already had strict parsing and coherent deployment binding, but operators still needed a dependency-free way to detect tampering and reject stale or incorrectly targeted deployments before executable callbacks are inspected or bound.

Impact

This gives embedded and self-hosted deployments a production-oriented symmetric authentication path while preserving the zero-runtime-dependency package. It is intentionally not a replacement for Sigstore/TUF or other asymmetric public-identity and distribution systems.

Verification

  • 491 tests passed on the pinned environment
  • 95.71% branch-aware total coverage; authenticated deployment module 94%
  • Ruff format/check passed
  • strict mypy passed for all 34 source files
  • sdist and wheel built and passed Twine checks
  • clean-venv installed-wheel CLI and example smoke tests passed
  • adversarial tests cover tampering, expiry, audience mismatch, rollback floors, duplicate JSON keys, bounds, and verification-before-callback-inspection

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added authenticated tool-gate deployment envelopes using HMAC-SHA-256.
    • Added deployment fingerprints, audience binding, sequence checks, key rotation, and validity windows.
    • Added CLI workflows for creating, verifying, loading, and inspecting deployment envelopes.
    • Added authenticated deployment binding for tool gates and dispatchers.
    • Added atomic envelope file handling and JSON Schema support.
  • Documentation

    • Added guides covering authenticated deployments, security boundaries, architecture, API usage, and quickstart workflows.
  • Tests

    • Added comprehensive coverage for authentication, tampering, expiration, replay protection, persistence, schemas, and CLI behavior.

Walkthrough

The change adds freshness-aware HMAC authentication for complete tool-gate deployments. It introduces fingerprints, envelopes, verification, bounded persistence, CLI workflows, authenticated gate and dispatcher binding, schemas, tests, CI smoke coverage, and documentation.

Changes

Authenticated deployment support

Layer / File(s) Summary
Envelope contract and verification
src/samsarix_ethics/authenticated_deployment.py, src/samsarix_ethics/provenance.py, src/samsarix_ethics/schema.py, src/samsarix_ethics/io.py, src/samsarix_ethics/errors.py, src/samsarix_ethics/__init__.py
Adds versioned deployment fingerprints, HMAC-SHA-256 envelopes, strict claim validation, verification, schemas, bounded atomic I/O, authentication errors, and public exports.
CLI authentication workflows
src/samsarix_ethics/cli.py
Adds gate-deployment authenticate and verify-authentication, key loading, timestamp and sequence validation, envelope rendering, schema selection, and fingerprint output.
Authenticated binding and execution
src/samsarix_ethics/gate.py, src/samsarix_ethics/dispatch.py, examples/authenticated_deployment_demo.py
Adds authenticated deployment binding for ToolGate and ToolDispatcher. The demo persists, reloads, verifies, binds, and executes a constrained tool deployment.
Validation and delivery coverage
tests/test_authenticated_deployment.py, tests/test_cli.py, tests/test_public_api.py, .github/workflows/ci.yml
Adds coverage for tampering, freshness, key handling, persistence, schemas, binding order, CLI workflows, exports, source smoke tests, wheel smoke tests, and the authenticated demo.
Authenticated deployment documentation
README.md, SECURITY.md, CHANGELOG.md, ROADMAP.md, docs/*
Documents the envelope contract, APIs, CLI usage, architecture, security boundaries, limitations, adoption workflow, schema inventory, and release status.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: authentication for tool-gate deployments.
Description check ✅ Passed The description explains the change, rationale, impact, security boundaries, and verification results, with only minor template differences.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/authenticated-deployments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/API.md`:
- Around line 438-443: Update the `authenticate_tool_gate_deployment`
documentation to state that the HMAC-SHA-256 covers the envelope’s
`unsigned_dict()` or all non-MAC fields, rather than every envelope field. Keep
the description consistent with the later `unsigned_dict()` definition.

In `@docs/AUTHENTICATED_DEPLOYMENTS.md`:
- Around line 58-73: Make both documented authentication verification examples
deterministic by adding --at 2026-08-02T12:00:00Z to the verify-authentication
commands in docs/AUTHENTICATED_DEPLOYMENTS.md lines 58-73 and docs/QUICKSTART.md
lines 197-212, matching the envelope’s validity window.

In `@docs/QUICKSTART.md`:
- Line 238: Add the missing `samsarix-ethics schema
tool-gate-deployment-envelope` command to the schema list under “Start a policy
of your own” in the Quickstart, matching the ordering and formatting used by
README.md and docs/POLICY_FORMAT.md.

In `@ROADMAP.md`:
- Around line 86-88: Update the roadmap sentence describing the HMAC envelope to
explicitly identify its authenticated artifact as a complete tool-gate
deployment or ToolGateDeployment, replacing the ambiguous “Single-file
deployments” wording while preserving the remaining caller-owned
responsibilities.

In `@src/samsarix_ethics/authenticated_deployment.py`:
- Line 43: Update the MAC generation and validation pattern around _mac and _MAC
to derive the version and algorithm prefix from
TOOL_GATE_DEPLOYMENT_AUTH_VERSION and _ALGORITHM instead of hardcoding
v1:hmac-sha256. Ensure both emitted MACs and the accepted regular expression
remain synchronized when either constant changes.
- Around line 424-438: Update the authentication flow around the trusted_keys
loop to select envelope.key_id from the raw keyring before validating key
material, so unused malformed entries do not affect verification. Preserve the
key-count bound, validate the selected key ID with _identifier, validate only
its key bytes with _key, and use that validated key for _mac and existing trust
errors.

In `@src/samsarix_ethics/dispatch.py`:
- Around line 164-193: The authenticated identity is discarded after
verification, so bound dispatchers and gates cannot report which envelope
authorized them. Update bind_authenticated_deployment in dispatch.py and
ToolGate.bind_authenticated_deployment in gate.py to retain the complete
VerifiedToolGateDeployment, pass or store it on the resulting object, and expose
it through a read-only property containing key_id, sequence, verified_at, and
deployment_fingerprint while preserving verification before registered_tools
access.

In `@src/samsarix_ethics/provenance.py`:
- Around line 105-112: Update fingerprint_tool_gate_deployment to annotate
deployment as ToolGateDeployment, adding a TYPE_CHECKING-only import while
preserving the existing local runtime import and isinstance validation. Ensure
deferred annotations are enabled as indicated before using the type-only
reference.

In `@src/samsarix_ethics/schema.py`:
- Around line 141-153: The schema definitions for key_id, audience, mac, and
sequence duplicate runtime constraints from authenticated_deployment. Update
schema.py to derive these limits from _IDENTIFIER, _AUDIENCE, _MAC, and
MAX_DEPLOYMENT_AUTH_SEQUENCE, avoiding an import cycle; if direct reuse is not
possible, add a test asserting the schema patterns match the runtime regex
source strings.

In `@tests/test_authenticated_deployment.py`:
- Around line 290-295: Update the isolation assertion in the test around
get_tool_gate_deployment_envelope_schema by mutating the initially returned
schema object directly, then obtain a second schema from the function and assert
its title remains unchanged. Remove the copy import if no other tests in the
file use it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a8c1806c-9f62-42b2-8586-02b4e5da29ba

📥 Commits

Reviewing files that changed from the base of the PR and between 18416b0 and 15010ce.

📒 Files selected for processing (25)
  • .github/workflows/ci.yml
  • CHANGELOG.md
  • README.md
  • ROADMAP.md
  • SECURITY.md
  • docs/ADOPTION.md
  • docs/API.md
  • docs/ARCHITECTURE.md
  • docs/AUTHENTICATED_DEPLOYMENTS.md
  • docs/POLICY_FORMAT.md
  • docs/PRODUCTIZATION.md
  • docs/QUICKSTART.md
  • examples/authenticated_deployment_demo.py
  • src/samsarix_ethics/__init__.py
  • src/samsarix_ethics/authenticated_deployment.py
  • src/samsarix_ethics/cli.py
  • src/samsarix_ethics/dispatch.py
  • src/samsarix_ethics/errors.py
  • src/samsarix_ethics/gate.py
  • src/samsarix_ethics/io.py
  • src/samsarix_ethics/provenance.py
  • src/samsarix_ethics/schema.py
  • tests/test_authenticated_deployment.py
  • tests/test_cli.py
  • tests/test_public_api.py

Comment thread docs/API.md
Comment thread docs/AUTHENTICATED_DEPLOYMENTS.md Outdated
Comment thread docs/QUICKSTART.md
Comment thread ROADMAP.md Outdated
Comment thread src/samsarix_ethics/authenticated_deployment.py Outdated
Comment thread src/samsarix_ethics/authenticated_deployment.py Outdated
Comment thread src/samsarix_ethics/dispatch.py
Comment thread src/samsarix_ethics/provenance.py Outdated
Comment thread src/samsarix_ethics/schema.py
Comment thread tests/test_authenticated_deployment.py Outdated
@Deathcharge
Deathcharge merged commit c8e8824 into main Aug 2, 2026
6 checks passed
@Deathcharge
Deathcharge deleted the codex/authenticated-deployments branch August 2, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant