Coder Social home page Coder Social logo

ansible-collections / community.sops Goto Github PK

View Code? Open in Web Editor NEW
74.0 9.0 20.0 3.76 MB

Simple and flexible tool for managing secrets

Home Page: https://galaxy.ansible.com/ui/repo/published/community/sops/

License: GNU General Public License v3.0

Python 92.43% Shell 7.57%
ansible-collection sops secret-management hacktoberfest

community.sops's Introduction

Community Sops Collection

CI Codecov REUSE status

The community.sops collection allows integrating getsops/sops in Ansible.

getsops/sops is a tool for encryption and decryption of files using secure keys (GPG, KMS, age). It can be leveraged in Ansible to provide an easy to use and flexible to manage way to manage ecrypted secrets' files.

Please note that this collection does not support Windows targets.

Sops version compatibility

The following table shows which versions of sops were tested with which versions of the collection. Older (or newer) versions of sops can still work fine, it just means that we did not test them. In some cases, it could be that a minimal required version of sops is explicitly documented for a specific feature. Right now, that is not the case.

community.sops version getsops/sops version
0.1.0 3.5.0+
1.0.6 3.5.0+
main branch 3.5.0, 3.6.0, 3.7.3, 3.8.0

Tested with Ansible

Tested with the current Ansible 2.9, ansible-base 2.10, ansible-core 2.11, ansible-core 2.12, ansible-core 2.13, ansible-core 2.14, ansible-core 2.15, ansible-core 2.16, and ansible-core 2.17 releases and the current development version of ansible-core. Ansible versions before 2.9.10 are not supported.

The vars plugin requires ansible-base 2.10 or later.

External requirements

You will need to install sops manually before using plugins provided by this collection.

Collection Documentation

Browsing the latest collection documentation will show docs for the latest version released in the Ansible package, not the latest version of the collection released on Galaxy.

Browsing the devel collection documentation shows docs for the latest version released on Galaxy.

We also separately publish latest commit collection documentation which shows docs for the latest commit in the main branch.

If you use the Ansible package and do not update collections independently, use latest. If you install or update this collection directly from Galaxy, use devel. If you are looking to contribute, use latest commit.

Included content

This collection provides:

  • a lookup plugin sops that allows looking up a sops-encrypted file content;
  • a vars plugin sops that allows loading Ansible vars from sops-encrypted files for hosts and groups;
  • an action plugin load_vars that allows loading Ansible vars from a sops-encrypted file dynamically during a playbook or role;
  • a module sops_encrypt which allows to encrypt data with sops.
  • a role install which allows to install sops and GNU Privacy Guard.
  • two playbooks install and install_localhost which allow to install sops and GNU Privacy Guard.

Using this collection

Installing sops

To install sops, you can use the community.sops.install role. The role also installs GNU Privacy Guard (GPG).

Examples:

tasks:
  # To use the sops_encrypt module on a remote host, you need to install sops on it:
  - name: Install sops on remote hosts
    ansible.builtin.include_role:
      name: community.sops.install
    vars:
      sops_version: 2.7.0  # per default installs the latest version

  # To use the lookup plugin, filter plugin, vars plugin, or the load_vars action,
  # you need sops installed on localhost:
  - name: Install sops on localhost
    ansible.builtin.include_role:
      name: community.sops.install
    vars:
      sops_install_on_localhost: true

lookup plugin

The lookup plugin can be accessed with the community.sops.sops key.

Examples:

tasks:
  - name: Output secrets to screen (BAD IDEA!)
    ansible.builtin.debug:
        msg: "Content: {{ lookup('community.sops.sops', '/path/to/sops-encrypted-file.enc.yaml') }}"

  - name: Add SSH private key
    ansible.builtin.copy:
        content: "{{ lookup('community.sops.sops', user + '-id_rsa') }}"
        dest: /home/{{ user }}/.ssh/id_rsa
        owner: "{{ user }}"
        group: "{{ user }}"
        mode: 0600
    no_log: true  # avoid content to be written to log

See Lookup Plugins for more details on lookup plugins.

filter plugin

The filter plugin can be used in Jinja2 expressions by the name community.sops.decrypt. It can decrypt sops-encrypted data coming from other sources than files.

Example:

tasks:
  - name: Load sops encrypted data
    ansible.builtin.set_fact:
      encrypted_data: "{{ lookup('file', '/path/to/sops-encrypted-file.enc.yaml') }}"

  - name: Output secrets to screen (BAD IDEA!)
    ansible.builtin.debug:
      msg: "Content: {{ encrypted_data | community.sops.decrypt(output_type='yaml') }}"

See Filter Plugins for more details on filters.

Please note that if you put a Jinja2 expression in a variable, it will be evaluated every time it is used. Decrypting data takes a certain amount of time. If you need to use an expression multiple times, it is better to store its evaluated form as a fact with ansible.bulitin.set_fact first:

tasks:
  - name: Decrypt data once
    ansible.builtin.set_fact:
      decrypted_data: "{{ encrypted_data | community.sops.decrypt }}"
    run_once: true  # if encrypted_data is identical on all hosts

  - name: Use decrypted secrets multiple times
    ansible.builtin.openssl_privatekey:
      path: "/path/to/private_{{ item }}.pem"
      passphrase: "{{ decrypted_data }}"
      cipher: auto
    loop:
      - foo
      - bar
      - baz

By using {{ encrypted_data | community.sops.decrypt }} instead of {{ decrypted_data }} in the openssl_privatekey task, the data would be decrypted three times for every host this is executed for. With the ansible.builtin.set_fact and run_once: true, it is evaluated only once.

vars plugin

Vars plugins only work in ansible >= 2.10 and require explicit enabling. One way to enable the plugin is by adding the following to the defaults section of your ansible.cfg:

vars_plugins_enabled = host_group_vars,community.sops.sops

See VARIABLE_PLUGINS_ENABLED for more details.

After the plugin is enabled, correctly named group and host vars files will be transparently decrypted with sops.

The files must end with one of these extensions:

  • .sops.yaml
  • .sops.yml
  • .sops.json

Here is an example file structure

├── inventory/
│   ├── group_vars/
│   │   └── all.sops.yml
│   ├── host_vars/
│   │   ├── server1.sops.yml
│   │   └── server2/
│   │       └── data.sops.yml
│   └── hosts
├── playbooks/
│   └── setup-server.yml
└── ansible.cfg

You could execute the playbook in this example with the following command. The sops vars files would be decrypted and used.

$ ansible-playbook playbooks/setup-server.yml -i inventory/hosts

Determine when to load variables

Ansible 2.10 allows to determine when vars plugins load the data.

To run the sops vars plugin right after importing inventory, you can add the following to ansible.cfg:

[community.sops]
vars_stage = inventory

Caching variable files

