Skip to content

Commit b682473

Browse files
authored
Remove deprecated IBM finding plugin (#157)
BREAKING CHANGES: this notifier will be removed. Seems like ibm_cloud_security_advisor is [now deprecated](https://github.com/ibm-cloud-security/security-advisor-sdk-python/). It is having issues compatibility issues with Python 3.12.
1 parent 2868685 commit b682473

File tree

14 files changed

+41
-273
lines changed

14 files changed

+41
-273
lines changed

.flake8

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
max-line-length = 120
3+
exclude =
4+
.venv
5+
.build
6+
__pycache__
7+
.idea
8+
build

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.6.0
44
hooks:
55
- id: trailing-whitespace
66
- id: check-yaml
77
- id: fix-encoding-pragma
88
args: ["--remove"] # Not needed on python3
99
- repo: https://github.com/ambv/black
10-
rev: 22.12.0
10+
rev: 24.4.2
1111
hooks:
1212
- id: black
1313
- repo: https://github.com/PyCQA/flake8
14-
rev: 6.0.0
14+
rev: 7.1.0
1515
hooks:
1616
- id: flake8
1717
files: "^(compliance|test|demo)"
1818
- repo: https://github.com/PyCQA/bandit
19-
rev: 1.7.4
19+
rev: 1.7.9
2020
hooks:
2121
- id: bandit
2222
args: [--recursive]

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# [3.0.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v3.0.0)
2+
3+
- [CHANGED] Remove IBM findings notifier.
4+
15
# [2.0.1](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v2.0.1)
26

37
- [FIXED] Enable universal newlines when executing local commands.

compliance/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414
"""Compliance automation package."""
1515

16-
__version__ = "2.0.1"
16+
__version__ = "3.0.0"

compliance/config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ class ComplianceConfig(object):
4949
# Pagerduty service id to use for an accreditation
5050
# E.g. {"mycompany.soc2": "ABCDEFG"}
5151
"pagerduty": {},
52-
# Security Advisor FindingsAPI endpoint to use for an accreditation
53-
# E.g. {"mycompany.soc2": "https://my.findings.api/findings"}
54-
"findings": {},
5552
},
5653
"org": {"name": "YOUR_ORG", "settings": {}},
5754
}

