GebSecure Docs v0.1.0

Guides · Policies

GebSecure Policy Language (GSL)

Syntax and semantics of GSL — clauses, targets, expressions, functions, schedules, limits, approvals and the combining algorithm.

GSL is a small declarative language for deciding what agents, users and services may do. The parser, validator, formatter and evaluator live in packages/policy and are the same code in the server, the console editor and the offline CLI (gebsecure policies validate|fmt|test). Every GSL example in this documentation is parsed and validated by the documentation test suite.

Structure#

A policy document contains one or more policies. Each policy has a unique name and a body of clauses:

gsl
# Comments start with # or //
policy "support-small-refunds" {
  description "Support agents may refund up to 100 without approval"
  effect permit
  principal agent where "support" in principal.tags
  action "stripe:refunds.create"
  resource "stripe:charge/*"
  when has(context.amount) && context.amount <= 100
}

Names match ^[A-Za-z0-9][A-Za-z0-9 ._:/-]{0,127}$. A source is limited to 1 MB.

Clauses#

Clause Repeatable Meaning
description "…" no free text
priority N no integer (may be negative, default 0); candidates are evaluated highest first, and when every applicable permit requires approval the highest-priority permit's approval requirements apply
effect permit | forbid | require_approval no default permit
principal … no who the policy applies to (see below); default: anyone
action … / resource … no any, one pattern string, or in ["…", …]; default: any
environment "slug" / environment in [ … ] no environment slugs or tiers
when <expr> yes all when conditions must be true
unless <expr> yes the policy does not apply if any unless is true
schedule <days> HH:MM - HH:MM ["Time/Zone"] no applies only inside the window
limit count <= N per <duration> [by …] / limit sum(<expr>) <= N per <duration> [by …] yes rate and spending limits
require approval [when <expr>] [{ … }] yes an approval gate
risk above N / risk below N yes applies only when the risk score is above/below N (0–100)
tags ["…"] no labels for search and reporting

Principals#

principal any [where <expr>]
principal agent | user | service_account | application [, …] [where <expr>]
principal in ["<principal id>", …] [where <expr>]

principal in also matches a principal's references: group:<id> (an agent group: administrator-managed members of one project, Agents → Agent groups), team:<id>, tag:<tag>, role:<role> and owner:<user id>. Granting a group gives access to its current members; agents added later get it, agents removed lose it at once:

gsl
policy "support-reads-tickets" {
  principal in ["group:agrp_01h…"]
  action in ["zendesk:tickets.list", "zendesk:tickets.get"]
  resource any
}

Prefer groups over tag: for grants: an agent's tags are set when it is registered or updated, while group membership changes only through administrators and is audited.

Actions and resources#

Patterns use * (any characters within one /-separated segment), ** (anything, across segments) and ? (one character): "stripe:*" matches stripe:refunds.create; "github:repo/acme/**" matches github:repo/acme/web/pulls/7. Action patterns must look like service:verb (letters, digits, _ . : / - and *).

Effects and combining#

  1. A matching forbid denies — at every scope, regardless of permits.
  2. No applicable permit → deny (default deny).
  3. Any triggered approval gate — a require_approval policy, a require approval clause of an applicable permit, or a risk/DLP/taint gate — → APPROVAL_REQUIRED.
  4. Otherwise → ALLOW. Risk thresholds can only tighten the decision.

Fail-closed evaluation#

Reading a missing attribute yields undefined; comparing, ordering or doing arithmetic with it — or mixing types — is an evaluation error, never false. An erroring forbid applies, an erroring permit does not apply, and an erroring approval condition requires approval. Guard optional attributes with has(…):

gsl
policy "large-payments-need-finance" {
  effect permit
  principal agent
  action "payments:transfers.create"
  resource any
  # Without has(), a request without an amount would be an evaluation error (the permit would not apply).
  when has(context.amount) && context.amount > 0
  require approval when context.amount > 10000 {
    approvers team "finance"
  }
}

Expressions#

