Actors
An actor is a nominal boundary contract — an authentication scheme plus an
optional sealed identity — that a handler consumes on its by clause. The
compiler emits the verification at the boundary, before the body runs,
fail-closed. Actors are declared inside a context. For task-oriented recipes,
see Guides — Actors & access control.
Declaration
Section titled “Declaration”actor <Name> { auth = <Scheme>(<config>) , identity = <Type> } // base actoractor <Name> = <Base> where <predicate> // refinementSchemes
Section titled “Schemes”A closed, compiler-known set. auth = <Scheme> with keyed config where noted.
| Scheme | Config | Identity | Protocols | Verification |
|---|---|---|---|---|
None | — | () | any | none (anonymous; the prelude Visitor) |
Bearer | secret = "<ENV>" | a string-constructible type | http | JWT HS256 over Authorization: Bearer …; sub → identity; 401 |
Signature | secret, header, optional timestamp + tolerance | none | http | HMAC-SHA256 over the raw body; 401 |
SignedCookie | secret = "<ENV>", ttl, optional cookie, previous, sameSite | a string-constructible type | http | a signed, expiring session cookie that Bynk issues and verifies; sub → identity; 401. see Signed cookies |
Oidc | issuer, audience, jwks (all URLs/ids; no secret); optional trustFrom | a string-constructible type | http | RS256/ES256 JWT verified against the provider’s JWKS over Authorization: Bearer …; iss/aud/exp checked; sub → identity, and the verified claims → claims; 401 |
Internal | — | (), or CallerId for Caller | call/cron/queue | a call’s per-edge signature proves the calling context; cron and queue are platform-dispatched |
Foreign | secret = "<ENV>", optional worker = "<name>" | none | call | the caller, a Worker that is not Bynk, signs the call as the actor under the secret (wire format); 401 unsigned, 403 where the handler does not admit it |
secretvalues name an environment variable (the source theSecretscapability reads), not the key itself.- A
BearerorOidcactor’sidentitymust be a context-owned, string-constructible type, so the minted value is sealed to the context. - The seam consumes a
Bearer,OidcorSignaturecredential, as it does aSignedCookie’s: the handler’sheaders: RequestHeadersomits theAuthorizationheader (sobearer()isNone), or the signature header, and the handler sees only the identity (Request headers). - A
Signatureactor takes noidentityand a handler using it must take abody; it is HTTP-only. - An
Oidcactor names no secret — its trust root is the provider’s public JWKS. It is HTTP-only and, this slice, single-actor only (not a sum member, not a refinement base);alg: noneand symmetricHS*are rejected, as is a token whosesubis empty or missing. Asystemsuite can show the seam does so (by WrongAlgorithm,by NoSubject; see the failure principals). - A
Foreignactor is a caller that is not Bynk, declared by the context it calls. Its name starts with a capital letter, so it never reads as a context’s; it takes noidentity(the actor is the identity); itssecretmust be a string, may not be aBYNK_CALL_edge key’s name, and may not be any other actor’s secret in the context.bynk deploymints the secret, sets it on the context, and prints thewrangler secret putfor the foreign Worker’s operator, naming the Worker whenworkeris given.
Signed cookies
Section titled “Signed cookies”A SignedCookie actor authenticates a browser from a session cookie that Bynk itself issues
and verifies, so there is no token to mint elsewhere:
actor User { auth = SignedCookie( cookie = "__Host-session", // optional; this is the default secret = "SESSION_KEY", // env var holding the signing key previous = "SESSION_KEY_PREV", // optional; accepted for verification only ttl = 12.hours // required ), identity = UserId}| Key | Meaning |
|---|---|
secret | the environment variable holding the signing key (never the key). Required |
ttl | how long an issued cookie is valid, a positive whole number of seconds. Required; over 30 days warns |
cookie | the cookie’s name; defaults to __Host-session; a name without the __Host- prefix warns |
previous | the key being rotated out, accepted for verification only |
sameSite | Lax (the default), Strict or Unrestricted |
The cookie’s Domain and Path are not configurable: it is always host-only with Path=/.
The identity is minted from the cookie’s sub and must be a string-constructible type the
context owns, as for Bearer. A SignedCookie secret may not be any other actor’s secret.
What the seam does. A route guarded by a SignedCookie actor runs, before the body:
- A CSRF check, on
POST,PUT,PATCHandDELETE(aGETis safe and skips it). Only a request whoseSec-Fetch-Siteissame-originpasses on its own. Any other (same-site,cross-site,none, a user-initiated navigation that a state-changing request is not, or an unknown value) must carry anOriginthat is exactly one of the service’scorsorigins (scheme, host and port; the service must declarecredentials: true, a sibling subdomain counts only if it is listed, and a wildcard ornullnever qualifies). When the browser sent noSec-Fetch-Siteat all, this request’s own origin passes too. A request that reveals neither header is refused. Failure is403. - Reading the cookie. A missing cookie, or one sent more than once (a sign of cookie tossing
from another path or subdomain), is
401. - Verifying it. HMAC-SHA-256 under
secret, orpreviouswhen the cookie’skidnames it; the cookie must be for this actor, unexpired, issued no later than now, and valid for no longer than the actor’s currentttl. Any failure is401. A signing key that is missing, not base64url, or shorter than 32 bytes faults the request (500, and the log names the variable), never a quiet accept. - Minting the identity from the verified
sub; asubthat violates the identity type’s refinement is401.
Issuing and deleting the cookie
Section titled “Issuing and deleting the cookie”Inside the context that declares it, a SignedCookie actor has two members, so no other context can
mint its identity:
on POST("/login") (body: LoginRequest) -> Effect[HttpResult[String]] by v: Visitor given Clock { let Ok(id) = UserId.of(body.user) else { BadRequest("bad user") } let c <- User.issue(id) // Effect[Cookie] Created("welcome").withCookie(c)}
on POST("/logout") () -> Effect[HttpResult[()]] by u: User { NoContent.withCookie(User.expire()) // Cookie}User.issue(identity) takes the actor’s identity type and answers an Effect[Cookie]: the signed
cookie, valid for the actor’s ttl. It reads the time from the Clock,
so the handler lists Clock in given (bynk.actor.signed_cookie_issue_needs_clock), and a test can stub
it. It can only be called in a service handler, where the signing key arrives, not in a provider or an agent
(bynk.actor.signed_cookie_issue_outside_handler). The Cookie it returns is built by the scheme, not by you: the configured name,
HttpOnly, Secure, Path=/, no Domain, the actor’s SameSite and a Max-Age equal to ttl.
There are no attributes to get wrong, so you attach it with withCookie and nothing else.
User.expire() is the matching deletion (same name and path, empty, Max-Age=0), so a logout cannot
miss the cookie it set.
A stateless cookie cannot be revoked before it expires: a copy a user already took keeps working
until then. expire removes it from this browser; it does not invalidate the cookie. Keep the ttl short,
or keep the session on the server (see examples/sessions) if you need to log out everywhere.
The handler never sees the credential: the router leaves the session cookie out of the handler’s
cookies record and raw RequestCookies view, and a record that names it is refused
(bynk.actor.signed_cookie_read_directly). bynk deploy mints the secret variable when it is unset (see Signed cookies).
A system suite signs in as by User("ada") and probes the seam with by Nobody, by Forged and
by Expired (see the failure principals); a case’s own
Sec-Fetch-Site and Origin headers probe the CSRF check.
bynk openapi documents a route a SignedCookie actor guards with an apiKey security scheme
in: cookie, named after the cookie, and lists the seam’s refusals as responses: 401 always and, on a
state-changing method, 403 for a cross-site request.
What a signed cookie does and does not protect against
Section titled “What a signed cookie does and does not protect against”It does: reject a cookie that was forged, altered, issued for another actor, signed with a key the
seam does not hold, expired, or sent twice; refuse a cross-site state-changing request that the service
does not list; keep the credential out of the handler (its cookies and headers views omit it); and
keep the cookie from page scripts (HttpOnly), from plain HTTP (Secure), and from sibling subdomains
(__Host- and no Domain).
It does not: hide the cookie’s contents. The value is signed, not encrypted: anyone holding the
cookie can read its sub, so never put a secret in an identity. It cannot be revoked before ttl
(above). It does not stop a script already running on your own origin, and it is not a defence against a
stolen device. Rotating secret (moving the old value to previous, then dropping it) is how every
cookie is ended at once.
A SignedCookie actor stands alone on its route, like Oidc
(bynk.actor.signed_cookie_not_in_sum), cannot be the base of a refinement actor, and cannot guard
a @cache(scope: public) route (bynk.actor.signed_cookie_public_cache).
Reading claims
Section titled “Reading claims”An Oidc actor’s binder carries the verified token’s claims beside its
identity, as a TokenClaims:
on POST("/release") () -> Effect[HttpResult[String]] by w: Workload { let repository = w.claims.get("repository") // Option[String] let protected = w.claims.has("environment") // Bool Ok(repository.getOrElse("-"))}| Method | Returns | Reads |
|---|---|---|
get(name) | Option[String] | the claim when it is a JSON string; None for any other type, or none at all |
has(name) | Bool | whether the claim is present, of any type |
Every claim comes from a token whose signature, iss, aud and exp the seam
verified; a token that fails is 401 before the handler runs. The claims are
read where the token arrives and never kept: a TokenClaims can’t be a field, or
cross a call, a message or an agent (bynk.types.claims_at_boundary). Read the
claim you need and keep that String. Only an Oidc binder has .claims;
Bearer claims are a later addition.
Trust roots from the environment
Section titled “Trust roots from the environment”trustFrom = "<ENV>" names an environment variable whose JSON, when it is set,
replaces the declared trust roots at run time:
actor Workload { auth = Oidc( issuer = "https://token.actions.githubusercontent.com", audience = "bynk-registry", jwks = "https://token.actions.githubusercontent.com/.well-known/jwks", trustFrom = "WORKLOAD_OIDC_TRUST" ), identity = WorkloadId}{ "issuer": "http://127.0.0.1:8123", "jwks": "http://127.0.0.1:8123/jwks", "audience": "bynk-registry" }issuer and jwks are required, audience optional. Unset, the declaration
applies, so production behaviour is exactly what the actor says; set but
malformed, every request is refused (401) and the fault log says why — it never
falls back to the declaration. It is how a staging deployment trusts a staging issuer, and how a system
suite’s env moves the trust roots the test driver mints for (the driver is the
issuer; see testing an Oidc route). Like a secret, the
variable is the operator’s configuration. trustFrom must be a string
(bynk.actor.oidc_trust_from_not_string) naming a variable no actor uses as its
secret (bynk.actor.oidc_trust_from_is_secret).
The by clause
Section titled “The by clause”by <binder>: <Actor> // capture the identity as <binder>.identityby <Actor> // verify, capture nothing (optional binder)by <binder>: <A> | <B> | … // an ordered sum of peer actors, first-wins- HTTP, WebSocket and
callrequire abyclause, because the caller is a party and more than one actor is sensible. A public HTTP route writesby v: Visitor(bynk.actor.missing_by_on_http). Anon callhandler writes at leastby Caller, the explicit “any consuming context” (bynk.actor.missing_by_on_call);bynk check --fix=bynk.actor.missing_by_on_callinserts it, and a service-headerbycovers every handler without its own. The platform-only protocols default: cron →Scheduler, queue →Producer, email →Sender. An agent’son calloperations are reached only from inside their own context, so they name no caller. - Multi-actor sums resolve first-wins; the body
matches the resolved actor. Peers are distinguished by scheme (no duplicates), aNonecatch-all is last,Bearerrefinements are not members, and total failure is401. Oncall, a sum admits a Bynk context (Caller, or one refinement over it) and declared foreign callers, each told apart by name:by who: Caller | Legacy | Ledger. A sum has at most oneInternalmember (bynk.actor.duplicate_sum_scheme). SeveralForeignpeers may share a sum; each has its own secret. - Refinement actors (
<Admin> = <User> where <pred>) add an authorisation invariant over aBearerbase: scheme failure is401, predicate failure is403. The predicate is a closed set —hasClaim("n"),claimEquals("n","v"), composed with&&/||/!. AnAdminis usable wherever its base is.Calleris a refinement base too, with its own predicate (next bullet). - Refinements over
Caller(actor Admin = Caller where IsContext(shop.admin)) name the contexts that may call a service.IsContext(<context>, …)takes one or more qualified context names, written as names rather than strings; each must be a context of the project (bynk.actor.unknown_context). The predicate is admissible only overCaller(hasClaimandclaimEqualsstayBearer’s, andIsContextover aBeareractor isbynk.actor.refinement_predicate_unsupported), and composes with&&,||and!, so!IsContext(shop.legacy)is a deny-list. The refinement inheritsCaller’s scheme, its identity (CallerId) and its admissibility (on callonly). A call from a context it does not admit isbynk.actor.caller_not_admittedat the call, in a case’sby Admin("…")too; the callee also answers such a call403(wire format check 6). See Restrict who may call. Caller(onon call) yields the calling context’s qualified name asCallerId. It admits Bynk contexts only: a foreign caller is admitted by its own actor, never byCaller, so a handler that names onlyCallerrefuses one (403).
Prelude actors
Section titled “Prelude actors”| Name | Scheme | Identity | For |
|---|---|---|---|
Visitor | None | () | anonymous HTTP routes |
Caller | Internal | CallerId | the calling context (on call) |
Scheduler | Internal | () | cron |
Producer | Internal | () | queue |
Sender | Internal | SenderIdentity (minted by the Worker; () in a suite today) | inbound email |
Diagnostics
Section titled “Diagnostics”All bynk.actor.* codes are in the diagnostic index — among
them missing_by_on_http, scheme_not_admissible, signature_requires_body,
sum_requires_binder, duplicate_sum_scheme, unreachable_sum_arm,
caller_not_admitted, unknown_context,
refinement_base_unsupported, refinement_predicate_unsupported,
oidc_missing_issuer, oidc_missing_audience, oidc_missing_jwks,
oidc_identity_not_string_constructible, oidc_not_in_sum,
foreign_missing_secret, foreign_reserved_secret,
foreign_name_is_context_name, foreign_identity_unsupported,
foreign_secret_not_string, foreign_duplicate_secret, and the signed_cookie_* family.
Who, not whose
Section titled “Who, not whose”An actor answers who is at the boundary — it authenticates a party and seals
its identity. It deliberately does not answer whose a given object is:
object-level authorisation (may this user read this record?) is domain logic
in the handler body, by design. A where-clause invariant narrows who (a claim
the party carries), never whose.
The normative rules are Specification §5.7a; the emitted verification is §7.3.4a.