Mask values
Nikasa hides known credentials on its own, by fixed rules. Anything else you do not want in a report, you can mask from any report, at any time.
On this page
Nikasa hides the credentials it recognises on its own. This page shows what it hides, what it misses, and how to mask anything else from any report.
What Nikasa masks on its own #
Two kinds of value, each by a fixed rule. Nikasa never judges how random a value looks, so the same value is masked the same way in every run.
Known credentials, as markers #
A marker such as <secret 3f9a1c2e> holds a hash keyed with Nikasa's secret key. The same value always gives the same marker, so a changed password still shows, but the value cannot be read back. In a log line or a file path it reads <secret>.
A value becomes a marker in three ways, shown next.
By name #
The value of a field, form field, query parameter, header or compose setting is masked when its name says secret by its whole words:
- password, passwd, pwd, passphrase;
- credential, secret;
- a last word ending in token;
- api key, private key, session id.
Also masked:
- the
Authorizationand cookie headers; - a one-time code such as
otporverification_code, whose number is hidden too; - in free text, the word after such a name and a
:or=.
A name is split into words at punctuation, spaces and where lower case turns upper:
| Name | Masked? | Why |
|---|---|---|
refreshToken |
Yes | Splits into refresh and token. |
passwordless, secretary |
No | They are not the whole word. |
token_file, tokenCount |
No | Their last word is not a secret's. |
Under a secret name, strings are replaced, and numbers and true or false are kept. So a lifetime in seconds still shows, except for a one-time code.
By shape, wherever it stands #
- password hashes (bcrypt, argon2, scrypt, sha-crypt, Django's);
- PEM private keys;
- key prefixes (AWS, GitHub, Slack, Stripe, Google, OpenAI, Anthropic);
- JWTs.
A secret found once is hidden everywhere #
Take a value of 8 characters or more that either:
- the run saw under a secret's name, or
- the compose file sets for a setting such as
*_TOKEN,*_SECRET,*_PASSWORDor*_KEY.
It becomes its marker wherever else it stands as a whole word in that run's values and text.
Formats, so that runs line up #
Where a value becomes part of what is compared by presence (log lines, file paths, metric labels, span names and routes between services), it is replaced by its format:
| Reads as | For |
|---|---|
<uuid> |
A UUID |
<n> |
Each run of digits |
<ip> |
An IPv4 address |
0x<hex> |
A hex literal |
<hex> |
8 or more hex digits holding both a digit and a letter |
<duration> |
A Go duration |
<date> |
A JavaScript date |
<lsn> |
A Postgres log position |
A few more rules keep lines comparable:
- A request is known by its path and query, with UUIDs, numbers and hex ids as
<id>. - Colours are removed from log lines.
- A JSON line is read as its level and message.
- A line is cut at 500 characters.
What it does not catch #
Nothing else is masked unless you declare it. A word that only looks random, such as a session token in a log line, a content hash in a file name or a base64 id, shows as it came.
So a first report on a new app can show a credential Nikasa has no name for, such as session data kept in a table.
The report's coverage block says how much was masked:
masked by nk: known credential names and shapes, 14 values; nothing elseMask something yourself #
From any report, you can mask something Nikasa showed. Every later run, compare and diff masks it wherever Nikasa writes what it saw.
nk mask out --change nk-6f7cf426 # the place of a change report.md shows
nk mask out --change nk-6f7cf426 --field --plain # that field's name anywhere, as <masked>
nk mask --pattern 'app\.[0-9a-f]{8}\.js' --label chunk --plain --note "build hash"
printf %s "$TENANT_ID" | nk mask --value --label tenant # a value, from standard inputFour forms #
| Form | What it masks |
|---|---|
| A place | The place of a change, named by the key that report., the JSON report and every ticket show. |
| A field | With --field: the place's last name, matched anywhere in any case. |
| A pattern | A regex that runs in time linear in the text, so no pattern can make a run hang. One that does not compile, or that matches an empty text, is refused. |
| A value | Read from standard input and never from an argument, so it is in no shell history or process list. |
What replaces it #
- A marker such as
<masked 3f9a1c2e>, a keyed hash, so a change from one value to another still shows. --label tenantwrites<tenant 3f9a1c2e>.--plainwrites<masked>, so every value it covers reads the same. Use it for a per-build hash.- In log lines and file paths a marker is always plain.
Where it applies #
It applies in what Nikasa reads from each run, before anything else is made from it. Reports, ticket text, saved baselines and stored runs are made from those, so they never hold the value in clear. Saved runs and saved baselines are masked as they are read.
What it does not reach #
- the capture, the decrypted records, recorded outside calls, and packs from
nk record; - a saved baseline's outside calls, which stay encrypted;
- runs and reports made before the rule, CI logs, pull request comments and tickets already written. They keep the value.
The masks file #
Rules go in nk/masks.yaml. They are added after what the file holds, never rewritten or deleted. Each one notes the date, the Nikasa version and your --note.
| Flag | What it does |
|---|---|
--file |
Writes another file. |
--masks |
Makes runs read that file. |
Delete a rule to see its values again from the next run on.
A value is kept only as a digest #
The file holds the value's HMAC-SHA256 under a key derived from Nikasa's secret key, with a purpose of its own, and that key's id.
A value is matched as a whole token. So acme-corp is masked in /t/acme-corp/x and acme-corp.json, not in acme-corporation.
The same secret key everywhere #
The digest needs the same secret key wherever Nikasa runs. On a machine with none, nk mask --value and every compare reading a digest stop, and the message says what to do:
- set
NK_SECRET_KEY_FILEto that key's file, or - run
nk compareonce to make one.
A digest made under another key is refused. In CI, use the key NK_CI_SECRET_KEY gives.
Next steps #
- Your first compare: read a report and spot what to mask.
- Reading the report: where each change's key comes from.
- The secret key: what the key is and where to keep it.
- Security and your data: what leaves your machine and what stays in the output folder.
Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.