-
Notifications
You must be signed in to change notification settings - Fork 61
Adding batch_update_findings functionality to AWS SecurityHub integration #3948
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
Open
danielperez660
wants to merge
22
commits into
rapid7:aws_securityhub-2.1.0-release
Choose a base branch
from
danielperez660:SecurityHubArchiveFindings
base: aws_securityhub-2.1.0-release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
50c8550
feat: adding write to SH
127d466
feat: adding write to SH
84be987
feat: updating spec to use enmus and types
a3a0b5a
chore: formatting
047f76a
chore: refresh
0496337
chore: refresh
352f353
chore: refresh
72e7c90
chore: update refresh
8701422
chore: Tested and confirmed functionality
269435a
chore: Tested and confirmed functionality
ad019d8
Merge branch 'master' into SecurityHubArchiveFindings
danielperez660 67f50b4
feat: Update plugins/aws_securityhub/icon_aws_securityhub/actions/bat…
danielperez660 440f1ac
chore: moving logging away from the action and into the connection
57d186b
chore: put error handling back in place
1a9e56d
chore: Update plugins/aws_securityhub/plugin.spec.yaml
danielperez660 ce33d53
chore: padding and updating data type
14c8a97
chore: updating object type of finding_identifiers
eebbaeb
fix: bad quotations
d9237c2
fix: fixing datatype for workflow
4cc78b3
feat: adding tests and updating references to make code run smoothly
708ccfb
fix: fixing bad api response value referenced
408d446
fix: removing empty tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
plugins/aws_securityhub/icon_aws_securityhub/actions/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| # GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT | ||
|
|
||
| from .get_findings.action import GetFindings | ||
|
|
||
| from .batch_update_findings.action import BatchUpdateFindings | ||
2 changes: 2 additions & 0 deletions
2
plugins/aws_securityhub/icon_aws_securityhub/actions/batch_update_findings/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT | ||
| from .action import BatchUpdateFindings |
68 changes: 68 additions & 0 deletions
68
plugins/aws_securityhub/icon_aws_securityhub/actions/batch_update_findings/action.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import insightconnect_plugin_runtime | ||
| from insightconnect_plugin_runtime.exceptions import PluginException | ||
|
|
||
| from .schema import ( | ||
| BatchUpdateFindingsInput, | ||
| BatchUpdateFindingsOutput, | ||
| Input, | ||
| Output, | ||
| Component, | ||
| ) | ||
| from botocore.exceptions import ClientError | ||
|
|
||
| # Custom imports below | ||
| import logging | ||
|
danielperez660 marked this conversation as resolved.
|
||
|
|
||
| logging.getLogger("botocore") | ||
|
|
||
|
|
||
| class BatchUpdateFindings(insightconnect_plugin_runtime.Action): | ||
| def __init__(self): | ||
| super(self.__class__, self).__init__( | ||
| name="batch_update_findings", | ||
| description=Component.DESCRIPTION, | ||
| input=BatchUpdateFindingsInput(), | ||
| output=BatchUpdateFindingsOutput(), | ||
| ) | ||
|
|
||
| def run(self, params={}): | ||
| finding_identifiers = params.get(Input.FINDING_IDENTIFIERS) | ||
| note = params.get(Input.NOTE, None) | ||
| severity = params.get(Input.SEVERITY, None) | ||
| verification_state = params.get(Input.VERIFICATION_STATE, None) | ||
| confidence = params.get(Input.CONFIDENCE, None) | ||
| criticality = params.get(Input.CRITICALITY, None) | ||
| types = params.get(Input.TYPES, None) | ||
| user_defined_fields = params.get(Input.USER_DEFINED_FIELDS, None) | ||
| workflow = params.get(Input.WORKFLOW, None) | ||
| related_findings = params.get(Input.RELATED_FINDINGS, None) | ||
|
|
||
| update_params = { | ||
| "FindingIdentifiers": finding_identifiers, | ||
| "Note": note, | ||
| "Severity": severity, | ||
| "VerificationState": verification_state, | ||
| "Confidence": confidence, | ||
| "Criticality": criticality, | ||
| "Types": types, | ||
| "UserDefinedFields": user_defined_fields, | ||
| "Workflow": workflow, | ||
| "RelatedFindings": related_findings, | ||
| } | ||
|
|
||
| filtered_params = {param: value for param, value in update_params.items() if value is not None} | ||
| client = self.connection.aws.client("securityhub") | ||
|
|
||
| try: | ||
| results = client.batch_update_findings(**filtered_params) | ||
| except ClientError as error: | ||
| raise PluginException( | ||
| cause="AWS Security Hub API call failed.", | ||
| assistance=f"Verify your credentials and finding identifiers. Error: {error.response['Error']['Message']}", | ||
| data=error, | ||
| ) | ||
|
|
||
| return { | ||
| Output.PROCESSEDFINDINGS: results.get("ProcessedFindings", []), | ||
| Output.UNPROCESSEDFINDINGS: results.get("UnprocessedFindings", []), | ||
| } | ||
|
danielperez660 marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.