Overview
A policy is a document that defines the for a group of workers. Given a worker’s properties and their , it describes what accounts and access they should have. Klef compares that to the current state of your systems and generates a of changes to make reality match the policy. A policy is written in Klef Policy Language (KPL).Anatomy of a Policy
Policies describe who they apply to and how their target’s objects should look.KPL Reference
applies
Either everyone or a . Segments are a group of workers with something in common. They can be re-used across policies.
stage
A block for one . A worker is in exactly one stage at a time, and the block for that stage decides what applies to them.
A start date arrives at midnight, and a last work day passes at the time of day set in Settings under Terminations take effect, 6:00 PM by default. Both are read in the worker’s time zone, or the workspace’s when theirs is unknown. A termination Deel carries out ends access as soon as Deel ends the contract, which for a termination dated today is at once. To cut someone’s access off at once in other sources, set their last work day to a day that has already passed.
Only people the HRIS has hired are workers. A draft, an offer not yet accepted or a contract still awaiting a signature isn’t imported until it’s agreed.
Omitting a Stage
If a policy has no block for a stage, it says nothing about that stage, and the worker’s accounts keep whatever they already have.active block and a terminated block - both modifying a Slack account:
- The worker goes on parental leave on May 1st, and moves to the
leavestage. - Since the policy has no
leaveblock, Klef makes no changes and their Slack account stays active. - The worker returns on August 1st, and moves back to the
activestage. Theactiveblock applies again. - If the worker is instead
terminated, theterminatedblock applies and their Slack account is deactivated.
stage released
This block, unlike terminated, applies when the policy stops covering an account. This can occur if a worker leaves the segment or a target is removed from the policy. It’s not a worker lifecycle.
Without it, Klef changes nothing. The account stays as it is, with everything Klef granted on it, and Klef stops tracking it. A released block is the only way a policy takes something away on the way out, and it takes away only what it names.
released block left to apply. To take access away first, remove the target from the policy’s stages, keep its released block, let a plan apply, and then delete the policy.
Klef warns about a policy that has no released block for a target, and about a terminated or released block that has no line for a grant the policy gives at another stage.
target
A block naming one object in one , with the fields that object should have.
released (see status). Where Klef never creates the object, such as an Azure role assignment, a block must set it in every stage but released, because that is how Klef finds the account.
Some fields can’t take every line. The connector page says when a field is never changed once the account exists: Klef sets it on create and reports a later difference in the plan. A field the system sets itself can be read but not set, and a field the system never returns can be set but not read.
status
A target that Klef can create, invite, disable or remove has a status line. It says what the account should be.
The values a target takes depend on what its connector can do. Each connector page lists them. A value the connector cannot reach is an error that says what to write instead: Asana has no disabled user, so it asks for
removed.
A read can also report invited, for someone invited who has not accepted yet. A policy never writes it. An invitation already counts as enabled.
When the vendor shows the status in a field of its own, such as Entra’s accountEnabled, the field is listed and can be read. A policy sets status instead.
A block creates the account when the worker has none, in any stage but released, unless it switches the account off. removed never creates one. disabled creates one, switched off, only when a later stage the worker can still reach switches it on, in this policy or another, and only if the connector can create and disable. That way an account staged in pre_start is ready on the first day, and a terminated worker who never had the account does not get one just to be switched off. A worker on leave returns to active, and terminated is the last stage.
The editor warns when a block can create the account without a required field: the block leaves the field unmanaged, or it switches the account off without the field while another policy switches the account on later. Unless another policy sets the field, the plan creates nothing and says which field is missing.
Mappings
A line inside a target that sets one field.
A field with no line is left as it is. That includes a grant such as
licenses: a block that does not mention it keeps what an earlier stage gave. To take access away, write a shorter list or [].
A value can also come from a script or a lookup table, which is what resources are for.
Field Types
Templates
Text in quotes is a Liquid template, so it can read worker fields with{{ }} and use Liquid’s filters and tags. Text that runs to several lines is written as a heredoc, opened with <<TAG and closed by a line holding only the tag.
each
A mapping value that writes one row for every record in a worker collection, such as worker.assignments. It fills an array field.
where is an optional filter. Join clauses with and to require all of them, or with or to require any of them.
unmanaged
A mapping value that tells Klef to leave a field untouched. It means the same as leaving the line out, and says the silence is meant.
This is particularly useful on a grant such as groups, licenses, or channels. Klef retains what it had given in an earlier lifecycle stage, and does not warn that the block may have forgotten the grant.
notify
A block that sends a message when its stage’s changes apply, by email, Slack, Teams, or an HTTP request.
Its name, in quotes after the channel, is unique across your policies. Klef records what it has sent under that name, so renaming a notification makes it a new one.
Each recipient is one of these:
Slack
Teams
HTTP
Credentials
A credential block inside a target says the account should hold a credential, such as a password or a Temporary Access Pass. Klef issues it when the account lacks it, not on every run, andstatus = removed inside the block revokes it. A stage without the block leaves the credential alone.
Klef makes a password itself, to your workspace’s password rules, so a policy never writes one. A pass the system returns is kept encrypted. A notification can carry the link to either as {{ <system>.sign_in_url }}, which shows it once to the person it was sent to.
password and temporary_access_pass, Google Workspace holds password, and AWS holds login_profile, which opens console sign-in.