Skip to main content

Security and accounts

SekoiaCraft is meant to be put online in front of a restricted community. Two boundaries answer each other there, and they do not protect the same thing:

  • a session closes the interface: an account is needed to open a screen — and, in preprod and prod, a code from an authenticator app on top of the password;
  • a shared secret closes the five APIs: you have to know it to query them.

The second is the least visible and the most important. In dev, preprod and prod, the five backends are published on the Internet by Traefik, each on its own hostname: without that secret, anybody could read your communities, your datasets and your settings without ever seeing the login screen.

A third surface is public by design: the scoring pages of a CTF, served by web-score, have no session at all — see The public CTF pages below.

The accounts​

Four roles. Each grants a set of capabilities; a screen is reachable because the role holds the capability its loader requires.

RoleWhat it can do
Super administratorEverything, including the accounts and the General settings (Sekoia feed key, mail server).
Sekoia expertEverything a Sekoia user can do, plus pools, CTF, Learning, the Catalog and Monitoring. Not the Administration menu.
Sekoia userCommunities only: create one, configure it entirely, delete it, launch its threat scenarios — and see every standalone community, whoever created it.
TeacherCTF and Learning only: deploy a session and run it — logs, scenarios, timer, answer key, grading, reset — only for the sessions they deployed.

Two rules go beyond the menu, and they are enforced on the resource, not only on the screen:

  • A Sekoia user sees standalone communities only. A community that belongs to a pool — a team or a pool's template — is not in their list, and its page answers not found. Pools are an expert's.
  • A teacher sees their own sessions only. A session records who deployed it (the Created by column of CTF and Learning); a teacher's list holds only theirs, and opening someone else's brings them back to the list. Sessions deployed before this column existed have no author: only a super administrator or an expert sees them.

A refused resource answers not found rather than forbidden: “forbidden” would confirm it exists. Each role signs in on its own area (/ for the first two, /communautes for a Sekoia user, /ctf for a teacher), and every screen outside its zones returns 403 — the menu only mirrors that.

An account is closed (Close account) rather than deleted: deletion also erases the trace that it existed, and its last-login date with it. A closed account stays in the list and can no longer sign in.

The last active super administrator is protected. Demoting, closing, deleting them or sending them a new link is refused as long as no other active super administrator — signed up, password set — can take over: otherwise nobody could reopen the accounts screen.

In preprod and prod, an account opens with a password and a code from an authenticator app (Microsoft Authenticator, Google Authenticator, 1Password… — any TOTP app, RFC 6238). Nobody chooses a password for someone else:

  1. An administrator creates the account from Administration → Users — address, name, role, no password. The account is Waiting for activation.
  2. SekoiaCraft issues a single-use activation link, valid 48 hours. It is e-mailed if a mail server is set up (next section), and in every case shown once to the administrator, to copy — it is never shown again: only its hash is stored.
  3. The person opens the link, chooses their password, scans the QR code and enters the code shown. The link is used up, the session opens.
  4. From then on, signing in asks for the password, then the Verification code.

Send a new link — on each account line — resets access: the password and the authenticator are erased, the previous link stops working, and a new link is issued. It is the answer to an expired link as much as to a lost phone. You cannot send it to yourself.

Five wrong codes in a row lock the second step for 15 minutes; the lock is only revealed after a correct password. A code works once: replaying it is refused.

Accounts created before this mode keep their password, and enrol their authenticator at their next sign-in: after the password, a QR code to scan. An account that already has an authenticator asks for its code everywhere, dev included.

This mode is switched on by STRONG_AUTH: 'true', written as a literal in the preprod and prod composes (on api-config and migrate). In dev and on a workstation it is off: an administrator may still set a password at creation, and leaving the field empty sends an activation link instead — which keeps the whole journey testable without strong mode.

The mail server​

The link is e-mailed through an SMTP server set on screen, in Administration → General settings, card E-mail (SMTP): server, port (465 for implicit TLS, otherwise STARTTLS when offered), username, password, sender. Nothing goes in the environment: the settings are read again at every sending. Send a test e-mail sends one to the signed-in administrator and says what the server answered.

The SMTP password follows the discipline of the other keys: only its mask is ever shown, an empty field keeps it, the box erases it, and it is not encrypted. Without a server, nothing is lost: the link stays on the accounts screen, to send yourself — the screen says whether the e-mail left.

The first sign-in​

The administrator account (admin@sekoiacraft.local) is created on the first load of the reference data (pnpm db:seed, or the migrate container in a deployed environment). What it receives depends on the environment:

  • in preprod and prod: an activation link, printed only once in the output of that step. Open it, choose the password, scan the QR code: the first administrator signs up like any other account;
  • in dev and on a workstation: a password drawn at random, printed only once. Write it down, sign in, and change it from Administration → Users.

Neither exists anywhere else: the database only holds hashes, and no file receives them.

On a workstation, the banner is read from the logs of the container that seeded:

docker compose -f infrastructure/docker/docker-compose.dev.yml logs migrate

