# Logs

Secrets leak into logs, and intruders know it: one of the first things they do with stolen cloud credentials is search the logs. Plant one canary as a log line that looks like a configuration dump, and you'll know if anyone harvests secrets from your logs, whether it's an intruder, a compromised log vendor or someone inside.

## CloudWatch Logs

Pick a log group your application writes to, make a stream that looks like the others, and write one event. This uses the AWS CLI v2 and `jq`:

```sh
GROUP=/ecs/live/api
STREAM="ecs/api/$(openssl rand -hex 16)"
aws logs create-log-stream --log-group-name "$GROUP" --log-stream-name "$STREAM"
curl -fsSL https://get.snitchwallet.com | sh -s -- --decoy env:- --name live-cloudwatch-logs \
  | jq -Rsc '[{timestamp: (now * 1000 | floor), message: ("WARN Loaded signer settings from environment: " + (split("\n") | map(select(length > 0)) | join(" ")))}]' \
  | aws logs put-log-events --log-group-name "$GROUP" --log-stream-name "$STREAM" --log-events file:///dev/stdin
```

Things to know:

- **Retention.** The event disappears when the log group's retention period passes. The coins stay where they are, but the canary can no longer be found. Use a group with long retention, or plant a fresh canary when it expires and retire the old one to take its bait back.
- **Copies count too.** Subscriptions and exports copy the event to S3, a central logging account or your SIEM, so the canary covers those as well, under the same name.
- **Metric filters.** Check the message doesn't match one of your metric filters, or it'll set off an alarm of yours.
- **Reading isn't enough.** Like every canary, it fires when someone moves the bitcoin, not when they read the log.

## syslog, journald and log agents

On a server whose logs are shipped somewhere (Datadog, Splunk, Elastic, Loki or anything else that collects syslog or the journal), write the line on the server and let the agent ship it:

```sh
curl -fsSL https://get.snitchwallet.com | sh -s -- --decoy env:- --name prod-logs \
  | tr '\n' ' ' | logger -t payout-service
```

The pipe means `logger` gets the line, not your screen. It lands in the local log too, so this also catches an intruder on that server who reads `/var/log`.

## Datadog

To send it straight to Datadog's log intake instead:

```sh
curl -fsSL https://get.snitchwallet.com | sh -s -- --decoy env:- --name prod-datadog-logs \
  | jq -Rsc '[{service: "payout-service", ddsource: "python", status: "warn", message: ("Loaded signer settings from environment: " + (split("\n") | map(select(length > 0)) | join(" ")))}]' \
  | curl -fsS -X POST "https://http-intake.logs.datadoghq.com/api/v2/logs" \
      -H "DD-API-KEY: $DD_API_KEY" -H "Content-Type: application/json" --data-binary @-
```

Use your Datadog site's intake host if you're not on `datadoghq.com`, for example `http-intake.logs.datadoghq.eu`.
