# SOPS files

**SOPS files** is for teams that keep application secrets in a [SOPS](https://github.com/getsops/sops) file encrypted with KMS, stored in S3, and deployed into AWS Secrets Manager or SSM Parameter Store. It lets you open the file, change a value, save it and deploy it, without decrypting to a file on your Mac and without running SOPS and Terraform by hand.

The decrypted document exists only in ARNscope's memory and in the pipes of the `sops` process it starts. It is never written to disk, logged or put in an error message.

To browse and edit the secrets already in Secrets Manager, use the [Secrets](https://arnscope.com/docs/secrets) page instead. SOPS files is for the encrypted file those secrets are deployed from.

## Turn it on

SOPS files is a [Labs](https://arnscope.com/docs/labs) page: it needs the `sops` binary and a registry of files before it does anything, so it is off by default and stays out of the sidebar, quick open and background loading until you turn it on.

1. Open **Settings → Labs**.
2. Check **SOPS files**. If you had hidden the page from the sidebar before, turning it on puts it back.

A link, favourite or saved tab that opens SOPS files while it is off shows "SOPS files is in Labs" with a button to **Open Settings → Labs**.

If you used this editor when it was the **Secrets** page and had files in its registry, ARNscope turned SOPS files on for you once, when you updated. Your registry, tool paths and files are unchanged.

## What a file looks like

ARNscope reads a SOPS JSON file with one top-level **wrapper key** (for example `shared_secrets`, `stage_secrets` or `secrets`) that holds your secrets by name. Each secret is an object of keys:

```json
{
  "stage_secrets": {
    "/app/db/main": {
      "__description__": "Main database login",
      "__tags__": { "team": "payments" },
      "username": "app",
      "password": "…"
    }
  }
}
```

The secret name becomes the Secrets Manager name (1 to 512 characters from `A-Z a-z 0-9 / _ + = . @ -`). Its keys become one JSON `SecretString`, encoded the way Terraform's `jsonencode` encodes it, so a direct deploy and a Terraform deploy produce the same value. Keys starting with `_` or `//` are metadata: `__description__` sets the description, `__tags__` sets tags, and `__env__` sets an `env` tag. ARNscope also tags each secret with its `Name`. A secret must be an object, not a bare value.

A document can be up to 1 MiB.

## What you need

- **`sops`** on your Mac, and **`terraform`** if you deploy through Terraform. ARNscope looks in your `PATH`, `/opt/homebrew/bin` and `/usr/local/bin`, or you can set exact paths with **Tools** (the wrench) in the file list. It runs them without a shell, with only `PATH`, `HOME` and AWS profile variables.
- An AWS profile that can read and write the S3 object and use the KMS key or keys the file is encrypted with.

## Add a file

The plus button in the file list offers two ways in.

**Import existing file…** takes a SOPS file from a local path or an S3 object. ARNscope reads only its SOPS metadata and key names; it does not decrypt it. It shows the KMS keys the file uses and warns when the bucket's versioning is off.

**New encrypted file…** creates one. You give a label, choose where in S3 it should live, and pick the KMS keys (search the aliases of a profile and region; any one key can decrypt, and keys from several accounts let a file be shared across stages). ARNscope then asks for a profile for each KMS key's account, because SOPS needs working credentials for every key when it saves.

Both ask for:

| Field | Meaning |
| --- | --- |
| **Label** | The name shown in ARNscope |
| **Wrapper key** | The top-level object that holds the secret names |
| **Deploy** | **Direct** (ARNscope writes to Secrets Manager or Parameter Store itself) or **Terraform** (a stack you already have deploys them) |
| **Repository file** | The encrypted copy in your git checkout. Optional for direct deploys, required for Terraform. |

The repository file is chosen in a native **Open** or **Save** dialog, never typed in, so a page can never point ARNscope at a path of its own choosing. Saving a secret also writes the encrypted file there, atomically. You commit it yourself. ARNscope flags **repo differs** or **repo missing** when the repository copy and S3 disagree.

Everything ARNscope knows about your files (labels, S3 locations, deploy settings) is kept in a registry on this Mac. **Forget file…** removes a file from that registry only. The S3 object, the repository copy and the deployed secrets stay as they are, and you can import it again.

## Edit and save

**Decrypt and open** fetches the object from S3 and pipes it through `sops`. The file is marked **decrypted** while it is open.

- **Structured** edits one secret at a time: the list on the left (with a filter, and arrows to reorder), and for the selected secret its name, description, tags and keys. Values are masked until you reveal them.
- **Raw JSON** edits the whole decrypted document as text. It is disabled while the JSON is invalid.

Problems (such as an invalid secret name) show in the list. **Save** (⌘S) encrypts the document with the file's own keys, **verifies** that the result decrypts back to what you typed, uploads it with a precondition on the version you opened, and reads the object back to prove S3 holds exactly those bytes. A success says "Saved and verified" with the new S3 version. **Revert** undoes unsaved edits, and **Lock** discards the plaintext from memory.

**If the file changed in S3 since you opened it**, nothing is written, and a dialog lists the secrets and keys that differ with **Mine** and **Theirs** side by side (values masked, with a reveal button). Choose per row, then **Use merged result** to continue editing, **Discard mine, load theirs**, or **Back to my edits**.

Leaving a file with unsaved changes asks first.

## Deploy directly

A **Direct** file has a target profile and region and, under **Write to**, either **Secrets Manager** (the default) or **Parameter Store**.

### To Secrets Manager

With a Secrets Manager target, the **Deploy** panel shows the target profile and region and the S3 version. **Plan / check drift** compares what the file says with what Secrets Manager holds, and changes nothing. It shows, per secret, whether it would be **created**, **updated** or is **unchanged**, and per key whether it was added, removed or changed. Reveal buttons show the value in the file against the deployed value. The file's chip becomes **in sync** or **drift**.

A plan always uses the **saved** S3 version, and says so when you have unsaved edits.

Secrets that exist in AWS but not in the file are listed as **Only in AWS · never deleted automatically**. **A deploy creates and updates; it never deletes a secret.**

The deploy itself is a write:

1. Turn **Writes** on for the target profile and region ([Writes and confirmations](https://arnscope.com/docs/writes)). With it off, **Apply** is disabled and says which profile and region to turn on.
2. Click **Apply**. ARNscope re-checks that the S3 file, the plan and every secret are still as they were when you planned, then opens one native dialog: "Deploy … (S3 version …) to Secrets Manager in account …: create N, update M. Nothing is deleted." It says PRODUCTION where it applies and how many secrets look Terraform-managed.
3. If anything changed since the plan, it stops with **Stale plan — nothing was written** and a **Re-plan** link.

Each secret then shows its result. Writes are idempotent, so if some failed, plan and apply again to finish.

A secret that a Terraform stack also manages will be put back by the next `terraform apply`, unless the stack ignores `secret_string`. The plan marks those secrets and shows the `lifecycle { ignore_changes = [secret_string] }` snippet. You can list names of secrets a stack also manages in the file's settings (**Also managed by Terraform**).

**Applications read secrets when they start.** After a deploy, ECS services need a new deployment and Lambda functions need their execution environments recycled; running tasks keep the old values. ARNscope reminds you after every deploy.

### To Parameter Store

A Parameter Store target has a **Prefix** (such as `/staging/checkout`) and a **KMS key** for the SecureStrings; the default is the account's `alias/aws/ssm`. Each leaf key in the file becomes one SecureString under the prefix: `stripe.secret_key` becomes `/staging/checkout/stripe/secret_key`.

**Plan** compares the saved S3 version with Parameter Store and shows, per parameter, whether it would be created, updated or is unchanged, never a value. It records each parameter's version. Parameters under the prefix that the file does not have are listed as **Only in Parameter Store · never deleted automatically**.

**Apply** needs Writes on for the target profile and region and opens one native confirmation. If any parameter's version moved since the plan, the apply stops before the confirmation and writes nothing; one that moves after you confirm is skipped and reported as stale. Plan again and apply to finish. Services that read these parameters get the new values on their next fetch; ECS tasks read them at start-up. See [Parameter Store](https://arnscope.com/docs/parameter-store) for browsing the result.

## Deploy through Terraform

A **Terraform** file has one or more **stack targets**, each with a working directory, `init` and `plan` arguments, and an AWS profile. The stack reads the repository file with its `sops_file` data source. ARNscope checks that the file is inside the working directory and that the backend matches before it plans.

The panel runs the steps in order, streaming Terraform's output (with secret values masked):

1. **Write S3 version to repo** or **Upload repo copy to S3**, when the two differ, each after a confirmation.
2. **Init**, then **Plan**. A plan is saved with its resource counts and the names and actions of what changes; plan JSON is read in memory and its values are not kept.
3. **Apply plan** applies exactly that saved plan, never a new one. It needs Writes on for the target's AWS profile (in the profile's default region) and opens a native dialog: "Apply the saved Terraform plan for …: N to add, N to change, N to replace, N to destroy", with "This plan destroys resources" when it does.

ARNscope refuses to apply when the repository file or the S3 object changed after the plan, and Terraform itself rejects a plan whose state moved. In both cases the plan is discarded and you plan again. **Discard plan** throws away a saved plan; **Cancel** stops a running step.

Arguments are split on spaces and passed without a shell. Allowed: `init` with `-reconfigure`, `-upgrade` and `-backend-config=`; `plan` with `-var-file=`, `-var=`, `-target=`, `-replace=`, `-refresh=` and `-lock-timeout=`.

## Status chips

| Chip | Meaning |
| --- | --- |
| **local changes** | You have unsaved edits |
| **repo differs**, **repo missing** | The repository copy does not match S3, or is not there |
| **in sync**, **drift** | The last plan found nothing to change, or changes (with the count) |
| **deployed** | Last deployed from ARNscope, with the time and target on hover |
| **not deployed** | The S3 file changed since the last deploy from ARNscope |
| **unavailable** | The file could not be read; hover for the error |

## Permissions

| What | Actions |
| --- | --- |
| Find and read the file | `s3:GetBucketLocation`, `s3:ListBucket`, `s3:GetBucketVersioning`, `s3:GetObject`, and `kms:Decrypt` on the file's keys |
| Save, create, import, repository upload | `s3:PutObject`, `kms:GenerateDataKey`, `kms:Encrypt` (and `s3:GetObject` to read the result back) |
| Choose KMS keys | `kms:ListAliases` |
| Plan a direct deploy to Secrets Manager | `secretsmanager:ListSecrets`, `secretsmanager:DescribeSecret`, `secretsmanager:GetSecretValue` |
| Apply it | `secretsmanager:CreateSecret`, `secretsmanager:PutSecretValue`, `secretsmanager:UpdateSecret`, `secretsmanager:TagResource`, `secretsmanager:DescribeSecret` |
| Reveal a deployed value in the plan | `secretsmanager:DescribeSecret`, `secretsmanager:GetSecretValue` |
| Plan a direct deploy to Parameter Store | `ssm:DescribeParameters`, `ssm:GetParameters`, `kms:Decrypt` |
| Apply it | `ssm:DescribeParameters`, `ssm:PutParameter`, `kms:Encrypt`, `kms:GenerateDataKey` |
| Terraform | Whatever your stack and backend need; ARNscope runs `terraform` with the target's profile |

Saving to S3 is not behind the Writes switch, since it changes only the encrypted file you chose, with a version check and a verified read-back. Applying a deploy is, as is a Terraform apply. See [Writes and confirmations](https://arnscope.com/docs/writes). Every deploy, cancelled or not, is recorded in the [activity log](https://arnscope.com/docs/activity-log) without any secret value.

## Limitations

- **SOPS JSON files with KMS keys.** No YAML, dotenv or other key types such as age or PGP.
- **Creates and updates only.** A deploy never deletes a secret or parameter, and does not change a secret's KMS key, rotation, resource policy or replication. To rotate a secret or restore its previous version, use the [Secrets](https://arnscope.com/docs/secrets) page.
- **A Labs page.** It may change or go away; see [Labs](https://arnscope.com/docs/labs).
- **One operation per file at a time.** A second operation on the same file says "Another operation on this file is still running."
- **1 MiB per document.**
- **`sops` and `terraform` must be installed.** ARNscope does not bundle them.
- **Consumers need a restart** to read new values.

Using a layout that does not fit? Write to [hello@arnscope.com](mailto:hello@arnscope.com) and describe how your files are structured.

Source: https://arnscope.com/docs/sops-files
