Authentication
Your backend holds a project credential and mints short-lived device tokens from it. A token's grant says what it may write, what it may read, and how narrowly.
Lantern never asks a device to hold a project credential. Your own systems hold one, and mint each device a short-lived JWT from it. Lantern verifies the signature, resolves the client project from the credential the token names, and ignores anything the token says about which tenant it belongs to.
Two kinds of credential, same token shape:
| You hold | Signed with | Use when | |
|---|---|---|---|
| API key | fk_<id>_<secret> | HS256, the shared secret | Minting happens somewhere you are happy to keep a secret — a backend, a provisioning job |
| Signing key | Your private key | EdDSA, ES256 or RS256 | You would rather Lantern never hold anything that can sign |
Both are device keys, created per client project in the Lantern console — a
Device secret key gives you the API key, a Device public key holds your
public half. Both produce a token with a kid header naming the key, and
everything below applies equally to either. Each key has a maximum token lifetime — 24 hours
unless you set another when you create it.
Minting a token
import { mintToken } from "@lntrn/device/server";
const token = await mintToken({
apiKey: process.env.LANTERN_DEVICE_KEY!, // fk_<id>_<secret>
clientId: device.id,
ttlSeconds: 3600,
attrs: { plan: user.plan },
});From a registered signing key, pass the private half instead — it never leaves your systems:
const token = await mintToken({
signingKey: {
keyId: "01j9x…", // assigned by Lantern at registration
privateKey: process.env.LANTERN_PRIVATE_KEY!, // PKCS#8 PEM, private JWK, or a CryptoKey
},
clientId: device.id,
});The Go package mints the same tokens:
priv, _ := lanterndevice.ParsePrivateKey(pemBytes)
tok, err := lanterndevice.Mint(lanterndevice.MintOptions{
SigningKey: &lanterndevice.SigningKey{KeyID: keyID, PrivateKey: priv},
ClientID: deviceID,
TTL: time.Hour,
Attrs: map[string]string{"server": slug},
})There is nothing Lantern-specific in the result — it is an ordinary JWT, and any language with an HMAC can produce one:
// header
{ "alg": "HS256", "typ": "JWT", "kid": "01j9x…" }
// claims
{
"sub": "device-4711",
"iat": 1756512000,
"exp": 1756515600,
"forest": {
"write": { "attrs": { "plan": "pro" } }
}
}sub is your own identifier for the device and becomes its
service.instance.id on every record. exp is required, and must be within
the maximum lifetime configured on the key — a token that outlives it is
refused however well it is signed.
The grant lives in the claim named forest, a name kept for compatibility:
tokens minted before Lantern took over carry it, and they still verify.
Spell it exactly that way when you mint by hand.
The API key secret must never reach a device or a browser bundle. Mint on your
own infrastructure and hand the device the token. @lntrn/device/server
is a separate entry point so a bundler cannot pull it into a client build by
accident.
Grants: what a token may do
The grant claim, forest, is the token's authority. It has two independent
halves, and absence is denial:
- no
write→ the token cannot ingest; - no
read→ the token cannot query or tail.
The default from mintToken is write-only, which is what an ordinary device
wants.
Writing
"write": { "attrs": { "session_id": "s-9", "node": "n7" } }attrs are assertions. They are stamped onto every record sent with the
token and the device cannot override them — so "this token may only log
against session s-9" is enforced rather than trusted. Attributes pinned to the
key itself in the console win over these.
Asserted attributes are checked against your declared fields like any other: being in the token makes a value trustworthy, not exempt. An undeclared one is dropped, and so is one on the list of keys Lantern never stores.
Reading
const token = await mintToken({
apiKey: process.env.LANTERN_DEVICE_KEY!,
clientId: "support-session-8821",
canWrite: false,
ttlSeconds: 900,
read: {
primitives: ["logs", "events"],
filters: { "attr:session_id": ["s-9"] },
},
});In Go, the same grant is ReadOnly: true and
Read: &lanterndevice.ReadGrant{Primitives: …, Filters: …}.
filters narrow every read the token makes. Values within one key are OR;
keys AND together. The keys are the grant's own vocabulary, which is not quite
the one read requests use:
| In a grant | Matches | In a read request |
|---|---|---|
client_id | The device: the sub of the token that wrote it | service.instance.id |
level | Log severity | severity |
message | The log body | body |
name | An event's name | event.name |
logger | The logger a device SDK sent | — |
trace_id, span_id | Trace context | trace_id, span_id |
attr:<key> | One of the record's own attributes | attr:<key> |
Any other key refuses the token. A grant's filters match values exactly.
The narrowing is a ceiling, not a default: a request that sends its own filter can only narrow further. There is no filter a caller can send that widens what its token may see.
primitives limits the token to some of logs, metrics and events; omit
it for all three. Logs and events can be read back today; metrics cannot.
maxAgeSeconds floors the time range — a token with maxAgeSeconds: 86400
asking for a week returns the last day rather than an error. It has no meaning
on a live tail and is ignored there.
A read grant needs filters or all: true. One with neither is refused rather
than read as project-wide, so a bug that drops the filters cannot quietly widen
a token to your whole project.
Reading a whole project
read: { all: true }Permissive tokens are a legitimate thing to mint — a dashboard of your own, an export job, an internal tool. The key has to be allowed to mint one; see below.
What a key may delegate
Your code mints whatever it asks for, and Lantern refuses anything the key is not permitted to delegate. Each device key carries a policy, set when you create it and editable afterwards:
| Setting | Effect |
|---|---|
| Write | May mint write grants at all |
| Unrestricted write | May mint a write grant that asserts no attributes |
| Read | May mint read grants at all |
| Unrestricted read | May mint read: { all: true } |
| Required attributes | Every token must constrain these — asserted (or pinned) on the write side, filtered on the read side |
A new key may write, including unrestricted writes, and may not read: reading is a choice you make deliberately rather than a default you inherit.
Required attributes are the lever for a key that may only ever produce narrow
tokens. A key requiring session_id refuses a token that does not constrain
it even when the unrestricted settings are on, so a support-tooling key
cannot be turned into a project-wide one by whoever holds it. On the read
side the grant satisfies it with a filter on attr:session_id.
A token that exceeds its key's policy is refused as a permission failure, with a message naming what it asked for. The fix is on the minting side, not the key — you asked for authority that key does not carry.
Registering a signing key
If you would rather Lantern never hold anything capable of signing, register a public key instead:
- Generate a key pair. Ed25519 is the smallest and the default recommendation; ECDSA P-256 and RSA (2048 bits or more) are also accepted.
- In the client project's keys, add a Device public key and paste the public half — PEM or JWK, either is fine.
- Lantern assigns a key id. Put it in the
kidheader of every token you sign.
openssl genpkey -algorithm ed25519 -out lantern-signing.pem
openssl pkey -in lantern-signing.pem -puboutThe algorithm is fixed when you register the key and is never read from a token header, so a token that claims a different algorithm does not verify — you cannot be tricked into accepting one signed with the public key material.
Everything else is identical: same claims, same grants, same policy, same lifetime ceiling. Revoke a key in the console and its outstanding tokens stop working within seconds — open tails included — with a message saying the key was revoked rather than that it was unknown.
Pasting a private key is refused rather than quietly reduced to its public half. If you paste one by mistake, treat it as disclosed and rotate it.
Who can manage a project
Console access is separate from tokens. In the Lantern console, what you can do with a client project follows your Lantern role:
| Role | May |
|---|---|
| viewer | See client projects, their keys (never a secret), fields, releases, devices and records |
| editor | Also create, change and delete projects; create keys, change their policy and pinned attributes, revoke them; declare fields |
A key's secret is shown once, when it is created. A project's owner team groups projects in the console's lists; it does not restrict who can see or change them.
Using a read token
Send it as a bearer to Lantern's read API on the ingest host:
Authorization: Bearer <token>Nothing else identifies the project — it is always the key's. See Reading.
Errors
On the ingest a refusal is an HTTP status; on the read API it is the Connect code alongside it. The message says which of these it was.
| Status | Connect code | Message |
|---|---|---|
401 | unauthenticated | malformed token — not a JWT, or no kid |
401 | unauthenticated | unknown key — the kid names no key |
401 | unauthenticated | invalid token — the signature failed, or the algorithm is not the key's |
401 | unauthenticated | token: expired — exp has passed |
401 | unauthenticated | token: exp exceeds the key's max TTL — exp − iat is longer than the key allows |
401 | unauthenticated | token: the key this token names has been revoked |
403 | permission_denied | token: grant exceeds what this key may mint: … — the key's policy does not permit this grant |
403 | permission_denied | token: grant does not constrain an attribute the key requires: … |
403 | permission_denied | token: read grant has no filters and is not marked all — the fail-closed rule above |
403 | — | this token has no write grant — a read-only token tried to ingest |
403 | permission_denied | this token has no read grant — a write-only token tried to read |
Notes on scoping
A filter on an attribute the device sets partitions your data; it does not
authenticate it. A device that chooses its own session_id can choose someone
else's. Constrain on attributes that are pinned to the key or asserted in the
token — those are the ones a device cannot vary — when the boundary needs to
hold against the device itself rather than merely tidy the view.
Devices
Send logs, metrics, events and errors from apps and devices you ship — desktop, mobile, TV, embedded, daemons on someone else's hardware — with a short-lived device token.
Reading
Query a client project's logs and events and tail them live with a read token, over Lantern's ClientReadService. The token's grant decides what any call can see.