By default, the sops vars plugin caches decrypted files to avoid having to decrypt them every task. If this is not wanted, it can be explicitly disabled in ansible.cfg:

[community.sops]
vars_cache = false

Please note that when using vars plugin staging, this setting only has effect if the variables are not only loaded during the inventory stage. See the documentation of the community.sops.sops vars plugin for more details.

load_vars action plugin

The load_vars action plugin can be used similarly to Ansible's include_vars, except that it right now only supports single files. Also, it does not allow to load proper variables (i.e. "unsafe" Jinja2 expressions which evaluate on usage), but only facts. It does allow to evaluate expressions on load-time though.

Examples:

tasks:
  - name: Load variables from file and store them in a variable
    community.sops.load_vars:
        file: path/to/sops-encrypted-file.sops.yaml
        name: variable_to_store_contents_in

  - name: Load variables from file into global namespace, and evaluate Jinja2 expressions
    community.sops.load_vars:
        file: path/to/sops-encrypted-file-with-jinja2-expressions.sops.yaml
        # The following allows to use Jinja2 expressions in the encrypted file!
        # They are evaluated right now, i.e. not later like when loaded with include_vars.
        expressions: evaluate-on-load

sops_encrypt module

The sops_encrypt module can be used to create and update sops encrypted files. It assumes that sops is configured via environment variables or a .sops.yaml file.

Examples:

tasks:
  - name: Store secret text sops encrypted
    community.sops.sops_encrypt:
        path: path/to/sops-encrypted-file.sops
        content_text: This is some secret text.

  - name: Store secret binary data sops encrypted
    community.sops.sops_encrypt:
        path: path/to/sops-encrypted-file.sops
        content_binary: "{{ some_secret_binary_data | b64encode }}"

  - name: Store secret JSON data
    community.sops.sops_encrypt:
        path: path/to/sops-encrypted-file.sops.json
        content_json:
            key1: value1
            key2:
                - value2
                - key3: value3
                  key4: value5

  - name: Store secret YAML data
    community.sops.sops_encrypt:
        path: path/to/sops-encrypted-file.sops.yaml
        content_yaml:
            key1: value1
            key2:
                - value2
                - key3: value3
                  key4: value5

Troubleshooting

Spurious failures during encryption and decryption with gpg

Sops calls gpg with --use-agent. When running multiple of these in parallel, for example when loading variables or looking up files for various hosts at once, some of these can randomly fail with messages such as

Failed to get the data key required to decrypt the SOPS file.

Group 0: FAILED
  D13xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: FAILED
    - | could not decrypt data key with PGP key:
      | golang.org/x/crypto/openpgp error: Reading PGP message
      | failed: openpgp: incorrect key; GPG binary error: exit
      | status 2

  828xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: FAILED
    - | could not decrypt data key with PGP key:
      | golang.org/x/crypto/openpgp error: Reading PGP message
      | failed: openpgp: incorrect key; GPG binary error: exit
      | status 2

Recovery failed because no master key was able to decrypt the file. In
order for SOPS to recover the file, at least one key has to be successful,
but none were.

This is a limitation of gpg-agent which can be fixed by adding auto-expand-secmem to ~/.gnupg/gpg-agent.conf (reference on option, reference on config file).

