Skip to content

Commit 7965fcc

Browse files
committed
feat: add circleci orbs
1 parent 34f424e commit 7965fcc

File tree

23 files changed

+442
-65
lines changed

23 files changed

+442
-65
lines changed

.github/ISSUE_TEMPLATE/BUG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: "\U0001F41E Bug report"
3+
about: Report any bugs encountered while using this orb.
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
## Orb or Github Action version:
11+
12+
<!---
13+
e.g., 1.0.0
14+
find this information in your config.yml file;
15+
if the version is @volatile, check the top of your CircleCI-generated,
16+
expanded configuration file, viewable from the "Configuration" tab of
17+
any job page, for the orb's specific semantic version number
18+
-->
19+
20+
## What happened:
21+
22+
<!---
23+
please include any relevant links to CircleCI workflows or jobs
24+
where you saw this behavior
25+
-->
26+
27+
## Expected behavior:
28+
29+
<!--- what should happen, ideally? -->
30+
31+
## Additional Information:
32+
33+
<!--- Provide any additional context possible. -->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: "\U0001F680 Feature Request"
3+
about: Propose changes to the orb.
4+
title: ''
5+
labels: feature_request
6+
assignees: ''
7+
---
8+
9+
## Describe Request:
10+
11+
## Examples:
12+
13+
## Supporting Documentation Links:
14+

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: false
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
**SEMVER Update Type:**
3+
- [ ] Major
4+
- [ ] Minor
5+
- [ ] Patch
6+
7+
## Description:
8+
9+
<!---
10+
Describe your changes in detail, preferably in an imperative mood,
11+
i.e., "add `commandA` to `jobB`"
12+
-->
13+
14+
## Motivation:
15+
16+
<!---
17+
Share any open issues this PR references or otherwise describe the motivation to submit this pull request.
18+
-->
19+
20+
**Closes Issues:**
21+
- ISSUE URL
22+
23+
## Checklist:
24+
25+
<!--
26+
Thank you for contributing to CircleCI Orbs!
27+
before submitting your a request, please go through the following
28+
items and place an x in the [ ] if they have been completed
29+
-->
30+
- [ ] Scripts work locally
31+
- [ ] Github Action is working with and have describtion for each step and parameter.
32+
- [ ] All new jobs, commands, executors, parameters have descriptions (CircleCI).
33+
- [ ] Usage Example version numbers have been updated.
34+
- [ ] Changelog has been updated.
35+
- [ ] Update `quay.io/dreamquark/security-report:latest` after merging into main (for dreamquark reviewer only)

.github/workflows/report-example.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Security report workflow
2+
3+
# Controls when the action will run. Workflow runs when manually triggered using the UI
4+
# or API.
5+
on:
6+
push:
7+
branches:
8+
- main
9+
tags:
10+
- 'v*'
11+
paths:
12+
- docker-image/**
13+
workflow_dispatch:
14+
15+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
16+
jobs:
17+
# This workflow contains a single job called "greet"
18+
build:
19+
# The type of runner that the job will run on
20+
runs-on: ubuntu-20.04
21+
# Steps represent a sequence of tasks that will be executed as part of the job
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Extract branch name
26+
shell: bash
27+
run: echo "##[set-output name=branch;]${GITHUB_REF#refs/*/}"
28+
id: extract_branch
29+
30+
- name: Login to Quay.io
31+
uses: docker/login-action@v1
32+
with:
33+
registry: quay.io
34+
username: ${{ secrets.DOCKER_USERNAME }}
35+
password: ${{ secrets.DOCKER_PASSWORD }}
36+
37+
- name: Build & push security-report docker image
38+
run: |
39+
unameOut="${{ steps.extract_branch.outputs.branch }}"
40+
case "${unameOut}" in
41+
main) tag=stable;;
42+
develop) tag=latest;;
43+
v*) tag=${unameOut};;
44+
esac
45+
make -C docker-image DOCKER_TAG=${tag}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 DreamQuark
3+
Copyright (c) 2021 <organization>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# set default shell
2+
SHELL := /bin/bash
3+
.SHELLFLAGS = -c
4+
5+
NAMESPACE=dreamquark-ai
6+
VCS_PROVIDER=github
7+
ORG_NAME=dreamquark-ai
8+
ORB_NAME=ci-security-report
9+
ORB_FILE=./orbs/orb.yml
10+
ORB_DIR=./orbs
11+
VERSION=1.0.0
12+
13+
pack-orb:
14+
circleci orb pack $(ORB_DIR) > $(ORB_FILE)
15+
.PHONY: pack-orb
16+
17+
validate-orb:
18+
circleci orb validate $(ORB_FILE)
19+
.PHONY: validate-orb
20+
21+
publish-orb:
22+
circleci orb publish $(ORB_FILE) $(NAMESPACE)/$(ORB_NAME)@$(VERSION)
23+
.PHONY: publish-orb
24+
25+
all: pack-orb validate-orb publish-orb clear
26+
.PHONY: all
27+
28+
clear:
29+
rm -f $(ORB_FILE)
30+
.PHONY: clear