compliance/fetch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def fetchURL(self, url, params=None, creds=None): # noqa: N802
9090
org = self.config.raw_config.get("org", {}).get("name", "")
9191
ua = f'{org.lower().replace(" ", "-")}-compliance-checks'
9292
response = requests.get(
93-
url, params=params, auth=creds, headers={"User-Agent": ua}
93+
url, params=params, auth=creds, headers={"User-Agent": ua}, timeout=3600
9494
)
9595
response.raise_for_status()
9696
return response.content
@@ -151,7 +151,7 @@ def fetchLocalCommands( # noqa: N802
151151
if not cwd:
152152
cwd = os.path.expanduser("~")
153153
stdin = "\n".join(commands) + "\n"
154-
return check_output(
154+
return check_output( # nosec: B603 The input command can be anything.
155155
cmd, cwd=cwd, env=env, input=stdin, timeout=timeout, universal_newlines=True
156156
).rstrip()
157157

@@ -165,7 +165,7 @@ def fetch(url, name):
165165
166166
:returns: the path to the file.
167167
"""
168-
r = requests.get(url)
168+
r = requests.get(url, timeout=3600)
169169
r.raise_for_status()
170170
path = Path(tempfile.gettempdir(), name)
171171
with path.open("wb") as f:

compliance/locker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def get_locker_repo(self, locker="evidence locker"):
654654
def init_config(self):
655655
"""Apply the git configuration."""
656656
with self.repo.config_writer() as cw:
657-
for (section, cfg) in self.gitconfig.items():
657+
for section, cfg in self.gitconfig.items():
658658
for key, value in cfg.items():
659659
cw.set_value(section, key, value)
660660

compliance/notify.py

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
from compliance.utils.services.github import Github
2828
from compliance.utils.test import parse_test_id
2929

30-
from ibm_cloud_sdk_core.api_exception import ApiException
31-
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
32-
33-
from ibm_cloud_security_advisor import FindingsApiV1
34-
3530
import requests
3631

3732

@@ -861,7 +856,9 @@ def _send_message(self, message, channels):
861856
retries = self._config.get("retries", 3)
862857
retry = 0
863858
while retry < retries:
864-
response = requests.post(url, headers=headers, data=json.dumps(msg))
859+
response = requests.post(
860+
url, headers=headers, data=json.dumps(msg), timeout=180
861+
)
865862
if response.status_code == 429:
866863
time.sleep(int(response.headers.get("Retry-After", retry)) + 1)
867864
retry += 1
@@ -1050,77 +1047,6 @@ def _resolve_alert(self, test_id, test_desc, msg, accreditation):
10501047
)
10511048

10521049

1053-
class FindingsNotifier(_BaseNotifier):
1054-
"""
1055-
Findings notifier class.
1056-
1057-
Notifications are sent using the Findings API. This notifier is
1058-
configurable via :class:`compliance.config.ComplianceConfig`.
1059-
"""
1060-
1061-
def __init__(self, results, controls, push_error=False):
1062-
"""
1063-
Construct and initialize the Findings notifier object.
1064-
1065-
:param results: dictionary generated by
1066-
:py:class:`compliance.runners.CheckMode` at the end of the execution.
1067-
:param controls: the control descriptor that manages accreditations.
1068-
"""
1069-
super(FindingsNotifier, self).__init__(results, controls, push_error)
1070-
self._config = get_config().get("notify.findings")
1071-
self._creds = get_config().creds
1072-
api_key = self._creds["findings"].api_key
1073-
authenticator = IAMAuthenticator(apikey=api_key)
1074-
self.findings_api = FindingsApiV1(authenticator=authenticator)
1075-
1076-
def notify(self):
1077-
"""Send notifications to the Findings API."""
1078-
if self._push_error:
1079-
self.logger.error(
1080-
"Remote locker push failed. Findings notifier not triggered."
1081-
)
1082-
return
1083-
self.logger.info("Running the Findings notifier...")
1084-
if not self._config:
1085-
self.logger.warning("Using findings notification without config")
1086-
1087-
messages = list(self._messages_by_accreditations().items())
1088-
messages.sort(key=lambda x: x[0])
1089-
for accreditation, desc in messages:
1090-
if accreditation not in self._config:
1091-
continue
1092-
findings_api_endpoint = self._config[accreditation]
1093-
self.findings_api.set_service_url(findings_api_endpoint)
1094-
1095-
passed, failed, warned, errored = self._split_by_status(desc)
1096-
for _, _, msg in failed + errored + passed + warned:
1097-
self._create_findings(msg["body"])
1098-
1099-
def _create_findings(self, data):
1100-
occurrence_list = data["occurrence_list"]
1101-
account_id = data["account_id"]
1102-
provider_id = data["provider_id"]
1103-
status = 0
1104-
1105-
for occurrence in occurrence_list:
1106-
try:
1107-
response = self.findings_api.create_occurrence(
1108-
account_id=account_id, provider_id=provider_id, **occurrence
1109-
)
1110-
self.logger.info(response.status_code)
1111-
except ApiException as e:
1112-
status = e.code
1113-
self.logger.error(
1114-
"Finding creation failed "
1115-
f'for occurrence id {occurrence["id"]} '
1116-
f"with {str(e.code)}: {str(e)}"
1117-
)
1118-
except Exception as e:
1119-
status = -1
1120-
self.logger.error(f"Unexpected error occurred: {str(e)}")
1121-
return status
1122-
1123-
11241050
def get_notifiers():
11251051
"""
11261052
Provide a dictionary of all notifier class objects.
@@ -1137,5 +1063,4 @@ def get_notifiers():
11371063
"pagerduty": PagerDutyNotifier,
11381064
"gh_issues": GHIssuesNotifier,
11391065
"locker": LockerNotifier,
1140-
"findings": FindingsNotifier,
11411066
}

compliance/utils/services/pagerduty.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get(path, params=None, headers=None, creds=None):
5656
params.update({"limit": PAGES_LIMIT, "offset": offset})
5757
more = True
5858
while more:
59-
r = requests.get(url, headers=hdrs, params=params)
59+
r = requests.get(url, headers=hdrs, params=params, timeout=180)
6060
yield r
6161
more = r.json().get("more", False)
6262
if more:
@@ -77,7 +77,7 @@ def delete(path, params=None, headers=None, creds=None):
7777
:param creds: a Config object with PagerDuty credentials
7878
"""
7979
url, params, hdrs = _init_request(path, params, headers, creds)
80-
return requests.delete(url, headers=hdrs, params=params)
80+
return requests.delete(url, headers=hdrs, params=params, timeout=180)
8181

8282

8383
def put(path, params=None, headers=None, creds=None):
@@ -93,7 +93,7 @@ def put(path, params=None, headers=None, creds=None):
9393
:param creds: a Config object with PagerDuty credentials
9494
"""
9595
url, params, hdrs = _init_request(path, params, headers, creds)
96-
return requests.put(url, headers=hdrs, params=params)
96+
return requests.put(url, headers=hdrs, params=params, timeout=180)
9797

9898

9999
def post(path, params=None, headers=None, creds=None):
@@ -109,7 +109,7 @@ def post(path, params=None, headers=None, creds=None):
109109
:param creds: a Config object with PagerDuty credentials
110110
"""
111111
url, params, hdrs = _init_request(path, params, headers, creds)
112-
return requests.post(url, headers=hdrs, params=params)
112+
return requests.post(url, headers=hdrs, params=params, timeout=180)
113113

114114

115115
def send_event(
@@ -132,7 +132,9 @@ def send_event(
132132
}
133133
headers = {"Content-Type": "application/json"}
134134

135-
response = requests.post(PD_EVENTS_V2_URL, headers=headers, data=json.dumps(msg))
135+
response = requests.post(
136+
PD_EVENTS_V2_URL, headers=headers, data=json.dumps(msg), timeout=180
137+
)
136138
response.raise_for_status()
137139
if response.json().get("status") != "success":
138140
raise RuntimeError("PagerDuty Error: " + response.json())

doc-source/notifiers.rst

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Notifiers
88
The last phase in a typical framework check run is the notification
99
system. Multiple notifiers can be targeted as part of this phase by using
1010
the ``--notify`` option on the ``compliance --check`` command. Valid
11-
notifier options are ``stdout``, ``slack``, ``pagerduty``, ``findings``,
11+
notifier options are ``stdout``, ``slack``, ``pagerduty``,
1212
``gh_issues`` and, ``locker``. The general idea behind the notification
1313
system is that each ``test_`` can generate a short notification that has the
1414
following components:
@@ -347,33 +347,3 @@ locker. The summary markdown file will **only** be pushed to the remote
347347
evidence locker if the ``full-remote`` argument is applied to the ``evidence``
348348
option when executing your checks otherwise the file will remain in the local
349349
evidence locker. No additional configuration is required for this notifier.
350-
351-
Security Advisor Findings
352-
-------------------------
353-
354-
This configurable notifier will post findings to Security Advisor Findings API
355-
per accreditation. The following is an example configuration for this notifier
356-
to be added to a configuration file and used with the ``-C`` option when
357-
executing your compliance checks::
358-
359-
{
360-
"notify": {
361-
"findings": {
362-
"accr1": "https://us-south.secadvisor.cloud.ibm.com/findings",
363-
"accr2": "https://eu-gb.secadvisor.cloud.ibm.com/findings"
364-
}
365-
}
366-
}
367-
368-
Supported regions for Security Advisor Findings API
369-
- us-south: https://us-south.secadvisor.cloud.ibm.com/findings
370-
- eu-gb: https://eu-gb.secadvisor.cloud.ibm.com/findings
371-
372-
This notifier also needs to know the credentials for sending findings
373-
to Security Advisor Findings API. Include the following in your credentials
374-
file::
375-
376-
[findings]
377-
api_key=platform-api-key
378-
379-
``api_key`` is your IBM Cloud Platform API Key.

0 commit comments

Comments
 (0)