(See #34 and https://dev.gnupg.org/T4146 for more details.)

Contributing to this collection

See CONTRIBUTING.md

Release notes

See CHANGELOG.md.

Releasing, Versioning and Deprecation

This collection follows Semantic Versioning. More details on versioning can be found in the Ansible docs.

We plan to regularly release new minor or bugfix versions once new features or bugfixes have been implemented.

Releasing the current major version happens from the main branch. We will create a stable-1 branch for 1.x.y versions once we start working on a 2.0.0 release, to allow backporting bugfixes and features from the 2.0.0 branch (main) to stable-1. A stable-2 branch will be created once we work on a 3.0.0 release, and so on.

We currently are not planning any deprecations or new major releases like 2.0.0 containing backwards incompatible changes. If backwards incompatible changes are needed, we plan to deprecate the old behavior as early as possible. We also plan to backport at least bugfixes for the old major version for some time after releasing a new major version. We will not block community members from backporting other bugfixes and features from the latest stable version to older release branches, under the condition that these backports are of reasonable quality.

TODO

  • add a role providing sops installation (with version pinning)
  • a full test suite

Code of Conduct

This repository adheres to the Ansible Community code of conduct

More information

Licensing

This collection is primarily licensed and distributed as a whole under the GNU General Public License v3.0 or later.

See LICENSES/GPL-3.0-or-later.txt for the full text.

Parts of the collection are licensed under the BSD 2-Clause license.

All files have a machine readable SDPX-License-Identifier: comment denoting its respective license(s) or an equivalent entry in an accompanying .license file. Only changelog fragments (which will not be part of a release) are covered by a blanket statement in .reuse/dep5. This conforms to the REUSE specification.

community.sops's People

Contributors

abeluck avatar alexgeek avatar andersson007 avatar apollo13 avatar applejag avatar cpach avatar dependabot[bot] avatar endorama avatar felixfontein avatar flowerysong avatar gundalow avatar jpmens avatar nvanheuverzwijn avatar splushii avatar sylvainmetayer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

community.sops's Issues

Opt-in to Hacktoberfest

@felixfontein This year Hacktoberfest is opt-in, I like the initiative and there are a couple of things that contributors may do.

Would you add the hacktoberfest tag to this repo? I'm going to setup a couple of issues from the Roadmap project.

If `.sops.yaml` contains a `path_regex` sops_encrypt doesn't work

Hi 👋🏼

I am trying to use this module but it doesn't work when I have a .sops.yaml configuration file present. If I remove the .sops.yaml config file my task works.

env

✖ ansible --version
ansible [core 2.15.1]
  config file = None
  configured module search path = ['/Users/devin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/8.1.0/libexec/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/devin/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.11.4 (main, Jun 20 2023, 17:23:00) [Clang 14.0.3 (clang-1403.0.22.14.1)] (/opt/homebrew/Cellar/ansible/8.1.0/libexec/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
❯ ansible-galaxy collection list | grep sops
community.sops                1.6.4

sops configuration file

# /tmp/test/.sops.yaml
---
creation_rules:
  - path_regex: kubernetes/.*\.sops\.ya?ml
    encrypted_regex: "^(data|stringData)$"
    key_groups:
      - age:
          - "{{ bootstrap_age_public_key }}"
  - path_regex: ansible/.*\.sops\.ya?ml
    key_groups:
      - age:
          - "{{ bootstrap_age_public_key }}"

example task

    - name: Template out encrypted files
      community.sops.sops_encrypt:
        path: "/tmp/test/kubernetes/test.sops.yaml"
        encrypted_regex: ^(data|stringData)$
        age: ["{{ age_public_key }}"]
        content_yaml: "{{ lookup('file', 'templates/test.sops.yaml') | from_yaml }}"
        mode: "0755"
        force: true

ansible logs

TASK [Template out encrypted files] ******************************************************************************************
failed: [localhost] (item={'src': 'kubernetes/cert-manager-secret.sops.yaml.j2', 'dest': './kubernetes/test.sops.yaml', 'encrypt': True}) => {"ansible_loop_var": "item", "changed": false, "msg": "error with file to stdout: ErrorGeneric exited with code 1: error loading config: no matching creation rules found\n"}

It would be nice if we could unset config_path from always being present as I have confirmed that without this present I can encrypt. However maybe there is something else going on?

Collection contains invalid files

It seems that this collection contains problems like invalid characters inside YAML files, such collections/ansible_collections/community/sops/tests/integration/targets/filter_decrypt/files/hidden-json.yaml which contains tabs, something YAML specification explicitly forbids.

This is identified by both ansible-lint and yamllint tools.

I would advise configuring this and running ansible-lint as a github action, especially as in the near future, upload to galaxy will be rejected if violations are found.

Optionally you could also consider removing the test files from the archive, see ansible-community/community-topics#126

Vars plugin not decrypting, loads literal value

SUMMARY

Followed documentation as well as integration tests for good measure. Variables encrypted by sops is always loaded as a literal value, i.e. the encrypted block. I'd expect foo: test123456 but I get foo: ENC[AES256_GCM,data:K22FEU7O0d0bzA==,iv:Mq2QWkgcRr/RaIKdhmbpXO64voW0Xi2TQ6EH9mTc3iY=,tag:9HZQQrEZ8uRx6A2k7DRyJQ==,type:str].

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.sops

ANSIBLE VERSION
ansible [core 2.12.5]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/maximebeaudry/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/maximebeaudry/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/maximebeaudry/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/maximebeaudry/.local/bin/ansible
  python version = 3.9.1 (default, Apr 27 2022, 18:06:33) [GCC 8.3.0]
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /home/maximebeaudry/.ansible/collections/ansible_collections
Collection     Version
-------------- -------
community.sops 1.3.0  

# /home/maximebeaudry/.local/lib/python3.9/site-packages/ansible_collections
Collection     Version
-------------- -------
community.sops 1.2.1
CONFIGURATION
~$ ansible-config dump --only-changed
~$
OS / ENVIRONMENT

Debian 10

STEPS TO REPRODUCE

Folder structure

.
├── ansible.cfg
├── inventory
│   └── group_vars
|       └── test_group
|           └── secrets.sops.yml
│   └── hosts
├── playbook.yml
├── requirements.yml
└── .sops.yaml

ansible.cfg

[defaults]
vars_plugins_enabled = host_group_vars,community.sops.sops

secrets.sops.yml

foo: ENC[AES256_GCM,data:K22FEU7O0d0bzA==,iv:Mq2QWkgcRr/RaIKdhmbpXO64voW0Xi2TQ6EH9mTc3iY=,tag:9HZQQrEZ8uRx6A2k7DRyJQ==,type:str]
sops:
    kms: []
    gcp_kms: []
    azure_kv: []
    hc_vault: []
    age: []
    lastmodified: "2022-05-02T20:20:57Z"
    mac: ENC[AES256_GCM,data:GiJd/pYS6CAMVDl00wAh1YB36J1Ju27XekCYN7jlNdKMp4JDgE6R8vbRgMmAb3vyovsl7qH+PHOZQ4bEQVe4lHvobuXlOGwbHwl62IwBQJ0jrna92IcoUnPkMHNwphdfU7kd2B2Ip/fcJLV3PKCFSZTyCEGMc8bim2VdPEy11f0=,iv:eLXvVXjxZE83RPP4a/r1+Yvn6fVL+H8m6snYfE6zEaw=,tag:7FaVve0IsYcqo3IrOt9a9Q==,type:str]
    pgp:
        - created_at: "2022-05-02T20:20:39Z"
          enc: |
            -----BEGIN PGP MESSAGE-----

            hQIMA52j6clW5zNxARAAkDQaoP04qgZab1DzWXcY0JnFO92TMSKT5iAVWX4+5vsZ
            byJyLvKVOXrrRvjxZqDZA2RysOoyInK6tr8d4xwYN762iRJBlfu6UFoUh6AGUyjJ
            Ewm3Lvu47C5RF5pLfL7pO7Y97pTJyWjhFIR2JNfVGTCz6R87RbmNvHY/IDYe/GkJ
            hOGd1YHXKEZE6s4oOIUQtBp12RIx7QY2HabbuNbjNGZ4bfIELsQq7xoetmvQgFoC
            5sOi9B0UheeVdDxaD0f2v+SKXlHSYUSGjk1wixMju6kCV3rCILajAj3trmZ8PVFC
            kXzyxYfx1PnbLhsMZJcGnlQwl6GhO/RbSMfdP3AEd986wsSzZoJB0FeuzdXOWaY7
            UfXWLaUOLizh7VxUUbBlxQpPaZ4W87Q6sb+yGeBpu9zGGjfGHotCTS9EOEkhtvMn
            sxdBxov8zi/MFYNcG9iskaWhampOa4i6k+EGOI8ue3ewwpPTUak/mhiQ/BNRUBMl
            0BpTPK/OvCyLXSSslaAjC4nldFcS0wb1Iz54FYQ7bdjXuL1/b0wftsKYQT/1+k/e
            fajzueh4SeUGLjKtZJNP3lZx1pUqrCSVSqtv6mxvaEJsyml1IzSMQuoF4xoz+w3T
            dVnl5IkApRqTZAoGyxgV0CmoL100W3xyzJXFUxJrZb4MxvqBHrfZEYciaYkRzxTS
            XgEMNON4U1Vgaq7gdBYBJQIthuTBdBlmVd3lf/P/48OAUtvrSHk3p15nGFxC6/Fh
            9XsAczF1RP4dNkmWrLrLTcYz2QzUskM3M72SMtw8SELn83kGRJSZatcytTtVyzM=
            =nVvh
            -----END PGP MESSAGE-----
          fp: CAB33DAD02213F454BFFAC316112928125B538AB
    unencrypted_suffix: _unencrypted
    version: 3.7.1

hosts

[test_group]
10.142.0.7

playbook.yml

- hosts: test_group
  vars_files:
    - inventory/group_vars/test_group/secrets.sops.yml
  tasks:
    - debug:
        var: foo

requirements.yml

collections:
  - name: git+https://github.com/ansible-collections/community.sops
    version: main

.sops.yaml

---
creation_rules:
  - pgp: CAB33DAD02213F454BFFAC316112928125B538AB
EXPECTED RESULTS
PLAY [test_group] *********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************************************************
ok: [10.142.0.7]

TASK [debug] **************************************************************************************************************************************************************************************************************
ok: [10.142.0.7] => {
    "foo": "test123456"
}

PLAY RECAP ****************************************************************************************************************************************************************************************************************
10.142.0.7                 : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ACTUAL RESULTS
~$ ansible-playbook -i inventory/hosts playbook.yml

PLAY [test_group] *********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************************************************
ok: [10.142.0.7]

TASK [debug] **************************************************************************************************************************************************************************************************************
ok: [10.142.0.7] => {
    "foo": "ENC[AES256_GCM,data:K22FEU7O0d0bzA==,iv:Mq2QWkgcRr/RaIKdhmbpXO64voW0Xi2TQ6EH9mTc3iY=,tag:9HZQQrEZ8uRx6A2k7DRyJQ==,type:str]"
}

PLAY RECAP ****************************************************************************************************************************************************************************************************************
10.142.0.7                 : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 

Important information for collection maintainers

SUMMARY

Dear maintainers,

This is important for your collections!

  • In accordance with the Community decision, we have created the news-for-maintainers repository for announcements of changes impacting collection maintainers (see the examples) instead of Issue 45 that will be closed soon.

    • To keep yourself well-informed and, therefore, things in your collection working, please subscribe to the repository by using the Watch button in the upper right corner on the repository's home page.
    • If you do not want to get notifications about related discussions, please subscribe only to Issues.
    • Please read the brief guidelines on how the repository should be used.
    • Please avoid unnecessary discussions in issues, use the Discussions feature. Every comment posted will notify a lot of folks!
  • Also we would like to remind you about the Bullhorn contributor newsletter which has recently started to be released weekly. To learn what it looks like, see the past releases. Please subscribe and talk to the Community via Bullhorn!

  • Join us in #ansible-social (for news reporting & chat), #ansible-community (for discussing collection & maintainer topics), and other channels on Matrix/IRC.

  • Help the Community and the Steering Committee to make right decisions by taking part in discussing and voting on the Community Topics that impact the whole project and the collections in particular. Your opinion there will be much appreciated!

Thank you!

0.2.0 release

I'm planning to release 0.2.0 of this collection in a few days if nobody (in particular @endorama) complains :)

SOPS collection doesn't see environment variables set with Ansible environment keyword at the task level.

SUMMARY

SOPS collection doesn't see environment variables set with Ansible environment keyword at the task level.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.sops.load_vars

ANSIBLE VERSION
ansible 2.9.9
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/opt/ansible/lib/python3.6/site-packages/ansible
  executable location = /bin/ansible
  python version = 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
CONFIGURATION

OS / ENVIRONMENT

CentOS Linux 7 (Core), Linux 3.10.0-1127.10.1.el7.x86_64

STEPS TO REPRODUCE

A role with a community.sops.load_vars and environment keyword.

- name: Load SOPS Secrets.
  environment:
    AWS_ACCESS_KEY_ID: "{{ AWS_ACCESS_KEY_ID }}"
    AWS_SECRET_ACCESS_KEY: "{{ AWS_SECRET_ACCESS_KEY }}"
  community.sops.load_vars:
    file: "roles/my-role/dev-secrets.yml"
EXPECTED RESULTS

community.sops.load_vars should use provided environment variables and decrypt secret with KMS key.

ACTUAL RESULTS

community.sops.load_vars throws error that access is denied to the key. However same task works if ~/.aws/credentials is present:
[defualt]
AWS_ACCESS_KEY_ID=<>
AWS_SECRET_ACCESS_KEY=<>
So it looks community.sops.load_vars cannot see environment variables set with environment keyword. sops executable works with environment variables:
AWS_ACCESS_KEY_ID=<> AWS_SECRET_ACCESS_KEY=<> sops --kms "arn:aws:kms:..." -d roles/my-role/dev-secrets.yml

ESC[1;30mtask path: /tmp/ansible-pull-common/roles/my-role/tasks/main.yml:41ESC[0m
ESC[0;31mfatal: [test.us-east-1.dev.in]: FAILED! => {"changed": false, "message": "error with file /tmp/ansible-pull-common/roles/my-role/vars/dev-secrets.yml: CouldNotRetrieveKey exited with code 128: Failed to get the data key required to decrypt the SOPS file.\n\nGroup 0: FAILED\n  arn:aws:kms:...: FAILED\n    - | Error decrypting key: AccessDeniedException: The ciphertext\n      | refers to a customer master key that does not exist, does\n      | not exist in this region, or you are not allowed to access.\n      | \tstatus code: 400, request id:\n      | 9c8b4a35-115d-4f64-9685-b86d47e8a66a\n\nRecovery failed because no master key was able to decrypt the file. In\norder for SOPS to recover the file, at least one key has to be successful,\nbut none were.\n"}ESC[0m

Support setting sops_binary option for vars plugin

SUMMARY

Please expose sops_binary in ansible.cfg

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

community.sops.sops vars plugin

ADDITIONAL INFORMATION

It's currently not possible to set sops_binary for vars plugin, as it's not possible to use variables to configure vars plugin, and the setting is not exposed in ansible.cfg. This would be useful when creating a self-contained Ansible packages: SOPS is statically-linked binary that works everywhere and can be simply included in a package, but vars plugin looks for it in PATH only.

Please expose sops_binary option in the ansible.cfg, e. g. using

sops_binary:
    description:
        - Path to the sops binary.
        - By default uses C(sops).
    type: path
    version_added: 1.0.0
    ini:
        - key: sops_binary
          section: community.sops

If I am mistaken and there is a way to set it, please document it.

Document gpg-agent option `auto-expand-secmem`

Without it (which is unfortunately the default), running several decrypts (and possibly encrypts) in parallel causes strange errors such as

gpg: public key decryption failed: Cannot allocate memory
gpg: decryption failed: No secret key

which causes sops to fail with errors such as

Failed to get the data key required to decrypt the SOPS file.

Group 0: FAILED
  D13xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: FAILED
    - | could not decrypt data key with PGP key:
      | golang.org/x/crypto/openpgp error: Reading PGP message
      | failed: openpgp: incorrect key; GPG binary error: exit
      | status 2
  
  828xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: FAILED
    - | could not decrypt data key with PGP key:
      | golang.org/x/crypto/openpgp error: Reading PGP message
      | failed: openpgp: incorrect key; GPG binary error: exit
      | status 2

Recovery failed because no master key was able to decrypt the file. In
order for SOPS to recover the file, at least one key has to be successful,
but none were.

When using the vars plugin with enough hosts (say 10 or more), for me it happens quite often that some of them error out with this error.

Simply adding auto-expand-secmem to ~/.gnupg/gpg-agent.conf fixes this problem for me. Since this can be annoying more users, I think we should add it to the README.

Doesn't set `--output-type yaml` on `.yml` files, but only `.yaml` files

SUMMARY

The automatic --output-type is only set to yaml if the file extension is .yaml. This results in .yml files getting JSON formatting.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

sops_encrypt module

ANSIBLE VERSION
ansible [core 2.15.3]
  config file = /redacted/ansible.cfg
  configured module search path = ['/home/redacted/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /redacted/.venv/lib/python3.11/site-packages/ansible
  ansible collection location = /home/redacted/.ansible/collections:/usr/share/ansible/collections
  executable location = /redacted/.venv/bin/ansible
  python version = 3.11.4 (main, Jun  6 2023, 22:16:46) [GCC 12.3.0] (/redacted/.venv/bin/python)
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION
Collection     Version
-------------- -------
community.sops 1.6.4
CONFIGURATION
CONFIG_FILE() = /redacted/ansible.cfg
DEFAULT_FORKS(/redacted/ansible.cfg) = 200
DEFAULT_GATHERING(/redacted/ansible.cfg) = smart
DEFAULT_JINJA2_EXTENSIONS(/redacted/ansible.cfg) = jinja2.ext.do,jinja2.ext.i18n
DEFAULT_MANAGED_STR(/redacted/ansible.cfg) = "This file is Managed by Ansible - Please do not edit by hand changes will be overwritten!"
DEFAULT_ROLES_PATH(/redacted/ansible.cfg) = ['/redacted/roles.galaxy', '/redacted/roles']
DEFAULT_TIMEOUT(/redacted/ansible.cfg) = 30
DEFAULT_VAULT_IDENTITY_LIST(env: ANSIBLE_VAULT_IDENTITY_LIST) = ['/redacted/scripts/ansible-vault-keyring-client.py']
EDITOR(env: EDITOR) = nvim
HOST_KEY_CHECKING(/redacted/ansible.cfg) = False
INTERPRETER_PYTHON(/redacted/ansible.cfg) = /usr/bin/env python3
PAGER(env: PAGER) = less --raw-control-chars --quit-if-one-screen
VARIABLE_PLUGINS_ENABLED(/redacted/ansible.cfg) = ['host_group_vars', 'community.sops.sops']
OS / ENVIRONMENT

Linux 6.1.56
x86_64

STEPS TO REPRODUCE

Run the following playbook:

- hosts: localhost
  gather_facts: false
  tasks:
    - name: Create key vault file
      community.sops.sops_encrypt:
        path: "foo.yml"
        content_yaml:
          foo: bar
EXPECTED RESULTS

Content of foo.yml:

foo: ENC[AES256_GCM,data:rElC,iv:vBbFgYuKvnCrEjX2plYUvtcYmFtBpl3UBKa8xJfEv/c=,tag:oijrsyuNsykJ8J8KFVXMlQ==,type:str]
sops:
    kms: []
    gcp_kms: []
    azure_kv: []
    hc_vault: []
...snip
ACTUAL RESULTS

Content of foo.yml:

{
	"foo": "ENC[AES256_GCM,data:g0fG,iv:Bi+6De1oeqJEUnDN0zNa9me5Q0S07iOcN30eP9Z95YE=,tag:myrbR+PDl23dX0vmbP5+5A==,type:str]",
	"sops": {
		"kms": null,
		"gcp_kms": null,
		"azure_kv": null,
...snip

Vars plugin isn't loading variables

SUMMARY

I'm testing out the community.sops collection and the vars plugin does not appear to be behaving as expected.

My directory structure looks like this:

.
├── ansible.cfg
├── group_vars
│   └── all.sops.yaml
├── playbook.yml
├── requirements.yml
└── .sops.yaml

Where ansible.cfg looks like:

[defaults]
vars_plugins_enabled = host_group_vars,community.sops.sops

And playbook.yml looks like:

- hosts: localhost
  gather_facts: false
  tasks:
    - debug:
        var: users

And .sops.yaml looks like:

---
creation_rules:
  - pgp: >-
      3E70A502BB5255B6BB8E86BE362D63A80853D4CF

And requirements.yml looks like:

collections:
  - name: git+https://github.com/ansible-collections/community.sops
    version: main

(Running ansible-galaxy collection install ... just now should have installed commit 151f986.)

I have created group_vars/all.sops.yaml by running:

sops group_vars/all.sops.yaml

I can successfully decrypt this file with sops:

$ sops -d group_vars/all.sops.yaml
users:
-   name: alice
    password: secret

But running the playbook fails with:

TASK [debug] *********************************************************************************************************************************************************************************
ok: [localhost] => {
    "users": "VARIABLE IS NOT DEFINED!"
}

It look as if the the sops vars plugin is making no attempt to decrypt group_vars/all.sops.yaml.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.sops vars plugin

ANSIBLE VERSION
ansible 2.10.8
  config file = /home/lars/tmp/sopstest/ansible.cfg
  configured module search path = ['/home/lars/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/lars/.local/lib/python3.9/site-packages/ansible
  executable location = /home/lars/.local/bin/ansible
  python version = 3.9.4 (default, Apr  6 2021, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]
CONFIGURATION
VARIABLE_PLUGINS_ENABLED(/home/lars/tmp/sopstest/ansible.cfg) = ['host_group_vars', 'community.sops.sops']
OS / ENVIRONMENT

Fedora 33

STEPS TO REPRODUCE

(see above)

EXPECTED RESULTS

I expected the playbook to output the contents of the users variable defined in group_vars/all.sops.yaml.

ACTUAL RESULTS

The playbook was not aware of a users variable.

Renaming master branch to main

The Ansible team decided to rename the master branch in all Ansible-controlled collections to main (see ansible-collections/overview#83 and ansible-collections/overview#87 for history and more information). This also applies to community.sops. My suggestion would be to do this soon, especially before a first release is done, and before more people start cloning/forking this repository.

Right now, there are two forks (one by @liptanbiswas and mine), and probably some clones (@endorama surely has one). Information on updating local clones can be found here: https://github.com/ansible/community/wiki/Changing-the-git-default-branch-to-main#updating-local-clones Information on updating forks on github: https://github.com/ansible/community/wiki/Changing-the-git-default-branch-to-main#updating-a-fork-on-github

@endorama please tell us when we should do this change.

Decrypt secrets that are loaded through other lookup_plugins

SUMMARY

From my brief understanding of how the sops plugins are intended to be used I got the impression, that values are decrypted when the are "loaded" through one of the plugins. I'm wondering if it is possible to decrypt the data later down the line, so that one could use a different lookup plugin to load the encrypted data and then ansible would decrypt it once it is used.

ISSUE TYPE
  • Feature Idea

Cant specify parameter: _valid_extensions in ansible.cfg

Hello :)

In my ansible inventory i encrypt only some of the variables with the command:

sops —set ‘[“foo_password“] “password_value“‘ host_vars/example_host.yml

My .sops.yml looks like:

creation_rules:
  - age: <my-age-key>
     encrypted_regex: _(password|apikey)$
     mac_only_encrypted: true 

The encryption works fine and as expected, but the decryption is not working.
In ansible i use the community.sops.sops_vars-plugin and my ansible.cfg looks like:

[defaults]
vars_plugins_enabled = host_group_vars,community.sops.sops

[community.sops]
age_keyfile = <path to key-file>
config_file = <path to config-file>
_valid_extensions = [“.sops.yml“, “.sops.yaml“, “.sops.json“, “.yml“]

If i understood correctly i can say then community.sops.sops_vars-plugin with the parameter _valid_extensions that it should also read my normal yaml-files. But it does not work.

Thanks for your help, maybe i missunderstood something.

SOPS return code check is incorrect

SUMMARY

https://github.com/ansible-collections/community.sops/blob/main/plugins/module_utils/sops.py#L177 (and similarly in the encrypt() method later) checks if SOPS failed by doing

if exit_code > 0: 
  # handle error

This is incorrect: on POSIX systems, the return code can be negative if the child was killed by a signal (even if it killed itself, e. g. by SIGABRT, SIGSEGV etc.) as documented in the manual. When this happen, Ansible continues without an error, but uses undecryped data (don't know why, probably builtin vars plugin takes over?). This results in very hard-to-debug problems.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

sops collection, module_utils/sops.py

ANSIBLE VERSION

doesn't matter

COLLECTION VERSION

all of them

CONFIGURATION

doesn't matter

OS / ENVIRONMENT

all Linux (probably all UNIXes)

STEPS TO REPRODUCE

I found this when Git (un)helpfully converted newlines in the binary to CRLF. The resulting binary, when run, got killed by SIGTRAP immediately after execve().

You could probably replace sops binary with a shell script that kills itself or something.

EXPECTED RESULTS

Ansible fails with an error, describing what happened (e. g. "SOPS killed by signal no. 5)"

ACTUAL RESULTS

Ansible continues without an error, using ciphertext as data

Ansible Contributor Summit. Tuesday, April 12, 2022.

Ansible Contributor Summit

We are happy to announce that the registration for the Ansible Contributor Summit is open!

Why
  • This is a great opportunity for interested people to meet, discuss related topics, share their stories and opinions, get the latest important updates and just to hang out together.

  • There will be different announcements & presentations by Community, Core, Cloud, Network, and other teams.

  • Current contributors will be happy to share their stories and experience with newcomers.

  • There will be links to interactive self-passed instruqt scenarios shared during the event that help newcomers learn different aspects of development.

Where/when

Online on Matrix and Youtube. Tuesday, April 12, 2022, 12:00 - 20:00 UTC.

How to join
  • Add the event to your calendar. Use the ical URL (for example, in Google Calendar "Add other calendars" > "Import from URL") instead of importing the .ics file so that any updates to the event will be reflected in your calendar.

  • Check out the Summit page:

    • Add you name to attendees.
    • Suggest summit topics that would be interesting to you to hear about.
    • Vote on and propose changes to topics suggested by others.
    • If you want to be a presenter, please contact the Ansible Community team via [email protected].

We are looking forward to seeing you!:)

load_vars with static=false

Looks like I forgot to create the issue for #19.

Anyway, I now found out that soon there will be a change in Ansible (which is backported also to stable-2.10 and stable-2.9) which will break static: false.

Maybe we should remove that functionality before actually releasing, because it is guaranteed to stop working soon. @endorama what do you think?

MacOS Install not working

To cut to the chase:

PLAY [Provision System] *********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************************
[WARNING]: Platform darwin on host 127.0.0.1 is using the discovered Python interpreter at /usr/bin/python3, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-
core/2.14/reference_appendices/interpreter_discovery.html for more information.
ok: [127.0.0.1]

TASK [Install SOPS] *************************************************************************************************************************************************************************************************************************************

TASK [community.sops.install : Validating arguments against arg spec 'main' - Install Mozilla sops] *****************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [community.sops.install : Gather required information on localhost] ********************************************************************************************************************************************************************************
ok: [127.0.0.1 -> localhost]

TASK [community.sops.install : Show system information] *************************************************************************************************************************************************************************************************
ok: [127.0.0.1] => {
    "msg": "Architecture: arm64\nDistribution: MacOSX 13\nDistribution version: 13.0.1\nOS family: Darwin"
}

TASK [community.sops.install : Include distribution specific variables] *********************************************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [community.sops.install : Start determining source] ************************************************************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [community.sops.install : Auto-detect source to install sops from] *********************************************************************************************************************************************************************************
included: /Users/simbleau/.ansible/collections/ansible_collections/community/sops/roles/install/tasks/detect_source.yml for 127.0.0.1

TASK [community.sops.install : Check whether system packages are a valid source of sops latest] *********************************************************************************************************************************************************
skipping: [127.0.0.1]

TASK [community.sops.install : Check whether GitHub is a valid source of sops] **************************************************************************************************************************************************************************
skipping: [127.0.0.1]

TASK [community.sops.install : Ensure that something was detected] **************************************************************************************************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Was not able to determine installation source for sops latest for MacOSX 13.0.1. Please open an issue in https://github.com/ansible-collections/community.sops/issues if you think this should work."}

NO MORE HOSTS LEFT **************************************************************************************************************************************************************************************************************************************

PLAY RECAP **********************************************************************************************************************************************************************************************************************************************
127.0.0.1                  : ok=7    changed=0    unreachable=0    failed=1    skipped=2    rescued=0    ignored=0

Release planning

Let's use this issue to discuss when to release a new version.

Collection requirements: repository structure

Following https://github.com/ansible-collections/overview/blob/5185727690d3fdef2d7ef44ae893e2c2ac9b5f6e/collection_requirements.rst#repo-structure

galaxy.yml

  • The tags field MUST be set

  • Collection dependencies used are expected to be stable, hence MUST be set to '>=1.0.0'

    • This means that all collection dependencies have to specify lower bounds on the versions, and these lower bounds should be stable releases, and not versions of the form 0.x.y.

    • When creating new collections where collection dependencies are also under development, you need to watch out since Galaxy checks whether dependencies exist in the required versions:

      1. Assume that foo.bar depends on foo.baz
      2. First release foo.baz as 1.0.0.
      3. Then modify foo.bar's galaxy.yml to specify '>=1.0.0' for foo.baz
      4. Finally release foo.bar as 1.0.0

README.md

meta/runtime.yml

Example: meta/runtime.yml

  • MUST define the minimum version of Ansible which this collection works with

    • If the collection works with Ansible 2.9, then this should be set to >=2.9.10
    • It's usually better to avoid adding <2.11 as a restriction, since this for example makes it impossible to use the collection with the current ansible-base devel branch (which has version 2.11.0.dev0)

Modules & Plugins

Documentation

All module and plugin DOCUMENTATION and RETURN MUST:

  • Use the FQCN for M(...) and - module: references of seealso subsections. See Linking within module documentation <https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#linking-within-module-documentation>_

  • Use the field version_added to document the version of the collection for which an option, module or plugin was added.

    • Use collection version numbers for version_added, and not Ansible version numbers or other unrelated version numbers.
    • If you for some reason really have to specify version numbers of Ansible or of another collection, you have to provide version_added_collection. We strongly recommend to NOT do this.
    • Not every option, module or plugin must have version_added. You should use it to mark when new content (modules, plugins, options) were added to the collection. The values are shown in the documentation, and this can be very useful for your users.

All module and plugin EXAMPLES MUST:

  • Use FQCN for module (or plugin) name.
  • For modules (or plugins) left in ansible-base use ansible.builtin. as a FQCN prefix, for example, ansible.builtin.template

Other items:

  • You MUST Use the FQCN for extends_documentation_fragment:, unless you are referring to doc_fragments from ansible-base
  • The CONTRIBUTING.md (or README.md) file MUST state what types of contributions (pull requests, feature requests, and so on) are accepted and any relevant contributor guidance. Issues (bugs and feature request) reports must always be accepted

convenience playbooks fail to missing facts

SUMMARY

Coming from https://docs.ansible.com/ansible/latest/collections/community/sops/docsite/guide.html

the Task Install system packages
https://github.com/ansible-collections/community.sops/blob/b7bfe2a78660de3ceb37f3ccc84c3255ef007fa1/roles/install/tasks/main.yml#LL68C5-L68C5
Fails to the missing facts gathering here
https://github.com/ansible-collections/community.sops/blob/b7bfe2a78660de3ceb37f3ccc84c3255ef007fa1/playbooks/install_localhost.yml#LL7C22-L7C22
Here I'm unsure if the Documentation or the playbook should be updated.
setting the \"use\" option option could maybe be done, not not yet seen this option.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

task

ANSIBLE VERSION
ansible [core 2.13.1]
  config file = None
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/.local/bin/ansible
  python version = 3.10.11 (main, Apr  5 2023, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)]
  jinja version = 3.0.3
  libyaml = False
COLLECTION VERSION
# /home/user/.local/lib/python3.10/site-packages/ansible_collections
Collection     Version
-------------- -------
community.sops 1.2.2  

# /home/user/.ansible/collections/ansible_collections
Collection     Version
-------------- -------

CONFIGURATION
---
OS / ENVIRONMENT

Fedora 38

STEPS TO REPRODUCE
ansible-playbook community.sops.install_localhost
EXPECTED RESULTS

No failure

ACTUAL RESULTS
TASK [community.sops.install : Install system packages] **************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: NoneType: None
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Could not detect which package manager to use. Try gathering facts or setting the \"use\" option."}

Collection requirements: CI testing

Follows https://github.com/ansible-collections/overview/blob/5185727690d3fdef2d7ef44ae893e2c2ac9b5f6e/collection_requirements.rst#licensing

CI Testing

  • You MUST run ansible-test sanity from the latest stable ansible-base/ansible-core branch.
  • You SHOULD suggest to additionally run ansible-test sanity from the ansible/ansible devel branch so that you find out about new linting requirements earlier.
  • The sanity tests MUST pass.
    • Adding some entries to the test/sanity/ignore*.txt file is an allowed method of getting them to pass, except cases listed below.
    • You SHOULD not have ignored test entries. A reviewer can manually evaluate and approve your collection if they deem an ignored entry to be valid.
    • You MUST not ignore the following validations. They must be fixed before approval:
      validate-modules:doc-choices-do-not-match-spec
      validate-modules:doc-default-does-not-match-spec
      validate-modules:doc-missing-type
      validate-modules:doc-required-mismatch
      validate-modules:mutually_exclusive-unknown
      validate-modules:nonexistent-parameter-documented
      validate-modules:parameter-list-no-elements
      validate-modules:parameter-type-not-in-doc
      validate-modules:undocumented-parameter
    • All entries in ignores.txt MUST have a justification in a comment in the ignore.txt file for each entry. For example plugins/modules/docker_container.py use-argspec-type-path # uses colon-separated paths, can't use type=path.
    • Reviewers can block acceptance of a new collection if they don't agree with the ignores.txt entries.
  • You MUST run CI against each of the "major versions" (2.10, 2.11, 2.12, etc) of ansible-base/ansible-core that the collection supports. (Usually the HEAD of the stable-xxx branches.)
    • All CI tests MUST run against every pull request and SHOULD pass before merge.
    • All CI tests MUST pass for the commit that releases the collection.
    • All CI tests MUST run regularly (nightly, or at least once per week) to ensure that repos without regular commits are tested against the latest version of ansible-test from each ansible-base/ansible-core version tested.

All of the above can be achieved by using the following GitHub Action template, see this example.

- path_regex of .sops.yaml uses wrong input

SUMMARY

It checks the value of the current working directory instead the path of the file

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.sops.sops_encrypt

ANSIBLE VERSION

$ ansible --version
ansible [core 2.12.5]
config file = None
configured module search path = ['/home/tfoerste/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /home/tfoerste/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/lib/python-exec/python3.9/ansible
python version = 3.9.12 (main, Apr 29 2022, 22:11:52) [GCC 11.2.1 20220115]
jinja version = 3.1.2
libyaml = True

OS / ENVIRONMENT

LInux (Gentoo), Mac

Release 0.1.0

Opening this task to coordinate the release of the first version 🎉

Follows #5 and #8

@felixfontein is there something else I need to do before this release? Will the Changelog be created automatically or should I take care of that?


Release process:

  • push tag 0.1.0

How to test the vars plugin?

The old pre-collections PR for the sops vars plugins was easy to test , just drop it in a plugins/var dir, add vars_plugins to your ansible.cfg and you were off.

However now things are more complicated, and aren't working.

I have the collection installed from my reqs file:

collections:
  - type: git
    name: https://github.com/ansible-collections/community.sops.git
    version: 762eec08170d98d1a253cb2aa6fe120fa1f98b80

Yet, Ansible isn't picking up the plugin.

please accept "age" keys like "kms"

Rationale:

Currently we have the age keys within .sops.yaml specified.
But path_regex cannot be used in creation_rules b/c the input filename is alwaqys /dev/stdin.
So we cannot have different age keys for different files to be encrypted currently.

lookup 'sops' not found

Problem

I don't know why, but only writing

ansible localhost -m debug -a msg="{{ lookup('sops', 'test.yml') }}"

leads to...

localhost | FAILED! => {
    "msg": "lookup plugin (sops) not found"
}

The current solution is to reference the fully qualified lookup name:

ansible localhost -m debug -a msg="{{ lookup('community.sops.sops', 'test.yml') }}"

Context

  • ansible 2.10.1rc3
  • python version = 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]

Installed 'community.sops' with

ansible-galaxy collection install -r requirements.yml

... whereas requirements.yml contains:

collections:
  - name: https://github.com/ansible-collections/community.sops.git
    type: git

Collection requirements: collection infrastructure

Follows https://github.com/ansible-collections/overview/blob/5185727690d3fdef2d7ef44ae893e2c2ac9b5f6e/collection_requirements.rst#collection-infrastructure

Collection Infrastructure

  • MUST have a publicly available issue tracker, that does not require a paid level of service to create an account or view issues.
  • Collections MUST have a Code of Conduct (CoC)
    • The collection's CoC MUST be compatible with the Ansible CoC
    • Collections SHOULD consider using the Ansible CoC if they do not have a CoC that they consider better
    • The Diversity and Inclusion working group may evaluate all CoCs and object to a collection's inclusion based on the CoCs contents
  • MUST be published to Ansible Galaxy.

Inclusion in Ansible 3.0.0

SUMMARY

While it not totally clear yet what the conditions will be for new collections to be included in Ansible 2.11, I think community.sops has good chances:

If we want to get included, I suggest we use this ticket to track that.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

collection

cannot install the collection

SUMMARY

Seems like sops is not added to galaxy:

ansible-galaxy collection install community.sops
Process install dependency map
ERROR! Failed to find collection community.sops:*
ISSUE TYPE
  • Installation issue
COMPONENT NAME

community.sops

ANSIBLE VERSION

ansible --version
ansible 2.9.10
  config file = None
  python version = 3.7.6 (default, Dec 30 2019, 19:38:26) [Clang 11.0.0 (clang-1100.0.33.16)]

CONFIGURATION
OS / ENVIRONMENT

macOS

STEPS TO REPRODUCE
ansible-galaxy collection install community.sops

Lookup plugin strips newline by default creating issues with ssh private keys

SUMMARY

Lookup plugin strips newline by default creating issues with ssh private keys. When copying the key the following error may be observed when trying to use the resulting key in an ssh session due to the default nature of the lookup plugin stripping trailing newlines.

Load key "/home/my_user_id/.ssh/my_ssh_private_key": invalid format

######################
Current documentation:
######################

lookup plugin

The lookup plugin can be accessed with the community.sops.sops key.

Examples:

tasks:

  • name: Output secrets to screen (BAD IDEA!)
    ansible.builtin.debug:
    msg: "Content: {{ lookup('community.sops.sops', '/path/to/sops-encrypted-file.enc.yaml') }}"

  • name: Add SSH private key
    ansible.builtin.copy:
    content: "{{ lookup('community.sops.sops', user + '-id_rsa') }}"
    dest: /home/{{ user }}/.ssh/id_rsa
    owner: "{{ user }}"
    group: "{{ user }}"
    mode: 0600
    no_log: true # avoid content to be written to log

#######################################################
Proposed update: add the option for rstrip to the ssh key example
#######################################################
### lookup plugin

The lookup plugin can be accessed with the community.sops.sops key.

Examples:

tasks:

  • name: Output secrets to screen (BAD IDEA!)
    ansible.builtin.debug:
    msg: "Content: {{ lookup('community.sops.sops', '/path/to/sops-encrypted-file.enc.yaml') }}"

  • name: Add SSH private key
    ansible.builtin.copy:
    content: "{{ lookup('community.sops.sops', user + '-id_rsa', rstrip='no') }}"
    dest: /home/{{ user }}/.ssh/id_rsa
    owner: "{{ user }}"
    group: "{{ user }}"
    mode: 0600
    no_log: true # avoid content to be written to log

ISSUE TYPE
  • Documentation Report
COMPONENT NAME

Lookup plugin

ANSIBLE VERSION
ansible 2.10.8

Cannot build release changelog

@felixfontein while building the changelog for the release I encountered this error:

❯ antsibull-changelog release -v
ERROR! vars community.sops.sops missing documentation (or could not parse documentation): unknown doc_fragment(s) in file /tmp/antsibull-changelog075ng27d/collections/ansible_collections/community/sops/plugins/vars/sops.py: ansible.builtin.vars_plugin_staging
Traceback (most recent call last):
  File "/home/endorama/.cache/pypoetry/virtualenvs/community.sops-kPWhnm6H-py3.8/lib/python3.8/site-packages/antsibull_changelog/cli.py", line 228, in run
    return arguments.func(arguments)
  File "/home/endorama/.cache/pypoetry/virtualenvs/community.sops-kPWhnm6H-py3.8/lib/python3.8/site-packages/antsibull_changelog/cli.py", line 435, in command_release
    plugins = load_plugins(paths=paths, collection_details=collection_details,
  File "/home/endorama/.cache/pypoetry/virtualenvs/community.sops-kPWhnm6H-py3.8/lib/python3.8/site-packages/antsibull_changelog/plugins.py", line 400, in load_plugins
    _load_collection_plugins(plugins_data, paths, collection_details, use_ansible_doc)
  File "/home/endorama/.cache/pypoetry/virtualenvs/community.sops-kPWhnm6H-py3.8/lib/python3.8/site-packages/antsibull_changelog/plugins.py", line 350, in _load_collection_plugins
    plugins_data['plugins'][plugin_type] = load_plugin_metadata(
  File "/home/endorama/.cache/pypoetry/virtualenvs/community.sops-kPWhnm6H-py3.8/lib/python3.8/site-packages/antsibull_changelog/plugins.py", line 298, in load_plugin_metadata
    plugins_data = run_ansible_doc(paths, playbook_dir, plugin_type, plugins_list)
  File "/home/endorama/.cache/pypoetry/virtualenvs/community.sops-kPWhnm6H-py3.8/lib/python3.8/site-packages/antsibull_changelog/plugins.py", line 267, in run_ansible_doc
    output = subprocess.check_output(command)
  File "/home/endorama/.asdf/installs/python/3.8.10/lib/python3.8/subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/home/endorama/.asdf/installs/python/3.8.10/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ansible-doc', '--json', '-t', 'vars', '--playbook-dir', '/tmp/antsibull-changelog075ng27d', 'community.sops.sops']' returned non-zero exit status 1.

The line unknown doc_fragment(s) in file /tmp/antsibull-changelog075ng27d/collections/ansible_collections/community/sops/plugins/vars/sops.py: ansible.builtin.vars_plugin_staging point to line 66 in sops.py vars plugin:

extends_documentation_fragment:
- ansible.builtin.vars_plugin_staging
- community.sops.sops

Is it ok to remove that line? Has been added in #32

I'm using antsibull-changelog 0.11.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.