Salt: Warnings from salt.pillar.gpg in Fluorine

Created on 11 Dec 2018  路  8Comments  路  Source: saltstack/salt

Description of Issue/Question

It looks like some changes in #45781 or #46542 broke the salt.pillar.gpg https://docs.saltstack.com/en/latest/ref/pillar/all/salt.pillar.gpg.html:

% tail -2 etc/salt/minion
ext_pillar:
  - gpg: {}

% cat pillar/test.sls
key: value

% LANG=C salt-call --local pillar.items
[WARNING ] Could not decrypt cipher value, received: b'gpg: no valid OpenPGP data found.\n[GNUPG:] NODATA 1\n[GNUPG:] NODATA 2\ngpg: decrypt_message failed: eof\n'
[WARNING ] Could not decrypt cipher value, received: b'gpg: no valid OpenPGP data found.\n[GNUPG:] NODATA 1\n[GNUPG:] NODATA 2\ngpg: decrypt_message failed: eof\n'
local:
    ----------
    key:
        value

If I restore the salt/renderers/gpg.py back to the 2013.3.3 state, everything works as expected.

Versions Report

Salt fluorine branch, revision 241741a6d0104ffec9d2aaf29bb579e945c0c39a

CC: @secumod @DmitryKuzmenko

Bug P3 severity-medium

Most helpful comment

Done. =)

All 8 comments

This is also slower, because it attempts to decrypt each pillar value, even if there is no PGP signature:

        # Possibly just encrypted data without begin/end marks
        return _decrypt_ciphertext(cipher)

At least two tests need to be added:

  1. That there are no attempts to decrypt unencrypted keys
  2. That there are no WARNINGs in the log

Looking at the code I think it is #46542 because when I did #45781 my assumption was we always annotate PGP ciphertext with proper BEGIN/END marks. However, it seems we also want to have unannotated PGP ciphertext, which was fixed in #46542.

I'm not sure what the proper behaviour should be here, because if we want "no attempts to decrypt unencrypted keys" but still want support for "unannotated PGP ciphertext", we need some way to identify OpenPGP messages without BEGIN/END marks. We can do that by trying to parse the data according to RFC 4880, but in your setup that would still make it slow, because it will try to parse every pillar value by default.

In my opinion, gpg renderer should not be enabled by default for all pillars, but rather in specific files in a "shebang" line on as-needed basis. Apart from mentioned performance issues you may as well get security issues, because the salt-master has only one master decryption key. If you by accident stick your encrypted value into the wrong file - it will still be rendered and decrypted - therefore the secret may potentially leak to a less trusted minion. By specifying the gpg renderer explicitly only in files, which really need it, there is less risk it may happen.

And from security perspective with on-needed gpg renderer the WARNING message is justified in my opinion: if your pillar definition does not have any secrets - the renderer for this pillar should be disabled to avoid someone accidentally modifying the definition and leaking some sensitive data.

But all these are just my thoughts - I guess the maintainers should agree what the proper behaviour should be here.

In my opinion, gpg renderer should not be enabled by default for all pillars

See the docs I mentioned above: https://docs.saltstack.com/en/latest/ref/pillar/all/salt.pillar.gpg.html
It is not possible to add the GPG renderer to external pillars without enabling it globally. If you use any of the following pillar backends, you will lose the ability to encrypt the data: https://docs.saltstack.com/en/latest/ref/pillar/all/index.html#all-salt-pillars

but rather in specific files in a "shebang" line on as-needed basis.

Many folks use the different strategy: they only encrypt some of the pillar values. Forcing them to encrypt everything or split their pillar files seems wrong, and reduces the master performance.

@DmitryKuzmenko Are you sure that the ability to decrypt raw data was actually there? This is the code before #45781: https://github.com/saltstack/salt/pull/45781/files#diff-2c20356d759feadcae8c50c2a46596c6L303. The logic is quite straightforward - if GPG_HEADER.search(obj) is False, then the obj value is returned as is, without any attempts to decrypt it.

@max-arnold just re-reviewed the original code and my update. Yes you're right. I've been confused by the original test that was calling _decrypt_ciphertext with raw crypted data.
So the correct fix would be to change https://github.com/saltstack/salt/pull/46542/files#diff-2c20356d759feadcae8c50c2a46596c6R303 to return cipher. And update the test accordingly.

@DmitryKuzmenko You or me? :)

Done. =)

Backported the fix to fluorine #50831

I can confirm that the issue is solved. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qiushics picture qiushics  路  3Comments

nixjdm picture nixjdm  路  3Comments

sfozz picture sfozz  路  3Comments

udf2457 picture udf2457  路  3Comments

golmaal picture golmaal  路  3Comments