diff --git a/abst/__version__.py b/abst/__version__.py index 27c88a7..75f9fed 100644 --- a/abst/__version__.py +++ b/abst/__version__.py @@ -10,7 +10,7 @@ "CLI Command making OCI Bastion and kubernetes usage simple and fast" ) -__version__ = "2.2.3" +__version__ = "2.2.4" __author__ = "Jiri Otoupal" __author_email__ = "jiri-otoupal@ips-database.eu" __license__ = "MIT" diff --git a/abst/bastion_support/bastion_scheduler.py b/abst/bastion_support/bastion_scheduler.py index 03a31c3..250e971 100644 --- a/abst/bastion_support/bastion_scheduler.py +++ b/abst/bastion_support/bastion_scheduler.py @@ -6,9 +6,9 @@ from click import clear from rich.align import Align +from abst.bastion_support.oci_bastion import Bastion from abst.config import default_stack_location, default_stack_contents, \ default_contexts_location -from abst.bastion_support.oci_bastion import Bastion from abst.wrappers import load_stack_decorator @@ -99,18 +99,18 @@ def __display_loop(cls): sleep(3) @classmethod - def _run_indefinitely(cls, func): + def _run_indefinitely(cls, func, force: bool = False): while True: if cls.stopped: return try: - func() + func(force=force) finally: sleep(1) @classmethod @load_stack_decorator - def run(cls): + def run(cls, force=False): signal.signal(signal.SIGINT, BastionScheduler.kill_all) signal.signal(signal.SIGTERM, BastionScheduler.kill_all) rich.print("Will run all Bastions in parallel") @@ -123,7 +123,7 @@ def run(cls): Bastion.load_json(Bastion.get_creds_path_resolve(context_name)).get("region", None)) cls.__live_stack.add(bastion) t = Thread(name=context_name, target=cls._run_indefinitely, - args=[bastion.create_forward_loop], daemon=True) + args=[bastion.create_forward_loop, force], daemon=True) thread_list.append(t) t.start() rich.print(f"Started {context_name}") diff --git a/abst/bastion_support/oci_bastion.py b/abst/bastion_support/oci_bastion.py index 7331df5..aa0c85a 100644 --- a/abst/bastion_support/oci_bastion.py +++ b/abst/bastion_support/oci_bastion.py @@ -25,6 +25,7 @@ class Bastion: session_list = [] session_desc = dict() custom_ssh_options: str = "-o ServerAliveInterval=20" + force_ssh_options: str = "-o StrictHostKeyChecking=no -o ServerAliveInterval=20 -o UserKnownHostsFile=/dev/null" def __init__(self, context_name=None, region=None): self.context_name = context_name @@ -162,7 +163,7 @@ def create_managed_loop(self, shell: bool = False): self.kill() @mark_on_exit - def create_forward_loop(self, shell: bool = False): + def create_forward_loop(self, shell: bool = False, force: bool = False): from abst.bastion_support.bastion_scheduler import BastionScheduler if BastionScheduler.stopped: @@ -203,7 +204,7 @@ def create_forward_loop(self, shell: bool = False): ssh_tunnel_arg_str = self.run_ssh_tunnel_port_forward(bid, host, ip, port, shell, - creds.get("local-port", 22), ssh_pub_key_path) + creds.get("local-port", 22), ssh_pub_key_path, force) while status := (sdata := self.get_bastion_state())[ "lifecycle_state"] == "ACTIVE" and \ @@ -231,10 +232,13 @@ def run_ssh_tunnel_managed_session(self, bid, host, private_key_path, username, exit_code = self.__run_ssh_tunnel_call(ssh_tunnel_args, shell, already_split=True) return ssh_tunnel_args, exit_code - def run_ssh_tunnel_port_forward(self, bid, host, ip, port, shell, local_port, ssh_pub_key_path): + def run_ssh_tunnel_port_forward(self, bid, host, ip, port, shell, local_port, ssh_pub_key_path, force=False): print(f"Bastion {self.get_print_name()} initialized") print(f"Initializing SSH Tunnel for {self.get_print_name()}") - ssh_tunnel_arg_str = f"ssh {self.custom_ssh_options} -N -L {local_port}:{ip}:{port} -p 22 {bid}@{host} -vvv -i {ssh_pub_key_path.strip('.pub')}" + additional_args = "" if not force else self.force_ssh_options + + ssh_tunnel_arg_str = (f"ssh {self.custom_ssh_options} -N -L {local_port}:{ip}:{port} -p 22 {bid}@{host} " + f"-vvv -i {ssh_pub_key_path.strip('.pub')} {additional_args}") self.__run_ssh_tunnel(ssh_tunnel_arg_str, shell) return ssh_tunnel_arg_str diff --git a/abst/cli_commands/parallel/commands.py b/abst/cli_commands/parallel/commands.py index 20d8393..ec60ab7 100644 --- a/abst/cli_commands/parallel/commands.py +++ b/abst/cli_commands/parallel/commands.py @@ -3,8 +3,8 @@ from InquirerPy import inquirer from abst.bastion_support.bastion_scheduler import BastionScheduler -from abst.utils.misc_funcs import setup_calls from abst.tools import display_scheduled +from abst.utils.misc_funcs import setup_calls @click.group(help="Parallel Bastion Control group") @@ -47,9 +47,13 @@ def remove(debug, context_name): @parallel.command("run", help="Run All Bastions in fullauto") @click.option("--debug", is_flag=True, default=False) -@click.option("-y", is_flag=True, default=False) -def run(debug, y): +@click.option("-y", is_flag=True, default=False, help="Automatically confirm") +@click.option("-f", "--force", is_flag=True, default=False, help="Will force connections ignoring security policies") +def run(debug, y, force): setup_calls(debug) + if force: + rich.print("[red]Running in force mode[/red][gray] this mode is less secure as it is ignoring key checking and" + " security policies involving known_hosts[/gray]") display_scheduled() if not y: try: @@ -62,7 +66,7 @@ def run(debug, y): if not confirm: rich.print("[green]Cancelling, nothing started[/green]") exit(0) - BastionScheduler.run() + BastionScheduler.run(force) @parallel.command("display", help="Display current Bastions is stack") diff --git a/abst/main.py b/abst/main.py index ff803f3..a4699e0 100644 --- a/abst/main.py +++ b/abst/main.py @@ -4,6 +4,7 @@ import click import rich from InquirerPy import inquirer +from requests import ConnectTimeout from abst.__version__ import __version_name__, __version__ from abst.bastion_support.bastion_scheduler import BastionScheduler @@ -16,6 +17,7 @@ from abst.cli_commands.kubectl_cli.commands import ssh_pod, log_pod from abst.cli_commands.parallel.commands import parallel from abst.config import default_creds_path, default_contexts_location, default_conf_path +from abst.notifier.version_notifier import Notifier from abst.utils.misc_funcs import setup_calls @@ -83,6 +85,10 @@ def clean(): def main(): + try: + Notifier.notify() + except (ConnectionError, ConnectTimeout): + return False Bastion.create_default_location() cli() diff --git a/abst/utils/misc_funcs.py b/abst/utils/misc_funcs.py index 5b24c3a..d4ee565 100644 --- a/abst/utils/misc_funcs.py +++ b/abst/utils/misc_funcs.py @@ -4,20 +4,14 @@ from typing import Optional import rich -from requests import ConnectTimeout from rich.logging import RichHandler from abst.bastion_support.oci_bastion import Bastion from abst.config import default_contexts_location -from abst.notifier.version_notifier import Notifier def setup_calls(debug): setup_debug(debug) - try: - Notifier.notify() - except (ConnectionError, ConnectTimeout): - return False def setup_debug(debug):