Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions osism/commands/console.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# SPDX-License-Identifier: Apache-2.0

import json
import os
import shutil
import socket
import subprocess
import tempfile
from typing import Optional

from cliff.command import Command
Expand Down Expand Up @@ -201,10 +204,23 @@ def take_action(self, parsed_args):
if type_console == "ansible":
subprocess.call(f"/run-ansible-console.sh {host}", shell=True)
elif type_console == "clush":
subprocess.call(
f"/usr/local/bin/clush -l {settings.OPERATOR_USER} -g {host}",
shell=True,
)
# Create a per-invocation known_hosts file to avoid race conditions
# with fanout:64 concurrent SSH connections while still persisting
# host keys during the session.
fd, tmp_known_hosts = tempfile.mkstemp(prefix="clush_known_hosts_")
try:
os.close(fd)
if os.path.exists(KNOWN_HOSTS_PATH):
shutil.copy2(KNOWN_HOSTS_PATH, tmp_known_hosts)
subprocess.call(
f'/usr/local/bin/clush -l {settings.OPERATOR_USER}'
f' -o "-o UserKnownHostsFile={tmp_known_hosts}"'
f' -g {host}',
shell=True,
)
Comment on lines +215 to +220
Copy link

Choose a reason for hiding this comment

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

security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'call' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

Source: opengrep

finally:
if os.path.exists(tmp_known_hosts):
os.unlink(tmp_known_hosts)
elif type_console == "ssh":
# Try to resolve as an inventory group
group_hosts = get_hosts_from_group(host)
Expand Down