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

Evaluate SOPS to encrypt Ansible variables #97

Closed
ricsanfre opened this issue Jan 28, 2023 · 1 comment
Closed

Evaluate SOPS to encrypt Ansible variables #97

ricsanfre opened this issue Jan 28, 2023 · 1 comment

Comments

@ricsanfre
Copy link
Owner

ricsanfre commented Jan 28, 2023

Evaluate Mozilla SOPS as an alternative to ansible-vault when encrypting vault.yml file

Instead of using ansible-vault, use SOPS to only encrypt the variables values contained in vault.yml file and not the whole content.

Ansible provides support to encrypt and decrypt using SOPS within paybooks (Ansible communiy SOPS collection)

References

@ricsanfre
Copy link
Owner Author

ricsanfre commented Feb 1, 2023

Testing SOPS

Installing SOPS

  • Step 1: Install sops from binary

    wget https://github.com/mozilla/sops/releases/download/v3.7.3/sops-v3.7.3.linux.amd64
    sudo chmod +x sops-v3.7.3.linux.amd64
    sudo cp sops-v3.7.3.linux.amd64 /usr/local/bin
  • Step 2: Extract gpg key

    gpg --list-secret-keys <user>

    Get gpg key fingerprint from "sec" part

  • Step 3: Create .sops.yaml in $HOME directory

    creation_rules:
        - pgp: >-
             <gpg-key-fingerprint>

Encrypting a yaml file

  • Step1: Edit a file using sops

    sops tets.yaml

    add the following content to the file

    vault:
      app:
        admin:
          user: usuario1
          password: password1

    After saving the file the following warning is showed

    [PGP]    WARN[0000] Deprecation Warning: GPG key fetching from a keyserver within sops will be removed in a future version of sops. See https://github.com/mozilla/sops/issues/727 for more information.
  • Step 2: Edit file with vi

    File looks like this:

    vault:
        app:
            admin:
                user: ENC[AES256_GCM,data:A5lF9wbszbw=,iv:zHR2doM1P6vVKC2aPCthq5eBW9o01N6mjfc9DjJuXjo=,tag:IarHtdYUXYUtga16tSodcA==,type:str]
                password: ENC[AES256_GCM,data:VTU8g4msh98i,iv:kMt5OJkuJ/tvO6Pmpu1znmCOXjCaokXwLywmssDz5d4=,tag:ps2FFHdu5CHE2CHDVQiQhQ==,type:str]
    sops:
        kms: []
        gcp_kms: []
        azure_kv: []
        hc_vault: []
        age: []
        lastmodified: "2023-02-01T16:11:44Z"
        mac: ENC[AES256_GCM,data:awV2gGIVlbS4t86pKH0lzXEbpcRSlOzzqjqhhHDk14qwrrJBookqfZmI/xOtFIGDqB3nMxb/SvAxaprNzcXlOFi1cAPO91qj7rBh+xFy5A6a7uUb/qHPbMiE/u9oazSjXaeuRFGiLuNsPa8UyMXeq/kH1FHOcuY/0Z8RT2bLHIA=,iv:cqEN7NzfkMLMI2k05uRnmbftgE5ns04OfGo893h3Vps=,tag:9Ade+xQ5xrdKtV4PWuHHsw==,type:str]
        pgp:
            - created_at: "2023-02-01T16:06:50Z"
              enc: |
                -----BEGIN PGP MESSAGE-----
    
                hQGMA43TzuNmqDHYAQv8DTpNCcgJPTubgPf6iX/pwCGrMJOZqMlB56m8AulvOjdQ
                FNpiEzsvvfHMfn1chOdAPTv4lW0qb5pIvPE7PzKq4zf8S1BqdlaCaohLlS1ChkDj
                AzqTXqEkDdYuimSKRjs7sMz2jG9G5dmfrV/ckGNHf3iDNWA3ZGs97ALn7SbIRR3J
                EkA3F93yqyTz01+0Plt7GjstSzasp06xHRoHBhIyHguyzHeA0pRy1IaqOPRLjlnr
                /RrqOT/4rE+x50+/IqQ3df4NWz8ag1792j8D05ym7Hxpnke89YAzBAmPah76n1Hg
                NCqeshgI+3fDyB2K1SQ71hnangSq8k5pBgE/SovjbRbHWacUtrUwvmHJ2GEOgFgJ
                fmKzkFE/Od5NvRAFFq8ZzocU0lycYUNKZd8btFmRIoCMYFXc78iPVWXw1rcvfep5
                e1U9LYhTa0+nevokEB7f7Lp8kEbM29ozhgcs06GIjzVesze6LjDe//6mFSg3zglq
                IpFD+moH0nYKmp8IymwZ0l4BiuodvS9lAgHOIu3xDaecCoxWGzRCZeBzG/+0nQOm
                3lG3l8hXJfFqlbyCk7bZdJLSRTk0wI8c+RsIkPOyEXH+OjiVuSvRioAQJHidLd4p
                xnI+rpF1pkzdO6sRAKsx
                =NXog
                -----END PGP MESSAGE-----
              fp: 6DF60CF66A196DE1F58BDCA074A39198228337DC
        unencrypted_suffix: _unencrypted
        version: 3.7.3

Conclusion

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