Skip to content

Add typing_extensions to salt-ssh thin tarball - #62234

Closed
lastmikoi wants to merge 1 commit into
saltstack:masterfrom
lastmikoi:ltspython-sshthin
Closed

lastmikoi wants to merge 1 commit into
saltstack:masterfrom
lastmikoi:ltspython-sshthin

Conversation

@lastmikoi

Copy link
Copy Markdown
Contributor

What does this PR do?

When one uses salt-ssh 3003+ on python3.6-running targets (who are numerous, see RHEL, CentOS, RockyLinux, etc..., as OS vendors are supporting python3.6 and fixing security issues themselves even if upstream py36 is End Of Life), salt-ssh will include a backport of python3.7's contextvars module in the salt thin tarball.

However, the contextvars backport makes uses of the immutables module.

This module went through a typing refactor (see MagicStack/immutables#62) which landed in its v0.16 release on August 2021.

However, that typing refactor added a new dependency, typing_extensions, but only on pre-3.8 deployments (see https://github.com/MagicStack/immutables/blob/master/immutables/_protocols.py#L13).

This third-order dependency (!) is nowhere to be found on the salt ssh thin tarball, which leads to several issues (#59942) as that import error triggers a cascade of exceptions.

This PR aims to fix that issue by adding typing_extensions to the thin tarball.

Note: First-time Salt contributor here, don't hesistate to walk me through stuff if you think I missed something in my reading of the Contributor's Guide !

What issues does this PR fix or reference?

Fixes: #59942

New Behavior

salt-ssh will add typing_extensions to the thin tarball in the cases where immutables is imported (i.e. target is running python 3.6)

Merge requirements satisfied?

Commits signed with GPG?

Yes

@lastmikoi
lastmikoi requested a review from a team as a code owner June 28, 2022 20:56
@lastmikoi
lastmikoi requested review from Ch3LL and removed request for a team June 28, 2022 20:56
@welcome

welcome Bot commented Jun 28, 2022

Copy link
Copy Markdown

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

Comment thread salt/utils/thin.py
mods.append(contextvars)
if has_immutables:
mods.append(immutables)
mods.append(typing_extensions)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some testing and I can only replicate the issue when my master and the target are python 3.6. If master is 3.8 and target is 3.6 it works. Can we add some logic here that only adds the typing_extensions if the master is running < python 3.8.

@Ch3LL

Ch3LL commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

@lastmikoi are you able to loop back to this PR with the feedback I previously submitted?

@Ch3LL

Ch3LL commented Sep 29, 2022

Copy link
Copy Markdown
Contributor

bump @lastmikoi did you see my feedback?

@lastmikoi

Copy link
Copy Markdown
Contributor Author

Hi @Ch3LL !

I have seen your feedback, I've been trying to find time to work on it as I remembered I could reproduce the issue on my 3.6 salt-master, but I haven't found the time to take care of it just yet. I'll get you updated !

@lastmikoi

lastmikoi commented Oct 15, 2022 •

Copy link
Copy Markdown
Contributor Author

@Ch3LL I have been able to reproduce the issue on a clean(-ish) Python3.9 master virtualenv with Salt 3005 against a freshly installed CentOS7 target.

`salt-ssh test.ping` Traceback
        Traceback (most recent call last):
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/loader/context.py", line 10, in <module>
            import _contextvars as contextvars
        ModuleNotFoundError: No module named '_contextvars'
        
        During handling of the above exception, another exception occurred:
        
        Traceback (most recent call last):
          File "/var/tmp/.lastmikoi_dd8a91_salt/salt-call", line 27, in <module>
            salt_call()
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/scripts.py", line 435, in salt_call
            import salt.cli.call
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/cli/call.py", line 3, in <module>
            import salt.cli.caller
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/cli/caller.py", line 12, in <module>
            import salt.channel.client
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/channel/client.py", line 13, in <module>
            import salt.crypt
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/crypt.py", line 26, in <module>
            import salt.payload
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/payload.py", line 12, in <module>
            import salt.loader.context
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/loader/__init__.py", line 15, in <module>
            import salt.config
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/config/__init__.py", line 100, in <module>
            _DFLT_IPC_WBUFFER = _gather_buffer_space() * 0.5
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/config/__init__.py", line 88, in _gather_buffer_space
            import salt.grains.core
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/grains/core.py", line 31, in <module>
            import salt.modules.cmdmod
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/modules/cmdmod.py", line 31, in <module>
            import salt.utils.templates
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/utils/templates.py", line 27, in <module>
            from salt.loader.context import NamedLoaderContext
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/loader/context.py", line 13, in <module>
            import contextvars
          File "/var/tmp/.lastmikoi_dd8a91_salt/py3/contextvars/__init__.py", line 4, in <module>
            import immutables
          File "/var/tmp/.lastmikoi_dd8a91_salt/py3/immutables/__init__.py", line 18, in <module>
            from ._protocols import MapKeys as MapKeys
          File "/var/tmp/.lastmikoi_dd8a91_salt/py3/immutables/_protocols.py", line 17, in <module>
            from typing_extensions import Protocol
        ModuleNotFoundError: No module named 'typing_extensions'
        [ERROR   ] An un-handled exception was caught by Salt's global exception handler:
        ModuleNotFoundError: No module named 'typing_extensions'
        Traceback (most recent call last):
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/loader/context.py", line 10, in <module>
            import _contextvars as contextvars
        ModuleNotFoundError: No module named '_contextvars'
        
        During handling of the above exception, another exception occurred:
        
        Traceback (most recent call last):
          File "/var/tmp/.lastmikoi_dd8a91_salt/salt-call", line 27, in <module>
            salt_call()
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/scripts.py", line 435, in salt_call
            import salt.cli.call
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/cli/call.py", line 3, in <module>
            import salt.cli.caller
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/cli/caller.py", line 12, in <module>
            import salt.channel.client
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/channel/client.py", line 13, in <module>
            import salt.crypt
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/crypt.py", line 26, in <module>
            import salt.payload
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/payload.py", line 12, in <module>
            import salt.loader.context
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/loader/__init__.py", line 15, in <module>
            import salt.config
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/config/__init__.py", line 100, in <module>
            _DFLT_IPC_WBUFFER = _gather_buffer_space() * 0.5
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/config/__init__.py", line 88, in _gather_buffer_space
            import salt.grains.core
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/grains/core.py", line 31, in <module>
            import salt.modules.cmdmod
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/modules/cmdmod.py", line 31, in <module>
            import salt.utils.templates
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/utils/templates.py", line 27, in <module>
            from salt.loader.context import NamedLoaderContext
          File "/var/tmp/.lastmikoi_dd8a91_salt/pyall/salt/loader/context.py", line 13, in <module>
            import contextvars
          File "/var/tmp/.lastmikoi_dd8a91_salt/py3/contextvars/__init__.py", line 4, in <module>
            import immutables
          File "/var/tmp/.lastmikoi_dd8a91_salt/py3/immutables/__init__.py", line 18, in <module>
            from ._protocols import MapKeys as MapKeys
          File "/var/tmp/.lastmikoi_dd8a91_salt/py3/immutables/_protocols.py", line 17, in <module>
            from typing_extensions import Protocol
        ModuleNotFoundError: No module named 'typing_extensions'


`salt-ssh --versions-report`
Salt Version:
          Salt: 3005
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.2
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.4
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.15.0
        pygit2: Not Installed
        Python: 3.9.12 (main, May 15 2022, 19:24:24)
  python-gnupg: Not Installed
        PyYAML: 6.0
         PyZMQ: 20.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.3
 
System Versions:
          dist: arch  
        locale: utf-8
       machine: x86_64
       release: 5.18.15-arch1-1
        system: Linux
       version: Arch Linux

By applying my patch, installing typing_extensions<4.2.0, and rebuilding the thin with -t, the issue dissapears. Rolling back my patch (but keeping typing_extensions installed on the targetmaster host) make the issue appear once again.

This seems harder to reproduce outside of my environment than I anticipated, so I'm available for further testing until we figure out this thing.

@Ch3LL

Ch3LL commented Oct 18, 2022

Copy link
Copy Markdown
Contributor

And what python version is your target? python 3.6?

in 3006 we will only be supporting python >=3.7. Does this also show up when the target version python is 3.7. I'm assuming it does, but if you are willing to confirm I would appreciate it.

@lastmikoi

Copy link
Copy Markdown
Contributor Author

Spent an hour or so getting a py37 working on my CentOS7 environment to make sure I could test it.

The issue does not impact py37 targets, as the contextvars module is present in stdlib, which skips the backport entirely, its broken third-order dependency included.

I understand the need to move past py36 for future releases of SaltStack, but I will have to manage py36 hosts for at least a year and a half (EL 7 EOL), so I would still consider applying my patch if only for 3005, which I would pin my EL7 minions to.

@Ch3LL

Ch3LL commented Nov 3, 2022

Copy link
Copy Markdown
Contributor

I wonder if this would work for your use case: https://docs.saltproject.io/en/latest/topics/ssh/ssh_ext_alternatives.html#ssh-ext-alternatives

Also, another thought is to make this configurable instead of adding typing_extensions. So in the future a user could easily add a library to the tarball.

mwarkentin added a commit to getsentry/salt that referenced this pull request Mar 15, 2023
saltstack#59942
saltstack#62234

confirmed working from my mac to both deb10 (snuba-transactions-tiger) and deb11 (access-logs) targets
@dwoz

dwoz commented Dec 10, 2023

Copy link
Copy Markdown
Contributor

Closing this due to inactivity. Anyone should feel free to re-open it if they want to see it through to the end in one release cycle.

This branch was previously deployed

1 inactive deployment
ci — 5b32963c Deployed Dec 11, 2023 by dwoz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Abandoned help-wanted Community help is needed to resolve this

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] v3003 a salt-master using python 3.7+ using salt-ssh cannot work with a minion using python3.5 or 3.6

3 participants