Skip to content

Commit

Permalink
winrm - ensure callers PATH for kinit is set (#77401)
Browse files Browse the repository at this point in the history
* winrm - ensure callers PATH for kinit is set

* Fix unit test expectations

* Fix type annotation
  • Loading branch information
jborean93 committed Mar 30, 2022
1 parent 353511a commit 60b4200
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/winrm-kinit-path.yml
@@ -0,0 +1,2 @@
bugfixes:
- winrm - Ensure ``kinit`` is run with the same ``PATH`` env var as the Ansible process
3 changes: 2 additions & 1 deletion lib/ansible/plugins/connection/__init__.py
Expand Up @@ -8,6 +8,7 @@
import fcntl
import os
import shlex
import typing as t

from abc import abstractmethod
from functools import wraps
Expand Down Expand Up @@ -48,7 +49,7 @@ class ConnectionBase(AnsiblePlugin):
# When running over this connection type, prefer modules written in a certain language
# as discovered by the specified file extension. An empty string as the
# language means any language.
module_implementation_preferences = ('',) # type: tuple[str, ...]
module_implementation_preferences = ('',) # type: t.Iterable[str]
allow_executable = True

# the following control whether or not the connection supports the
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/connection/winrm.py
Expand Up @@ -320,7 +320,7 @@ def _kerb_auth(self, principal, password):
display.vvvvv("creating Kerberos CC at %s" % self._kerb_ccache.name)
krb5ccname = "FILE:%s" % self._kerb_ccache.name
os.environ["KRB5CCNAME"] = krb5ccname
krb5env = dict(KRB5CCNAME=krb5ccname)
krb5env = dict(PATH=os.environ["PATH"], KRB5CCNAME=krb5ccname)

# Add any explicit environment vars into the krb5env block
kinit_env_vars = self.get_option('kinit_env_vars')
Expand Down
8 changes: 6 additions & 2 deletions test/units/plugins/connection/test_winrm.py
Expand Up @@ -6,6 +6,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os

import pytest

from io import StringIO
Expand Down Expand Up @@ -255,8 +257,9 @@ def mock_communicate(input=None, timeout=None):
assert len(mock_calls) == 1
assert mock_calls[0][1] == expected
actual_env = mock_calls[0][2]['env']
assert list(actual_env.keys()) == ['KRB5CCNAME']
assert sorted(list(actual_env.keys())) == ['KRB5CCNAME', 'PATH']
assert actual_env['KRB5CCNAME'].startswith("FILE:/")
assert actual_env['PATH'] == os.environ['PATH']

@pytest.mark.parametrize('options, expected', [
[{"_extras": {}},
Expand Down Expand Up @@ -287,8 +290,9 @@ def test_kinit_success_pexpect(self, monkeypatch, options, expected):
mock_calls = mock_pexpect.mock_calls
assert mock_calls[0][1] == expected
actual_env = mock_calls[0][2]['env']
assert list(actual_env.keys()) == ['KRB5CCNAME']
assert sorted(list(actual_env.keys())) == ['KRB5CCNAME', 'PATH']
assert actual_env['KRB5CCNAME'].startswith("FILE:/")
assert actual_env['PATH'] == os.environ['PATH']
assert mock_calls[0][2]['echo'] is False
assert mock_calls[1][0] == "().expect"
assert mock_calls[1][1] == (".*:",)
Expand Down

0 comments on commit 60b4200

Please sign in to comment.