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

CIAC-9020 adding 3 new commands to prisma cloud compute #32303

Merged
merged 42 commits into from Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
eac3877
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 18, 2024
1864682
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 18, 2024
a2c7240
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 18, 2024
b748c92
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 21, 2024
fce19ba
Merge branch 'master' into pcc_new_commands
edik24 Jan 21, 2024
ea9fec5
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 21, 2024
f26c0f0
Merge remote-tracking branch 'origin/pcc_new_commands' into pcc_new_c…
edik24 Jan 21, 2024
398c635
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 21, 2024
0cf83bd
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 21, 2024
5f31336
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 22, 2024
05e42e1
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 23, 2024
59e00db
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 23, 2024
d83e2b6
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 23, 2024
ec7493d
Merge branch 'master' into pcc_new_commands
edik24 Jan 23, 2024
3d979db
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 25, 2024
19e57c7
Merge remote-tracking branch 'origin/pcc_new_commands' into pcc_new_c…
edik24 Jan 25, 2024
bb05b6f
Merge branch 'master' into pcc_new_commands
edik24 Jan 25, 2024
c13e132
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 31, 2024
9bb3efb
Merge remote-tracking branch 'origin/pcc_new_commands' into pcc_new_c…
edik24 Jan 31, 2024
4a55582
Merge branch 'master' into pcc_new_commands
edik24 Jan 31, 2024
a309085
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 31, 2024
e7770ce
Merge remote-tracking branch 'origin/pcc_new_commands' into pcc_new_c…
edik24 Jan 31, 2024
0b0b354
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Jan 31, 2024
ad45048
Merge remote-tracking branch 'origin/master' into pcc_new_commands
edik24 Feb 1, 2024
ff25eb0
Merge branch 'master' into pcc_new_commands
edik24 Feb 1, 2024
a5d3573
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Feb 1, 2024
eeae3f0
Merge remote-tracking branch 'origin/pcc_new_commands' into pcc_new_c…
edik24 Feb 1, 2024
45b8762
Merge branch 'master' into pcc_new_commands
edik24 Feb 1, 2024
b8c4c1e
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Feb 1, 2024
fd7c29c
Merge remote-tracking branch 'origin/pcc_new_commands' into pcc_new_c…
edik24 Feb 1, 2024
758c961
Merge branch 'master' into pcc_new_commands
edik24 Feb 4, 2024
607b39e
Merge branch 'master' into pcc_new_commands
edik24 Feb 4, 2024
ba9e65d
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Feb 4, 2024
263301c
Merge remote-tracking branch 'origin/pcc_new_commands' into pcc_new_c…
edik24 Feb 4, 2024
701099b
Merge branch 'master' into pcc_new_commands
edik24 Feb 4, 2024
25d67ef
Merge branch 'master' into pcc_new_commands
edik24 Feb 4, 2024
294dc72
Merge branch 'master' into pcc_new_commands
edik24 Feb 5, 2024
0de6e0b
CIAC-9020 adding 3 new commands to prisma cloud compute
edik24 Feb 5, 2024
946c420
Merge remote-tracking branch 'origin/pcc_new_commands' into pcc_new_c…
edik24 Feb 5, 2024
56a7d77
Merge branch 'master' into pcc_new_commands
edik24 Feb 5, 2024
a348752
Merge branch 'master' into pcc_new_commands
edik24 Feb 6, 2024
a8dd908
Merge branch 'master' into pcc_new_commands
edik24 Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Packs/PrismaCloudCompute/.secrets-ignore
Expand Up @@ -7,3 +7,4 @@ file:README.md
file:Integrations/PaloAltoNetworks_PrismaCloudCompute/README.md
https://raw.githubusercontent.com
https://user-images.githubusercontent.com
8.8.8.0
@@ -1,3 +1,5 @@
import json

import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
import urllib.parse
Expand Down Expand Up @@ -533,6 +535,24 @@ def get_runtime_container_audit_events(self, params: Optional[dict] = None) -> L
"""
return self._http_request(method="GET", url_suffix="audits/runtime/container", params=params)

def archive_audit_incident(self, incident_id: str, data: Optional[str] = None) -> dict:
"""
Sends a request to archive audit incident.

Returns:
list[dict]: runtime container audit events information.
"""
suffix = f'audits/incidents/acknowledge/{incident_id}'
return self._http_request(method="patch", url_suffix=suffix, data=data, resp_type="response")

def get_runtime_host_audit_events(self, all_results: bool = False, params: Optional[dict] = None) -> List[dict]:
if all_results:
return self._get_all_results(url_suffix="audits/runtime/host", params=params)
return self._http_request(method="GET", url_suffix="audits/runtime/host", params=params)

def get_runtime_container_policy(self) -> dict:
return self._http_request(method="GET", url_suffix="policies/runtime/container")


def format_context(context):
"""
Expand Down Expand Up @@ -2336,6 +2356,10 @@ def get_container_scan_results(client: PrismaCloudComputeClient, args: dict) ->
compliance_ids = argToList(args.get("compliance_ids"))
agentless = args.get("agentless")
search = args.get("search")
all_results = argToBoolean(args.get("all_results", "false"))

if all_results:
limit = 0

