Skip to Content
Xeonr Developer Docs

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 holdSigned withUse when
API keyfk_<id>_<secret>HS256, the shared secretMinting happens somewhere you are happy to keep a secret — a backend, a provisioning job
Signing keyYour private keyEdDSA, ES256 or RS256You 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 grantMatchesIn a read request
client_idThe device: the sub of the token that wrote itservice.instance.id
levelLog severityseverity
messageThe log bodybody
nameAn event's nameevent.name
loggerThe logger a device SDK sent—
trace_id, span_idTrace contexttrace_id, span_id
attr:<key>One of the record's own attributesattr:<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:

SettingEffect
WriteMay mint write grants at all
Unrestricted writeMay mint a write grant that asserts no attributes
ReadMay mint read grants at all
Unrestricted readMay mint read: { all: true }
Required attributesEvery 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:

  1. Generate a key pair. Ed25519 is the smallest and the default recommendation; ECDSA P-256 and RSA (2048 bits or more) are also accepted.
  2. In the client project's keys, add a Device public key and paste the public half — PEM or JWK, either is fine.
  3. Lantern assigns a key id. Put it in the kid header of every token you sign.
openssl genpkey -algorithm ed25519 -out lantern-signing.pem
openssl pkey -in lantern-signing.pem -pubout

The 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:

RoleMay
viewerSee client projects, their keys (never a secret), fields, releases, devices and records
editorAlso 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.

StatusConnect codeMessage
401unauthenticatedmalformed token — not a JWT, or no kid
401unauthenticatedunknown key — the kid names no key
401unauthenticatedinvalid token — the signature failed, or the algorithm is not the key's
401unauthenticatedtoken: expired — exp has passed
401unauthenticatedtoken: exp exceeds the key's max TTL — exp − iat is longer than the key allows
401unauthenticatedtoken: the key this token names has been revoked
403permission_deniedtoken: grant exceeds what this key may mint: … — the key's policy does not permit this grant
403permission_deniedtoken: grant does not constrain an attribute the key requires: …
403permission_deniedtoken: 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
403permission_deniedthis 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.

On this page