Skip to content

docs(examples): add runnable signed operator-grant and CIBA step-up approval supervisor middleware example #6145

Backlog

Description

@Epistetechnician

User Story

I use OpenShell to run autonomous agents inside isolated sandboxes with L7 egress enforcement and need a fail-closed, cryptographically verifiable human-in-the-loop approval gate before high-risk outbound HTTP requests (such as production mutations or sensitive API calls) are allowed to proceed. I need a runnable supervisor middleware example demonstrating how an external service verifies a pinned operator's Ed25519-signed scoped grant or out-of-band (CIBA-style) step-up approval bound to the gateway-attested sandbox_id and request digest, without ever exposing operator signing keys inside the sandbox.

Problem Statement

OpenShell provides an external supervisor middleware contract (SupervisorMiddleware + HttpHooks) and ships examples/supervisor-middleware-content-guard for payload inspection, alongside the ANS identity example track (#5011). Today, there is no runnable example showing how to use the existing http_request / pre_credentials hook to enforce operator-signed, short-lived step-up authorization (scoped OperatorGrants and action-digest-bound CIBA approvals) that fails closed on missing, expired, revoked-device, or cross-sandbox replayed approvals.

This is a self-contained example contribution under examples/ that requires no OpenShell runtime or protobuf changes.

Impact / Why This Matters

Static L7 network policies allow or deny endpoints coarsely, which forces operators to choose between permanently permitting high-risk endpoints or blocking them entirely. Teams building human-in-the-loop approval gates on top of OpenShell currently have to piece together Describe / ValidateConfig capability negotiation, pre_credentials preflight handling, fail-closed denial diagnostics, Overwrite header attestation (to defeat workload header forgery), and cryptographic binding to RequestContext.sandbox_id from scratch.

A runnable reference example gives operators and extension authors a verified starting point for cryptographic step-up approval and complements the ongoing Credential Issuer Interface work (RFC 0023 / PR #5139) on the request-time mediation path.

Proposed Design

Add a standalone, runnable Rust example under examples/supervisor-middleware-operator-grant/ following the structure of examples/supervisor-middleware-content-guard/.

Externally observable behavior:

  1. Manifest & Config Validation (SupervisorMiddleware):
    • Advertises the openshell.supervisor-middleware.http-hooks capability bound strictly to http_request in the pre_credentials phase (Preflight-only, ContinueWithoutBody).
    • Validates per-policy config (operator_card_path, grant_store_path, required_tier, header_prefix) at policy-load time via ValidateConfig.
  2. Cryptographic Verification (HttpHooks.EvaluateHttpRequestHook):
    • Loads a pinned operator card (enrolled Ed25519 devices, revocation list, per-device tier_max) and an operator-controlled grant/approval store outside the sandbox.
    • Computes a deterministic SHA-256 action_digest over (sandbox_id, method, authority, path) and verifies either:
      • a signed scoped OperatorGrant matching operator_did, sandbox_id, non-revoked enrolled signer device, expiry, and tier >= required_tier, or
      • a signed out-of-band CIBA approval bound to the exact action_digest and required_tier.
    • Fails closed (HttpDenial with structured MiddlewareDiagnostics reason codes, never logging raw signatures or query parameters) on missing, expired, revoked-device, insufficient-tier, tampered-action, or cross-sandbox replayed approvals.
  3. Anti-Forgery Header Attestation:
    • On allow, uses WriteHeader with ExistingHeaderAction::Overwrite to stamp verified attestation headers (x-openshell-operator-id, x-openshell-grant-kind, x-openshell-approval-id, x-openshell-action-digest), replacing any forged headers supplied by the sandbox workload.

Suggested UX (if applicable)

Gateway middleware registration:

[[openshell.supervisor.middleware]]
name = "operator-grant-example"
grpc_endpoint = "http://127.0.0.1:50055"
binding_policy = "allowlist"
bindings = ["http_request_pre_credentials"]

Bundled sandbox policy (examples/supervisor-middleware-operator-grant/policy.yaml):

network_middlewares:
  operator-grant-gate:
    middleware: operator-grant-example
    order: 50
    on_error: fail_closed
    endpoints:
      include: ["api.example.com"]
    config:
      operator_card_path: "/etc/openshell/operator-card.json"
      grant_store_path: "/var/run/openshell/operator-grants.json"
      required_tier: 2
      header_prefix: "x-openshell"

Acceptance Criteria

  • examples/supervisor-middleware-operator-grant/ builds and passes cargo test and cargo clippy --all-targets -- -D warnings as a standalone package against the workspace openshell-core and openshell-policy crates.
  • Unit and gRPC contract tests verify:
    • valid signed OperatorGrant allows a matching sandbox and overwrites workload-forged attestation headers;
    • valid CIBA approval allows the exact bound (sandbox_id, method, authority, path) and denies a tampered path;
    • cross-sandbox replay of a valid grant is denied;
    • revoked signer devices and expired grants are denied;
    • Describe advertises http_request / pre_credentials, and ValidateConfig rejects invalid tiers or missing paths;
    • the bundled policy.yaml passes openshell_policy::parse_sandbox_policy and validate_sandbox_policy.
  • README.md documents the trust boundary, prototype/example scope, configuration, and verification commands without requiring production secrets.

Alternatives Considered

  • Static L7 network policy alone: Cannot express time-bounded, per-action human step-up approval or cryptographic device binding.
  • Built-in supervisor feature: Unnecessary; the existing external SupervisorMiddleware + HttpHooks contract already supports pre_credentials preflight gating, fail-closed denial, and Overwrite header mutations with zero runtime changes.
  • Gateway interceptor: Governs control-plane RPCs rather than per-request sandbox HTTP egress, making supervisor middleware the right extension point for outbound request gating.
  • Credential Issuer TokenMinter (RFC 0023 / PR docs(rfc): propose credential issuer service #5139): Well suited for credential minting/refresh flows, whereas request-time step-up gating on arbitrary outbound HTTP calls belongs in supervisor middleware; the two compose cleanly.

Compatibility Investigation

  • A complete working reference implementation is staged on a fork branch for review once this issue is triaged: examples/supervisor-middleware-operator-grant.
  • Verified locally on Rust 1.95.0: cargo test (8/8 passing) and cargo clippy --all-targets -- -D warnings (0 warnings), including openshell_policy validation of the bundled policy.yaml.
  • Requires no changes to proto/ or any core OpenShell crate.

Activity

  1. added
    state:triage-needed
    on Dec 1, 2026
  2. FrostGod commented on Dec 2, 2026

    @FrostGod
    Contributor

    @purp wanna take a stab at the DOCS part

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:triage-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions