Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secrets format needs changes #401

Open
elikoga opened this issue Nov 14, 2023 · 1 comment
Open

secrets format needs changes #401

elikoga opened this issue Nov 14, 2023 · 1 comment

Comments

@elikoga
Copy link
Contributor

elikoga commented Nov 14, 2023

Related issues are

@elikoga
Copy link
Contributor Author

elikoga commented Nov 21, 2023

Probleme/Use-Cases:

  • git diff - keine spezielle Konfiguration
  • git diff - mit Konfiguration (textconv, external diff)
  • Übersicht über die aktuelle Environment Konfiguration + Secrets
  • Bearbeiten von Konfiguration + Secrets
  • environment independent secrets (und konfiguration)

Status quo:

Batou <= 2.3

  • Projekt-weite Konfiguration in ./components (python source)

  • Environment-spezifische Konfiguration in ./environments/<env>/environment.cfg (using python configparser ini format)

  • Environment-spezifische Secret-Konfiguration in ./environments/<env>/secrets.cfg (using python configparser ini format, gpg encrypted)

  • Environment-spezifische Secret-Blobs/Dateien in ./environments/<env>/secrets-* (gpg encrypted)

  • git diff - no textconv:

    • alle verschlüsselten Dateien sind binary
    • werden nur als ganze Datei verändert
  • git diff - textconv:

    • schwer/nerviger da .cfg Dateien nicht un-ambiguous gpg sind
    • möglich, aber zu hacky
      • sowas wie (file $1 | grep -q "ASCII") && cat $1 || gpg --decrypt $1 als textconv
  • Übersicht über die aktuelle Environment Konfiguration + Secrets:

    • ./batou secrets summary Zeigt an, welche environments secrets haben, und wen sie als recipient haben
  • Bearbeiten von Konfiguration + Secrets:

    • ./batou secrets edit <env> [file] öffnet $EDITOR mit entschlüsselten secrets
    • normale Konfiguration lebt in environment.cfg
  • environment independent secrets:

    • not possible

