Skip to content

Enable FIPS compatibility for python 3.9+ - #2189

Open
davidesba wants to merge 1 commit into
paramiko:mainfrom
davidesba:main
Open

davidesba wants to merge 1 commit into
paramiko:mainfrom
davidesba:main

Conversation

@davidesba

Copy link
Copy Markdown

Starting from python 3.9, a keyword-only argument "usedforsecurity" is introduced in hashlib hashing algorithms.
In a FIPS environment MD5 algorithm can not be used in a security context.
This change sets this not security context for MD5 fingerprint.

@jun66j5

jun66j5 commented Feb 22, 2023

Copy link
Copy Markdown
Contributor

The same pull #1928 has been requested.

@davidesba
davidesba force-pushed the main branch 3 times, most recently from 8c99aca to c598539 Compare February 22, 2023 11:51
@bskinn

bskinn commented Feb 23, 2023

Copy link
Copy Markdown
Contributor

Indeed, @jun66j5, but #1928 takes a different approach. Both might be valuable to consider.

@bskinn bskinn added Feature Feature request eval needed Triage -> maintainer signal labels Feb 23, 2023
@jvrsantacruz

Copy link
Copy Markdown

Changes in this PR do not change functionality and it should be harmless to merge.

Could we have the fix merged before evaluating the other related PR (#1928) that might bring many changes?

@bskinn

bskinn commented Feb 27, 2023

Copy link
Copy Markdown
Contributor

Changes in this PR do not change functionality and it should be harmless to merge.

Perhaps so, but that's not the only consideration.

Are there any non-FIPS circumstances where it might be desirable for the usedforsecurity argument to be passed as True?

If so, then at least some discussion seems worthwhile as to whether usedforsecurity should also be exposed in the user-facing API.

@jvrsantacruz

jvrsantacruz commented Feb 27, 2023 •

Copy link
Copy Markdown

Are there any non-FIPS circumstances where it might be desirable for the usedforsecurity argument to be passed as True?

@bskinn luckily no, the usage of md5 in the code is to calculate the fingerprint of the public key which is not a security issue as it is not hashing passwords or secrets but the public key and always that, so adding usedforsecurity=False is just a way of reflecting the current usage and it should be never True in any case.

Changed in version 3.9: All hashlib constructors take a keyword-only argument usedforsecurity with default value True. A false value allows the use of insecure and blocked hashing algorithms in restricted environments. False indicates that the hashing algorithm is not used in a security context, e.g. as a non-cryptographic one-way compression function.

https://docs.python.org/3/library/hashlib.html#hash-algorithms

@bskinn

bskinn commented Feb 27, 2023

Copy link
Copy Markdown
Contributor

@bskinn luckily no, the usage of md5 in the code is to calculate the fingerprint of the public key which is not a security issue as it is not hashing passwords or secrets but the public key and always that, so adding usedforsecurity=False is just a way of reflecting the current usage and it should be never True in any case.

Ah, ok -- makes sense.

It would be good to document this explicitly, either with a code comment or a remark in the docstring.

If there's a straightforward test that could be added, that'd be ideal too.

This also calls for a CHANGELOG entry, I think.

@bskinn bskinn removed the Feature request eval needed Triage -> maintainer signal label Feb 27, 2023
@jvrsantacruz

Copy link
Copy Markdown

Hi! How are you?

Can we help somehow to make this advance and merge it?

We're deploying a fork of paramiko and it's not the best situation.

Thank you!

@bskinn

bskinn commented May 9, 2023

Copy link
Copy Markdown
Contributor

Flagging for consideration as part of the key/auth work on #387

@scovetta

Copy link
Copy Markdown

I'd rather see the hash algorithm changed to some SHA-256 or SHA-512, since IMHO, hashing public keys is a security context, presumably because the caller would be making some decision based on the hash. So marking usedforsecurity=False would be misleading.

openstack-mirroring pushed a commit to openstack/networking-generic-switch that referenced this pull request Mar 5, 2025
In order for n-g-s to be able to run on a node in FIPS enforcing mode,
it *must* not use md5. However, paramiko's code has a get_fingerprint
call where it is fingerprinting data for the exchange to identify
a difference, which can use any algorithm realistically.

Anyhow, this is necessary because it appears that paramiko's maintainer
is not really interested in fixing the md5 usage. As a result, we're
forced to monkeypatch paramiko, which is loaded by netmiko, which is
what NGS uses.

This should be fixed in paramiko, but also it seems several changes
been proposed without forward movement.

https: //github.com/paramiko/paramiko/pull/688
https: //github.com/paramiko/paramiko/pull/1103
https: //github.com/paramiko/paramiko/pull/2189
https: //github.com/paramiko/paramiko/pull/2496
https: //github.com/paramiko/paramiko/issues/2383
https: //github.com/paramiko/paramiko/issues/396
Related-Bug: 2098819
Change-Id: Ia3fb9d2baa14be1726197d1115e92adc9ce5ce0a
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Mar 5, 2025
* Update networking-generic-switch from branch 'master'
  to b351b9136d569b02c8b94df3e52fdd10038df3c4
  - Merge "don't use paramiko's get_fingerprint (md5)"
  - don't use paramiko's get_fingerprint (md5)
    
    In order for n-g-s to be able to run on a node in FIPS enforcing mode,
    it *must* not use md5. However, paramiko's code has a get_fingerprint
    call where it is fingerprinting data for the exchange to identify
    a difference, which can use any algorithm realistically.
    
    Anyhow, this is necessary because it appears that paramiko's maintainer
    is not really interested in fixing the md5 usage. As a result, we're
    forced to monkeypatch paramiko, which is loaded by netmiko, which is
    what NGS uses.
    
    This should be fixed in paramiko, but also it seems several changes
    been proposed without forward movement.
    
    https: //github.com/paramiko/paramiko/pull/688
    https: //github.com/paramiko/paramiko/pull/1103
    https: //github.com/paramiko/paramiko/pull/2189
    https: //github.com/paramiko/paramiko/pull/2496
    https: //github.com/paramiko/paramiko/issues/2383
    https: //github.com/paramiko/paramiko/issues/396
    Related-Bug: 2098819
    Change-Id: Ia3fb9d2baa14be1726197d1115e92adc9ce5ce0a
rnetser pushed a commit to RedHatQE/openshift-virtualization-tests that referenced this pull request Oct 5, 2026
…6430)

