# Servers and VMs

Give every server you keep its own canary, planted at first boot. The decoy is a file on that server, and the alert names it. This works on any Linux server or VM, on any cloud or on bare metal.

## By hand

```sh
curl -fsSL https://get.snitchwallet.com | sh
```

It prints a link. Approve the server in your browser, then fund the address it prints. Run as root, it plants the decoy under `/etc`; run as another user, under that user's config directory.

To choose where the decoy goes, for example next to a real service's settings:

```sh
curl -fsSL https://get.snitchwallet.com | sh -s -- --decoy env:/etc/payments/.env
```

If the file already exists, the decoy is appended and the file keeps its modification time. `--decoy json:/opt/payments/hot-wallet.json` writes a wallet file instead, and only to a new file.

## cloud-init and Terraform

Create an auth key in the dashboard (**Keys**, then **Auth keys for unattended installs**). Give it as many uses as servers you'll launch, and a short expiry. Then put the install in the server's user-data. This works on every image that runs cloud-init: AWS, Google Cloud, Azure, DigitalOcean, Hetzner, Linode, OVHcloud, Vultr and others.

```yaml
#cloud-config
write_files:
  - path: /run/enroll-key
    permissions: "0600"
    content: "${authkey}"
runcmd:
  - curl -fsSL https://get.snitchwallet.com | sh -s -- --authkey-file /run/enroll-key; rm -f /run/enroll-key
```

With Terraform, fill in the key with `templatefile`:

```hcl
variable "enroll_key" {
  type      = string
  sensitive = true
}

resource "aws_instance" "web" {
  # ...
  user_data = templatefile("${path.module}/cloud-init.yaml", { authkey = var.enroll_key })
}
```

Pass the key as `TF_VAR_enroll_key` rather than in a `.tfvars` file, so it stays out of git. It still ends up in Terraform state, which is fine for a key that can only add canaries.

> Anything on the server can read its user-data, on AWS through the instance metadata service. An intruder who reads it learns that a canary was planted, but not where. To keep even that hidden, fetch the auth key from your secret store at boot instead, or install through config management.

### Servers you replace

A per-machine canary's key exists only on its server. Destroy the server and its bait (about $10–25) goes with it, unless you retire the canary and move the coins first. Servers that Terraform replaces on every change are better served by [one canary per role](/docs/#pick-a-pattern), stored in your secret manager. See [AWS](/docs/aws) for Auto Scaling groups.

### Never in an image

Run the install at first boot, never in Packer or another image build. A canary baked into an image is shared by every server built from it, so the alert can't tell you which one leaked.

## Ansible, Chef, Puppet and Salt

Pick a decoy path that doesn't exist yet, and use it as the guard, so the canary is planted once per server:

```yaml
- name: Plant a SnitchWallet canary
  ansible.builtin.shell: >
    curl -fsSL https://get.snitchwallet.com | sh -s --
    --decoy env:/etc/payments/.env --name {{ inventory_hostname }}
  args:
    creates: /etc/payments/.env
  environment:
    SNITCH_AUTHKEY: "{{ snitch_authkey }}"
  no_log: true
```

Keep `snitch_authkey` in Ansible Vault. In Chef, Puppet or Salt, run the same command in an `execute`, `exec` or `cmd.run` resource, with `creates` set to the decoy path and the key in the `SNITCH_AUTHKEY` environment variable.

## Existing fleets

To add canaries to servers that are already running, run the one-liner on each with the tool you already use to run commands across them: SSH in a loop, Ansible, or AWS Systems Manager Run Command. Pass the auth key in `SNITCH_AUTHKEY`:

```sh
curl -fsSL https://get.snitchwallet.com | SNITCH_AUTHKEY="$KEY" sh
```
