summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2022-04-14 02:53:01 +1000
committerGitHub <noreply@github.com>2022-04-13 11:53:01 -0500
commit874f4323ef1c6126abd2c446f313473491c524ba (patch)
treedaa04925c6876feb6119ce4d74f6ff5162670c49
parent402d914841344df07b596826dc06a9f28a5d5b59 (diff)
downloadansible-874f4323ef1c6126abd2c446f313473491c524ba.tar.gz
winrm - ensure callers PATH for kinit is set (#77401) (#77402)
* winrm - ensure callers PATH for kinit is set * Fix unit test expectations * Fix type annotation (cherry picked from commit 60b4200bc6fee69384da990bb7884f58577fc724)
-rw-r--r--changelogs/fragments/winrm-kinit-path.yml2
-rw-r--r--lib/ansible/plugins/connection/winrm.py2
-rw-r--r--test/units/plugins/connection/test_winrm.py8
3 files changed, 9 insertions, 3 deletions
diff --git a/changelogs/fragments/winrm-kinit-path.yml b/changelogs/fragments/winrm-kinit-path.yml
new file mode 100644
index 0000000000..574a02bbf9
--- /dev/null
+++ b/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
diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py
index c9d8dbc4c1..807ba55fcc 100644
--- a/lib/ansible/plugins/connection/winrm.py
+++ b/lib/ansible/plugins/connection/winrm.py
@@ -304,7 +304,7 @@ class Connection(ConnectionBase):
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)
# Stores various flags to call with kinit, these could be explicit args set by 'ansible_winrm_kinit_args' OR
# '-f' if kerberos delegation is requested (ansible_winrm_kerberos_delegation).
diff --git a/test/units/plugins/connection/test_winrm.py b/test/units/plugins/connection/test_winrm.py
index e6bf9ad291..4478911c02 100644
--- a/test/units/plugins/connection/test_winrm.py
+++ b/test/units/plugins/connection/test_winrm.py
@@ -6,6 +6,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
+import os
+
import pytest
from io import StringIO
@@ -255,8 +257,9 @@ class TestWinRMKerbAuth(object):
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": {}},
@@ -287,8 +290,9 @@ class TestWinRMKerbAuth(object):
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] == (".*:",)