Signed decisions and inputs

A signed decision proves which policy gave which output for which input, and when.

The decision is an in-toto statement, the format of in-toto for a signed claim about an artifact. It is in a DSSE envelope, a standard format for signed data. cosign, the signing tool of the Sigstore project, can verify it.

The predicate type is https://rego4k.dev/decision/v1. Signed decisions explains why and when to sign.

Module What it holds
rego4k-signing-signer DecisionSigner, SigningKey, InputSigner and Decision.reproduce. It needs the engine and the bundles.
rego4k-signing-verifier DecisionVerifier, Trust and the format of a decision. It has no engine, for a system that only receives decisions.
rego4k-server-signing SignedDecisions.module: the routes /v1/signed/data/... of the decision server.

Sign a decision

A SigningKey is a private key, its key ID, and the certificate chain of its public key.

DecisionSigner evaluates an entrypoint of a bundle and signs the decision.

The decision holds:

Signatures.kt
val rego = Rego(Builtins.Pure.stdlib(Re2Engine), clock = clock)
val bundle = Bundle.read(policies)
val key = SigningKey(
    "decisions-2026",
    Key(certificates.resolve("leaf.key").readText(), SignatureAlgorithm.ES256),
    // the chain
    certificates.resolve("leaf.pem").readText() +
        certificates.resolve("intermediate.pem").readText(),
)
val signer = DecisionSigner(bundle, rego, key)
val signed = signer.sign(
    Query.Entrypoint("authz/allow"),
    input,
    bundle.data(rego),
    Principal("https://login.example.com", "billing"),
)
Signatures.kt, lines 38 to 53, on GitHub

Verify and reproduce a decision

DecisionVerifier verifies the signature with a Trust, and gives the decision. A Trust is one of these:

An auditor with the bundle, the input and the data can also evaluate the query again at the time of the decision, with the recorded provided values, and compare the output. reproduce throws a DecisionException if the output is different.

Signatures.kt
val verifier = DecisionVerifier(
    Trust.Authorities(
        certificates.resolve("root.pem").readText(),
        SignatureAlgorithm.ES256,
    ),
)
// the certificate chain and the signature, or a DecisionException
val decision = verifier.verify(envelope)
val rego = Rego(Builtins.Pure.stdlib(Re2Engine), clock = clock)
val bundle = Bundle.read(policies)
// the same output at the time of the decision
decision.reproduce(bundle, rego, input, bundle.data(rego))
Signatures.kt, lines 61 to 72, on GitHub

Only a decision that called no impure builtin can be reproduced. A DecisionSigner with pure = true does not sign an impure decision.

Sign an input

An upstream system can sign the input that it sends to the decision server, for one entrypoint. Then the decision holds the signed input, and the server can prove that the upstream sent this input.

InputSigner signs the input with the time of its clock and a new random id.

Signatures.kt
// the upstream system
val envelope = InputSigner(upstreamKey, clock)
    .sign(Query.Entrypoint("authz/allow"), input)
// POST /v1/signed/data/authz/allow
val body = Obj.of("input" to input, "signedInput" to JsonReader.parse(envelope))
// the server
val verified = SignedInput.verify(
    envelope,
    Trust.Keys(mapOf("billing-2026" to upstreamPublicKey)),
)
Signatures.kt, lines 82 to 91, on GitHub

The README of rego4k-signing-verifier has the format of a signed decision and of a signed input, and how to verify them with cosign.

The README of rego4k-server-signing explains how the server names the principal and checks the signed inputs.