Skip to content

Commit a7fdb55

Browse files
committed
Merge remote-tracking branch 'origin/issue581'
* origin/issue581: issue #581: expose mitogen_mask_remote_name variable.
2 parents 300c734 + f30a4c0 commit a7fdb55

File tree

10 files changed

+138
-2
lines changed

10 files changed

+138
-2
lines changed

ansible_mitogen/connection.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@
5858
LOG = logging.getLogger(__name__)
5959

6060

61+
def get_remote_name(spec):
62+
"""
63+
Return the value to use for the "remote_name" parameter.
64+
"""
65+
if spec.mitogen_mask_remote_name():
66+
return 'ansible'
67+
return None
68+
69+
6170
def optional_int(value):
6271
"""
6372
Convert `value` to an integer if it is not :data:`None`, otherwise return
@@ -135,6 +144,7 @@ def _connect_ssh(spec):
135144
'connect_timeout': spec.ansible_ssh_timeout(),
136145
'ssh_args': spec.ssh_args(),
137146
'ssh_debug_level': spec.mitogen_ssh_debug_level(),
147+
'remote_name': get_remote_name(spec),
138148
}
139149
}
140150

@@ -150,6 +160,7 @@ def _connect_docker(spec):
150160
'container': spec.remote_addr(),
151161
'python_path': spec.python_path(),
152162
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
163+
'remote_name': get_remote_name(spec),
153164
}
154165
}
155166

@@ -166,6 +177,7 @@ def _connect_kubectl(spec):
166177
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
167178
'kubectl_path': spec.mitogen_kubectl_path(),
168179
'kubectl_args': spec.extra_args(),
180+
'remote_name': get_remote_name(spec),
169181
}
170182
}
171183

@@ -181,6 +193,7 @@ def _connect_jail(spec):
181193
'container': spec.remote_addr(),
182194
'python_path': spec.python_path(),
183195
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
196+
'remote_name': get_remote_name(spec),
184197
}
185198
}
186199

@@ -196,6 +209,7 @@ def _connect_lxc(spec):
196209
'python_path': spec.python_path(),
197210
'lxc_attach_path': spec.mitogen_lxc_attach_path(),
198211
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
212+
'remote_name': get_remote_name(spec),
199213
}
200214
}
201215

@@ -211,6 +225,7 @@ def _connect_lxd(spec):
211225
'python_path': spec.python_path(),
212226
'lxc_path': spec.mitogen_lxc_path(),
213227
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
228+
'remote_name': get_remote_name(spec),
214229
}
215230
}
216231

@@ -254,6 +269,7 @@ def _connect_su(spec):
254269
'python_path': spec.python_path(),
255270
'su_path': spec.become_exe(),
256271
'connect_timeout': spec.timeout(),
272+
'remote_name': get_remote_name(spec),
257273
}
258274
}
259275

@@ -272,6 +288,7 @@ def _connect_sudo(spec):
272288
'sudo_path': spec.become_exe(),
273289
'connect_timeout': spec.timeout(),
274290
'sudo_args': spec.sudo_args(),
291+
'remote_name': get_remote_name(spec),
275292
}
276293
}
277294

@@ -289,6 +306,7 @@ def _connect_doas(spec):
289306
'python_path': spec.python_path(),
290307
'doas_path': spec.become_exe(),
291308
'connect_timeout': spec.timeout(),
309+
'remote_name': get_remote_name(spec),
292310
}
293311
}
294312

@@ -305,6 +323,7 @@ def _connect_mitogen_su(spec):
305323
'python_path': spec.python_path(),
306324
'su_path': spec.become_exe(),
307325
'connect_timeout': spec.timeout(),
326+
'remote_name': get_remote_name(spec),
308327
}
309328
}
310329

@@ -322,6 +341,7 @@ def _connect_mitogen_sudo(spec):
322341
'sudo_path': spec.become_exe(),
323342
'connect_timeout': spec.timeout(),
324343
'sudo_args': spec.sudo_args(),
344+
'remote_name': get_remote_name(spec),
325345
}
326346
}
327347

@@ -338,6 +358,7 @@ def _connect_mitogen_doas(spec):
338358
'python_path': spec.python_path(),
339359
'doas_path': spec.become_exe(),
340360
'connect_timeout': spec.timeout(),
361+
'remote_name': get_remote_name(spec),
341362
}
342363
}
343364

ansible_mitogen/transport_config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ def mitogen_kind(self):
231231
The type of container to use with the "setns" transport.
232232
"""
233233