Batou >= 2.4

  • Projekt-weite Konfiguration in ./components (python source)

  • Environment-spezifische Konfiguration in ./environments/<env>/environment.cfg (using python configparser ini format)

  • Environment-spezifische Secret-Konfiguration in ./environments/<env>/secrets.cfg.{gpg,age} (using python configparser ini format, gpg/age encrypted)

  • Environment-spezifische Secret-Blobs/Dateien in ./environments/<env>/secrets-*.{gpg,age} (gpg/age encrypted)

  • git diff - no textconv:

    • alle verschlüsselten Dateien sind binary
    • werden nur als ganze Datei verändert
  • git diff - textconv:

    • ist möglich, aber noch undokumentiert, da bspw. age unhandlich ist (will passwort für jede Datei)
      • in `git config``:
        [diff "gpg"]
            textconv = gpg --no-tty --decrypt
        [diff "age"]
            textconv = age --decrypt -i <YOUR_PRIVATE_KEY_FILE>
        
      • in .gitattributes:
        *.gpg diff=gpg
        *.age diff=age
        
    • git diff zeigt dann die entschlüsselten Inhalte an
  • Übersicht über die aktuelle Environment Konfiguration + Secrets:

    • ./batou secrets summary Zeigt an, welche environments secrets haben, und wen sie als recipient haben
  • Bearbeiten von Konfiguration + Secrets:

    • ./batou secrets edit <env> [file] öffnet $EDITOR mit entschlüsselten secrets
    • normale Konfiguration lebt in environment.cfg
  • environment independent secrets:

    • not possible

Changes/Vorschläge

git diff - keine spezielle Konfiguration:

  • Variante 1: Wir encrypten secrets direkt in der environment.cfg per-field
    • in environment.cfg:
      [environment]
      
      [host:foohost]
      components = barcomponent
      
      [component:barcomponent]
      secret_value = -----BEGIN AGE ENCRYPTED FILE-----
      YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IHlFVGhhQSB0WndK
      ZHpFTmJlMUlMaXg5ZXJyL2ZCZXN5OUNRSitQUkI2VmZBK0F0WDNvCnNTT2I3Wkcw
      cmtRMW00RElxdURmSEhHOGhYWS9Ea2hQRzZlVEh2Yk03bDgKLS0tIHl4blJYK0hl
      V0o2YjZaSHdQT3pJV05lUXAzWlcyYWtxL2lrUndDdVcxczQKv9MICqh5I0yEpWQC
      5aZXNY5c7916Rfg9wsCvGzA1BjCBw5bUWQYX
      -----END AGE ENCRYPTED FILE-----
      
    • mit gpg respektive -----BEGIN PGP MESSAGE-----
    • bearbeiten der secrets mit ./batou secrets edit <env> wie zuvor
    • vorteil: git diff zeigt sofort an, welche keys sich geändert haben
    • vorteil: macht merge-konflikte mit secrets sauberer
    • nachteil: die Informationen, welche keys verschlüsselt sind, werden "geleaked"
    • nachteil: environment.cfg wird sehr lang, da jedes secret 7+ Zeilen braucht
  • variante 2: Wir encrypten die secrets.cfg.{age|gpg} wie in variante 1
    • example:
      • in environment.cfg:
        [environment]
        
        [host:foohost]
        components = barcomponent
        
      • in secrets.cfg (notice: no encrypted file extension since this is plaintext)
        [component:barcomponent]
        secret_value = -----BEGIN AGE ENCRYPTED FILE-----
        YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IHlFVGhhQSB0WndK
        ZHpFTmJlMUlMaXg5ZXJyL2ZCZXN5OUNRSitQUkI2VmZBK0F0WDNvCnNTT2I3Wkcw
        cmtRMW00RElxdURmSEhHOGhYWS9Ea2hQRzZlVEh2Yk03bDgKLS0tIHl4blJYK0hl
        V0o2YjZaSHdQT3pJV05lUXAzWlcyYWtxL2lrUndDdVcxczQKv9MICqh5I0yEpWQC
        5aZXNY5c7916Rfg9wsCvGzA1BjCBw5bUWQYX
        -----END AGE ENCRYPTED FILE-----
        
      • bearbeiten der secrets mit ./batou secrets edit <env> wie zuvor
      • vorteil: git diff zeigt sofort an, welche keys sich geändert haben
      • vorteil: macht merge-konflikte mit secrets sauberer
      • nachteil: die Informationen, welche keys verschlüsselt sind, werden "geleaked"

git diff - mit Konfiguration (textconv, external diff):

  • Variante 1: Befehl ./batou secrets diff <file1> <file2> hinzufügen
    • entschlüsselt beide Dateien und zeigt den diff an
    • kann dann als external diff in git verwendet werden
      • d.h. git diff zeigt dann die entschlüsselten Inhalte an
      • age, gpg wird dann genauso wie von batou verstanden angezeigt
    • vorteil: Konfiguriertes git diff zeigt alle secrets Änderungen an
    • nachteil: nicht so allgemein wie Variante 2
  • Variante 2: Befehl ./batou secrets decrypt-to-stdout <file> hinzufügen
    • entschlüsselt eine Datei und schreibt sie auf stdout
    • kann dann als textconv in git verwendet werden
      • d.h. git diff zeigt dann die entschlüsselten Inhalte an
      • age, gpg wird dann genauso wie von batou verstanden angezeigt
    • vorteil: allgemein nützlicher Befehl
    • vorteil: Konfiguriertes git diff zeigt alle secrets Änderungen an

Übersicht über die aktuelle Environment Konfiguration + Secrets:

  • Befehl ./batou show-environment <env> hinzufügen
    • zeigt ge-parste Environment Konfiguration, gemerged mit Secrets
      • annotiert mit quelle des Werts
    • sowas wie:
      $ ./batou show-environment dev
      [environment] # all values from environment.cfg
      connect_method = local
      
      [host:foohost]
      service_user = foouser # from environment.cfg
      components = barcomponent # from environment.cfg
      data-foo = <REDACTED> # from secrets.cfg
      
      [component:barcomponent]
      normal_value = 42 # from environment.cfg
      secret_value = <REDACTED> # from secrets.cfg
      
    • mit Flag --show-secrets werden die secrets nicht redacted

Bearbeiten von Konfiguration + Secrets:

  • Vorschlag: Befehl ./batou secrets edit: --watch flag
    • erlaubt es, eine Datei zu bearbeiten, sodass on-save verschlüsselt wird
    • sobald der editor geschlossen wird, beendet sich der Befehl
    • vorteil: einfacherer cycle von "secret bearbeiten" <-> "testen"
  • Um Merge Konflikte zu lösen/vermeiden: Git custom merge driver:
    • Befehl hinzufügen: ./batou secrets merge-driver <ancestor> <current> <other> <marker-size> <merged>
    • schiebt den Merge Konflikt in die verschlüsselte Datei rein
    • vorteil: merge konflikte sind sauberer
    • nachteil: merge konflikte sind immer noch merge konflikte
    • nachteil: hoher magic/wtf faktor (kommt mir fragil vor)

Environment independent secrets:

  • Vorschlag:
    • Ein pseudo-environment project wird eingeführt
    • ./batou secrets edit project öffnet $EDITOR mit entschlüsselten secrets
    • die Konfiguration der anderen environments wird von project geerbt
    • nachteil: pseudo-environment
  • Vorschlag:
    • Projekt-weite Konfiguration in ./ oder ./environments/
      • Plaintext: project.cfg
      • Secrets secrets.cfg.{age|gpg}
      • Format wie in ./environments/<env>/
    • Befehl ./batou secrets edit <env> [file] -> ./batou secrets edit [env] [file] (optional)
      • wenn env nicht angegeben ist, wird project.cfg verwendet
      • wenn env angegeben ist, wird secrets.cfg verwendet
    • werden von environment-spezifischer Konfiguration überschrieben

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant