Skip to content

Policy

Feature Flags can use a Policy product to control sensitive actions.

Use Policy when you want to protect:

  • flag changes
  • publishes
  • rollbacks
  • audit access
  • internal admin routes
Terminal window
import { policy } from "@layeron/modules"
const flagPolicy = policy({
name: "flags-admin",
rules: [
{
id: "flags-admins",
effect: "allow",
actions: ["flags:*"],
resources: ["feature_flags:*"],
subjects: ["admin"],
},
],
})
const flags = featureFlags({
name: "main",
policy: flagPolicy,
flags: {
checkoutV2: flag.boolean({ default: false }),
},
})

With Policy attached, Layeron checks the subject, action, and resource before the flag product accepts admin work.

Use actions like:

  • flags:read
  • flags:evaluate
  • flags:publish
  • flags:rollback

Pass a subject when an admin tool publishes, reads history, or rolls back:

Terminal window
await flags.publish({
environment: "prod",
message: "Enable checkout v2",
subject: {
kind: "admin",
id: "user_123",
roles: ["release-manager"],
},
})

Most application reads stay simple:

Terminal window
const enabled = await flags.enabled("checkoutV2", {
tenantId: tenant.id,
})

Use Policy when a flag read itself should be restricted, such as a server-only flag or an internal operator view.

Keep rollout logic in Feature Flags and access control in Policy.

  • Feature Flags decides what value a request sees.
  • Policy decides who may change or inspect the rollout.