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

ci: Ensure password su succeeds fails on macOS + Python 3.9 #885

Closed
moreati opened this issue Dec 18, 2021 · 1 comment
Closed

ci: Ensure password su succeeds fails on macOS + Python 3.9 #885

moreati opened this issue Dec 18, 2021 · 1 comment
Labels
affects-0.3 Issues related to 0.3.X Mitogen releases bug Code feature that hinders desired execution outcome

Comments

@moreati
Copy link
Member

moreati commented Dec 18, 2021

Python 3.9 + macOS + Ansible tests fail, e.g. https://dev.azure.com/mitogen-hq/mitogen/_build/results?buildId=281&view=results

PLAY [integration/become/su_password.yml] **************************************

TASK [Ensure su password absent but required. _raw_params=whoami] **************
fatal: [target]: FAILED! => 
  msg: 'error occurred on host Mac-1639846751180.local: su password is required'
...ignoring

TASK [assert that=['out.failed', "( ('password is required' in out.msg) or ('password is required' in out.module_stderr) )"], fail_msg=out={{out}}] ***
ok: [target] => changed=false 
  msg: All assertions passed

TASK [Ensure password su incorrect. _raw_params=whoami] ************************
fatal: [target]: FAILED! => 
  msg: 'error occurred on host Mac-1639846751180.local: su password is incorrect'
...ignoring

TASK [assert that=out.failed and (
  ('Incorrect su password' in out.msg) or
  ('su password is incorrect' in out.msg)
)
, fail_msg=out={{out}}] ***
ok: [target] => changed=false 
  msg: All assertions passed

TASK [Ensure password su succeeds. _raw_params=whoami] *************************
fatal: [target]: FAILED! => 
  msg: |-
    error occurred on host Mac-1639846751180.local: EOF on stream; last 100 lines received:
    Password:
    shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/encodings/__init__.py", line 98, in search_function
        mod = __import__('encodings.' + modname, fromlist=_import_tail,
      File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/encodings/base64_codec.py", line 9, in <module>
        import base64
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 982, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 925, in _find_spec
      File "<frozen importlib._bootstrap_external>", line 1414, in find_spec
      File "<frozen importlib._bootstrap_external>", line 1383, in _get_spec
      File "<frozen importlib._bootstrap_external>", line 1347, in _path_importer_cache
    PermissionError: [Errno 13] Permission denied

Discovered while trying to add an Ansible 5 job on macOS. Affects all Ansible versions supported by 0.3.x, and appears to affect even when ANSIBLE_STRATEGY=linear.

@moreati moreati added bug Code feature that hinders desired execution outcome affects-0.3 Issues related to 0.3.X Mitogen releases labels Dec 18, 2021
@moreati
Copy link
Member Author

moreati commented Feb 26, 2024

Seeing this again. Some similarities with ansible/ansible#19729, but ultimately looks like a Python importlib misbehaviour python/cpython#115911

moreati added a commit to moreati/mitogen that referenced this issue Mar 4, 2024
…eadable

On macOS when using a become plugin as an unprivileged user, to another
unprivileged user it is likely that the current working directory can't be
read. In this case os.cwd() raises PermissionError.

On versions of Python currently in the wild (March 2024, CPython <= 3.13) if
any non-builtin or non-frozen module (e.g. zlib, base64) is imported then
`importlib._bootstrap_external.PathFinder._path_importer_cache()` attempts to
call os.cwd() without catching PermissionError.

The previous comment about needing an extra .encode() appears to be wrong,
atleast for Python 3.x >= 3.6.

Command size increased by 54 bytes, bootstrap by 804 bytes. Changed from
codecs module to binascii & zlib because they're extensions, and importing
them triggers fewer supporting imports (e.g. encodings module).

Before

```
✗ ./preamble_size.py
SSH command size: 705
Bootstrap (mitogen.core) size: 17078 (16.68KiB)

                              Original          Minimized           Compressed
mitogen.parent            97884 95.6KiB  50515 49.3KiB 51.6%  12727 12.4KiB 13.0%
mitogen.fork               8436  8.2KiB   4130  4.0KiB 49.0%   1648  1.6KiB 19.5%
mitogen.ssh               10892 10.6KiB   6952  6.8KiB 63.8%   2113  2.1KiB 19.4%
mitogen.sudo              12089 11.8KiB   5924  5.8KiB 49.0%   2249  2.2KiB 18.6%
mitogen.select            12325 12.0KiB   2929  2.9KiB 23.8%    964  0.9KiB 7.8%
mitogen.service           41699 40.7KiB  22477 22.0KiB 53.9%   5885  5.7KiB 14.1%
mitogen.fakessh           15577 15.2KiB   7989  7.8KiB 51.3%   2623  2.6KiB 16.8%
mitogen.master            51398 50.2KiB  25715 25.1KiB 50.0%   6886  6.7KiB 13.4%
```

After

```
✗ ./preamble_size.py
SSH command size: 759
Bootstrap (mitogen.core) size: 17882 (17.46KiB)

                              Original          Minimized           Compressed
mitogen.parent            98173 95.9KiB  50571 49.4KiB 51.5%  12747 12.4KiB 13.0%
mitogen.fork               8436  8.2KiB   4130  4.0KiB 49.0%   1648  1.6KiB 19.5%
mitogen.ssh               10892 10.6KiB   6952  6.8KiB 63.8%   2113  2.1KiB 19.4%
mitogen.sudo              12089 11.8KiB   5924  5.8KiB 49.0%   2249  2.2KiB 18.6%
mitogen.select            12325 12.0KiB   2929  2.9KiB 23.8%    964  0.9KiB 7.8%
mitogen.service           41699 40.7KiB  22477 22.0KiB 53.9%   5885  5.7KiB 14.1%
mitogen.fakessh           15577 15.2KiB   7989  7.8KiB 51.3%   2623  2.6KiB 16.8%
mitogen.master            56116 54.8KiB  29427 28.7KiB 52.4%   7627  7.4KiB 13.6%
```

Fixes mitogen-hq#885
Refs python/cpython#115911
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-0.3 Issues related to 0.3.X Mitogen releases bug Code feature that hinders desired execution outcome
Projects
None yet
Development

No branches or pull requests

1 participant