[PATCH 1/2] fix(ssh config): do not emit messages on stdout

9 views
Skip to first unread message

Felix Moessbauer

unread,
Feb 12, 2024, 4:06:59 AMFeb 12
to kas-...@googlegroups.com, jan.k...@siemens.com, Felix Moessbauer
When setting up the ssh config, commands were executed without proper
handling of the output. By that, output was emitted on stdout, which
interfered with the output of the shell or the dump plugin.

This patch fixes this by running these commands using the run_cmd
infrastructure.

Signed-off-by: Felix Moessbauer <felix.mo...@siemens.com>
---
kas/libkas.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/kas/libkas.py b/kas/libkas.py
index bd447ed73..fee9c2749 100644
--- a/kas/libkas.py
+++ b/kas/libkas.py
@@ -334,17 +334,17 @@ def ssh_cleanup_agent():
"""
Removes the identities and stops the ssh-agent instance
"""
- env = get_context().environ
+ ctx = get_context()
# remove the identities
- process = Popen(['ssh-add', '-D'], env=env)
- process.wait()
- if process.returncode != 0:
+ (ret, _) = run_cmd(['ssh-add', '-D'], cwd=ctx.kas_work_dir,
+ env=ctx.environ, fail=False, liveupdate=False)
+ if ret != 0:
logging.error('failed to delete SSH identities')

# stop the ssh-agent
- process = Popen(['ssh-agent', '-k'], env=env)
- process.wait()
- if process.returncode != 0:
+ (ret, _) = run_cmd(['ssh-agent', '-k'], cwd=ctx.kas_work_dir,
+ env=ctx.environ, fail=False, liveupdate=False)
+ if ret != 0:
logging.error('failed to stop SSH agent')


--
2.39.2

Felix Moessbauer

unread,
Feb 12, 2024, 4:07:02 AMFeb 12
to kas-...@googlegroups.com, jan.k...@siemens.com, Felix Moessbauer
This patch replaces the raw os.popen command in the ssh_setup_agent with
a run_cmd. By that, the command runs in a more isolated environment
and also emits all messages via the kas logging mechanism. It also no
longer depends on the executing shell.

Signed-off-by: Felix Moessbauer <felix.mo...@siemens.com>
---
kas/libkas.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kas/libkas.py b/kas/libkas.py
index fee9c2749..309320684 100644
--- a/kas/libkas.py
+++ b/kas/libkas.py
@@ -352,9 +352,11 @@ def ssh_setup_agent(envkeys=None):
"""
Starts the ssh-agent
"""
- env = get_context().environ
+ ctx = get_context()
+ env = ctx.environ
envkeys = envkeys or ['SSH_PRIVATE_KEY', 'SSH_PRIVATE_KEY_FILE']
- output = os.popen('ssh-agent -s').readlines()
+ (_, output) = run_cmd(['ssh-agent', '-s'], env=env,
+ cwd=ctx.kas_work_dir, liveupdate=False)
for line in output:
matches = re.search(r"(\S+)\=(\S+)\;", line)
if matches:
--
2.39.2

Jan Kiszka

unread,
Feb 12, 2024, 5:53:34 AMFeb 12
to Felix Moessbauer, kas-...@googlegroups.com
On 12.02.24 10:06, 'Felix Moessbauer' via kas-devel wrote:
> When setting up the ssh config, commands were executed without proper

When *cleaning up* - fixing up on merge.

Jan
Siemens AG, Technology
Linux Expert Center

Jan Kiszka

unread,
Feb 12, 2024, 5:54:40 AMFeb 12
to Felix Moessbauer, kas-...@googlegroups.com
On 12.02.24 10:06, 'Felix Moessbauer' via kas-devel wrote:
Thanks, both applied.

Jan
Reply all
Reply to author
Forward
0 new messages