# Google Cloud and Azure

On Google Cloud and Azure, give VMs you keep their own canary at first boot, and give everything that scales (Cloud Run, managed instance groups, Container Apps, App Service, scale sets) one canary per role, stored in Secret Manager or Key Vault next to the role's real secrets. For GKE and AKS, see [Kubernetes](/docs/kubernetes).

## Google Cloud

### Secret Manager and Cloud Run

Store the canary as a secret, straight from the pipe:

```sh
curl -fsSL https://get.snitchwallet.com | sh -s -- --decoy json:- --name gcp-api \
  | gcloud secrets create payout-wallet --data-file=-
```

Expose it to a Cloud Run service as an environment variable. Use `--update-secrets`, which adds to the service's existing secrets; `--set-secrets` replaces them all:

```sh
gcloud run services update api --update-secrets=PAYOUT_WALLET_KEYSTORE=payout-wallet:latest
```

The service's account needs the Secret Manager Secret Accessor role on the secret. Grant it before you update the service: an instance that can't read one of its secrets doesn't start.

### Compute Engine

Ubuntu and Debian images run cloud-init, so the [cloud-init install](/docs/servers#cloud-init-and-terraform) works as the `user-data` metadata value. A startup script also works, but startup scripts run on every boot, so guard it with the decoy path:

```sh
#!/bin/sh
[ -e /etc/payments/.env ] && exit 0
curl -fsSL https://get.snitchwallet.com | SNITCH_AUTHKEY="$(gcloud secrets versions access latest --secret=enroll-key)" \
  sh -s -- --decoy env:/etc/payments/.env
```

For managed instance groups, give the group one canary in Secret Manager and have the startup script write it where a service would keep a wallet:

```sh
#!/bin/sh
install -d -m 700 /etc/payout-service
gcloud secrets versions access latest --secret=payout-wallet > /etc/payout-service/hot-wallet.json
chmod 600 /etc/payout-service/hot-wallet.json
```

## Azure

### Key Vault

Store the canary in Key Vault. `--value @-` reads it from the pipe, and `-o none` matters: by default `az keyvault secret set` prints the secret's value back:

```sh
curl -fsSL https://get.snitchwallet.com | sh -s -- --decoy json:- --name azure-api \
  | az keyvault secret set --vault-name YOUR-VAULT --name payout-wallet --value @- -o none
```

Key Vault secret names allow only letters, digits and hyphens.

### App Service and Functions

Add an app setting that references the secret. The app's managed identity needs the Key Vault Secrets User role:

```sh
az webapp config appsettings set -g YOUR-GROUP -n YOUR-APP \
  --settings "PAYOUT_WALLET_KEYSTORE=@Microsoft.KeyVault(VaultName=YOUR-VAULT;SecretName=payout-wallet)"
```

If the reference can't be resolved, the app sees the `@Microsoft.KeyVault(...)` text itself, so check the setting's status in the portal.

### Container Apps

Reference the Key Vault secret from the app, then expose it as an environment variable. The app's managed identity needs the Key Vault Secrets User role:

```sh
az containerapp secret set -g YOUR-GROUP -n YOUR-APP \
  --secrets "payout-wallet=keyvaultref:https://YOUR-VAULT.vault.azure.net/secrets/payout-wallet,identityref:system"
az containerapp update -g YOUR-GROUP -n YOUR-APP --set-env-vars "PAYOUT_WALLET_KEYSTORE=secretref:payout-wallet"
```

### Virtual machines

Pass the [cloud-init install](/docs/servers#cloud-init-and-terraform), with your auth key in place of `${authkey}`, as custom data when you create the VM:

```sh
az vm create -g YOUR-GROUP -n web-1 --image YOUR-IMAGE --custom-data cloud-init.yaml
```

For scale sets, give the set one canary in Key Vault, and have its cloud-init read it with the scale set's managed identity.
