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

Visual Guard Rail for Network Containment #130

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
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
40 changes: 39 additions & 1 deletion falcon_toolkit/containment/perform_containment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import tabulate

from caracara import Client
from caracara.common.csdialog import csradiolist_dialog


def result_output(
Expand Down Expand Up @@ -71,6 +72,38 @@ def result_output(
))


def guard_rail_confirmation(device_count: int, action: str) -> bool:
"""Confirm via a visual Prompt Toolkit box whether the user really wants to (un)contain."""
if action == "contain":
confirmation_options = [
(False, "Abort"),
(True, f"Network contain {device_count} devices"),
]
prompt_text = f"Are you sure you want to network contain {device_count} devices?"
else:
confirmation_options = [
(False, "Abort"),
(True, f"Release {device_count} devices from network containment"),
]
prompt_text = (
f"Are you sure you want to release {device_count} devices "
"from network containment?"
)

confirmation: bool = csradiolist_dialog(
title="Confirm Network Containment Action",
text=prompt_text,
values=confirmation_options,
).run()

if confirmation:
click.echo(click.style("User confirmed action", bold=True, fg='green'))
return True

click.echo(click.style("Aborted!", bold=True, fg='red'))
return False


def perform_containment_action(
device_ids: List[str],
client: Client,
Expand All @@ -82,12 +115,17 @@ def perform_containment_action(
if action not in ("contain", "lift_containment"):
raise ValueError(f"{action} is not a supported device action in this function")

device_count = len(device_ids)
if not guard_rail_confirmation(device_count, action):
return

limit = 100
resources = []
errors = []

for i in range(0, len(device_ids), limit):
for i in range(0, device_count, limit):
click.echo("Changing the network containment status on a batch of systems...", nl=False)

response = client.hosts.hosts_api.perform_action(
action_name=action,
ids=device_ids[i: i + limit],
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "falcon-toolkit"
version = "3.4.0"
version = "3.4.1"
description = "Toolkit to interface with CrowdStrike Falcon via the API"
license = "MIT"
authors = [
Expand Down
Loading