Skip to content

Commit ebe1316

Browse files
committed
Initial version.
1 parent f9372df commit ebe1316

File tree

11 files changed

+2197
-1
lines changed

11 files changed

+2197
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
docker-compose.override.yml

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -----------------
2+
FROM composer:1.9 AS build-env
3+
4+
COPY . /opt/ghsec-jira/
5+
6+
WORKDIR /opt/ghsec-jira
7+
8+
RUN composer install --prefer-dist --no-dev
9+
10+
# -----------------
11+
FROM php:7.3.12-alpine
12+
13+
COPY --from=build-env /opt/ghsec-jira/ /opt/ghsec-jira/
14+
15+
ENTRYPOINT ["/opt/ghsec-jira/bin/ghsec-jira", "sync"]

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,77 @@
11
# github-security-jira
2-
Github Action for integrating Security Alerts with JIRA
2+
GitHub Action for mapping security alerts to Jira tickets.
3+
4+
5+
## Setup
6+
7+
You need the following pieces set up to sync alerts with Jira:
8+
9+
1. Two repo secrets containing a GitHub access token and a Jira API token, respectively.
10+
2. A workflow file which runs the action on a schedule, continually creating new tickets when necessary.
11+
12+
13+
### Repo secrets
14+
The `reload/github-security-jira` action requires you to [create two encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets) in the repo:
15+
16+
1. A secret called `GitHubSecurityToken` which should contain a [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) for the GitHub user under which this action should be executed. The token must include the `public_repo` scope if checking only public repos, or the `repo` scope for use on private repos. Also, the user must have [access to security alerts in the repo](https://help.github.com/en/github/managing-security-vulnerabilities/managing-alerts-for-vulnerable-dependencies-in-your-organization).
17+
2. A secret called `JiraApiToken` containing an [API Token](https://confluence.atlassian.com/cloud/api-tokens-938839638.html) for the Jira user that should be used to create tickets.
18+
19+
20+
### Workflow file setup
21+
The [GitHub workflow file](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow#creating-a-workflow-file) should reside in any repo where you want to sync security alerts with Jira.
22+
23+
It has some required and some optional settings, which are passed to the action as environment variables:
24+
25+
- `GH_SECURITY_TOKEN`: A reference to the repo secret `GitHubSecurityToken` (**REQUIRED**)
26+
- `JIRA_TOKEN`: A reference to the repo secret `JiraApiToken` (**REQUIRED**)
27+
- `JIRA_HOST`: The endpoint for your Jira instance, e.g. https://foo.atlassian.net (**REQUIRED**)
28+
- `JIRA_USER`: The ID of the Jira user which is associated with the 'JiraApiToken' secret, eg '[email protected]' (**REQUIRED**)
29+
- `JIRA_PROJECT`: The project key for the Jira project where issues should be created, eg `TEST` or `ABC`. (**REQUIRED**)
30+
- `JIRA_ISSUE_TYPE`: Type of issue to create, e.g. `Security`. Defaults to `Bug`. (*Optional*)
31+
- `JIRA_WATCHERS`: Jira users to add as watchers to tickets. Use the [YAML block scalar literal style indicator with stripping chomping indicator](https://yaml-multiline.info/) (pipe and dash: `|-`) to add multiple watchers. (*Optional*)
32+
- `JIRA_RESTRICTED_GROUP`: If set, the action will add a restricted comment to the ticket, viewable by only this Jira group. (*Optional*)
33+
- `JIRA_RESTRICTED_COMMENT`: The comment to post. Use the YAML multiline operator for adding linebreaks to the comment. (*Optional, but required if group is set*)
34+
35+
Here is an example setup which runs this action every 15 mins.
36+
37+
```yaml
38+
name: GitHub Security Alerts for Jira
39+
40+
on:
41+
schedule:
42+
- cron: '*/15 * * * *'
43+
44+
jobs:
45+
syncSecurityAlerts:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: "Sync security alerts to Jira issues"
49+
uses: reload/[email protected]
50+
env:
51+
GH_SECURITY_TOKEN: ${{ secrets.GitHubSecurityToken }}
52+
JIRA_TOKEN: ${{ secrets.JiraApiToken }}
53+
JIRA_HOST: https://foo.atlassian.net
54+
JIRA_USER: [email protected]
55+
JIRA_PROJECT: ABC
56+
JIRA_ISSUE_TYPE: Security
57+
JIRA_WATCHERS: |-
58+
59+
60+
JIRA_RESTRICTED_GROUP: Developers
61+
JIRA_RESTRICTED_COMMENT: |-
62+
Remember to evaluate severity here and set ticket priority.
63+
Check out the guide [in our wiki|https://foo.atlassian.net/wiki/]!
64+
```
65+
66+
67+
## Local development
68+
69+
Copy `docker-composer.override.example.yml` to `docker-composer.override.yml` and edit according to your settings.
70+
71+
After that, you can execute the Symfony console app like so:
72+
73+
```
74+
docker-compose run --rm ghsec-jira --verbose --dry-run
75+
```
76+
77+
Remove the `--dry-run` option to actually create issues in Jira.

action.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'Sync GitHub Security Alerts with Jira'
2+
description: 'Synchronize the current repo alert state with JIRA and creates tickets accordingly.'
3+
author: 'reload'
4+
outputs:
5+
result:
6+
description: 'A string summarizing actions performed'
7+
runs:
8+
using: 'docker'
9+
image: 'Dockerfile'
10+
branding:
11+
icon: 'rotate-cw'
12+
color: 'green'

bin/ghsec-jira

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__.'/../vendor/autoload.php';
5+
6+
use Symfony\Component\Console\Application;
7+
use GitHubSecurityJira\SyncCommand;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
13+
$application = new Application('ghsec-jira');
14+
$command = new SyncCommand();
15+
16+
$application->add($command);
17+
$application->setDefaultCommand('sync');
18+
$application->run();

composer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "reload/github-security-jira",
3+
"description": "Create Jira tickets for GitHub security alerts",
4+
"license": "MIT",
5+
"require": {
6+
"php": ">=7.2.0",
7+
"lesstif/php-jira-rest-client": "^1",
8+
"softonic/graphql-client": "^1.2",
9+
"symfony/console": "^4",
10+
"symfony/yaml": "^5.0"
11+
},
12+
"autoload": {
13+
"psr-4": {
14+
"GitHubSecurityJira\\": "src/"
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)