params = assign_params(
offset=offset, limit=limit, collections=collections, accountIDs=account_ids, clusters=clusters, namespaces=namespaces,
Expand Down Expand Up @@ -2501,6 +2525,136 @@ def get_runtime_container_audit_events(client: PrismaCloudComputeClient, args: d
)


def archive_audit_incident_command(client: PrismaCloudComputeClient, args: dict) -> str:
"""
Archives or Unarchives the audit incident according to the provided incident ID

Args:
client (PrismaCloudComputeClient): prisma-cloud-compute client.
args (dict):prisma-cloud-archive-audit-incident command arguments.

Returns:
string: A string that indicates success or failure
"""
incident_id = args.get("incident_id") or ""
data = {'acknowledged': True if args.get("action") == "archive" else False}
client.archive_audit_incident(incident_id=incident_id, data=json.dumps(data))
return f'Incident {incident_id} was successfully {"archived" if args.get("action") == "archive" else "unarchived"}'


def get_host_audit_list_command(client: PrismaCloudComputeClient, args: dict) -> CommandResults:
"""
Retrieves the runtime host audit events.

Args:
client (PrismaCloudComputeClient): prisma-cloud-compute client.
args (dict):prisma-cloud-compute-runtime-host-audit-events-list command arguments.

Returns:
CommandResults: command-results object.
"""
limit, offset = parse_limit_and_offset_values(
limit=args.get("limit", "50"), offset=args.get("offset", "0")
)
clusters = argToList(args.get("clusters"))
namespaces = argToList(args.get("namespaces"))
audit_id = argToList(args.get("audit_id"))
profile_id = argToList(args.get("profile_id"))
image_name = argToList(args.get("image_name"))
container = argToList(args.get("container"))
container_id = argToList(args.get("container_id"))
_type = argToList(args.get("type"))
effect = argToList(args.get("effect"))
user = argToList(args.get("user"))
_os = argToList(args.get("os"))
app = argToList(args.get("app"))
hostname = argToList(args.get("hostname"))
_time = args.get("time")
attack_type = argToList(args.get("attack_type"))
severity = args.get("severity")
message = args.get("message")
all_results = argToBoolean(args.get("all_results", "false"))

params = assign_params(
offset=offset, limit=limit, clusters=clusters, namespaces=namespaces, id=audit_id, profileID=profile_id,
imageName=image_name, container=container, containerID=container_id, type=_type, effect=effect,
user=user, time=_time, os=_os, app=app, hostname=hostname, attack_type=attack_type, severity=severity, message=message,
)
if runtime_host_audit_events := client.get_runtime_host_audit_events(all_results=all_results, params=params):
table = tableToMarkdown(
name="Runtime Host Audit Events Information",
t=[
{
"ID": audit_events.get("_id", None),
"Hostname": audit_events.get("hostname", None),
"User": audit_events.get("user", None),
"Type": audit_events.get("type", None),
"AttackType": audit_events.get("attackType", None),
"Message": audit_events.get("msg", None),
"Severity": audit_events.get("severity", None),
"Effect": audit_events.get("effect", None)
} for audit_events in runtime_host_audit_events
],
headers=["ID", "Hostname", "User", "Type", "AttackType", "Message", "Severity", "Effect"],
removeNull=True,
)
else:
table = "No results found."

return CommandResults(
outputs_prefix="PrismaCloudCompute.RuntimeHostAuditEvents",
outputs_key_field="_id",
outputs=runtime_host_audit_events,
readable_output=table,
raw_response=runtime_host_audit_events
)


def get_container_policy_list_command(client: PrismaCloudComputeClient, args: dict) -> CommandResults:
"""
Retrieves the runtime policy for containers protected by Defender. A policy consists of ordered rules

Args:
client (PrismaCloudComputeClient): prisma-cloud-compute client.
args (dict):prisma-cloud-compute-runtime-container-policy-list command arguments.

Returns:
CommandResults: command-results object.
"""
limit, offset = parse_limit_and_offset_values(
limit=args.get("limit", "50"), offset=args.get("offset", "0")
)
all_results = argToBoolean(args.get("all_results", "false"))

if runtime_container_policy_events := client.get_runtime_container_policy():
runtime_rules = runtime_container_policy_events.get("rules") or []
if len(runtime_rules) > limit and not all_results:
runtime_rules = runtime_rules[offset * limit:offset * limit + limit]

table = tableToMarkdown(
name="Runtime Container Policy Events Information",
t=[
{
"Name": audit_events.get("name", None),
"Owner": audit_events.get("owner", None),
"Modified": audit_events.get("modified", None),
} for audit_events in runtime_rules
],
headers=["Name", "Owner", "Modified"],
removeNull=True,
)
else:
table = "No results found."

return CommandResults(
outputs_prefix="PrismaCloudCompute.Policies.RuntimeContainerPolicy",
outputs_key_field="_id",
outputs=runtime_rules,
readable_output=table,
raw_response=runtime_rules
)


def main():
"""
PARSE AND VALIDATE INTEGRATION PARAMS
Expand Down Expand Up @@ -2614,6 +2768,12 @@ def main():
return_results(results=get_hosts_info(client=client, args=demisto.args()))
elif requested_command == "prisma-cloud-compute-runtime-container-audit-events-list":
return_results(results=get_runtime_container_audit_events(client=client, args=demisto.args()))
elif requested_command == "prisma-cloud-archive-audit-incident":
return_results(results=archive_audit_incident_command(client=client, args=demisto.args()))
elif requested_command == "prisma-cloud-compute-runtime-host-audit-events-list":
return_results(results=get_host_audit_list_command(client=client, args=demisto.args()))
elif requested_command == "prisma-cloud-compute-runtime-container-policy-list":
return_results(results=get_container_policy_list_command(client=client, args=demisto.args()))
# Log exceptions
except Exception as e:
return_error(f'Failed to execute {requested_command} command. Error: {str(e)}')
Expand Down