Skip to content

salt-cloud prints minions private key to output #56069

Open

Description

@DagW

Description of Issue

We are running salt-cloud commands from an Orchestration via Jenkins, and saw the minions private key being printed out to the logs.
I'd rather not see this in the output!

Example output from the cloud.create command:

    "__id__": "salt-cloud-create",
    "__run_num__": 1,
    "__sls__": "orch.aws.provision-host",
    "changes": {
        "ret": {
            "instance-hostname.com-create-runner": {
                "instance-hostname.com": {
                    "deploy_kwargs": {
                        "name": "instance-hostname.com",
                        "vm_": {
                            ........
                            "priv_key": "-----BEGIN RSA PRIVATE KEY-----\n entire private key contents here",
                            .........
                        }
                    }
                }
            }
        }
    }

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)
Example SLS file

salt-cloud-create:
  salt.parallel_runners:
  - runners:
      instance-cloud-create-runner-1:
      - name: cloud.create
      - kwarg:
          instances:
          - instance.cloud
          provider: ec2-provider
          availability_zone: eu-central-1b
          image: ami-04cf43aca3e6f3de3
          size: t3.small
          rename_on_destroy: true
          ssh_username: centos

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)
Run the following example sls file.

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

> salt-cloud -V
Salt Version:
            Salt: 2019.2.0

Dependency Versions:
 Apache Libcloud: 2.2.1
            cffi: 1.6.0
        cherrypy: 5.6.0
        dateutil: 2.6.1
       docker-py: Not Installed
           gitdb: 0.6.4
       gitpython: 1.0.1
           ioflo: Not Installed
          Jinja2: 2.7.2
         libgit2: 0.26.3
         libnacl: Not Installed
        M2Crypto: 0.31.0
            Mako: Not Installed
    msgpack-pure: Not Installed
  msgpack-python: 0.5.6
    mysql-python: Not Installed
       pycparser: 2.14
        pycrypto: 2.6.1
    pycryptodome: Not Installed
          pygit2: 0.26.4
          Python: 2.7.5 (default, Jun 20 2019, 20:27:34)
    python-gnupg: Not Installed
          PyYAML: 3.11
           PyZMQ: 15.3.0
            RAET: Not Installed
           smmap: 0.9.0
         timelib: Not Installed
         Tornado: 4.2.1
             ZMQ: 4.1.4

System Versions:
            dist: centos 7.6.1810 Core
          locale: ANSI_X3.4-1968
         machine: x86_64
         release: 3.10.0-957.21.3.el7.x86_64
          system: Linux
         version: CentOS Linux 7.6.1810 Core

Activity

  1. dhiltonp commented on Feb 6, 2020

    @dhiltonp
    Contributor

    A solution might be to change your log levels!

    I suspect this is an DEBUG or INFO log level message that is logging the results of all commands. Can you confirm this? Including the exact log message (deleting the private key/ip address) would be helpful for confirming what is going on.

  2. DagW commented on Feb 10, 2020

    @DagW
    Author

    Hello! The problem is that it is being printed in the result, and that is stored in our jenkins build logs. It's not being printed to logs.

    We are triggering an orchestration via salt-api, and in the json formatted result we can see the private key.

  3. dhiltonp commented on Feb 12, 2020

    @dhiltonp
    Contributor

    What do you think about filtering the output via a pipe prior to saving your data?

    Something like: salt-cloud... | grep -v '\"priv_key\":' >> log

  4. DagW commented on Feb 12, 2020

    @DagW
    Author

    That would work if we were running the salt-cloud commands by cli,

    But we are calling the salt-api from Jenkins to start an orchestration, and in the result JSON the key is present.

    I guess we could filter the output from salt-api in the Jenkins pipeline, before printing the result.
    Maybe there is some log level flag to the salt-api that I could use?

    However I'm not sure the private key is meant to be printed out in the output.

  5. added
    bug
    Confirmed
    and removed on Mar 10, 2020
  6. added this to the Approved milestone on Mar 10, 2020
  7. waynew commented on Mar 10, 2020

    @waynew
    Contributor

    This looks like it's probably a bug. I discussed with @dwoz and we both feel that private keys should simply never be displayed (if known).

    However, this is probably an isolated place - we should probably be doing something like filtering in our outputters for a variety of potential keys in dictionaries so they don't actually end out getting accidentally shown.

    The correct workaround for now is to filter the output, perhaps with grep as David mentioned

  8. added
    severity-critical
    Magnesium
    and removed
    severity-critical
    on Jul 6, 2020
  9. 20 remaining items

  10. added
    severity-critical
    and removed
    severity-high
    on May 4, 2021
  11. added
    Phosphorus v3005.0
    and removed
    Silicon v3004.0
    on Sep 16, 2021
  12. removed
    Phosphorus v3005.0
    on Feb 23, 2022
  13. cmcmarrow commented on Dec 6, 2022

    @cmcmarrow
    Contributor

    The core team wants to write a Protected Class that Wraps around protected data that we could then send via message pack but if it got logged it will just say PROTECTED.

  14. added
    v3000.7
    on Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ConfirmedSalt-Cloudbugseverity-criticalv3000.7

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions