One door for every tool, with rules
Put every tool call through one checkpoint that decides allow, deny or ask a person, from rules kept in a file.
You build: gateway.py and policy.yaml, with tests for each kind of decision and a record of every call.
- Python 3.11 or newer and uv
-
01Route every tool call through one function that knows who is calling, which tool and with what
uv run pytest tests/test_gateway.py -qYou pass when: A test passes showing that no tool can be reached without going through the gateway.
-
02Write three rules: support staff cannot pay, refunds over 100 need a person, everyone can look up a parcel
Rules in a file can be read and signed off by someone who does not read code. Larger teams use a policy language such as Cedar for the same job.
uv run pytest tests/test_policy.py -qYou pass when: Tests pass for one allow, one deny and one needs-approval case.
-
03Call a tool that no rule mentions
uv run pytest tests/test_policy.py -q -k unknownYou pass when: It is denied. Anything not allowed by a rule is refused.
-
04Record every decision with its reason
tail -n 3 audit.jsonlYou pass when: One line per call: who, tool, decision and the rule that decided it.
The check runs on the computer, not on your word: a step passes when its command exits with 0 there.
Computers are not set up on this site yet. Run each command on your own machine and compare with "You pass when".
Commands run in labs/52-gateway-policy and may take up to 60 seconds each. Every command starts a new shell: put keys and settings in a .env file there, it is loaded each time.