Time: 20 minutes. Track: security and compliance. Before this: developer lesson 1.
By the end of this lesson you will be able to:
- say what the landing scan looks for, and when it runs;
- read a finding as the forge records it: the rule, the place and a hash, never the secret;
- say who may clear a finding, how a report accounts for it, and what to do instead when the secret is real.
A secret, submitted
Every change is scanned when it is submitted, before it can land, for secrets and for regulated data such as payment card numbers. The scan runs inside the forge, so no change reaches main unscanned. Start a forge and submit a change that holds a card number:
$ af-server --dev
...$ source ~/af-dev/dev/env
$ af workspace add ~/w
Workspace at /home/you/w
Paths: **
main has no landing yet
$ cd ~/w
$ af new -m "Add the payment settings"
Working on change toooxovqqwnxylmzpyqruurvornvvyxn at commit 550b9bdbea3e3fb4a25b15ffbf02f8f2a8f78639b6f1c67813c961cc933161fe
$ printf 'gateway = "https://pay.example.com"\ntest_card = "4111111111111111"\n' > payments.toml
$ af submit
Submitted commit 1149c425f78800f80e9d5fd1094f495821383b78cce29d655022c81d398afb83, 1 edit in its last snapshotThe change waits for a clearance:
$ af status
Change toooxovqqwnxylmzpyqruurvornvvyxn (submitted) at commit 1149c425f78800f80e9d5fd1094f495821383b78cce29d655022c81d398afb83
Landing waits for: clearance
The landing scan found 1 thingWhat the forge recorded
af scan shows each finding: the rule that matched, the file and line, and the SHA-256 of what matched, never the match itself. The forge’s records are kept for good, so a secret written into them could never be taken back; a hash lets anyone with the secret confirm the finding without the record holding it. The rules are named by their version and hashed too, so an auditor can tell exactly what was checked:
$ af scan
commit 1149c425f78800f80e9d5fd1094f495821383b78cce29d655022c81d398afb83: 1 finding, by gitleaks v8.30.1 default rules; atoll-forge regulated data
rules sha256 eb894a9ed5a3e046adfeea5b6a2745e835fcddd9534b73f545c2a974c3f6103e
payments.toml:2 payment-card-number sha256 9bbef19476623ca56c17da75fd57734dbf82530686043a6e491c6d71befe8f6eWho may clear it
A finding can be cleared, with a reason, when it is not a real secret: a test value, or a key already rotated. Only a person who holds the approver role, and may read every path the change touches, may clear one:
$ af clear @ --reason "a test card"
Error: PermissionDenied: only a person who holds approver clears findings
[1]An approver may clear a finding on a change of their own line, as they may approve one, unless the forge requires another person (af-server --two-administrators): there a clearance is always a second person’s judgment. Either way it is recorded with its reason, as SOC 2 and ISO 27001 ask of a change that bypasses a control, and every compliance report lists a clearance from the change’s own line as an exception. This card number is real, so nobody should clear it.
When the secret is real
A submitted change is not edited again; take it back and start again without the secret. Abandoning it keeps its record, finding and all:
$ af abandon | tee ~/abandon.out
Abandoned change toooxovqqwnxylmzpyqruurvornvvyxn
$ export FIRST=$(sed -n 's/^Abandoned change \([k-z]*\).*/\1/p' ~/abandon.out)
$ af new -m "Add the payment settings"
Working on change mvtlzxrpkwrrzmtqntxxttvmmxxrypxu at commit 457355c733524ae460df15e11ba92aa0b5cde5a5bb3156b089893c6e05aecba7
$ printf 'gateway = "https://pay.example.com"\n' > payments.toml
$ af submit
Submitted commit f19d2f2712272b1e671343c8819777a14ec2cb8090cc1425726d35da42c947ad, 1 edit in its last snapshot$ af status
Change mvtlzxrpkwrrzmtqntxxttvmmxxrypxu (landed) at commit f19d2f2712272b1e671343c8819777a14ec2cb8090cc1425726d35da42c947adThe abandoned change’s finding is still in the record:
$ af scan $FIRST
commit 1149c425f78800f80e9d5fd1094f495821383b78cce29d655022c81d398afb83: 1 finding, by gitleaks v8.30.1 default rules; atoll-forge regulated data
rules sha256 eb894a9ed5a3e046adfeea5b6a2745e835fcddd9534b73f545c2a974c3f6103e
payments.toml:2 payment-card-number sha256 9bbef19476623ca56c17da75fd57734dbf82530686043a6e491c6d71befe8f6eA real secret that was ever submitted must still be rotated: it reached the forge’s storage with the change, and the record says so.
Exercises
-
Submit a change with a key in it that a cloud provider would issue, and see which rule names it.
$ af new -m "Add the deploy settings" Working on change qptywxsywlywsvznozyqmtkzomvnqyrz at commit 06bab1f7d92615f577b70eff57adeb5eac2809484dc94e6bbc01aa37d0b17b9b $ printf 'token = "ghp_aB3dE5fG7hJ9kL1mN3pQ5rS7tU9vW1xY3zA5"\n' > deploy.toml $ af submit Submitted commit a685e2618673de067132c1000f94bf040461451975dafb45c8c404d5714bfcc3, 1 edit in its last snapshot$ af scan commit a685e2618673de067132c1000f94bf040461451975dafb45c8c404d5714bfcc3: 1 finding, by gitleaks v8.30.1 default rules; atoll-forge regulated data rules sha256 eb894a9ed5a3e046adfeea5b6a2745e835fcddd9534b73f545c2a974c3f6103e deploy.toml:1 github-pat sha256 79250a072c8c922d4687861c950378cd2e6bf5d54913a8f91552fd2627657e69 -
The token was real: take that change back. Then a fixture holds Visa’s published test card number, which is no secret. Take the approver role, and clear the finding on your own change, with the reason. What does the change do then?
$ af abandon Abandoned change qptywxsywlywsvznozyqmtkzomvnqyrz $ af grant dev@localhost approver --reason "clearing test fixtures" done: it took effect at once, on your word as an administrator $ af new -m "Add a payment fixture" Working on change oosqwptylwtszuwkttpusrovkypvwyrz at commit b0b6b4c09de58ced545b6dc7dc784c0a5277957e44d7453a5e685999ddbbec54 $ printf 'id,card\n1,4111 1111 1111 1111\n' > orders.csv $ af submit Submitted commit babeef47f311420297818cb55b59ff9e9fe3930c30abcb8ba1070d2912850620, 1 edit in its last snapshot$ af scan commit babeef47f311420297818cb55b59ff9e9fe3930c30abcb8ba1070d2912850620: 1 finding, by gitleaks v8.30.1 default rules; atoll-forge regulated data rules sha256 eb894a9ed5a3e046adfeea5b6a2745e835fcddd9534b73f545c2a974c3f6103e orders.csv:2 payment-card-number sha256 6a7e0e79b018d08c9d1bb20be79999a7778399f7ee17258b3a0d36d4b4a7bec5$ af clear @ --reason "Visa's published test number, never a real card" commit babeef47f311420297818cb55b59ff9e9fe3930c30abcb8ba1070d2912850620: 1 finding, by gitleaks v8.30.1 default rules; atoll-forge regulated data rules sha256 eb894a9ed5a3e046adfeea5b6a2745e835fcddd9534b73f545c2a974c3f6103e orders.csv:2 payment-card-number sha256 6a7e0e79b018d08c9d1bb20be79999a7778399f7ee17258b3a0d36d4b4a7bec5 cleared 1 finding of commit babeef47f311420297818cb55b59ff9e9fe3930c30abcb8ba1070d2912850620 of change oosqwptylwtszuwkttpusrovkypvwyrz$ af status Change oosqwptylwtszuwkttpusrovkypvwyrz (landed) at commit babeef47f311420297818cb55b59ff9e9fe3930c30abcb8ba1070d2912850620 Based on landing 1 The landing scan found 1 thingIt lands: your clearance counted, recorded with its reason, and the period’s compliance report lists it as a clearance from the change’s own line.
-
An agent writes the token of exercise 1 again, but in base64, as a configuration file might hold it. Does the scan still find it, and is it the same secret?
$ af new -m "Add the deploy settings, encoded" Working on change wnvtzzmvrsysuskxqqnlnyluwpmmrmvu at commit 2f9d1b7c4ab0e9d35e2c7a61f08b3d4c95e7a2b1c0d6f8e3a4b5c6d7e8f9a0b1 $ printf 'token = "Z2hwX2FCM2RFNWZHN2hKOWtMMW1OM3BRNXJTN3RVOXZXMXhZM3pBNQ=="\n' > deploy.toml $ af submit Submitted commit 7c3e5a9b1d2f4e6a8c0b2d4f6a8c0e2b4d6f8a0c2e4b6d8f0a2c4e6b8d0f2a4c, 1 edit in its last snapshot$ af scan commit 7c3e5a9b1d2f4e6a8c0b2d4f6a8c0e2b4d6f8a0c2e4b6d8f0a2c4e6b8d0f2a4c: 2 findings, by gitleaks v8.30.1 default rules; atoll-forge regulated data rules sha256 eb894a9ed5a3e046adfeea5b6a2745e835fcddd9534b73f545c2a974c3f6103e deploy.toml:1 generic-api-key sha256 202d600f781b2a9a8e0f720160c60a0de08abba14a188456af785de3ed6d8b52 deploy.toml:1 github-pat sha256 79250a072c8c922d4687861c950378cd2e6bf5d54913a8f91552fd2627657e69 decoded from base64 (depth 1)Two findings. The encoded text, as written, looks like a key to Gitleaks’ generic rule. The scan also decodes base64, hex, percent-encoding and unicode escapes and reads the text again, as Gitleaks does, up to five encodings deep: decoded, it is a GitHub token. That finding says it was decoded from base64, one encoding deep, is on the line that holds the encoded text, and has exercise 1’s hash, since the hash is always of the secret itself, however it was written.
Check your understanding
Why does the record hold a hash of the secret and not the secret?
The forge’s records are kept for good. A secret written into them could never be removed; its hash proves what was found to anyone who has the secret, and tells nothing to anyone who has not.
You hold the approver role. Can you clear a finding on your own change?
Yes, unless the forge requires another person (af-server --two-administrators); there no clearance counts from the change’s own line, as no approval does, and a clearance is a second person’s judgment. Where yours counts, every compliance report lists it as an exception.
An agent hex-encodes a key, then base64-encodes that, before writing it. Does it get past the scan?
No. The scan decodes each encoding it finds and reads the text again, up to five encodings deep, as Gitleaks does, so the key is found on the line that holds it, with the same hash as the key written plainly.
A card number reached a submitted change, and the change was abandoned. Is that the end of it?
No: it reached the forge’s storage with the change, so the card must be treated as exposed. The abandoned change’s finding stays in the record; purging can erase the contents themselves when they must go.
Next
Security lesson 5: Keys an auditor can account for accounts for the organization’s keys. Permissions and approvals explains clearances and approvals in depth.