Skip to content
Playground(another site)

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.

actor <Name> { auth = <Scheme>(<config>) , identity = <Type> } // base actor
actor <Name> = <Base> where <predicate> // refinement

A closed, compiler-known set. auth = <Scheme> with keyed config where noted.

SchemeConfigIdentityProtocolsVerification
None—()anynone (anonymous; the prelude Visitor)
Bearersecret = "<ENV>"a string-constructible typehttpJWT HS256 over Authorization: Bearer …; sub → identity; 401
Signaturesecret, header, optional timestamp + tolerancenonehttpHMAC-SHA256 over the raw body; 401
SignedCookiesecret = "<ENV>", ttl, optional cookie, previous, sameSitea string-constructible typehttpa signed, expiring session cookie that Bynk issues and verifies; sub → identity; 401. see Signed cookies
Oidcissuer, audience, jwks (all URLs/ids; no secret); optional trustFroma string-constructible typehttpRS256/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 Callercall/cron/queuea call’s per-edge signature proves the calling context; cron and queue are platform-dispatched
Foreignsecret = "<ENV>", optional worker = "<name>"nonecallthe 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
  • secret values name an environment variable (the source the Secrets capability reads), not the key itself.
  • A Bearer or Oidc actor’s identity must be a context-owned, string-constructible type, so the minted value is sealed to the context.
  • The seam consumes a Bearer, Oidc or Signature credential, as it does a SignedCookie’s: the handler’s headers: RequestHeaders omits the Authorization header (so bearer() is None), or the signature header, and the handler sees only the identity (Request headers).
  • A Signature actor takes no identity and a handler using it must take a body; it is HTTP-only.
  • An Oidc actor 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: none and symmetric HS* are rejected, as is a token whose sub is empty or missing. A system suite can show the seam does so (by WrongAlgorithm, by NoSubject; see the failure principals).
  • A Foreign actor 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 no identity (the actor is the identity); its secret must be a string, may not be a BYNK_CALL_ edge key’s name, and may not be any other actor’s secret in the context. bynk deploy mints the secret, sets it on the context, and prints the wrangler secret put for the foreign Worker’s operator, naming the Worker when worker is given.

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
}
KeyMeaning
secretthe environment variable holding the signing key (never the key). Required
ttlhow long an issued cookie is valid, a positive whole number of seconds. Required; over 30 days warns
cookiethe cookie’s name; defaults to __Host-session; a name without the __Host- prefix warns
previousthe key being rotated out, accepted for verification only
sameSiteLax (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:

  1. A CSRF check, on POST, PUT, PATCH and DELETE (a GET is safe and skips it). Only a request whose Sec-Fetch-Site is same-origin passes 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 an Origin that is exactly one of the service’s cors origins (scheme, host and port; the service must declare credentials: true, a sibling subdomain counts only if it is listed, and a wildcard or null never qualifies). When the browser sent no Sec-Fetch-Site at all, this request’s own origin passes too. A request that reveals neither header is refused. Failure is 403.
  2. Reading the cookie. A missing cookie, or one sent more than once (a sign of cookie tossing from another path or subdomain), is 401.
  3. Verifying it. HMAC-SHA-256 under secret, or previous when the cookie’s kid names it; the cookie must be for this actor, unexpired, issued no later than now, and valid for no longer than the actor’s current ttl. Any failure is 401. 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.
  4. Minting the identity from the verified sub; a sub that violates the identity type’s refinement is 401.

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.

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).

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("-"))
}
MethodReturnsReads
get(name)Option[String]the claim when it is a JSON string; None for any other type, or none at all
has(name)Boolwhether 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.

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).

by <binder>: <Actor> // capture the identity as <binder>.identity
by <Actor> // verify, capture nothing (optional binder)
by <binder>: <A> | <B> | … // an ordered sum of peer actors, first-wins
  • HTTP, WebSocket and call require a by clause, because the caller is a party and more than one actor is sensible. A public HTTP route writes by v: Visitor (bynk.actor.missing_by_on_http). An on call handler writes at least by Caller, the explicit “any consuming context” (bynk.actor.missing_by_on_call); bynk check --fix=bynk.actor.missing_by_on_call inserts it, and a service-header by covers every handler without its own. The platform-only protocols default: cron → Scheduler, queue → Producer, email → Sender. An agent’s on call operations 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), a None catch-all is last, Bearer refinements are not members, and total failure is 401. On call, 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 one Internal member (bynk.actor.duplicate_sum_scheme). Several Foreign peers may share a sum; each has its own secret.
  • Refinement actors (<Admin> = <User> where <pred>) add an authorisation invariant over a Bearer base: scheme failure is 401, predicate failure is 403. The predicate is a closed set — hasClaim("n"), claimEquals("n","v"), composed with &&/||/!. An Admin is usable wherever its base is. Caller is 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 over Caller (hasClaim and claimEquals stay Bearer’s, and IsContext over a Bearer actor is bynk.actor.refinement_predicate_unsupported), and composes with &&, || and !, so !IsContext(shop.legacy) is a deny-list. The refinement inherits Caller’s scheme, its identity (CallerId) and its admissibility (on call only). A call from a context it does not admit is bynk.actor.caller_not_admitted at the call, in a case’s by Admin("…") too; the callee also answers such a call 403 (wire format check 6). See Restrict who may call.
  • Caller (on on call) yields the calling context’s qualified name as CallerId. It admits Bynk contexts only: a foreign caller is admitted by its own actor, never by Caller, so a handler that names only Caller refuses one (403).
NameSchemeIdentityFor
VisitorNone()anonymous HTTP routes
CallerInternalCallerIdthe calling context (on call)
SchedulerInternal()cron
ProducerInternal()queue
SenderInternalSenderIdentity (minted by the Worker; () in a suite today)inbound email

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.

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.