Ejemplo n.º 1
0
    def _run_config(self, runner: ArmoryInstance, check_run=False) -> None:
        logger.info(bold(red("Running evaluation script")))

        b64_config = self._b64_encode_config()
        options = ""
        if self.no_docker:
            options += " --no-docker"
        if check_run:
            options += " --check"
        if logger.level == logging.DEBUG:
            options += " --debug"

        runner.exec_cmd(f"python -m armory.scenarios.base {b64_config}{options}")
Ejemplo n.º 2
0
    def _run_config(
        self,
        runner: ArmoryInstance,
        check_run=False,
        num_eval_batches=None,
        skip_benign=None,
        skip_attack=None,
        validate_config=None,
    ) -> int:
        logger.info(bold(red("Running evaluation script")))

        b64_config = self._b64_encode_config()
        options = self._build_options(
            check_run=check_run,
            num_eval_batches=num_eval_batches,
            skip_benign=skip_benign,
            skip_attack=skip_attack,
            validate_config=validate_config,
        )
        if self.no_docker:
            kwargs = {}
            python = sys.executable
        else:
            kwargs = {"user": self.get_id()}
            python = "python"

        cmd = f"{python} -m armory.scenarios.base {b64_config}{options}"
        return runner.exec_cmd(cmd, **kwargs)
Ejemplo n.º 3
0
 def _run_jupyter(self, runner: ArmoryInstance, ports: dict) -> None:
     user_id = os.getuid() if os.name != "nt" else 0
     group_id = os.getgid() if os.name != "nt" else 0
     port = list(ports.keys())[0]
     lines = [
         "About to launch jupyter.",
         bold("*** To connect on the command line as well, in a new terminal, run:"),
         bold(
             f"    docker exec -it -u {user_id}:{group_id} {runner.docker_container.short_id} bash"
         ),
         bold("*** To gracefully shut down container, press: Ctrl-C"),
         "",
         "Jupyter notebook log:",
     ]
     logger.info("\n".join(lines))
     runner.exec_cmd(
         f"jupyter lab --ip=0.0.0.0 --port {port} --no-browser --allow-root",
         user="******",
     )
Ejemplo n.º 4
0
    def _run_jupyter(self, runner: ArmoryInstance, ports: dict) -> None:
        if not self.root:
            logger.warning("Running Jupyter Lab as root inside the container.")

        user_group_id = self.get_id()
        port = list(ports.keys())[0]
        lines = [
            "About to launch jupyter.",
            bold("*** To connect on the command line as well, in a new terminal, run:"),
            bold(
                red(
                    f"    docker exec -it -u {user_group_id} {runner.docker_container.short_id} bash"
                )
            ),
            bold("*** To gracefully shut down container, press: Ctrl-C"),
            "",
            "Jupyter notebook log:",
        ]
        logger.info("\n".join(lines))
        runner.exec_cmd(
            f"jupyter lab --ip=0.0.0.0 --port {port} --no-browser --allow-root",
            user="******",
        )
Ejemplo n.º 5
0
 def _run_command(self, runner: ArmoryInstance, command: str) -> int:
     logger.info(bold(red(f"Running bash command: {command}")))
     return runner.exec_cmd(command,
                            user=self.get_id(),
                            expect_sentinel=False)
Ejemplo n.º 6
0
 def _run_command(self, runner: ArmoryInstance, command: str) -> None:
     logger.info(bold(red(f"Running bash command: {command}")))
     runner.exec_cmd(command)