-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[BUG] gpg.decrypt not working when use_passphrase=True #62806
Comments
@OrangeDog You still around? If you have time, could you please verify this issue? |
That line does indeed look wrong, and other functions in the module don't have it. It was added by @garethgreenaway in 641b719. It is unclear why. |
I'm guessing that when the original author wrote this, he probably had Something along the lines of: gpg_passphrase:
gpg_passphrase: ">0aX+:@>apw_mW3v>--hw5gxJ?msekrDtyG=tsBikNd.rG:ebP" Unfortunately, it's only treated as a dictionary for the As a side note -- one feature that would be really nice to have would be I might try to develop this feature when I have some time.... |
Just to be clear, the only modification that needs to happen is: --- /usr/lib/python3.10/site-packages/salt/modules/gpg.py.orig 2022-10-04 07:08:31.244654831 +0200
+++ /usr/lib/python3.10/site-packages/salt/modules/gpg.py 2022-10-04 22:45:59.934524234 +0200
@@ -1247,7 +1247,6 @@ def encrypt(
gpg_passphrase = __salt__["pillar.get"]("gpg_passphrase")
if not gpg_passphrase:
raise SaltInvocationError("gpg_passphrase not available in pillar.")
- gpg_passphrase = gpg_passphrase["gpg_passphrase"]
else:
gpg_passphrase = None
@@ -1352,7 +1351,6 @@ def decrypt(
gpg_passphrase = __salt__["pillar.get"]("gpg_passphrase")
if not gpg_passphrase:
raise SaltInvocationError("gpg_passphrase not available in pillar.")
- gpg_passphrase = gpg_passphrase["gpg_passphrase"]
else:
gpg_passphrase = None |
I finally learned the basics of mock unit testing. Ok I have the fix for this current issue along with the associated unit test. I'll push a PR out within the next few days. As a side note, I really want to rework that entire |
Description
The
gpg.decrypt
function is not working when theuse_passphrase=True
argument is present.Setup
I'm simply following the examples listed here.
https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.gpg.html
Steps to Reproduce the behavior
create a gpg key
salt-call gpg.create_key key_type='rsa' key_length=3072 name_real=logrotate name_email=logrotate@localhost expire_date=0 use_passphrase=True
encrypt file
salt-call gpg.decrypt filename='/root/script.py.asc' use_passphrase=True
This is the resulting error:
Expected behavior
It should decrypt the file
Versions Report
salt --versions-report
Salt Version: Salt: 3005Dependency Versions:
cffi: 1.15.0
cherrypy: Not Installed
dateutil: 2.8.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.0.3
libgit2: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.3
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.20
pycrypto: Not Installed
pycryptodome: 3.15.0
pygit2: Not Installed
Python: 3.10.7 (main, Sep 7 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-1)]
python-gnupg: 0.5.0
PyYAML: 6.0
PyZMQ: 22.3.0
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.4
System Versions:
dist: fedora 36
locale: utf-8
machine: x86_64
release: 5.19.11-200.fc36.x86_64
system: Linux
version: Fedora Linux 36
PASTE HERE
Additional context
Add any other context about the problem here.
This issue is caused by this:
/usr/lib/python3.10/site-packages/salt/modules/gpg.py
If I comment out that
gpg_passphrase = gpg_passphrase["gpg_passphrase"]
line, it works fine.Not sure what the purpose of that line is anyway.
The
gpg_passphrase
has already been set withgpg_passphrase = __salt__["pillar.get"]("gpg_passphrase")
Note:
gpg.encrypt
also fails whenuse_passphrase=True
is providedand commenting out/removing that
gpg_passphrase = gpg_passphrase["gpg_passphrase"]
line in the encrypt function resolves the issue.The text was updated successfully, but these errors were encountered: