getsops / getsops/sops

YAML starting three dashes not preserved during encryption

Open
#1,158 5 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
23.1k
Forks
1.1k
Avg merge
1d 11h
Merged PRs (30d)
9

Description

The https://yaml.org/spec/1.2.2/#22-structures says

YAML uses three dashes (“---”) to separate directives from document content. This also serves to signal the start of a document (...)

The sops 3.7.2 (and possibly earlier too) do not preserve the --- present in YAML file when running with --in-place option.

For example, here is my test.yaml

---
apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
  name: test-secret
data:
  crt: MTIzNDU2Nzg5MA==

which I encrypt with

sops --encrypt --in-place --azure-kv $(az keyvault key show --name sops-key-aks --vault-name kv-aks-dev --query key.kid --output tsv) .\test.yaml`

and here is the result:

>  head .\test.yaml
apiVersion: ENC[AES256_GCM,data:Ruc=,iv:mlHqE4A4ZSG9nOySG34gWAIN/GGqWmryS4F+/TV1VnE=,tag:HFp30nc6Eur03F7GPh/+ow==,type:str]
kind: ENC[AES256_GCM,data:xBQRIkJU,iv:EVzl7BT5nfVj7JD0eziDUQLwWwyXMyOQ6PJqntgE+O8=,tag:DnnBdBwmbOFRJdPFJy2EPw==,type:str]
type: ENC[AES256_GCM,data:LRD+jCyosIIwgFmtkgaAD2M=,iv:g35TjzFYJ4hxbW/nC2i8EbeASHkkQehd0UxXGlVkKBc=,tag:TjH30dUgCqqEOCkdR7Mnxw==,type:str]
metadata:
    name: ENC[AES256_GCM,data:fGAaeI+eKLgh4NY=,iv:RxRusjFjTnq+5Aqkoy5I3+0iqXuEeiArqGwB0gBJDqE=,tag:nF+ibSJvYYy6GJS4C59b1w==,type:str]
data:
    crt: ENC[AES256_GCM,data:P7WgLE0BIVZMBRYjsnIUZQ==,iv:TvdrJ9RLhG3UPZZlzMlOPeM6YsON+aOXfSCkmMKx1VQ=,tag:t9ovrrUsJQ+YYlHufIkkAQ==,type:str]
sops:
    kms: []

This is not a big deal but an annoyance for those using CI/CD linting their YAML-s with https://yamllint.readthedocs.io/en/latest/rules.html#module-yamllint.rules.document_start

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided test.yaml and the sops --encrypt --in-place command, then trace the YAML encryption and serialization path. Verify that the document-start marker (---) remains in the encrypted output while the existing data is still encrypted and valid for yamllint.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.