##### What this PR does / why we need it:

On FIPS-enabled clusters, the `ocp-virt-validation-checkup-rhel9` image
uses RHEL 9.8 as base with the system Python interpreter. The system
Python links `hashlib` against RHEL's system OpenSSL, which enforces
FIPS mode when the cluster has FIPS enabled
(`/proc/sys/crypto/fips_enabled = 1`).

In FIPS mode, `hashlib.md5()` without `usedforsecurity=False` raises
`UnsupportedDigestmodError`, causing all SSH connectivity checks into
VMs to fail:

```
Function: rrmngmnt.host.run_command  Kwargs: {'command': ['exit'], 'tcp_timeout': 60}
Last exception: UnsupportedDigestmodError: [digital envelope routines] unsupported.
```

**Root cause:** `paramiko.pkey.md5` (imported from `hashlib`) is called
by:
- `PKey.get_fingerprint()` — used for display/logging of host key
fingerprints in all host key policies (`AutoAddPolicy`, `RejectPolicy`,
`WarningPolicy`) and during SSH client auth
- `PKey._read_private_key_pem()` — used for password-protected PEM key
decryption

CI (Jenkins) uses the `openshift-virtualization-tests:latest` image
(Fedora 41 + `uv` standalone Python) which bundles its own OpenSSL that
does not inherit the host FIPS policy — hence no failure there.

