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

openssl_privatekey module's passphrase is obfuscated from unexpected places #590

Open
alxgomz opened this issue Apr 5, 2023 · 2 comments

Comments

@alxgomz
Copy link

alxgomz commented Apr 5, 2023

SUMMARY

When generating a private key using community.crypto.openssl_privatekey the passphrase used is obfuscated in the whole output. While this can appear a good security measure it can actually be problematic or even leak the passphrase it self without realizing it.
the more complex the passphrase the less likely it happens but that's still a problem. In all honesty, that happened to me while working on molecule tests which use a dummy password but that sound like a security risk to me still.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

openssl_privatekey

ANSIBLE VERSION
ansible [core 2.12.5]
  config file = /Users/xxxxx/tmp/test/ansible/ansible.cfg
  configured module search path = ['/Users/xxxxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/xxxxx/.virtualenvs/aad/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/xxxxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/xxxxx/.virtualenvs/aad/bin/ansible
  python version = 3.9.16 (main, Dec  7 2022, 10:16:11) [Clang 14.0.0 (clang-1400.0.29.202)]
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION
Collection       Version
---------------- -------
community.crypto 2.10.0
CONFIGURATION
DEFAULT_FILTER_PLUGIN_PATH(/Users/xxxxx/tmp/test/ansible/ansible.cfg) = ['/Users/xxxxx/tmp/test/ansible/share/plugins/filter']
OS / ENVIRONMENT

MacOSX & Linux

STEPS TO REPRODUCE

just run the playbook bellow

---
- hosts: localhost
  gather_facts: false
  tasks:
    - name: Generate CA
      community.crypto.openssl_privatekey:
        backup: true
        path: /tmp/myCA.crt
        passphrase: tmp/myCA
        cipher: auto
      register: cakey

    - debug:
        var: cakey
EXPECTED RESULTS

the registered variable should have a pristine payload where no data is obfuscated or redacted.

ACTUAL RESULTS

The registered var's payload contains ******** obfuscation string (here in the filename attribute but it could be somewhere else).
This make the registered variable unusable in subsequent tasks and gives very good hints of what the passphrase actually is (e.g. in the case, should you know the destination path, you'd be able to guess the passphrase.

ok: [localhost] => {
    "cakey": {                 
        "changed": true,                                                   
        "diff": {   
            "after": {     
                "can_parse_key": true,
                "key_is_consistent": null,
                "public_data": {
                    "exponent": 65537,
                    "modulus": 93089325085453677931699883481848815110737166793833508624510226993946482226599374790748216726165739090327109244423092512
836643520421098276338671531504563049504083339782358563986351560182143002664965881636467464879002882188505335542016615001578016721048526103482129388559
019947562222309786971140684087082789856040581899013966395066757399162966769130458743633737328576632389015262045329979992018310838454182214185773652614
832515702524603284395596561101164793990017393908807564418314017244510868124867672448916773496357750381956431653462562963818302699168707984201470548257
256183708278821692422875047610198528828941716225447341930054603845486331472616628265033505728704405606484375688021414172225693916811892071237670519783
184323664624033722401912196503453604369356635107757739064727304508092998012275303264756476858266380188315591476661209716230209676730503501097947360709
408888288412438963019653167733769414796921017200456988833209675318849427449259687690945225957077415721237096604372097167642325725939144340373739601089
374935128333332511157092059240902548832291541652164390233908314023853025966684824486512224072100492786295403462229379050287156089114092268870918954063
3077332998465447522416658259276976102949645362223442333769151517,                                                                                     
                    "size": 4096                                                                                                                      
                },                                                                                                                                    
                "public_key": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA5C4VkB0SuQhH6WuW8tTr\nGZjTCsg88XVzfSC4zFiVX7mP6
AOXTJ0SoNi93xhmmkXH6VBNMpgiFDZgU4/jBz/r\n+OqDasUU4h045KepvYVk11OHC0ZYjqgz07F4CuhuqMOGlO5WI3Ct5b9USiduU2Te\nuKT4V1GdYu65lfUEnyGTJAFdxz9QLKX/lGUz9wPlL3H
1wCnWeYv9uaBIjCcu74gA\nzJoq2G2j0OmJKr62Q2JsAyebtZAQtOP4m6MoWlOT+2hZSAKsuaIQyxsqMSqdXm8H\n6CRkqI88agDZEAebJRnJWs1QHo2q57TQwYXokwXwQAcpATbZkMxY1GBq2ibEu
Q89\nbDdH5/MlF1BJDgijlInUMEroxwfujjX5VA9aeoRBYnOkpRboEGXOm5mgLlFOvSm3\nW26/QXO3HtqCVk1AiyIomFOEDaMPSXEOXGQDvw5kjaxbiUh1dbWkStKoLQT/sleh\nzt1KECzu+cbTY
GLdv2NbqdkPf8jfz/LUbkCAvQ4rWUkhgU9r0O2F8VWwG3GWv711\nRnsIDT72xswS3gB8bSROu1Yx3ahCdKr9y3OGJdSlA2H2kranz5HT2q6EXDAwKn9Z\n4+wfAuVYcLo+5KuZMZadsU6BpYIQ4pY
iX7V3FgohihBlpAuRG1i5+IwqfaHUfs2f\nMXZ5h86Ez6Umsf78aUWgNB0CAwEAAQ==\n-----END PUBLIC KEY-----\n",
                "public_key_fingerprints": {
                    "sha256": "ce:4a:a9:e9:e0:bb:70:98:83:fb:ee:da:29:d5:06:cd:06:4a:42:47:fd:85:90:f4:b8:14:cf:d1:13:0a:c3:1f"
                },
                "type": "RSA"
            },
            "before": {}
        },
        "failed": false,
        "filename": "/tmp/********.crt",
        "fingerprint": {
            "blake2b": "a1:94:b1:c0:9f:e9:48:55:fd:6f:6f:92:2a:e8:62:8a:ae:8a:e8:4e:20:43:ad:3e:d3:6e:9d:f5:7c:e2:f6:5e:1a:36:d7:5e:ea:a2:cb:40:0c:00:
9d:9c:14:0d:11:36:53:2b:0a:fa:c6:d5:c5:33:c6:ad:22:8f:1d:1f:34:c7",
            "blake2s": "65:43:7d:dd:c6:b3:c1:01:57:97:87:f9:33:1a:6d:8a:e8:0f:13:21:70:d0:96:90:73:4c:b3:d2:c5:35:81:fb",
            "md5": "d5:ef:09:1b:56:4b:3a:53:a8:80:d2:97:0e:63:84:cc",
            "sha1": "df:31:75:d5:f1:41:5a:3d:65:cf:73:d8:56:78:d5:77:14:ea:a2:1f",
            "sha224": "b0:11:bc:1c:20:27:6e:72:5f:7b:a2:0a:fe:4e:b5:0f:c7:7d:9a:49:ad:99:68:7e:a1:ac:b4:94",
            "sha256": "ce:4a:a9:e9:e0:bb:70:98:83:fb:ee:da:29:d5:06:cd:06:4a:42:47:fd:85:90:f4:b8:14:cf:d1:13:0a:c3:1f",
            "sha384": "8e:ba:cc:b4:a1:6d:18:b6:3c:ff:41:2f:b1:e0:dd:e2:18:73:03:19:42:16:85:16:d9:59:82:e1:fa:07:cf:b2:ee:b3:57:64:d7:13:15:c6:d9:80:0
d:3d:68:04:29:4c",
            "sha3_224": "a8:d1:0d:43:06:05:2d:7d:8a:57:ea:77:92:da:bc:e4:de:5f:c8:02:8b:22:42:bf:6c:80:70:9d",
            "sha3_256": "c8:55:73:d8:4f:03:54:31:df:64:56:fd:17:a3:cc:af:53:47:76:f8:7f:7c:b9:04:8f:22:d2:76:96:94:6a:f8",
            "sha3_384": "69:5d:21:f1:de:db:52:6b:51:44:e4:0b:13:70:13:80:8b:33:ce:e6:b3:c0:1a:d1:4b:d5:79:ab:00:ba:7c:23:1a:8b:3f:51:96:43:66:0a:79:c7
:ab:35:e8:5a:ba:16",
            "sha3_512": "5d:b7:06:08:09:13:a4:4e:01:61:1c:35:84:c2:af:fd:16:03:e3:bb:65:50:12:df:fa:3e:9d:e3:7a:30:6a:5e:85:ea:59:bd:5e:f3:89:33:e4:fc
:62:a9:10:66:fe:65:8c:97:06:65:34:7d:51:65:60:b2:fd:f9:e6:e4:cf:26",
            "sha512": "12:06:ac:23:86:f0:7e:41:e0:a8:eb:77:cb:a1:9d:35:16:75:1d:17:99:57:35:3d:1a:24:c5:c4:00:3d:76:3c:a1:ac:7f:c6:b4:70:8f:71:74:28:e
8:67:f5:5c:62:eb:c2:63:f5:4f:f9:f6:eb:a3:4b:3a:dc:85:46:51:91:51",
            "shake_128": "70:fd:49:1e:7c:bf:1f:8d:e3:db:f9:08:f4:09:ae:b3:fe:b8:1c:88:32:de:6d:eb:9d:6c:79:12:03:9a:cb:b8",
            "shake_256": "07:8f:67:83:30:9f:97:19:41:76:7c:fa:d3:13:b4:05:68:5d:17:21:01:3e:5b:14:05:30:2a:30:b3:dc:1d:1b"
        },
        "size": 4096,
        "type": "RSA"
    }
}
@alxgomz
Copy link
Author

alxgomz commented Apr 5, 2023

looks similar to #587 in some way but I decided to open a new issue to bring proper reproduction steps (and the previous submiter seemed to say his passphrase was not matching output strings)

@felixfontein
Copy link
Contributor

This is unfortunately by design of ansible-core, and there's nothing this collection can do about it (except telling users to use proper passwords that don't show up in filenames or other random information).

The only thing we (on our side) could do is not mark the passphrase fields as no_log=True in the argument spec, but then AnsibleModule will automatically log these values (I for example can see them in the syslog of the machine where the module is executed on), which is something I think we can agree on that should never ever happen :)

the more complex the passphrase the less likely it happens

It's very unlikely if you are using a serious (randomly generated) passphrase. Assuming a 8-char passphrase where every char is taken from the lower- and uppercase ASCII letters + digits, the chance that it matches a random 8-char sequence is less than 10^-14. That is similar likely as winning a 6 from 49 lottery jackpot twice in a row.

alxgomz added a commit to Alfresco/alfresco-ansible-deployment that referenced this issue Apr 7, 2023
alxgomz added a commit to Alfresco/alfresco-ansible-deployment that referenced this issue Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants