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

feat: enable connecting to rootfull pods #313

Closed
wants to merge 5 commits into from
Closed

feat: enable connecting to rootfull pods #313

wants to merge 5 commits into from

Conversation

0b11stan
Copy link

Fixing #300.
It only works with sudo for now.

@0b11stan
Copy link
Author

I saw some tests in tests/integration/targets/connection_podman and I would gladly add some but I do not understand how to use them. I'll look at it tomorrow.

Copy link
Member

@sshnaidm sshnaidm left a comment

Choose a reason for hiding this comment

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

I'll need to test it, please see comments inline.

@@ -68,6 +70,20 @@
- name: ansible_podman_executable
env:
- name: ANSIBLE_PODMAN_EXECUTABLE
podman_rootless:
description: Whether the container should be run as root.
Copy link
Member

Choose a reason for hiding this comment

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

I think you meant "should be run as rootless"?

Copy link
Author

Choose a reason for hiding this comment

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

You are right, I changed it !

if not podman_cmd:
raise AnsibleError("%s command not found in PATH" % podman_exec)
local_cmd = [podman_cmd]
elif not sudo_cmd:
Copy link
Member

Choose a reason for hiding this comment

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

This check makes sense only if "root" connection is set. We don't want to fail all cases where there is no sudo in the host.

@@ -102,11 +145,17 @@ def _podman(self, cmd, cmd_args=None, in_data=None, use_container_id=True):
:param in_data: data passed to podman's stdin
:return: return code, stdout, stderr
"""
rootless = self.get_option('podman_rootless')
Copy link
Member

Choose a reason for hiding this comment

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

By default we need to follow the current user behavior. This setting makes sense only when current user is not root and rootless is false. I think this check we should do here.
Otherwise when this module is running from root user you have to set rootless to false every time, and this is not convenient.

podman_exec = self.get_option('podman_executable')
podman_cmd = distutils.spawn.find_executable(podman_exec)
sudo_cmd = distutils.spawn.find_executable('sudo')
Copy link
Member

Choose a reason for hiding this comment

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

This check makes sense only if "root" connection is set. We don't want to fail all cases where there is no sudo in the host.

elif not sudo_cmd:
raise AnsibleError("sudo command not found in PATH")

local_cmd = [podman_cmd] if rootless else [sudo_cmd, '-Sk', podman_cmd]
Copy link
Member

Choose a reason for hiding this comment

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

Like I mentioned before, the default behavior should be for current user.
Probably it's better to set setting like root_connection, not rootless

@0b11stan
Copy link
Author

Hi @sshnaidm thank you for your review, I indeed did not think of the case where the user is already root. I proposed a new version that resolve a few of your feedbacks but I agree that it's not a perfect fix. I'll try to provide a better solution in the following days but I'm not sure I understand your idea with the root_connection setting, may you explain it further ?

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants