Skip to content

API reference

policy(options) creates a Layeron Policy module for authorization decisions, redaction rules, and audit metadata.

Terminal window
import { policy } from "@layeron/modules"

Create a Layeron Policy module for authorization, redaction, and audit metadata.

Terminal window
policy(options?: PolicyModuleOptions): PolicyModule

Layeron Policy module returned by policy(options).

FieldTypeDescription
name”policy”Module name.
configPolicyModuleOptionsNormalized Policy module configuration.
observabilityLayeron.Observability.ObservabilityConfig | undefinedEffective observability policy recorded on the module declaration.

Options accepted by policy(options).

FieldTypeDescription
namestring | undefinedStable Policy instance name. Defaults to default.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
databaseNamestring | undefinedLayeron Database product instance name used for Policy state.
bindingstring | undefinedRuntime binding name used for Policy state.
defaultDecision”allow” | “deny” | undefinedDecision returned when no rule matches. Defaults to deny.
rulesPolicyRule[] | undefinedAuthorization rules evaluated by this Policy instance.
redactionPolicyRedactionRule[] | undefinedRedaction rules available through redactionPolicy().
auditPolicyAuditOptions | undefinedAudit settings for Policy decisions.
observabilityLayeron.Observability.ObservabilityConfig | undefinedObservability settings for policy decisions, denials, and audit events.

Authorization rule evaluated by Policy.

FieldTypeDescription
idstringStable rule id used in decisions and audit records.
effectPolicyEffectDecision produced when the rule matches.
actionsstring[]Action patterns matched against the requested action.
resourcesstring[]Resource patterns matched against type:id.
subjectsstring[] | undefinedSubject patterns matched against kind, kind:id, role, or scope.
conditionsPolicyCondition | undefinedAdditional match requirements for the rule.
priorityint32 | undefinedRule priority. Higher priority rules are evaluated first.
descriptionstring | undefinedHuman-readable rule description.

Extra match requirements for a Policy rule.

FieldTypeDescription
tenant”match” | undefinedRequire the subject tenant to match the resource or context tenant.
owner”subject” | undefinedRequire the resource owner id to match the subject id.
requiredRolesstring[] | undefinedRequire the subject to include every listed role.
requiredScopesstring[] | undefinedRequire the subject to include every listed scope.

Rule that selects fields or headers for redaction.

FieldTypeDescription
idstringStable redaction rule id.
target”log” | “observability” | “all”Runtime surface where the redaction rule applies.
fieldsstring[] | undefinedStructured field names to redact.
headersstring[] | undefinedHeader names to redact.
descriptionstring | undefinedHuman-readable redaction rule description.

Audit settings for Policy decisions.

FieldTypeDescription
decisionsboolean | undefinedRecord all Policy decisions when enabled.
deniesboolean | undefinedRecord denied Policy decisions when enabled. Defaults to true.

Subject that asks to perform a Policy action.

FieldTypeDescription
kindPolicySubjectKindSubject kind used for matching and audit records.
idstring | undefinedStable subject id.
rolesstring[] | undefinedRoles attached to the subject.
scopesstring[] | undefinedScopes attached to the subject.
tenantIdstring | undefinedTenant id associated with the subject.
attributesRecord<unknown> | undefinedAdditional structured subject attributes.

Resource targeted by a Policy action.

FieldTypeDescription
typestringResource type used in rule resource patterns.
idstringStable resource id used in rule resource patterns.
tenantIdstring | undefinedTenant id associated with the resource.
ownerIdstring | undefinedSubject id that owns the resource.
attributesRecord<unknown> | undefinedAdditional structured resource attributes.

Context attached to a Policy evaluation.

FieldTypeDescription
workspaceIdstring | undefinedWorkspace id associated with the evaluation.
projectIdstring | undefinedProject id associated with the evaluation.
environmentIdstring | undefinedEnvironment id associated with the evaluation.
moduleIdstring | undefinedModule id associated with the evaluation.
requestIdstring | undefinedRequest id associated with the evaluation.
traceIdstring | undefinedTrace id associated with the evaluation.
tenantIdstring | undefinedTenant id associated with the evaluation.
attributesRecord<unknown> | undefinedAdditional structured evaluation attributes.

Input accepted by Policy evaluation.

FieldTypeDescription
subjectPolicySubjectSubject requesting the action.
actionstringAction string matched against rule action patterns.
resourcePolicyResourceResource targeted by the action.
contextPolicyContext | undefinedOptional context attached to the evaluation.

Decision returned by Policy evaluation.

FieldTypeDescription
decision”allow” | “deny”Final allow or deny result.
reasonstringHuman-readable reason for the decision.
matchedRuleIdsstring[]Rule ids that matched the evaluation input.

Decision effect produced by a Policy rule.

ValueDescription
allowAllow the matching action.
denyDeny the matching action.

Kind of subject evaluated by Policy.

ValueDescription
anonymousUnauthenticated or unidentified caller.
userEnd user subject.
serviceService-to-service subject.
adminAdministrative subject.
moduleLayeron module subject.
productLayeron product subject.
systemLayeron system subject.

Evaluate one subject, action, resource, and context against Policy rules.

Terminal window
evaluate(input: PolicyEvaluateInput): PolicyDecision
MethodDescription
redactionPolicy()Build an observability redaction policy from policy redaction rules.