Security
This page covers three things. It covers how Connect protects the secrets it keeps. It covers how Connect limits what a tenant’s setup can reach. It covers how Connect stands up to clocks it does not know. For each, it says what you set and watch for. The rest of the checklist (the admin API, device listeners, biometric data, packages) is in operations.
Secrets kept in the database
Section titled “Secrets kept in the database”These are kept in the database sealed with the secret key:
- Broker passwords.
- Webhook signing secrets.
- Device keys. That is the key a device must present, the one on its way to it, and the one it presented.
- Sync group credentials.
- Sensitive commands waiting to be handed out.
- Tenants’ secrets.
- Delivery keys.
The secret key is HOURADVANTAGE_SECRET_KEY, or the file HOURADVANTAGE_SECRET_KEY_FILE names. houradm gen-secret-key makes a key. Every instance sharing the database needs the same one. See secrets at rest.
An instance started without a key (hourd run) looks for secrets in the database first. If there are any, it refuses to start. It names the first kind it found:
HOURADVANTAGE_SECRET_KEY is not set, and the database keeps secrets (adevice key, at least), which would be kept in plain text: give everyinstance the key (`houradm gen-secret-key` makes one), or setHOURADVANTAGE_ALLOW_PLAIN_TEXT_SECRETS=true to keep secrets in plain textAn install that keeps secrets in plain text on purpose sets HOURADVANTAGE_ALLOW_PLAIN_TEXT_SECRETS=true on every instance.
An install with no secrets yet starts without a key. It says in its log that it will refuse to start once one is kept.
A request to keep a secret is refused at the request (409). The answer names HOURADVANTAGE_SECRET_KEY and HOURADVANTAGE_ALLOW_PLAIN_TEXT_SECRETS, and nothing is kept. This covers:
- A delivery key issued.
- A sink’s
secret. - A broker password.
- A secret value.
- A key given to a device (
device register --key,device key).
What a device sends is never refused for want of a key, as that would drop punches. Two things a device sends are kept in plain text:
- A key a device presents while it waits to be allowed.
- A person enrolled at a clock with a keypad PIN or password.
The next start refuses until the key is given.
hourd dev keeps everything in memory unless given a database, and is never refused.
Changing the key
Section titled “Changing the key”You can change the key without downtime:
- Give every instance the new key in
HOURADVANTAGE_SECRET_KEYand the old one inHOURADVANTAGE_SECRET_KEYS_OLD(or the files their_FILEvariables name). - Restart the instances one at a time. Until every running instance has the new key, secrets stay sealed with the old one, which every instance can open. Once they all have it, everything kept is sealed again with the new key, once, and the log says so.
- Once every instance has run with the new key, take the old one out of
HOURADVANTAGE_SECRET_KEYS_OLD.
After that, don’t start an instance with only the old key. It cannot open what is sealed with the new one.
The instances running meanwhile go back to sealing with the old key. But what was sealed again stays sealed with the new one.
While some running instance has no key at all (a key being introduced), secrets stay in plain text. Live views keep working throughout.
Where a tenant’s setup reaches
Section titled “Where a tenant’s setup reaches”A tenant’s webhook sinks post from the server. Its MQTT listeners connect to their broker from the server too. The server is on the install’s own network. So they reach public addresses only. An internal address is refused:
| Refused | |
|---|---|
| IPv4 | 0.0.0.0/8. Loopback 127.0.0.0/8. Private 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. The carriers’ shared space 100.64.0.0/10. Link-local 169.254.0.0/16 (cloud metadata services among them). 192.0.0.0/24. Benchmarking 198.18.0.0/15. The reserved 240.0.0.0/4 (which holds 255.255.255.255). Azure’s 168.63.129.16. |
| IPv6 | ::, ::1, link-local fe80::/10, site-local fec0::/10, unique-local fc00::/7 and Teredo 2001::/32. |
| IPv4 inside IPv6 | ::ffff:127.0.0.1, ::127.0.0.1, NAT64 64:ff9b::/96 and 6to4 2002::/16 are judged as the IPv4 address they carry. |
The check is made on the address each connection goes to, not on the name in the setup. A name is resolved at each connection, and its internal addresses are left out. A name that resolves only to internal addresses is refused, however it resolved when the setup was saved. So DNS cannot be used to get around the check.
Webhooks follow no redirect and go through no proxy. A broker’s TLS certificate is still checked against the broker’s name.
A refused webhook delivery fails. It is tried again as any failed delivery is. Its sink’s status says why:
sink 'payroll': error sending request: ... payroll.internal is an internaladdress (10.20.3.4), which a tenant's setup may not reach; the install canallow it in tenant_destinationsA refused broker connection shows on the listener’s status as a broker that cannot be reached. It also shows in the log (mqtt broker connection refused), saying why.
If a tenant’s webhook sink has a URL that names an internal address the install has not allowed (an address, or localhost), it is saved all the same. The answer carries a warning that its deliveries will fail. hourctl prints the warning. A name that resolves to an internal address is known only when a connection is made, so it is not warned of.
A change of tenant_destinations reaches the sinks already running. An address allowed is posted to from then on. One taken away is refused.
The install allows more in the tenant_destinations setting. The list holds addresses, CIDR ranges and host names. It applies to every tenant. A listed name may resolve to any address.
hourctl settings set tenant_destinations=10.20.0.0/16,payroll.internalThe install’s own sinks (/api/sinks, hourctl --install sink) are not filtered.
Trusted roots
Section titled “Trusted roots”Each TLS connection the server or hourctl makes trusts the root certificates (the roots) of one store:
| Connection | Roots trusted |
|---|---|
| Webhook sinks | The public roots Mozilla publishes (webpki-roots). They are compiled into the program. No setting adds a certificate authority. |
| Postgres | The same, plus the file sslrootcert (or PGSSLROOTCERT) names. With sslmode=verify-ca or verify-full and a file given, that file alone, as libpq does. |
| MQTT over TLS | The host’s root store (in the container image, its ca-certificates). SSL_CERT_FILE and SSL_CERT_DIR override it. |
hourctl | The same public roots as the webhook sinks, compiled in. |
The compiled-in roots change with the program’s release. The host’s store changes with the host’s ca-certificates.
To trust a private certificate authority:
- For Postgres, give its certificate in
sslrootcert. - For MQTT, add it to the host’s store (
update-ca-certificates), or pointSSL_CERT_FILEat a bundle that holds it.
A held device’s key
Section titled “A held device’s key”A device nobody registered, at an endpoint with new_devices = "hold", waits to be allowed. While it waits with no key of its own, the first key it presents is kept, sealed, as the key it was held with. The device shows key_held: true.
Allowing it and adopting its key (adopt_key: true, hourctl device key ENDPOINT DEVICE --adopt) makes that key its own. That key is the one presented when the operator saw it, never a key presented later.
Anyone can send a message under a waiting device’s serial number. A message presenting another key while the device is held is not taken as its key. It is a conflict. The device shows when the latest was (key_conflict_at).
An operator who has checked the clock and wants the key it is presenting now says so in so many words (adopt_presented_key: true, --adopt-presented). Setting, adopting or taking away the device’s key clears both (keys).
A message can be refused for the device’s status (held or blocked) or rate. It still counts as a sighting (last_seen). It never moves the address the device is reached at. It never moves the values its path or topic gave (params, which address MQTT replies). Only a message the device is let in on does.
Device keys in the traffic log and the log
Section titled “Device keys in the traffic log and the log”A device puts its key in every message. A ZK clock puts it in each poll’s query. A cloud device puts it in each envelope. Whoever guesses at a key puts the guess there.
Neither reaches the traffic log (/api/tenants/{tenant}/traffic, the live stream) or the log. The key the package found in the message, right or wrong, is replaced in the query and the body by its size (<redacted N bytes>). A sensitive command’s payload is replaced the same way in the reply. The message not accepted line that a refused message is logged with names the request without the key.
A device’s key is shown only by device show. The wire capture (hourctl wire) is the one view that shows messages as they are.
A package’s log lines
Section titled “A package’s log lines”A package writes to the log with log.info, log.warn and log.error. Each line says the package (name@version). It also says whom the call is for: the tenant, the endpoint and, where the call is about one device, the device. The device is empty where there is none, for a hook that decides for no device.
A line is cut to 4096 bytes. The number of bytes cut is said.
A package may write 100 lines at once and 50 a second after that. Lines over that are left out of the log. The next line written says how many were left out.
Whoever watches the package (hourd dev, hourctl pkg replay) is given every line, whole.
A package that logs a device’s data writes it to the log. Its authors keep keys, PINs and templates out of its lines.
What the probes tell anyone
Section titled “What the probes tell anyone”/livez, /api/ready and /api/health need no login, for load balancers and monitoring. They say whether the instance lives, takes work and has its database. For readiness they also say why not.
They do not say which instance it is, its version or the cluster’s environment. That information tells a scan what to aim at. It is at GET /api/instance, behind the login or an install token. hourctl status reads it, and so does hourctl for the environment it names before a change.
Refused requests to the admin API
Section titled “Refused requests to the admin API”A request the admin API turns away before any route sees it is counted in houradvantage_admin_refused_total, by reason. The reasons are:
origin,host,peer_token,scope,token,forwardedandlogin_busy.login_wrong, for a login that does not check out.login_missing, for none sent.- For deliveries into Time and Attendance,
delivery_signatureanddelivery_limited.
Such a request is also logged at warn. The log has at most one line a minute for each reason and client address, with how many there were since.
The line names the reason, the address and, cut short, what was asked (the Host, the Origin, the path). It never holds a token, a password or a signature.
A request refused for its Host or Origin is answered 403 with the reason in {"error": ...}.
The address is the connection’s peer. Behind a load balancer, it is the balancer’s.
Slow devices and connection limits
Section titled “Slow devices and connection limits”A device listener cuts off a client that holds a connection without using it:
- Request headers must arrive within 10 seconds.
- A connection that moves no bytes for 30 seconds, while none of its requests is being worked on, is closed.
- Each instance holds at most 10,000 connections on a listener.
A request body is read for as long as it keeps arriving. A clock on a slow link (GPRS, say) sends a large body slowly. So the body is cut off (408) only when nothing arrives for 30 seconds, or when it has not all arrived in 15 minutes.
A body over limits.max_body_bytes is refused (413) as soon as the limit is passed.
The admin API’s socket is served with the same timeouts. It holds at most 1,024 connections open at once, so a client that connects and says nothing cannot hold it.
A stream (hourctl wire, stream, events --follow) is a request being answered, not an idle connection. It stays open.
The admin API speaks HTTP/1.1.
The audit trail
Section titled “The audit trail”Every change made through the admin API is recorded with who made it. That is the login’s user name, token:<name> for an API token, or local without a login.
These are removed, or kept as their size, first. So none is in an entry:
password,secretandkeyfields, and a sink’s signingsecret.- A var or secret’s value. The trail says who set which one, never the body.
- A sync group’s keypad PINs, passwords, card numbers, templates and photos, and the values of settings a member marks sensitive. These are kept as their size only.
- An action’s parameters the device’s package marks sensitive. These are kept as their size only.
A delivery key’s secret is in no entry. A tenant’s document loaded into Time and Attendance is streamed, never held. Its entry says who loaded it, without the document.
Some entries are the engine’s own, not a request’s. The user is houradvantage. The action is its name for what it did, not a method and a path. There are two:
job.paused: a job paused itself at its abort threshold.biometric.refused: biometrics dropped from a sync group’s people because the install refuses them.
Events posted and deliveries are data, as a device’s messages are. They are not changes, so they are not in the trail. Neither are reads, scenario runs, costings and previews, and the instances’ own calls to each other.
A request body is kept up to 64 KiB. A longer one is cut there and ends with ...[cut: N of M bytes kept].
Each entry’s summary says what the change did. A revocation (of an API token or a delivery key) names what was revoked: the token, its scope, who made it and when it was last used. A token or key revoked is kept in its list, flagged revoked, with its secret dropped. So token:<name> in the trail always means one token.
What is a secret is decided by the route the body was sent to, not by a field’s name.
An entry also names the address its request came from (client). That is the connection’s address. When the connection is one of the trusted_proxies, it is the address that proxy forwarded. The request’s log lines carry it too.
The tenant of an entry is the one its path names. For a tenant or a scoped token being made (POST /api/tenants, POST /api/attendance/tenants, POST /api/tokens), it is the one its body names.
Take a request that fails after it had changed something. An example is a tenant’s deletion that stopped the tenant and revoked its tokens, then met a database it could not use. Such a request says what it had done and that it then failed. Tokens a request revoked are refused at once on the instance that answered, whatever the answer.
An entry is written before the change is made, with who asked, the route, the tenant, the address and the request’s id. It is finished when the request has been answered. Its time (at) is when the change was made.
If the entry cannot be written, the request is refused (a 5xx, saying the change could not be added to the audit trail) and nothing is changed. Try it again when the database is back.
Each entry says how far its change got in outcome, with the HTTP status of the answer in status:
done: the request succeeded. The summary says what it did. The entry keeps the request body, with its secrets taken out. A request that failed after it had changed something is alsodone. Its summary says what was done and that it then failed.failed: the request was answered with an error and changed nothing. The entry keeps no body.started: the entry was written and the trail was not told how the request ended. The instance stopped, or the database was not there when it finished. The change may have happened. Look at the thing it names before you repeat it. The log says which entries could not be finished.
The engine pauses a job itself at its abort threshold (job.paused). That is the exception to the order. The pause is decided as the job is saved, so its entry is written just after. If the database is down at that moment, the entry can be missing. The job’s own job.paused event, which is saved with the pause, says it happened.
Entries are numbered as they are written, not as they commit. One committed a moment after a higher number may appear after a read has passed it. A reader that must not miss one reads again from a little before where it got to, or reads by time (since). The entries are told apart by their number.
The trail is read through GET /api/audit (hourctl audit), a page at a time from a sequence number (after). You can limit it by any of these:
user.tenant: the tenant the request named in its path, in either engine’s routes.action: a prefix of the method and path.sinceanduntil.request_id.
On the command line, the matching flags are hourctl audit --by, -t, --action, --since, --until and --request, in the same order. The filters hold together, and an index serves each one.
Entries are kept for ever. audit_retention_days is unset by default (see retention). It removes entries older than it. retention_days never does.
Devices nobody registered
Section titled “Devices nobody registered”A device that calls under a serial number nobody registered is a stranger.
Which serial numbers are registered is kept whole in memory on every instance, from the notes the instances send each other. So a registered device is never taken for a stranger. And a serial nobody registered costs the database no read of a row.
Connect does not meter strangers by rate or by time. What it bounds is a count you set:
- A serial not kept in memory is looked for once, by a read of the devices added lately. Messages that find their device missing while one such read is under way on an instance share it. So a flood of made-up serial numbers costs about one read per read in flight, never one per message. A device registered on another instance a moment ago is found by it and let in, not refused.
- At an endpoint that refuses strangers (
new_devices = "refuse"), an unregistered device is answered 403, and nothing is written. - At an endpoint where strangers may register,
limits.max_pending_devicesand a tenant’spending_devicesanddeviceslimits bound how many are kept. Past the count, a new device is answered 429 (too many devices waiting, ortoo many devicesat the tenant’s limit) until some are allowed, blocked, forgotten or expire. A waiting device that has MQTT messages set aside keeps its place forlimits.set_aside_days(7 by default) instead of 24 hours. The punches it sent are worth more than the place (messages set aside).
A real new clock within these bounds registers and is announced with device.new. Many clocks set up at once may find the waiting room full and be asked to try again. Register them beforehand (hourctl device register) so none waits.
Strangers turned away (unknown, waiting room full, or naming no acceptable device) are logged together. There is one line a minute per endpoint and status, with how many were turned away since the last (repeats). There is never a line per request.
Request ids
Section titled “Request ids”Every admin API answer carries an X-Request-Id. It is the caller’s, when it is 1 to 128 letters, digits, -, _, . or :. Otherwise it is a new 64-bit random id. An odd or oversized id is replaced whole, never cleaned up or cut short. So what reaches the log and the answers is always plain.
The id is in these places:
- On every log line written while the request runs (the
adminspan). - In an
{"error"}body’srequest_id. - In the audit trail entry of the change the request made.
- In the
requestof every event made while it ran (events).
Device messages get one the same way (the message span), from the proxy in front (request ids at the balancer).
A request id is for following a request, and nothing else. A caller chooses it, so nothing is allowed, looked up or deduplicated by it.
hourctl sends one per command (every call of the command the same). It prints the id with any refusal, and takes one with --request-id.
Idempotency keys
Section titled “Idempotency keys”A POST or PATCH sent with an Idempotency-Key header (1 to 255 visible ASCII characters) is done once, however often it is sent. This holds for 24 hours from when it was first sent, on whichever instance it reaches. The first request runs. Its answer is kept with the key and the request’s method, path, query and body.
| The same key with | Answer |
|---|---|
| The same request | As the first was, refusals too. It carries Idempotent-Replayed: true, and the first request’s id in Original-Request. Nothing runs again. |
| Another request | Refused (422). |
| The same request while the first still runs | Refused (409). A request that holds its key for more than 10 minutes is taken to have died with its instance. The same request sent again then runs. |
Keys are kept per scope. The install’s scope is the login and an install token. Each tenant token’s scope is apart. So one tenant’s token cannot read another’s answers by guessing its keys.
These answers are not kept, and the retry runs:
- An answer that says to try again (429, 503).
- An answer streamed as it is made (an export).
- An answer larger than 4 MiB.
- An answer that carries a secret shown once (a new API token, a delivery key). A copy kept for a day would be a second place to read the secret from. So it is sent
Cache-Control: no-storeand its key is let go.
The retry of such a request whose answer was lost runs again. For a new API token, the token’s name is taken (409). Revoke it and make another, with another name. For a delivery key, another delivery key is issued. Revoke the one never seen.
A tenant’s import, streamed to the engine, takes no key. PUT and DELETE ignore it, being idempotent already.
hourctl sends every change under a key of its own. It sends it again under that key when the answer says to try again (502, 503, 504) or the connection was lost on the way. It makes three tries at most.
Events posted into a tenant
Section titled “Events posted into a tenant”POST /api/tenants/{tenant}/events and POST /api/attendance/tenants/{tenant}/events take the admin login, an install token, or a token scoped to that tenant of that engine (connect:<tenant>, attend:<tenant>).
Give each system that posts a token of its own, scoped to the tenant it posts into. Revoke it to stop it.
A post is at most 100 events of at most 16 KiB of data each (posting events).
Deliveries into Time and Attendance
Section titled “Deliveries into Time and Attendance”POST /api/attendance/tenants/{tenant}/deliveries takes no login, only a signature by one of the tenant’s delivery keys.
Keys must not be guessed at speed. So deliveries whose signature does not check out are counted by the sender, whatever tenants they name. After 10, the sender’s next delivery is answered 429 (Retry-After), before a byte of its body is read. This lasts until a failure is forgiven every 10 seconds.
A tenant id that cannot be one is refused like a tenant that does not exist (401), without its body being read or the database asked.
At most 8 deliveries have their bodies read at once before their signature has been checked (128 MiB at most). A ninth is answered 503 with Retry-After, and the sink sends it again.
The sender is the client address as the device listeners read it. That is the peer’s address. When the peer is one of trusted_proxies, it is the address the peer forwarded in X-Forwarded-For. An IPv6 address counts as its /64.
Behind a load balancer, set trusted_proxies, or every sender behind it shares the balancer’s count. Each instance keeps its own count.
The admin API’s API tokens are held to the same count. A sender that has asked with 10 bearers that were not tokens is answered 429 for bearers this instance does not know, without asking the database.