Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← Week 18: Sandboxing and Governance

Week 18 / Lesson 2

Binding policy and approval to execution

Reject operations outside the exact authorized parameters and policy.

Section 2.1 1 of 7

Overview

Focus

Reject operations outside the exact authorized parameters and policy.

Your route through the lesson

  • 2.2 Runtime policy decisions
  • 2.3 Approval records, scope, and expiry
  • 2.4 Rechecking authority before effects
  • 2.5 Put it into practice
  • 2.6 Guided comparison
  • 2.7 An expired approval reused for a new operation

All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.

Section 2.2 2 of 7

Runtime policy decisions

Focus

Evaluate structured requests against policy independently of model wording.

A runtime policy decides whether a concrete operation is permitted. It consumes authenticated actor, project, operation, target, payload scope, and relevant limits. The decision should be made by trusted code or a service at the execution boundary, not inferred from how confidently a model describes the request.

For a local export, policy might permit worker1 in project p1 to write one bounded report to local-report. It denies cross-project data, unknown destinations, and oversized payloads. A request can be structurally valid yet fail policy. Conversely, a harmless narrative that says approved is not an approval record.

Keep policy version and decision reason so outcomes are reproducible. Fail closed when required fields are missing: absence of destination must not mean any destination. Separate policy permission from process capability. A process may technically write a path but still lack application authorization; a permitted operation may fail because the runtime correctly denies an unexpected path. Both layers matter. A policy fixture can test decision logic, while the previous lesson's restricted worker supplies separate evidence about actual system-call boundaries.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A model says an export is approved but no approval record exists. Decision?
2. Destination is missing from a required request field. Safe default?
3. A process can technically write a file. Does that mean the application has authorized the write?

Section 2.3 3 of 7

Approval records, scope, and expiry

Focus

Bind approvals to exact actor, project, operation, payload, destination, and expiry.

An approval is a scoped authorization record, not a reusable sentiment. It should identify who approved, which actor may execute, the project, logical operation identifier, destination, payload identity, maximum size, expiry, and relevant policy version. A changed parameter can change the consequence and therefore require new approval.

The weekly fixture binds a SHA-256 payload digest to the synthetic export. If bytes change, the digest changes and the old approval no longer matches. The operation identifier prevents an approval for export7 from automatically authorizing export8. A production executor also needs replay control if an approval is single-use, typically recording consumption with the logical effect so duplicate attempts reconcile rather than create new effects.

Expiry is evaluated at execution time under a defined clock. The fixture allows now less than expires, so exactly at expiry the request is denied. Use an appropriate trusted clock in a real system and define behavior for long-running work. Approval can authorize an operation without guaranteeing it will succeed; runtime errors and remote uncertainty still require outcome records. Do not convert an approval decision into a fabricated effect-completion claim.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Approval expires at 200 and now equals 200 under now < expires. Allowed?
2. Approval names export7; request names export8 with the same payload. What should happen?
3. Does approval prove the effect completed?

Section 2.4 4 of 7

Rechecking authority before effects

Focus

Recheck authority immediately before effects and reconcile duplicate attempts.

A gap between checking and acting can invalidate authorization. A destination may change, approval may expire, or project membership may be revoked while work is prepared. The executor should validate the exact final parameters immediately before the consequential action, using authoritative state rather than an earlier model summary.

For local publication, prepare content in scratch, compute its digest, check approval for that digest and path, then publish through a controlled operation. Where possible, make approval consumption and local effect recording atomic. For a remote effect, retain the logical operation identifier and reconcile uncertain outcomes. A second attempt should not create a new effect merely because the first acknowledgment was lost.

Do not allow the worker to modify the approved request after the check. Use immutable request data or rederive and compare the final canonical parameters. Canonicalization means representing equivalent requests consistently before hashing or comparison; it must not hide meaningful differences such as destination or project. The core fixture tests exact fields and expiry, while production replay consumption, revocation, and atomic publication remain explicit integration requirements rather than implied guarantees.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A destination changes after an early approval check. What should execution do?
2. A remote export times out after submission. Before a new effect attempt, what is needed?
3. What should canonicalization preserve?