On a deployed environment, you have to read it on the server, in the deployment directory (/home/<SSH_USER>/sekoiacraft/<env> by default — one directory per environment, so dev and preprod can share a host without sharing a .env):

ssh <SSH_USER>@<SSH_HOST>
cd ~/sekoiacraft/prod
docker compose -f docker-compose.prod.yml --env-file .env logs migrate

The link points at WEB_PUBLIC_URL — https://<WEB_HOST> in the deployed composes.

Those logs do not survive the next deployment

The pipeline does not bring them back — the banner never appears in a GitLab job's output, and that is deliberate: job logs are retained and readable by every maintainer of the project.

And deploy.sh starts every deployment with a docker compose down, which removes the migrate container and its logs with it. The reading window therefore closes at the next deployment. Add to that the fact that the banner is only printed once in the life of the environment — the seed is create-only, and later deployments merely note that the account exists.

In practice: use the link right after the first go-live — it expires after 48 hours anyway —, or issue a new one with the procedure in Access is lost.

In dev, every deployment is a first installation

A commit on develop redeploys dev from scratch: deploy.sh removes the containers, the volumes and the application images of the previous deployment before starting the new one. The database is empty again, the administrator account is recreated, and its password is drawn again at every commit — the one written down yesterday no longer opens anything. Set DEV_ADMIN_INITIAL_PASSWORD (next section) and the account keeps the same password from one deployment to the next.

Preprod and prod keep their volumes: the account, like everything else, survives their deployments, and prisma migrate deploy evolves their schema without losing anything.

Choosing the initial password from a vault​

Set ADMIN_INITIAL_PASSWORD in the seed's environment: it is then used as-is, and never printed — it already comes from a vault, writing it into logs would be taking it back out. In preprod and prod, no link is then printed: the administrator signs in with that password and enrols their authenticator at the first sign-in.

  • On a workstation: one line in the root .env, or in front of the command (ADMIN_INITIAL_PASSWORD=… pnpm db:seed).
  • In deployment: a GitLab variable <ENV>_ADMIN_INITIAL_PASSWORD, marked “Masked”, under Settings → CI/CD → Variables. It is the only environment variable deploy.sh does not require: without it, the deployment proceeds normally.

It is only read on the first installation. Setting it on an already-seeded environment changes nothing as long as the account exists — see the procedure below.

Access is lost​

A forgotten password, a lost phone, an expired link: the answer is a new activation link.

If another administrator can still sign in, it is immediate: they open Administration → Users and click Send a new link on the account concerned.

Otherwise — the last administrator is locked out —, the recovery runs on the server, in the deployment directory, and prints the link in your own terminal:

cd ~/sekoiacraft/prod
docker compose -f docker-compose.prod.yml --env-file .env \
run --rm migrate node prisma/seed/reset-app-user-access.ts admin@sekoiacraft.local

On a workstation: pnpm --filter @sekoiacraft/database reset-access admin@sekoiacraft.local.

Three things are worth knowing about it:

  • It works on any account, by its address, and does what Send a new link does: password and authenticator erased, previous link dead, new link valid 48 hours. A closed account stays closed.
  • It bypasses the last-administrator safeguard, which lives in api-config. That is precisely why it is a recovery procedure run from the server and not a button: whoever can run it can already reach the database.
  • run --rm, never logs: the link appears in your terminal and nowhere else, out of any retention.

No password is written in the repository, and that is deliberate: a versioned admin/admin is known to every reader of the code, production included, and it survives there all the longer because nobody remembers it exists.

The shared secret between the frontend and the APIs​

A single variable, the same everywhere: INTERNAL_API_KEY. The frontend sets it as an x-internal-key header on each of its calls; the five backends check it on all their routes.

# A random value, to be set in the installation's .env
openssl rand -base64 32

What it authenticates is the caller, never a user. The backends have no notion of an actor: roles live in the frontend's session, and it is the frontend that refuses a write to a reader. An identity-bearing token would have no use here, and it would have to be revoked, rotated and have the clocks of five services that do not talk to each other kept in agreement.

Three behaviours are worth knowing:

  • Without a key, the APIs are open, and they say so at startup (INTERNAL_API_KEY is not set: this API accepts every request). That is deliberate: an installation being updated must not fall over in error before its operator has set the key. In dev, preprod and prod, however, it is the only thing closing the APIs — set it.
  • The health routes stay free (/health, /health/ready, /health/stream). Docker's checks query them without a header; a refusal would make every container unhealthy, hence the deployment a failure.
  • Swagger stays displayed on /api, but its “Try it out” calls require the header. The page's “Authorize” button lets you enter it.

The public CTF pages​