README.md

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
# Dreamquark security report action
1+
# Dreamquark CI security report
22

3-
This action is meant for generating differntial secirity reports based on [trivy](https://github.com/aquasecurity/trivy) to be published as a comment of a pull request.
3+
This action is meant for generating differential security reports based on [Trivy](https://github.com/aquasecurity/trivy) to be published as a comment of a pull request.
44

5-
From a base image used as reference, it underlies the new security failures and the one that have been removed after changes in your source code.
5+
From a base image used as reference, it underlies the new security vulnerabilities and the one that have been removed after changes in your source code.
66

77

88
## Example of usage
99

10-
Before calling the action make sure to get the images (the base and the new one) in the pipeline either by pulling or building them.
10+
>### Prerequesites
11+
12+
Before calling the action or the orbs, you need to make sure, in the job or in the workflow that:
13+
* An environment variable is set in your GitHub secrets or in your CircleCI context valued with
14+
a valid Github PAT with rights on repositories. The scripts expect to get an environment variable named
15+
`GITHUB_PAT`.
16+
17+
* The images (the base and the new one) exist in the pipeline either by pulling or building them.
18+
19+
>### Use of the Github Action
1120
1221
```name: Example of workflow for security report
1322
@@ -21,35 +30,88 @@ jobs:
2130
- uses: actions/checkout@master
2231
2332
- name: Pull the base image
24-
run: docker pull python:3.10-rc-slim
33+
run: docker pull python:3.8-buster
2534
2635
- name: Build the new image
2736
run: docker build -t python:security-test -f example/Dockerfile .
2837
2938
- name: "Security reports"
30-
uses: dreamquark-ai/github-action-security-report@main
39+
uses: dreamquark-ai/ci-security-report@main
3140
env:
32-
GITHUB_PAT: ${{secrets.SECURITY_REPORT_ACTION_EXAMPLE_PAT}}
41+
GITHUB_PAT: ${{secrets.PAT_SECURITY_REPORT_ACTION_EXAMPLE}}
3342
with:
3443
image: 'python'
35-
base-tag: 3.10-rc-slim
44+
base-tag: '3.8-buster'
3645
new-tag: 'security-test'
37-
orga: 'dreamquark-ai'
38-
repo: 'github-action-security-report'
46+
orga: 'PaulBarrie'
47+
repo: 'ci-security-report-example'
3948
pr-nb: ${{ github.event.number }}
40-
topic: 'example'
49+
topic: 'github-example'
4150
```
4251

52+
>### Use of the CircleCI Orb
53+
54+
```version: 2.1
55+
56+
orbs:
57+
security-report: dreamquark-ai/ci-security-report@1.0.0
58+
59+
executors:
60+
security-report: dreamquark-ai/ci-security-report@1.0.0
61+
62+
jobs:
63+
security-report-example:
64+
executor: security-report/default
65+
working_directory: /root/ci-example
66+
steps:
67+
- checkout
68+
- setup_remote_docker:
69+
docker_layer_caching: false
70+
version: 20.10.2
71+
- run:
72+
name: "Build & pull the images for security report"
73+
command: |
74+
docker pull python:3.8-buster
75+
docker build -t python:security-test -f example/Dockerfile .
76+
77+
- security-report/security-report:
78+
image: 'python'
79+
base-tag: '3.8-buster'
80+
new-tag: 'security-test'
81+
orga: 'PaulBarrie'
82+
repo: 'ci-security-report-example'
83+
topic: 'circleci-example'
84+
85+
workflows:
86+
CI-security-test:
87+
jobs:
88+
- security-report-example:
89+
context: security-report-example
90+
```
4391
## Inputs
4492

4593
| Name | Type | Default | Required | Description |
4694
|--- |:-: |:-: |:-: |:-: |
4795
image | `string` | | `true` | The image on which differential reports must be performed |a
4896
base-tag | `string` | `latest` | `true` | The tag of the base image used as reference |a
4997
new-tag | `string` | `security-test` | `true` | The tag of the new image used to seek out new and removed vulnerabilities |a
98+
repo | `string` | `dreamquark-ai` | `true` | Your GitHub organization name |a
5099
repo | `string` | | `true` | Repository on which the action is triggered |a
51100
pr-nb | `string` | | `true` | PR number on which to comment with the security report |a
52101
topic | `string` | `image` | `true` | The title of the report: used to identify the security report |a
53102

54103

104+
## Code Description
105+
106+
As you may notice in the GitHub action and orb's command definition, the last step consists in executing a `main.sh` script. This script calls three others:
107+
108+
* A `parse-json.sh` script which will find the differences between the two previously generated Trivy report and will generate two json array files with all the vulnerabilities and their related details in the subfolder report:
109+
* A `old.json` file that will contain a list of all the vulnerabilities that have been withdrawn (i.e: the one which are in the report of the base image but not in the report of the new image).
110+
111+
* A `new.json` file that will contain a list of all the vulnerabilities that have been added (i.e: the one which are not in the report of the base image but are in the report of the new image).
55112

113+
* A `md-template.sh` script which will, from the two previously generated json files, generate a markdown summary with two tables containing the new and the removed vulnerabilities.
114+
* A `comment-pr.sh` script that will comment the specified pull request with the previously generated markdown report. Basically:
115+
* It looks like if a report already exists by parsing all the comments and checking if one matches with the specified topic.
116+
* If so, it deletes the previous comment (the previous security report in the pull request).
117+
* And to finish it adds a comment in the pull request using the markdown report.

action.yaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Security report'
1+
name: 'CI Security Report'
22
description: 'Compare security reports between PR and develop'
33
inputs:
44
image:
@@ -26,13 +26,17 @@ inputs:
2626
description: 'The title of the report: used to identify the security report'
2727
default: 'image'
2828
required: true
29+
trivy-timeout:
30+
description: Set the time '<n>m' until when Trivy scan has to stop
31+
default: 20m
32+
2933
runs:
3034
using: 'composite'
3135
steps:
3236
- name: "Install trivy and set up folders"
3337
shell: bash
3438
run: |
35-
mkdir -p ${{ github.action_path }}/reports
39+
mkdir -p ${{ github.action_path }}/scripts/reports
3640
sudo apt-get install wget apt-transport-https gnupg lsb-release
3741
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
3842
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
@@ -41,17 +45,21 @@ runs:
4145
4246
- name: "Security report on base image"
4347
shell: bash
44-
working-directory: ${{ github.action_path }}/reports
45-
run: trivy -q -f json -o report-base.json ${{inputs.image}}:${{inputs.base-tag}}
48+
working-directory: ${{ github.action_path }}/scripts/reports
49+
run: >
50+
trivy -q -f json -o report-base.json --timeout ${{inputs.trivy-timeout}}
51+
${{inputs.image}}:${{inputs.base-tag}}
4652
4753
- name: "Security report on the new image"
4854
shell: bash
49-
working-directory: ${{ github.action_path }}/reports
50-
run: trivy -q -f json -o report-new.json ${{inputs.image}}:${{inputs.new-tag}}
55+
working-directory: ${{ github.action_path }}/scripts/reports
56+
run: >
57+
trivy -q -f json -o report-new.json --timeout ${{inputs.trivy-timeout}}
58+
${{inputs.image}}:${{inputs.new-tag}}
5159
5260
- name: "Compare the reports"
5361
shell: bash
54-
working-directory: ${{ github.action_path }}
62+
working-directory: ${{ github.action_path }}/scripts
5563
run: >
5664
./main.sh --image ${{inputs.image}} --base-tag ${{inputs.base-tag}} --new-tag ${{inputs.new-tag}}
5765
--pull-request ${{inputs.pr-nb}} --topic ${{inputs.topic}} --repo ${{inputs.repo}} --orga ${{inputs.orga}}

0 commit comments

Comments
 (0)