Skip to content

Commit

Permalink
feat(resources-list): added resources info in issue description (#213)
Browse files Browse the repository at this point in the history
* feat(resources-list): added resources info in issue description

* fix(lint-issues): fixed lint issues

* feat(resources): added padding
  • Loading branch information
maira-samtek authored Jun 18, 2024
1 parent 83af8cc commit d41cf2f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 66 deletions.
83 changes: 18 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<h1 align="center" style="border-bottom: none;">macpro-security-hub-sync</h1>

<h3 align="center">NPM module to create Jira issues for all findings in Security Hub for the current AWS account.</h3>
Expand Down Expand Up @@ -55,16 +54,10 @@

</p>



## Usage



Set a few enviroment variables that are expected by the package:



```
export JIRA_HOST=yourorg.atlassian.net
Expand All @@ -77,24 +70,16 @@ export JIRA_TOKEN="a very long string" // This should be a [Personal Access Toke
```



Install the package with a dependency manager of your choice, probably as a dev dependency:



```
npm install @enterprise-cmcs/macpro-security-hub-sync --save-dev
```



Import the package and execute a sync:



```
import { SecurityHubJiraSync } from "@enterprise-cmcs/macpro-security-hub-sync";
Expand All @@ -103,12 +88,8 @@ await new SecurityHubJiraSync().sync();
```



Or, override defaults by passing more options:



```
await new SecurityHubJiraSync({
Expand All @@ -129,36 +110,22 @@ customfield_14151: [{value: "Not Applicable "}],
```



## Info



#### Overview



This package syncs AWS Security Hub Findings to Jira.



- When the sync utility is run, each Security Hub Finding type (Title) is represented as a single issue. So if you have violated the 'S3.8' rule three individual times, you will have one S3.8 Jira Issue created.

- By default, CRITICAL and HIGH severity findings get issues created in Jira. However, this is configurable in either direction (more or less sensitivity).

- When the utility runs, previously created Jira issues that no longer have an active finding are closed. In this way, Jira issues can be automatically closed as the Findings are resolved, if you run the utility on a schedule (recommended).



#### Sync Process



The SecurityHubJiraSyncOptions class's main function is sync. The sync process follows this process:



1. Get all open Security Hub issues (identified by a label convention) from Jira

2. Get all current findings from Security Hub
Expand All @@ -167,20 +134,14 @@ The SecurityHubJiraSyncOptions class's main function is sync. The sync process f

4. Create Jira issue (including labels from our label convention) for current findings that do not already have a Jira issue



#### Instructions to test locally with a yarn project



- in your terminal from your local clone of macpro-security-hub-sync with your development branch

- `yarn link` (note, when testing is complete, run `yarn unlink`)
- `yarn link` (note, when testing is complete, run `yarn unlink`)

that will return output like:



```
yarn link v1.22.19
Expand All @@ -195,26 +156,18 @@ info You can now run `yarn link "@enterprise-cmcs/macpro-security-hub-sync"` in
```



- npm install

- npm run build (this builds the package)



In your local yarn project that will be using the macpro-security-hub-sync package, run:

- `rm -rf node_modules`

- `rm -rf node_modules`

- `yarn link "@enterprise-cmcs/macpro-security-hub-sync"`
- `yarn link "@enterprise-cmcs/macpro-security-hub-sync"`

that will return output like:



```
yarn link v1.22.19
Expand All @@ -227,38 +180,45 @@ success Using linked package for "@enterprise-cmcs/macpro-security-hub-sync".
```



- `yarn install`
- `yarn install`

- Note: when testing is complete run `yarn unlink "@enterprise-cmcs/macpro-security-hub-sync"`


## Supplementary Functions

Below are additional functionalities provided by this package.

#### Automated Closure for Advanced Workflows
#### Automated Closure for Advanced Workflows

Starting from version 1.7.0, this package includes support for automated closure, specifically designed to enhance enterprise workflows within Jira. This feature supports complex workflows that have multiple paths to resolution. To enable automated closure, you need to specify the following parameter:

```
AUTO_CLOSE = true
```

When this parameter is set to true, the system will automatically close tickets based on predefined criteria, streamlining the workflow process and ensuring that issues are resolved efficiently.

#### Skipping Automated Closure

If the AUTO_CLOSE variable is set to false, the package will not automatically close the ticket. Instead, it will append a comment to the relevant ticket to indicate that the issue has been resolved, including the resolution date. For example, if the variable is configured as follows:

```
AUTO_CLOSE = false
```

a comment similar to the following will be added to the ticket, with "Resolved" prefixed to the ticket title:

```
`As of ${new Date(Date.now()).toDateString()}, this Security
Hub finding has been marked resolved`
```

This feature allows for greater control over the closure process, ensuring that stakeholders are informed about the resolution without automatically closing the ticket.

#### Issue Linking Feature

Introduced in version 1.7.2, this feature facilitates the linking of newly created issues to a specified Jira issue ID using a desired link type. The link type can be any of the available Jira Issue Link Types such as 'Relates', 'Blocks', 'Duplicates', etc. To utilize this functionality, you need to set the following environment variables:

```
JIRA_FEATURE_KEY='Pj-12'
JIRA_LINK_TYPE='Relates'
Expand All @@ -267,30 +227,23 @@ JIRA_LINK_TYPE='Relates'
The above configuration will establish links between newly created tickets and 'Pj-12' under the "Relates" relationship. This feature is particularly useful for maintaining a clear and organized relationship between issues, aiding in better tracking and management.

#### Jira Ticket Assignee

This feature assigns the newly created ticket to the Jira user specified in the variable. To configure this feature, use the following variable:

```
ASSIGNEE='user1253'
```

By setting this variable, the package will ensure that the new ticket is assigned to the specified user, streamlining the task assignment process and ensuring that the appropriate team member is notified immediately. This enhances accountability and ensures that issues are addressed promptly by the correct individual.

## Contributing



Work items for this project are tracked in Jira. Check out the [project kanban board](https://qmacbis.atlassian.net/jira/software/c/projects/OY2/boards/251) to view all work items affecting this repo.



If you don't have access to Jira, would like access to Jira, or would like to drop us an idea without pursuing Jira access, please visit the [slack channel](https://cmsgov.slack.com/archives/C04MBTV136X).



## License



[![License](https://img.shields.io/badge/License-CC0--1.0--Universal-blue.svg)](https://creativecommons.org/publicdomain/zero/1.0/legalcode)



See [LICENSE](LICENSE) for full details.
8 changes: 8 additions & 0 deletions src/libs/security-hub-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import {
AwsSecurityFinding,
} from "@aws-sdk/client-securityhub";

export interface Resource {
Id: string;
Partition: string;
Region: string;
Type: string;
}
export interface SecurityHubFinding {
title?: string;
region?: string;
Expand All @@ -16,6 +22,7 @@ export interface SecurityHubFinding {
description?: string;
standardsControlArn?: string;
remediation?: Remediation;
Resources?: Resource[];
}

export class SecurityHub {
Expand Down Expand Up @@ -126,6 +133,7 @@ export class SecurityHub {
? finding.ProductFields.StandardsControlArn
: "",
remediation: finding.Remediation,
Resources: finding.Resources,

Check failure on line 136 in src/libs/security-hub-lib.ts

View workflow job for this annotation

GitHub Actions / Release

Type 'import("/home/runner/work/macpro-security-hub-sync/macpro-security-hub-sync/node_modules/@aws-sdk/client-securityhub/dist-types/models/models_1").Resource[] | undefined' is not assignable to type 'import("/home/runner/work/macpro-security-hub-sync/macpro-security-hub-sync/src/libs/security-hub-lib").Resource[] | undefined'.
};
}
}
25 changes: 24 additions & 1 deletion src/macpro-security-hub-sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Jira, SecurityHub, SecurityHubFinding } from "./libs";
import { Jira, Resource, SecurityHub, SecurityHubFinding } from "./libs";
import { IssueObject } from "jira-client";
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";

Expand Down Expand Up @@ -153,6 +153,23 @@ export class SecurityHubJiraSync {
}
return updatesForReturn;
}
makeResourceList(resources: Resource[] | undefined) {
if (!resources) {
return `No Resources`;
}
const maxLength = Math.max(...resources.map(({ Id }) => Id?.length || 0));
const title = "Resource Id".padEnd(maxLength + maxLength / 2 + 4);

let Table = `${title}| Partition | Region | Type \n`;
resources.forEach(({ Id, Partition, Region, Type }) => {
Table += `${Id.padEnd(maxLength + 2)}| ${Partition.padEnd(
11
)} | ${Region.padEnd(9)} | ${Type} \n`;
});

Table += `------------------------------------------------------------------------------------------------`;
return Table;
}

createIssueBody(finding: SecurityHubFinding) {
const {
Expand Down Expand Up @@ -204,6 +221,12 @@ export class SecurityHubJiraSync {
h2. SecurityHubFindingUrl:
${this.createSecurityHubFindingUrl(standardsControlArn)}
h2. Resources:
Following are the resources those were non-compliant at the time of the issue creation
${this.makeResourceList(finding.Resources)}
To check the latest list of resources, kindly refer to the finding url
h2. AC:
* All findings of this type are resolved or suppressed, indicated by a Workflow Status of Resolved or Suppressed. (Note: this ticket will automatically close when the AC is met.)`;
Expand Down

0 comments on commit d41cf2f

Please sign in to comment.