The scoring pages of a CTF session are served by web-score, on their own hostname, without any sign-in: a player has no account on the application, and must not have one.

  • A player link is a bearer key. /t/<token> carries a random 32-character token, one per participant. Whoever holds it sees that participant's page and answers in its name — and nothing more: it opens no other participant, not even one reading the same community, and no screen of the application. Adding a participant creates a new link and changes none of the others. No public page ever shows a token; only the answer key screen does, to the facilitator. A link does not expire: it disappears with the CTF, when the CTF is reset.
  • The leaderboard and the dashboard open with the pool identifier, a UUID — hard to guess, but not a secret. They show participants' names and scores, never an answer, expected or given.
  • A player's last name is personal data, and the public pages only show its initial. A participant names itself on its page — a team name, or a player's last name, first name and company. Those are stored in clear on the participant's row, next to its token, and deleted with the CTF when it is reset — or with its community. The leaderboard, the dashboard and the campaign leaderboard only receive Ellen R. and the company: the full last name never leaves the server for them. The participant's own page and the facilitator's screens show it in full.
  • Answers are limited to thirty per ten seconds per link, names saved included. The limit lives in memory, one of the reasons web-score runs as a single replica.
  • web-score reaches the database directly, where the application goes through api-config and its shared secret — it calls no API, so it needs no INTERNAL_API_KEY. What it may do there is bounded by tests/web-score-guard.spec.ts: it never writes a community, never creates or deletes a participant — they are born in api-config —, never reads a token back, grades with the expected answers on the server without sending them to the browser, and never reads the evidence logs — and its public pages never name a player's last name.

What this security does not cover​

Saying it is better than letting it be believed.

  • Nothing is encrypted in the database — neither the intake keys, nor the feed key, nor the shared secret, nor the authenticators' secrets, nor the SMTP password. The decryption key would live on the same host as PostgreSQL, which would only add one step for anyone who already has access to the database. Passwords, for their part, are not stored: only their bcrypt hash is, and it never leaves PostgreSQL; an activation link is only stored as its SHA-256 hash.
  • Password attempts are not throttled. Only the second step locks (five codes, fifteen minutes). In preprod and prod, a guessed password still has to be followed by a code.
  • An account migrated from before strong mode enrols on trust. Whoever signs in with its password first scans the QR code. Sending a new link to existing accounts closes that window.
  • An activation link travels in an address, /activation/<token>: a reverse proxy writes it into its access log. It works once and for 48 hours; the page itself is neither cached nor sends its address to another site.
  • A role change takes effect on the next sign-in, or after twelve hours — the length of a session. The role is carried by the signed cookie, which avoids querying the database on every navigation. The accounts screen, however, always revalidates: a demoted administrator cannot give themselves a role back with a stale cookie. The deployment that introduced the four roles signed everyone out once: the old cookies named roles that no longer exist.
  • A community has one Sekoia API key, and it configures as well as it sends. It sends the inventories, and the Create in Sekoia buttons use it to create intakes — entity, module configuration, intake — and asset connectors — module configuration, connector, then its stop. It therefore carries the asset rights and the intake and connector (Symphony) configuration rights of its space; give it no more than what that community uses. Being the key of the daily inventories, it cannot be cleared once a session's intakes exist without stopping them: SekoiaCraft keeps it, unencrypted, like the other keys. It deletes as well: Delete in Sekoia removes with it the community's intakes, connectors and entity, so it needs the deletion rights too. To recognise the community's own intakes, it lists those of the whole space — their keys included: they stay in memory for the gesture, compared to the community's by a database filter, and are never logged, stored or returned.
  • The live updates are not filtered by role. The event stream every screen listens to carries signals — identifiers and counters — for all communities and sessions; each screen then reloads only what its role may read.
  • A teacher reads the answer key of their sessions. Players get a player link, never an account.
  • A player link cannot be renewed. Leaked during a session, it lets someone else answer in the participant's name until the CTF is reset — and an answer, once sent, uses up one of the flag's three attempts. Adding a participant gives the rightful player a new link, but the leaked one keeps working.
  • The shared secret is the same for all five APIs. That is what makes it generic; it is also what makes changing it require restarting the six services together. In strong mode, account management refuses to work without it (503): without the secret, anyone reaching api-config could set a password.

Summary of the variables​

VariableWho reads itRole
SESSION_SECRETthe frontendsigns the session cookie
INTERNAL_API_KEYthe frontend and the five backendscloses the APIs
ADMIN_INITIAL_PASSWORDthe seed, if it is setchooses the initial password
STRONG_AUTHapi-config and the seedactivation link and authenticator for all
WEB_PUBLIC_URLapi-config and the seedthe address activation links point at

The last two are not GitLab variables: they are written in the composes — STRONG_AUTH: 'true' as a literal in preprod and prod only, WEB_PUBLIC_URL: https://${WEB_HOST} in the three deployed environments. A forgotten variable would leave production in weak mode without anything failing; a literal is read in review. The mail server is not a variable either: it is set on screen.

The first three are injected by infrastructure/scripts/deploy.sh from the GitLab variables <ENV>_SESSION_SECRET, <ENV>_INTERNAL_API_KEY and <ENV>_ADMIN_INITIAL_PASSWORD. The first two are required — a deployment stops and names them if they are missing — and appear in .env.example.

The third is optional on both sides, and that holds together: an environment letting its initial password be drawn must be able to deploy, and requiring it would break every installation that has nothing to choose. It appears in no versioned .env either — the repository's environment contract demands a non-empty value there, which would amount to publishing exactly the credential we refuse to publish.