Section 2.5 5 of 7

Put it into practice

Focus

Run exact approval matching and rejection of changed, expired, and cross-project requests.

Download week18.py, save it in an exercise folder, and run python week18.py --lesson 2. This single practice is a deterministic policy fixture, not the container runtime probe. It uses a small processor and Python's standard library, finishes within seconds, and performs no real export or model call.

The request names project p1, actor worker1, operation export7, destination local-report, a digest, and size 16. The approval copies those scoped fields and adds expires=100 and max_size=20. dict(request, destination='other') creates a new dictionary with one changed value while leaving the original unchanged.

authorized compares five exact fields, checks now is before expiry, and checks size is within the maximum. all requires every field comparison to match. Assertions allow the original at time 90 and deny changed destination, cross-project p2, time 100, and operation export8. Expected PASS lists these rejection classes. This establishes the represented policy decisions. The fixture does not consume single-use approvals durably, contact an export service, or establish process isolation; those claims require their respective integrations.

Download this week’s Python lab ↓

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Original size 16 has max_size 20 and matching scope at time 90 before expiry 100. Decision?
2. dict(request, project="p2") does what?
3. A Boolean approval checker compares exact fields, expiry, and size but consumes no approval and publishes no effect. Which production property is absent?

Section 2.6 6 of 7

Guided comparison

Focus

Explain why each mutated request loses the original approval.

The worked request is allowed only as a conjunction: all required fields match, time is valid, and size is bounded. Matching most conditions is not sufficient. Changing local-report to other fails destination equality. Changing p1 to p2 fails project equality. Changing export7 to export8 fails logical operation equality. At now=100, the strict expiry comparison fails even though all fields still match.

The unchanged request at time 90 passes. That means its represented attempt is authorized; it does not mean an export occurred. The function returns a boolean and has no write or send behavior. This clean separation makes it possible to test policy without creating external effects.

A real executor should preserve the same exact binding while adding authenticated approval creation, policy versioning, revocation checks where required, replay handling, and effect evidence. It must also ensure the payload actually executed is the one hashed. Computing a digest and then allowing the worker to swap content would break the chain. The review therefore treats the fixture as a complete small decision checker and a contract for a future executor, not as a complete approval platform.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Four scoped fields match but destination differs. Does majority matching authorize?
2. authorized returns True without performing any write. What occurred?
3. A payload is hashed, then swapped before publication. What boundary broke?

Section 2.7 7 of 7

An expired approval reused for a new operation

Focus

Reject expired approval reused for a new operation even when the request sounds identical.

An approval permits report export X4 to local-report until time 500. At time 520, a worker requests export X5 with the same destination and nearly identical content, claiming it is just finishing the earlier work. Two boundaries changed: the approval expired and the logical operation identifier differs.

The worked executor checks authoritative time and operation identity and rejects the request. It records the reason without creating an effect. If X4 previously committed but its acknowledgment was lost, the correct path is reconciliation of X4, not reuse of the expired approval to create X5. If a genuinely new export is desired, it needs current authorization for its own exact scope.

This example shows why human-readable similarity is insufficient. Same title, same recipient, or almost the same payload can conceal a new consequence. Approval records should support exact comparison, and audit records should distinguish denied new work from recovered old work. A retry policy must not silently extend expiry or change operation identity. Reconciliation can establish what already happened without granting permission for an additional action.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. X4 approval expired at 500; X5 is requested at 520. What must happen?
2. X4 may have committed before acknowledgment was lost. Proper next step?
3. Can a retry policy silently extend an approval deadline?

Your personal notes

Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.

References and further reading
Ask your own AI assistant

Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.

Next lesson: Keeping usable and private audit records →