**Upstream status:** Known paramiko bug ([issue
#396](paramiko/paramiko#396), open since
2014). Multiple PRs submitted
([#1928](paramiko/paramiko#1928),
[#2189](paramiko/paramiko#2189),
[#2496](paramiko/paramiko#2496),
[#2624](paramiko/paramiko#2624)) — none merged.
No fix in `paramiko 5.0.0`.

**Fix:** Patch `paramiko.pkey.md5` at import time via `vars()` to use
`usedforsecurity=False`. This tells OpenSSL FIPS that the MD5 usage is
not for security purposes (fingerprint display/logging only).

**Validated on a FIPS-enabled cluster:**
`test_clone_from_block_to_fs_using_dv_template` fails without the patch
and passes with it on the `ocp-virt-validation-checkup-rhel9` image.

##### Which issue(s) this PR fixes:

CNV-98463

##### Special notes for reviewer:

`vars(paramiko.pkey).update(...)` is used instead of direct attribute
assignment to avoid mypy `attr-defined`/`method-assign` errors on
third-party module patching, without requiring `# type: ignore`
(prohibited by AGENTS.md) or a broad `ignore_errors` mypy override.

##### jira-ticket:

CNV-98463

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Improved compatibility for automated test runs in FIPS-enabled
environments. Application behavior and user-facing functionality are
unchanged; this update affects test setup only and does not alter
security protections. No new end-user features or other behavior changes
are included.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Ramón Lobillo <[email protected]>
Co-authored-by: Claude Sonnet 4.6 (1M context) <[email protected]>
ameya-keskar pushed a commit to ameya-keskar/openshift-virtualization-tests that referenced this pull request Oct 6, 2026
…edHatQE#6430)

##### What this PR does / why we need it:

On FIPS-enabled clusters, the `ocp-virt-validation-checkup-rhel9` image
uses RHEL 9.8 as base with the system Python interpreter. The system
Python links `hashlib` against RHEL's system OpenSSL, which enforces
FIPS mode when the cluster has FIPS enabled
(`/proc/sys/crypto/fips_enabled = 1`).

In FIPS mode, `hashlib.md5()` without `usedforsecurity=False` raises
`UnsupportedDigestmodError`, causing all SSH connectivity checks into
VMs to fail:

```
Function: rrmngmnt.host.run_command  Kwargs: {'command': ['exit'], 'tcp_timeout': 60}
Last exception: UnsupportedDigestmodError: [digital envelope routines] unsupported.
```

**Root cause:** `paramiko.pkey.md5` (imported from `hashlib`) is called
by:
- `PKey.get_fingerprint()` — used for display/logging of host key
fingerprints in all host key policies (`AutoAddPolicy`, `RejectPolicy`,
`WarningPolicy`) and during SSH client auth
- `PKey._read_private_key_pem()` — used for password-protected PEM key
decryption

CI (Jenkins) uses the `openshift-virtualization-tests:latest` image
(Fedora 41 + `uv` standalone Python) which bundles its own OpenSSL that
does not inherit the host FIPS policy — hence no failure there.

**Upstream status:** Known paramiko bug ([issue
RedHatQE#396](paramiko/paramiko#396), open since
2014). Multiple PRs submitted
([RedHatQE#1928](paramiko/paramiko#1928),
[RedHatQE#2189](paramiko/paramiko#2189),
[RedHatQE#2496](paramiko/paramiko#2496),
[RedHatQE#2624](paramiko/paramiko#2624)) — none merged.
No fix in `paramiko 5.0.0`.

**Fix:** Patch `paramiko.pkey.md5` at import time via `vars()` to use
`usedforsecurity=False`. This tells OpenSSL FIPS that the MD5 usage is
not for security purposes (fingerprint display/logging only).

**Validated on a FIPS-enabled cluster:**
`test_clone_from_block_to_fs_using_dv_template` fails without the patch
and passes with it on the `ocp-virt-validation-checkup-rhel9` image.

##### Which issue(s) this PR fixes:

CNV-98463

##### Special notes for reviewer:

`vars(paramiko.pkey).update(...)` is used instead of direct attribute
assignment to avoid mypy `attr-defined`/`method-assign` errors on
third-party module patching, without requiring `# type: ignore`
(prohibited by AGENTS.md) or a broad `ignore_errors` mypy override.

##### jira-ticket:

CNV-98463

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Improved compatibility for automated test runs in FIPS-enabled
environments. Application behavior and user-facing functionality are
unchanged; this update affects test setup only and does not alter
security protections. No new end-user features or other behavior changes
are included.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Ramón Lobillo <[email protected]>
Co-authored-by: Claude Sonnet 4.6 (1M context) <[email protected]>
Ahmad-Hafe pushed a commit to Ahmad-Hafe/openshift-virtualization-tests that referenced this pull request Oct 8, 2026
…edHatQE#6430)

##### What this PR does / why we need it:

On FIPS-enabled clusters, the `ocp-virt-validation-checkup-rhel9` image
uses RHEL 9.8 as base with the system Python interpreter. The system
Python links `hashlib` against RHEL's system OpenSSL, which enforces
FIPS mode when the cluster has FIPS enabled
(`/proc/sys/crypto/fips_enabled = 1`).

In FIPS mode, `hashlib.md5()` without `usedforsecurity=False` raises
`UnsupportedDigestmodError`, causing all SSH connectivity checks into
VMs to fail:

```
Function: rrmngmnt.host.run_command  Kwargs: {'command': ['exit'], 'tcp_timeout': 60}
Last exception: UnsupportedDigestmodError: [digital envelope routines] unsupported.
```

**Root cause:** `paramiko.pkey.md5` (imported from `hashlib`) is called
by:
- `PKey.get_fingerprint()` — used for display/logging of host key
fingerprints in all host key policies (`AutoAddPolicy`, `RejectPolicy`,
`WarningPolicy`) and during SSH client auth
- `PKey._read_private_key_pem()` — used for password-protected PEM key
decryption

CI (Jenkins) uses the `openshift-virtualization-tests:latest` image
(Fedora 41 + `uv` standalone Python) which bundles its own OpenSSL that
does not inherit the host FIPS policy — hence no failure there.

**Upstream status:** Known paramiko bug ([issue
RedHatQE#396](paramiko/paramiko#396), open since
2014). Multiple PRs submitted
([RedHatQE#1928](paramiko/paramiko#1928),
[RedHatQE#2189](paramiko/paramiko#2189),
[RedHatQE#2496](paramiko/paramiko#2496),
[RedHatQE#2624](paramiko/paramiko#2624)) — none merged.
No fix in `paramiko 5.0.0`.

**Fix:** Patch `paramiko.pkey.md5` at import time via `vars()` to use
`usedforsecurity=False`. This tells OpenSSL FIPS that the MD5 usage is
not for security purposes (fingerprint display/logging only).

**Validated on a FIPS-enabled cluster:**
`test_clone_from_block_to_fs_using_dv_template` fails without the patch
and passes with it on the `ocp-virt-validation-checkup-rhel9` image.

##### Which issue(s) this PR fixes:

CNV-98463

##### Special notes for reviewer:

`vars(paramiko.pkey).update(...)` is used instead of direct attribute
assignment to avoid mypy `attr-defined`/`method-assign` errors on
third-party module patching, without requiring `# type: ignore`
(prohibited by AGENTS.md) or a broad `ignore_errors` mypy override.

##### jira-ticket:

CNV-98463

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Improved compatibility for automated test runs in FIPS-enabled
environments. Application behavior and user-facing functionality are
unchanged; this update affects test setup only and does not alter
security protections. No new end-user features or other behavior changes
are included.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Ramón Lobillo <[email protected]>
Co-authored-by: Claude Sonnet 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants