Skip to content

A secret with no format before .sops deploys as a JSON wrapper: token.sops lands as {"data": "..."}, not the token #977

Closed

Description

@David-Noble-at-work

A secret whose name carries no format before .sops, such as token.sops, deploys as a JSON wrapper instead of its plaintext.

Reproduced 2026-09-29 at 0cf30415 plus #974's branch, by a throwaway test deleted afterwards. It encrypted hunter2\n with writ's own encrypter (pkg/sops NewEncrypter().Encrypt, path token), wrote it as myproj/token.sops, and deployed it with deploy.Execute:

ciphertext begins: "{"
deployed token = "{\n\t\"data\": \"hunter2\\n\"\n}\n"

The cause:

  • Encrypting. pkg/sops/encrypter.go:68 infers binary for a name with no format, and sops's BinaryStore writes its encrypted document as JSON, so the file begins with {.
  • Decrypting. pkg/sops/decrypt.go detectFormat finds no inner extension, so its content fallback (:109-113, "starts with {" gives json) picks the JSON store. The JSON store's EmitPlainFile marshals the tree, {"data": …}. Only the binary store unwraps data.
  • Coverage. pkg/sops/decrypt_test.go's "json content detection" row pins this behavior, and cmd/writ/writ/deploy/sops_integration_test.go exercises only .yaml.sops and .yaml.tmpl.sops.

Found by the review of #974, whose writ guide first showed token.sops as its example. That guide now shows format-bearing names, and names this issue.

Resolution

Decryption uses the format the encryption used. A name with no inner extension decrypts as binary (its plaintext unwrapped), not by sniffing the ciphertext's first byte, which is always { for sops's JSON-wrapped binary documents. A deploy test covers the no-format case.

Plan and design documents

Kind Document
Plan docs/plans/fix/977-secret-with-no-format-before.md
Design docs/architecture/3.5.13-encryption-provider.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions