Authentication and enrollment
Installation identity, device credentials, administration, and current security limitations.
The lab separates three credentials: an installation's private key enrolls the app; the device token submits and retrieves data for that device; and the administrator token manages the registry and settings through the dashboard.
Roles and scopes
| Credential | Purpose | Limitation |
|---|---|---|
| Installation key | POST /api/enroll | Recovers the identity derived from that installation; cannot select another device's ID. |
| Device token | History, uploads, configuration reads, and streaming for its own ID | Cannot list the registry or change remote settings. |
ADMIN_TOKEN | Registry, provisioning, and all device routes | A single credential for administering the lab. |
DEVICE_TOKEN_SECRET | Internal server secret | Signs identities and tokens; never sent to the app or dashboard. |
Both server secrets must contain at least 32 characters. Until they are configured, /api/ returns 503 not_configured. Health checks, assets, and public downloads do not depend on them.
The current code does not implement operator accounts, email login, RBAC, SSO, or administrative action auditing. Access to the data dashboard uses the administrator secret rather than a user session.
Automatic app enrollment
The flow implemented in geo-demo/src/features/tracking/enrollment.ts starts by reading the native state. If a configuration already exists, it preserves it, including across APK updates.
For an installation without a configuration:
- The app retrieves an existing key or generates 32 random bytes with
expo-crypto, represented as 64 lowercase hexadecimal characters. - It persists the key with
expo-secure-storebefore attempting a network request. This allows a request to be retried if its response is lost. - It sends the key as a Bearer credential to
/api/enroll, with a JSON body containing onlylabel. The default name combines manufacturer and model, limited to 80 characters. - The server uses HMAC to derive an ID consisting of
app-followed by 32 hexadecimal characters and adds the profile to the registry. - The response contains the profile and a token specific to that ID. The app validates the format and configures the native transport.
Concurrent app calls share the same pending operation. Enrollment has a 20-second timeout and rejects redirects. Reusing the same key returns the existing identity without renaming the profile, deleting history, or consuming another enrollment slot.
Enrollment is public within this lab: it requires neither an invitation nor administrator approval. An enrolled identity does not start collection or grant location permission; the user must still take action in the app. See Mobile app and Remote configuration.
Enrollment limits
The server stores an HMAC hash of the network source derived from CF-Connecting-IP, using local as a fallback. It allows up to ten new enrollments per source within a one-hour window that starts with the first enrollment in that window. The eleventh new installation receives 429 enrollment_limit.
Existing identities are recovered before this check, so a retry neither consumes the quota nor gets blocked by it. The registry also has a global capacity of 1000 devices; new enrollments beyond that receive 507 registry_capacity.
The network limit does not identify a person and may be shared by several devices using the same internet connection. The current API exposes neither enrollment deletion nor individual revocation.
How tokens are generated
The device token is the HMAC-SHA256 of geo-device:v1: concatenated with the ID, using DEVICE_TOKEN_SECRET as the key. The result uses URL-safe Base64 without padding and contains 43 characters. For the same ID and secret, the credential is deterministic.
Installation and network-source identities also use HMAC, with the context geo-enrollment:v1: and inputs separated by purpose. The installation key does not appear in the registry. Administrator credential comparison computes SHA-256 hashes of the values and compares their bytes without an early exit.
Device tokens do not expire. Changing DEVICE_TOKEN_SECRET invalidates all previous tokens and changes ID derivation for future enrollments using the same installation keys. This requires an operational reconnection and recovery strategy; it is not transparent per-device rotation.
Changing ADMIN_TOKEN invalidates the administrator credential for new requests. Open WebSockets are not reauthenticated for each message; rotation must account for existing connections.
Where credentials are stored
| Location | Current implementation |
|---|---|
| Installation key in the app | expo-secure-store; on iOS, with WHEN_UNLOCKED_THIS_DEVICE_ONLY. |
| Native token on Android | App-private SharedPreferences, in geoTrackingCredentials; this layer does not implement its own Keystore encryption. |
| Native token on iOS | Keychain through GeoTrackingTokenVault. |
| Administrator token in the dashboard | Page memory during the session, without writes to localStorage or sessionStorage. |
| Local Worker secrets | .dev.vars, created with restricted permissions by the initialization script. |
| Deployed Worker secrets | Cloudflare Workers secrets. |
The state exposed by the native tracking API does not include the token. The dashboard uses Bearer authentication over HTTP and the geo-token.TOKEN WebSocket subprotocol. The API rejects tokens in query strings and validates the WebSocket origin when present.
Signing out of the dashboard closes sockets, aborts pending requests, and clears points, the registry, the password field, and the credential held in memory. Signing out does not stop the phones: collection belongs to each app's local session and the active remote configuration.
Transport and current limitations
Native clients validate endpoints and require HTTPS, with development exceptions for localhost and emulators. Redirects are rejected to avoid forwarding credentials to another destination. The registry contains no tokens; the public static page alone does not grant access to location data.
provider: native describes the path used by the client. The API also accepts this value from an authenticated client and does not attest to the hardware or the physical authenticity of the coordinate. Synthetic tests should use provider: test so they remain distinguishable in the dashboard.
The current design is a lab with shared administrator credentials. Features such as session expiration, individual revocation, device invitations, per-operator permissions, and an audit trail are not implemented.
Sources and evidence
Sources: tracking-server/src/auth.ts, tracking-server/src/index.ts, tracking-server/src/registry.ts, geo-demo/src/features/tracking/device-enrollment.ts, geo-demo/src/features/tracking/enrollment.ts, geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingEngine.kt, and geo-demo/modules/geo-monitoring/ios/GeoTrackingTokenVault.swift.
tracking-server/test/registry.test.mjs covers idempotent enrollment, per-device scope, and network limits. tracking-server/test/server.test.mjs checks HTTP/WebSocket authentication and cross-origin rejection. Client tests are in geo-demo/src/features/tracking/__tests__/enrollment.test.ts. The presence of these tests does not amount to a complete security audit.