234+
@abc.abstractmethod
235+
def mitogen_mask_remote_name(self):
236+
"""
237+
Specifies whether to set a fixed "remote_name" field. The remote_name
238+
is the suffix of `argv[0]` for remote interpreters. By default it
239+
includes identifying information from the local process, which may be
240+
undesirable in some circumstances.
241+
"""
242+
234243
@abc.abstractmethod
235244
def mitogen_docker_path(self):
236245
"""
@@ -385,6 +394,9 @@ def mitogen_via(self):
385394
def mitogen_kind(self):
386395
return self._connection.get_task_var('mitogen_kind')
387396

397+
def mitogen_mask_remote_name(self):
398+
return self._connection.get_task_var('mitogen_mask_remote_name')
399+
388400
def mitogen_docker_path(self):
389401
return self._connection.get_task_var('mitogen_docker_path')
390402

@@ -593,6 +605,9 @@ def mitogen_via(self):
593605
def mitogen_kind(self):
594606
return self._host_vars.get('mitogen_kind')
595607

608+
def mitogen_mask_remote_name(self):
609+
return self._host_vars.get('mitogen_mask_remote_name')
610+
596611
def mitogen_docker_path(self):
597612
return self._host_vars.get('mitogen_docker_path')
598613

docs/ansible_detailed.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,11 @@ When used as a become method:
733733
* ``ansible_become_exe``: path to ``doas`` binary.
734734
* ``ansible_become_user`` (default: ``root``)
735735
* ``ansible_become_pass`` (default: assume passwordless)
736+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
737+
Ansible controller process on remote machines. To simplify diagnostics,
738+
Mitogen produces remote processes named like
739+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
740+
some circumstances.
736741
* ansible.cfg: ``timeout``
737742

738743
When used as the ``mitogen_doas`` connection method:
@@ -754,6 +759,11 @@ connection delegation is supported.
754759

755760
* ``ansible_host``: Name of Docker container (default: inventory hostname).
756761
* ``ansible_user``: Name of user within the container to execute as.
762+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
763+
Ansible controller process on remote machines. To simplify diagnostics,
764+
Mitogen produces remote processes named like
765+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
766+
some circumstances.
757767

758768

759769
.. _method-jail:
@@ -767,6 +777,11 @@ connection delegation is supported.
767777

768778
* ``ansible_host``: Name of jail (default: inventory hostname).
769779
* ``ansible_user``: Name of user within the jail to execute as.
780+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
781+
Ansible controller process on remote machines. To simplify diagnostics,
782+
Mitogen produces remote processes named like
783+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
784+
some circumstances.
770785

771786

772787
.. _method-kubectl:
@@ -780,6 +795,11 @@ connection delegation is supported.
780795

781796
* ``ansible_host``: Name of pod (default: inventory hostname).
782797
* ``ansible_user``: Name of user to authenticate to API as.
798+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
799+
Ansible controller process on remote machines. To simplify diagnostics,
800+
Mitogen produces remote processes named like
801+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
802+
some circumstances.
783803

784804

785805
Local
@@ -823,6 +843,11 @@ than the LXC Python bindings, as is usual with ``lxc``.
823843
* ``ansible_host``: Name of LXC container (default: inventory hostname).
824844
* ``mitogen_lxc_attach_path``: path to ``lxc-attach`` command if not available
825845
on the system path.
846+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
847+
Ansible controller process on remote machines. To simplify diagnostics,
848+
Mitogen produces remote processes named like
849+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
850+
some circumstances.
826851

827852

828853
.. _method-lxd:
@@ -839,6 +864,11 @@ the host machine.
839864
* ``ansible_host``: Name of LXC container (default: inventory hostname).
840865
* ``mitogen_lxc_path``: path to ``lxc`` command if not available on the system
841866
path.
867+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
868+
Ansible controller process on remote machines. To simplify diagnostics,
869+
Mitogen produces remote processes named like
870+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
871+
some circumstances.
842872

843873

844874
.. _machinectl:
@@ -855,6 +885,11 @@ connection delegation is supported. This is a light wrapper around the
855885
* ``ansible_user``: Name of user within the container to execute as.
856886
* ``mitogen_machinectl_path``: path to ``machinectl`` command if not available
857887
as ``/bin/machinectl``.
888+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
889+
Ansible controller process on remote machines. To simplify diagnostics,
890+
Mitogen produces remote processes named like
891+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
892+
some circumstances.
858893

859894

860895
.. _setns:
@@ -899,6 +934,11 @@ When used as a become method:
899934
* ``ansible_su_user``, ``ansible_become_user`` (default: ``root``)
900935
* ``ansible_su_pass``, ``ansible_become_pass`` (default: assume passwordless)
901936
* ``su_flags``, ``become_flags``
937+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
938+
Ansible controller process on remote machines. To simplify diagnostics,
939+
Mitogen produces remote processes named like
940+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
941+
some circumstances.
902942
* ansible.cfg: ``timeout``
903943

904944
When used as the ``mitogen_su`` connection method:
@@ -924,6 +964,11 @@ When used as a become method:
924964
* ``ansible_sudo_user``, ``ansible_become_user`` (default: ``root``)
925965
* ``ansible_sudo_pass``, ``ansible_become_pass`` (default: assume passwordless)
926966
* ``sudo_flags``, ``become_flags``
967+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
968+
Ansible controller process on remote machines. To simplify diagnostics,
969+
Mitogen produces remote processes named like
970+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
971+
some circumstances.
927972
* ansible.cfg: ``timeout``
928973

929974
When used as the ``mitogen_sudo`` connection method:
@@ -949,6 +994,11 @@ except connection delegation is supported.
949994
* ``ansible_ssh_private_key_file``
950995
* ``ansible_ssh_pass``, ``ansible_password`` (default: assume passwordless)
951996
* ``ssh_args``, ``ssh_common_args``, ``ssh_extra_args``
997+
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
998+
Ansible controller process on remote machines. To simplify diagnostics,
999+
Mitogen produces remote processes named like
1000+
`"mitogen:[email protected]:1234"`, however this may be a privacy issue in
1001+
some circumstances.
9521002
* ``mitogen_ssh_debug_level``: integer between `0..3` indicating the SSH client
9531003
debug level. Ansible must also be run with '-vvv' to view the output.
9541004
* ``mitogen_ssh_compression``: :data:`True` to enable SSH compression,

docs/changelog.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ Fixes
3939
startup on SuSE Linux 11, due to an incorrect version compatibility check in
4040
the Mitogen code.
4141

42+
* `#581 <https://github.com/dw/mitogen/issues/58>`_: a
43+
``mitogen_mask_remote_name`` Ansible variable is exposed, to allow masking
44+
the username, hostname and process ID of ``ansible-playbook`` running on the
45+
controller machine.
46+
4247

4348
Thanks!
4449
~~~~~~~
4550

4651
Mitogen would not be possible without the support of users. A huge thanks for
4752
bug reports, testing, features and fixes in this release contributed by
4853
`Orion Poplawski <https://github.com/opoplawski>`_,
49-
`Thibaut Barrère <https://github.com/thbar>`_, and
50-
`@Moumoutaru <https://github.com/Moumoutaru>`_.
54+
`Thibaut Barrère <https://github.com/thbar>`_,
55+
`@Moumoutaru <https://github.com/Moumoutaru>`_, and
56+
`@polski-g <https://github.com/polski-g>`_.
5157

5258

5359
v0.2.6 (2019-03-06)

tests/ansible/integration/connection_delegation/delegate_to_template.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'password': null,
4141
'port': null,
4242
'python_path': ["/usr/bin/python"],
43+
'remote_name': null,
4344
'ssh_args': [
4445
'-o',
4546
'UserKnownHostsFile=/dev/null',
@@ -67,6 +68,7 @@
6768
'password': null,
6869
'port': null,
6970
'python_path': ["/usr/bin/python"],
71+
'remote_name': null,
7072
'ssh_args': [
7173
'-o',
7274
'UserKnownHostsFile=/dev/null',

tests/ansible/integration/connection_delegation/local_action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'kwargs': {
2525
'connect_timeout': 10,
2626
'python_path': ["{{ansible_playbook_python}}"],
27+
'remote_name': null,
2728
'password': null,
2829
'username': 'root',
2930
'sudo_path': null,

tests/ansible/integration/connection_delegation/osa_container_standalone.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'lxc_info_path': null,
2222
'machinectl_path': null,
2323
'python_path': ['/usr/bin/python'],
24+
'remote_name': null,
2425
'username': null,
2526
},
2627
'method': 'setns',

0 commit comments

Comments
 (0)