Policy as code
Keep policies in version control, review and test them, and promote with CI.
Policies are security configuration. Manage them like code: keep them in your repository, test them offline, review
the diff, then push. These commands need @reqlo/cli 0.2.0 or later.
Repository layout
reqlo init creates this layout with a working example:
reqlo.config.yaml
reqlo/
schema.yaml # actions and resource types: reqlo schema push
policies/
documents.yaml
tests/
documents.test.yamlKeep reqlo/schema.yaml with your policies so every environment registers the same actions. reqlo schema push
shows a plan, creates what's missing and updates changed context schemas; it never archives anything.
environment: <ENVIRONMENT_ID> # from the API keys page; target for diff, push, versions and rollback
policies: reqlo/policies # default
tests: reqlo/tests # defaultEach policy file is one policy. The id ties the file to the policy in ReQlo. IDs are unique across ReQlo, so
generate one per policy and keep it:
node -e "console.log('POL_' + require('crypto').randomBytes(8).toString('hex'))"id: <YOUR_POLICY_ID>
name: Documents
rules:
- id: owners-read
effect: allow
actions: [documents.read]
condition: resource.attributes.owner_id == subject.id
- id: deny-confidential
effect: deny
actions: ["documents.*"]
condition: '!has(context.classification) || context.classification == "confidential"'Tests describe requests and the decision you expect. They run against your local files with the same evaluation engine the API uses.
cases:
- name: owner reads an internal document
agent: { id: agt_assistant, tags: [support] }
subject: { id: usr_1, kind: user }
action: documents.read
resource: { type: document, id: d1, attributes: { owner_id: usr_1 } }
context: { classification: internal }
expect: allow
- name: confidential is denied
agent: { id: agt_assistant }
subject: { id: usr_1, kind: user }
action: documents.read
resource: { type: document, id: d1, attributes: { owner_id: usr_1 } }
context: { classification: confidential }
expect: deny
reason_code: policy_deniedWorkflow
- Change a policy and its tests in a branch.
- Open a pull request. CI runs
reqlo policies validateandreqlo policies test, which need no network access. - A reviewer reads the file diff and
reqlo policies diff, which compares your files with what is published. - On merge, run
reqlo policies push --publish --yeswith a signed-in owner's or admin'sREQLO_ACCESS_TOKEN. - Roll back with
reqlo policies rollback <version>if needed.
Tests check rule logic, not your catalog: register actions and resource types first, because publishing rejects rules for unregistered actions. See Commands.
Review checklist
- Does any new rule broaden access? Is there a test for the boundary?
- Do deny rules depend on optional attributes without
has()? Publishing warns about these. - Are
caller-provenance attributes only used to limit, never to grant? - Is a
require_approvalrule's channel staffed?
Something wrong or unclear? Report an issue with this page.