Checking Access
This guide walks a complete access decision: you have an object to protect, a
caller to check, and you want KACS to tell you what they're allowed. The
exhaustive detail lives in
access.h and
security.h; here you
put them together.
When to use this #
Reach for peios_access_check when your
program is the resource manager — you own something that isn't a kernel object
(a document, an API route, a record) and you want to gate it with Peios
identities and rules. For actual kernel objects, don't pre-check; perform the
operation and let the kernel enforce.
Remember the check is advisory: it computes the answer, you enforce it.
When an identity authority supplies facts without an OS token, use the separate supplied-identity check. It preserves unknown versus known-empty groups and filtered versus complete claims. It never adopts the service's own token or creates a user session. Only an explicit granted decision permits admission; missing context requires more facts or refusal. Its initial backend runs inside libpeios and does not need a kernel rebuild. The token-based instructions below remain unchanged.
Step 1 — describe what protects the object #
An object is protected by a security descriptor. If you don't already have one, build it. Say the resource should be readable and writable by its owner and read-only for a "viewers" group:
/* An ACL: allow OWNER full, allow VIEWERS read. */
peios_acl_builder *acl = ;
;
;
size_t acl_len;
const void *acl_bytes = ;
/* Wrap it in a security descriptor with an owner. */
peios_sd_builder *sd = ;
;
;
size_t sd_len;
const void *sd_bytes = ;
(You can also write the descriptor as SDDL text and parse it — often easier when the policy is fixed.)
Step 2 — identify the subject #
The subject is a token. Most often it's the caller you opened from a
socket, or
your own effective token. In the request you pass either a token fd or -1
for your own effective token.
Step 3 — run the check #
Fill in a request and call. desired is what you're testing; mapping folds
any generic rights to the object class's specific bits (use the class's
published mapping — here you'll treat the object like a file):
struct peios_access_request req = ;
uint32_t granted = 0;
int rc = ;
Step 4 — interpret the result #
if else if else
The key idea: a denial is not an error to log and bail on — it's the
expected "no". And because granted is filled even on denial, you can ask for
a broad set of rights in one call and read back exactly which subset the
subject has, rather than probing right by right. Clean up the builders
(peios_acl_builder_free, peios_sd_builder_free) and the token fd when
done.
Intent is not an authorization ticket #
For a resource managed by the application, set backup or restore intent only when that resource operation actually has the corresponding purpose. The subject must still hold the enabled privilege, and the complete pipeline can narrow its contribution. The request's intent does not change the token.
A successful advisory check does not grant rights to a later filesystem open,
write, or descriptor update. Those operations enforce their own contracts.
Do not implement backup as "pre-check with backup intent, then assume any
ordinary open is authorized." Use the kernel object's supported operation
and retain its actual result. Likewise, a prior WRITE_OWNER result does
not eliminate the descriptor-update rules about the new owner SID.
For MAXIMUM_ALLOWED, inspect the returned mask rather than treating success
as a grant of every possible bit. Result-list checks apply object-type-tree
semantics; they are not a collection of unrelated scalar checks. A caller
that cannot reproduce local claims, PIP, mapping, or audit context should
record that gap instead of presenting a rehearsal as the original decision.
Per-property checks #
If your object has properties or property-sets with their own object ACEs,
evaluate the whole tree in one call with
peios_access_check_list:
supply an object-type tree and get one result per node, so you learn (for
instance) that a caller can read most of an object but not one protected field — without a separate check per field.
Auditing a decision #
Pass a non-NULL peios_access_audit to
learn what a SYSTEM_AUDIT ACE match would log, and whether a staged
central access policy would decide differently — the signal you watch when
rolling out a policy change.
If your daemon guards objects of its own, name the object in the request's audit context, so the kernel's audit record of the decision says what was checked:
struct peios_audit_field name = ;
uint8_t ctx;
ssize_t n = ;
req.audit_context = ctx;
req.audit_context_len = n; /* check n >= 0 first */
Do not write an event of your own recording the grant or the refusal. The kernel's record is the audit record, and a SACL on the object decides whether it is written (PGSS §6.7).
Next #
access.hreference — every field of the request and the audit outputs.- Access decisions — the operator-side account of how KACS reaches a verdict (and how to debug a surprising denial).