Category Syntax
Literals numbers, "strings" (escapes \n \t \" \\), true, false, null, lists [1, "a"]
Variables {% gsl-variables %}, with .field and [index] access
Logic &&, ||, ! or not
Comparison ==, != (deep equality), <, <=, >, >= (numbers or strings of the same type)
Membership x in list (element) or "key" in object; x not in list; list contains x, "text" contains "sub"
Patterns value like "pattern*" (the action/resource wildcard syntax), value matches "regex" (at most 256 characters; nested quantifiers are rejected)
Arithmetic + (numbers, or string concatenation), -, *, /, %, unary -

Variables#

Variable Attributes
principal id, type, tags, riskTier, owner, ownerTeam, orgRole, roles, teams, metadata, attributes, scopes, projectId, environmentId, delegated
action name, service, verb, category (read, write, delete, admin or other, derived from the verb), sensitivity
resource id (the resource string) plus the request's resourceAttributes (connector- or caller-defined)
context the request context (free-form)
env id, slug, tier, name, locked
time hour, minute, weekday (0 = Sunday), date, unix, iso — all UTC; use schedule for local time
risk score, level, signals
request ip, userAgent, runtime, sessionId, traceId
delegation depth, chain, originatingUser, parentAgent, scopes

Referencing another root variable is a syntax error; an unknown attribute of a known variable is a validation warning (unknown_attribute).

Functions#

Function Arguments Description
has() 1 true if the value is defined and not null
len() 1 length of a string, list or object
lower() 1 lowercase string
upper() 1 uppercase string
startsWith() 2 string prefix test
endsWith() 2 string suffix test
domain() 1 host part of a URL or email address
cidr() 2 IPv4 address is within CIDR range
min() 1–16 minimum of numbers
max() 1–16 maximum of numbers
abs() 1 absolute value
anyOf() 2 true if any element of list A is in list B
allOf() 2 true if every element of list A is in list B
rel() 3 relationship check (ReBAC): rel(subject, relation, object)

rel(subject, relation, object) checks relationship tuples managed with GET/POST /v1/authz/relationships (ReBAC); relationship data is prefetched for policies that use it.

Schedules#

gsl
policy "deploys-in-business-hours" {
  effect permit
  principal agent where "deployer" in principal.tags
  action "cloud:*/deploy*"
  resource any
  schedule weekdays 09:00 - 17:30 "Europe/Berlin"
}

policy "weekend-batch-jobs" {
  effect permit
  principal service_account
  action "jobs:*"
  resource any
  schedule [sat, sun] 00:00 - 06:00
}

Days are daily, weekdays, weekends or a list of sun mon tue wed thu fri sat (longer names are truncated to three letters). The time zone defaults to UTC and must be a valid IANA name. A window whose end is before its start wraps midnight (22:00 - 06:00); the part after midnight belongs to the previous day.

Limits#

gsl
policy "refund-budget" {
  effect permit
  principal agent
  action "stripe:refunds.create"
  resource any
  when has(context.amount)
  limit count <= 50 per 1h by agent
  limit sum(context.amount) <= 5000 per 24h by org
}

count counts requests, sum(expr) adds a numeric expression. Windows are durations (ms, s, m, h, d, w) between 1 second and 366 days. by chooses the bucket: principal (default) or agent (the calling principal), org, resource or owner (the agent's owner). Limits apply to permit policies: when a request would exceed one, the permit does not apply. The decision reports each limit's used and remaining.

Approvals (require approval)#

gsl
policy "production-changes" {
  effect require_approval
  principal any
  action in ["k8s:*/apply", "terraform:*/apply"]
  resource any
  environment in ["production"]
  require approval {
    approvers role "security_admin", team "platform"
    min 2
    mode sequential
    expires 24h
  }
}
Setting Values Default
approvers role "<role>", user "<id or email>", team "<id or slug>", owner (the agent's owner user or team) anyone holding approvals:decide
min 1–10 distinct approvers 1
mode parallel or sequential (one step per approval, in order) parallel
expires duration the organization's defaultApprovalTtlMinutes (60 minutes)

On a permit, require approval when <expr> adds a conditional gate; on effect require_approval the policy is itself a gate. A forbid policy cannot require approval (validation error forbid_approval). See Approvals.

Approval gates never grant access: they only add a human approval to what a permit allows. Approval rules in the console (Govern → Approval rules) generate such gates from sentences ("Delete actions need approval from 2 approvers"). They guard every attribute with has(…), because a gate whose condition reads a missing attribute fails closed and would require approval for unrelated actions.

Validation#

POST /v1/policies/validate, the console editor and gebsecure policies validate report diagnostics with a severity and a code:

Code Severity Cause
syntax error parse error (message includes the line and column)
unknown_function / arity error unknown function or wrong number of arguments
unsafe_regex error a matches pattern that may backtrack catastrophically
forbid_approval error require approval on a forbid policy
risk_range error risk above not lower than risk below
empty_schedule error start time equals end time
bad_action error an action pattern that is not service:verb-shaped
approvals_unsatisfiable error min exceeds the number of named user approvers
unknown_attribute warning an attribute not known for its variable
constant_comparison warning ordering two literals
forbid_limit warning limits on a forbid have no effect
overly_broad warning a permit for any principal, action and resource without conditions
default_approval info require_approval without an approval block

Deployments additionally run the policy's tests and conflict analysis: a new permit that an existing forbid always shadows blocks the deployment (HTTP 412 with the report). See Policy lifecycle.