close
The Wayback Machine - https://web.archive.org/web/20200929203422/https://github.com/saltstack/salt/issues/56645
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

[BUG] gpg.encrypt text=foo output=/some/file does not write to a file #56645

Open
oeuftete opened this issue Apr 15, 2020 · 4 comments
Open

[BUG] gpg.encrypt text=foo output=/some/file does not write to a file #56645

oeuftete opened this issue Apr 15, 2020 · 4 comments

Comments

@oeuftete
Copy link
Contributor

@oeuftete oeuftete commented Apr 15, 2020

Description

A clear and concise description of what the bug is.

Setup

Create/import a GPG key.

Steps to Reproduce the behavior

Try to encrypt some text:

[root@master1 salt]# salt-call gpg.encrypt text=foo recipients=2CFCA2B538DD0FAC75838096A4E89A0D3328D483 output=/tmp/encypted_foo.txt user=salt
local:
    ----------
    comment:
        Encrypted data has been written to /tmp/encypted_foo.txt
    res:
        True
[root@master1 salt]# cat /tmp/encypted_foo.txt
cat: /tmp/encypted_foo.txt: No such file or directory

Expected behavior

The file should be created.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
# salt-call test.versions_report
local:
    Salt Version:
               Salt: 3000.1
     
    Dependency Versions:
               cffi: Not Installed
           cherrypy: Not Installed
           dateutil: Not Installed
          docker-py: Not Installed
              gitdb: Not Installed
          gitpython: Not Installed
             Jinja2: 2.7.2
            libgit2: Not Installed
           M2Crypto: Not Installed
               Mako: Not Installed
       msgpack-pure: Not Installed
     msgpack-python: 0.6.2
       mysql-python: Not Installed
          pycparser: Not Installed
           pycrypto: 2.6.1
       pycryptodome: Not Installed
             pygit2: Not Installed
             Python: 2.7.5 (default, Aug  7 2019, 00:51:29)
       python-gnupg: 0.4.3
             PyYAML: 3.11
              PyZMQ: 15.3.0
              smmap: Not Installed
            timelib: Not Installed
            Tornado: 4.5.3
                ZMQ: 4.1.4
     
    System Versions:
               dist: centos 7.6.1810 Core
             locale: UTF-8
            machine: x86_64
            release: 5.3.0-46-generic
             system: Linux
            version: CentOS Linux 7.6.1810 Core
@oeuftete
Copy link
Contributor Author

@oeuftete oeuftete commented Apr 15, 2020

Pretty straightforward to see. The text case doesn't have any logic to output to file, the filename case does:

salt/salt/modules/gpg.py

Lines 1190 to 1205 in 5c450f3

if text:
result = gpg.encrypt(text, recipients, passphrase=gpg_passphrase)
elif filename:
if GPG_1_3_1:
# This version does not allow us to encrypt using the
# file stream # have to read in the contents and encrypt.
with salt.utils.files.flopen(filename, 'rb') as _fp:
_contents = salt.utils.stringutils.to_unicode(_fp.read())
result = gpg.encrypt(_contents, recipients, passphrase=gpg_passphrase, output=output)
else:
# This version allows encrypting the file stream
with salt.utils.files.flopen(filename, 'rb') as _fp:
if output:
result = gpg.encrypt_file(_fp, recipients, passphrase=gpg_passphrase, output=output, sign=sign)
else:
result = gpg.encrypt_file(_fp, recipients, passphrase=gpg_passphrase, sign=sign)

But either way, the return says the file was written if the result was ok.

salt/salt/modules/gpg.py

Lines 1209 to 1212 in 5c450f3

if result.ok:
if not bare:
if output:
ret['comment'] = 'Encrypted data has been written to {0}'.format(output)

@ritwikbadola
Copy link

@ritwikbadola ritwikbadola commented Apr 27, 2020

Can I try and solve this issue ?

@oeuftete
Copy link
Contributor Author

@oeuftete oeuftete commented Apr 27, 2020

Can I try and solve this issue ?

@ritwikbadola Definitely! Here's a link to information on contributing: https://docs.saltstack.com/en/latest/topics/development/contributing.html

@julianpacheco
Copy link

@julianpacheco julianpacheco commented Jun 5, 2020

Hope you don't mind @ritwikbadola I just entered a PR to resolve this issue since it's still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Aluminium
Awaiting triage
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.