Two-person approval
Scenario. Your finance team approves orders from EUR 20,000.00. Company policy now says that orders from EUR 30,000.00 also need the head of procurement.
You can add this as a new policy file, without touching the existing rules.
Start from a clean sandbox, in its directory:
./sandbox destroy
./sandbox up
Add the rule
Section titled “Add the rule”Copy the starter bundle and add a package. Sefra merges the rules of every package, so this requirement joins the existing one:
rm -rf two-person && cp -R bundle two-person
cat > two-person/policies/second_approver.rego <<'EOF'
package policies.second_approver
threshold_minor := 3000000 # EUR 30,000.00
require_approval contains {
"rule": "procurement.head_approval",
"message": sprintf("Order total %d is at least %d minor units.", [total, threshold_minor]),
"approver": {"role": "procurement_head"},
"distinct_from_requester": true,
} if {
input.intent.type == "procurement.create_purchase_order"
total := input.input.quantity * input.input.unit_price_minor
total >= threshold_minor
}
EOF
cat > two-person/policies/second_approver_test.rego <<'EOF'
package policies.second_approver_test
import data.policies.second_approver
order(quantity) := {
"intent": {"type": "procurement.create_purchase_order"},
"input": {"quantity": quantity, "unit_price_minor": 100000},
}
test_needs_head_at_threshold if {
count(second_approver.require_approval) == 1 with input as order(30)
}
test_no_head_below_threshold if {
count(second_approver.require_approval) == 0 with input as order(29)
}
EOF
./sandbox sefra bundle test two-person
SEFRA_TOKEN=$(./sandbox token admin) ./sandbox sefra bundle apply two-person
Place a large order
Section titled “Place a large order”An order of EUR 35,000.00 now needs both roles:
AGENT=$(./sandbox token agent)
RESPONSE=$(curl -sS -X POST http://127.0.0.1:18180/v1/executions \
-H "Authorization: Bearer $AGENT" -H "Content-Type: application/json" \
-H "Idempotency-Key: two-person-example-1" \
-d '{"intent": "procurement.create_purchase_order",
"input": {"vendor_id": "v_1001", "sku": "SERVER-RACK", "quantity": 35,
"unit_price_minor": 100000, "currency": "EUR", "department": "it-ops"},
"rationale": "Racks for the new server room"}')
echo "$RESPONSE" | jq '{status, required: .approval.required}'
EXECUTION=$(echo "$RESPONSE" | jq -r .execution_id)
APPROVAL=$(echo "$RESPONSE" | jq -r .approval.approval_id)
Approve as the first person
Section titled “Approve as the first person”After Maria approves, the order is still held, because the second role is outstanding:
SEFRA_OPERATOR_TOKEN=$(./sandbox token approver) ./sandbox sefra approvals approve "$APPROVAL" --comment "Within budget"
curl -sS "http://127.0.0.1:18180/v1/executions/$EXECUTION" -H "Authorization: Bearer $AGENT" | jq .status
Approve as the second person
Section titled “Approve as the second person”SEFRA_OPERATOR_TOKEN=$(./sandbox token head) ./sandbox sefra approvals approve "$APPROVAL" --comment "Agreed for the server room"
./sandbox wait "$EXECUTION" | jq '{status, output: .steps[0].output}'
Both decisions are now in the audit trail, each with its person and comment:
SEFRA_OPERATOR_TOKEN=$(./sandbox token admin) ./sandbox sefra executions audit "$EXECUTION" \
| jq -r '.events[] | select(.type == "approval.decided") | "\(.seq) \(.actor)"'
Variations
Section titled “Variations”- Require a stronger sign-in. Add
"min_evidence": "oidc"to the requirement, so that the person must decide on the approval page after signing in with your identity provider. - Two people with the same role. Requirements are merged by role, so one person satisfies every requirement that names their role. To need two people, name two roles.
To return to the starter policy:
SEFRA_TOKEN=$(./sandbox token admin) ./sandbox sefra bundle apply bundle