Skip to content

Commit b3c18f5

Browse files
author
Yoan Moscatelli
committed
♻️ migrate to python
1 parent 06b7067 commit b3c18f5

File tree

18 files changed

+912
-138
lines changed

18 files changed

+912
-138
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
FROM mcr.microsoft.com/devcontainers/base:jammy
22

3-
RUN export DEBIAN_FRONTEND=noninteractive && \
4-
curl -O -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh && \
5-
sudo sh install.sh -b /usr/local/bin
6-
7-
RUN export DEBIAN_FRONTEND=noninteractive && \
8-
curl -O -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh && \
9-
sudo sh install.sh -b /usr/local/bin
10-
11-
RUN export DEBIAN_FRONTEND=noninteractive && \
12-
curl -O -sSfL https://aquasecurity.github.io/trivy-repo/deb/public.key && \
13-
sudo apt-key add public.key && \
14-
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | tee -a /etc/apt/sources.list.d/trivy.list
15-
163
RUN export DEBIAN_FRONTEND=noninteractive && \
174
apt-get update && \
185
apt-get install --no-install-recommends -y \
@@ -25,7 +12,6 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
2512
p7zip-full \
2613
skopeo \
2714
tmux \
28-
trivy \
2915
vim \
3016
&& \
3117
apt-get clean

.devcontainer/devcontainer.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,32 @@
55
},
66
"features": {
77
"ghcr.io/devcontainers/features/github-cli:1": {},
8-
"ghcr.io/devcontainers/features/sshd:1": {}
8+
"ghcr.io/devcontainers/features/sshd:1": {},
9+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
910
},
1011
"customizations": {
1112
"vscode": {
1213
"extensions": [
14+
//Python support
15+
"ms-python.python",
16+
//Python test explorer
17+
"littlefoxteam.vscode-python-test-adapter",
18+
//PEP Pyton formatter
19+
"ms-python.black-formatter",
20+
//Python debugger
21+
"ms-python.debugpy",
22+
//Github Action helper
1323
"github.vscode-github-actions",
24+
//Github Copilot
1425
"GitHub.copilot",
26+
//Github Copilot chat
1527
"GitHub.copilot-chat",
28+
//Github Pull Request
1629
"GitHub.vscode-pull-request-github",
17-
"ms-vscode-remote.remote-containers",
30+
//Git history
1831
"donjayamanne.githistory",
19-
"solomonkinard.git-blame",
20-
"ms-python.python"
32+
//Git blame
33+
"solomonkinard.git-blame"
2134
],
2235
"settings": {
2336
"terminal.integrated.profiles.linux": {
@@ -31,5 +44,5 @@
3144
}
3245
},
3346
"remoteUser": "vscode",
34-
"postCreateCommand": ".devcontainer/setup.sh"
47+
"postCreateCommand": "bash .devcontainer/setup.sh"
3548
}

.devcontainer/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
requests==2.31.0
2-
GitPython==3.1.43
2+
GitPython==3.1.43
3+
pyunpack==0.3
4+
patool==2.2.0

.devcontainer/setup.sh

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ fi
1919
echo "Updating localtime"
2020
sudo ln -fs /usr/share/zoneinfo/UTC /etc/localtime
2121

22+
# Install act
23+
gh extension install https://github.com/nektos/gh-act
24+
25+
# Install dependencies
26+
echo "Installing dependencies"
27+
python3 src/main.py install
2228
echo "End of setup"

.github/workflows/tests.yaml

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,54 @@ name: "action-test"
22
on:
33
push:
44
pull_request:
5-
workflow_dispatch:
6-
inputs:
7-
ref:
8-
description: "the git revision to checkout"
9-
required: false
10-
repo:
11-
description: "repository to scan"
12-
required: false
13-
input_path:
14-
description: "path to the repository"
15-
default: "."
16-
required: false
17-
output_path:
18-
description: "path to store the sbom"
19-
default: "."
20-
required: false
215

226
jobs:
23-
247
test-as-action:
258
runs-on: ubuntu-22.04
269
steps:
27-
2810
- name: Checkout
2911
uses: actions/checkout@v4
3012
with:
3113
path: ./
14+
fetch-depth: 0
15+
fetch-tags: true
3216

33-
- name: Install syft
17+
- name: Download artifact
3418
shell: bash
35-
run: |
36-
export DEBIAN_FRONTEND=noninteractive && \
37-
curl -O -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh && \
38-
sudo sh install.sh -b /usr/local/bin
19+
run: curl -o /tmp/Core-15.0.iso https://distro.ibiblio.org/tinycorelinux/15.x/x86/release/Core-15.0.iso
20+
21+
- name: Scan repo
22+
uses: ./
23+
with:
24+
target: ./
25+
output-dir: "/tmp/test/sbom"
26+
syft-version: "1.1.0"
27+
vuln-report: True
3928

40-
- name: Run syft
29+
- name: Scan directory
4130
uses: ./
4231
with:
43-
repo: sbom-test
44-
input_path: ./tests
45-
output_path: .
46-
generate_vulnerability_report: "true"
32+
target: /etc
33+
output-dir: "/tmp/test/sbom"
34+
name: "ghactionetc"
35+
36+
- name: Scan iso
37+
uses: ./
38+
with:
39+
target: /tmp/Core-15.0.iso
40+
output-dir: "/tmp/test/sbom"
41+
version: "15.0"
42+
name: "tinycorelinux"
43+
vuln-report: False
4744

4845
- name: Print the content of generated sbom file
46+
shell: bash
4947
run: |
50-
for sbom in repo_*.json; do
48+
for sbom in /tmp/test/sbom/*.json; do
5149
echo "Content of $sbom"
5250
cat $sbom
5351
done
54-
for sbom in repo_*.html; do
52+
for sbom in /tmp/test/sbom/reports/*.html; do
5553
echo "Content of vulnerability result for SBOM: $sbom"
5654
cat $sbom
5755
done

.gitignore

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ dist/
6666
downloads/
6767
eggs/
6868
.eggs/
69-
lib/
70-
lib64/
7169
parts/
7270
sdist/
7371
var/
@@ -223,11 +221,6 @@ pyrightconfig.json
223221

224222
### VisualStudioCode ###
225223
.vscode/*
226-
!.vscode/settings.json
227-
!.vscode/tasks.json
228-
!.vscode/launch.json
229-
!.vscode/extensions.json
230-
!.vscode/*.code-snippets
231224

232225
# Local History for Visual Studio Code
233226
.history/

CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Contributing
2+
3+
Contributions are welcome! Please follow the guidelines below.
4+
5+
## Codespaces
6+
7+
This project is configured to work with GitHub Codespaces. To open the project in a Codespace, click the button below:
8+
9+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/scality/sbom)
10+
11+
## Run the action locally
12+
13+
`act` can be used to run the GitHub Actions workflow locally.
14+
It has been installed through the `gh` extension.
15+
To run the workflow locally, execute the following command:
16+
17+
```bash
18+
gh act push --rm --workflows=.github/workflows/tests.yaml -P ubuntu-22.04=ghcr.io/catthehacker/ubuntu:act-22.04
19+
```
20+
21+
For more information on how to use `act`, please refer to the [official documentation] or run `gh act --help`.
22+
23+
[official documentation]: https://nektosact.com/introduction.html

README.md

Lines changed: 133 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,154 @@
11
# Generate SBOM GitHub Action
22

3-
This action generates a Software Bill of Materials (SBOM) from git repositories using [Syft](https://github.com/anchore/syft).
3+
[![GitHub release](https://img.shields.io/github/release/scality/sbom.svg)](https://github.com/scality/sbom/releases/latest)
4+
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/anchore/sbom-action/blob/main/LICENSE)
45

5-
Syft will search in the entire repository and generate a sbom file for each language.
6+
A GitHub Action for creating a software bill of materials (SBOM)
7+
using [Syft](https://github.com/anchore/syft).
68

7-
Actually, only those languages are supported:
9+
## Basic Usage
810

9-
- python
10-
- go
11-
- javascript
12-
- github-actions
11+
```yaml
12+
- uses: scality/sbom@v1
13+
with:
14+
target: ./
15+
```
1316
14-
If you need to add more syft cataloger, please open an issue.
17+
This will create SBOM result files based on type, ex:
1518
16-
## Inputs
19+
- repo_sbom_v1.1.0-4-gd6cdf1f.json
20+
- repo_sbom_v1.2.0.json
21+
- image_nginx_latest.json
22+
- iso_myiso.iso_128.json
1723
18-
### `ref`
24+
If you want to scan a repository, you have to checkout it with `fetch-tags`.
25+
This is mandatory to get repo version for SBOM filename.
1926

20-
The git revision to checkout. Default is the current commit SHA.
27+
```yaml
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
fetch-tags: true
32+
```
2133

22-
### `repo`
34+
## Configuration
2335

24-
The repository to scan. This is required.
36+
### scality/sbom
2537

26-
### `input_path`
38+
The main [SBOM action](action.yml), responsible for generating SBOMs.
2739

28-
The path to the repository. This is required.
40+
| Parameter | Description | Default |
41+
| --------------------------- | ------------------------------------------------------------------------------------- | ---------------------- |
42+
| `grype-version` | Grype version to use | 0.77.2 |
43+
| `sfyt-version` | Syft version to use | 1.2.0 |
44+
| `trivy-version` | Trivy version to use | 0.50.1 |
45+
| `target` | A file/directory/iso on the filesystem to scan. | \<current directory> |
46+
| `format` | Format of SBOM file. | cyclonedx-json |
47+
| `name` | Name of the target, if you need to overwrite the detected. | |
48+
| `version` | Version of the target, if you need to overwrite the detected. ISO have no version. | |
49+
| `output_dir` | Path to store generated SBOM files. | /tmp/sbom |
50+
| `exclude_mediatypes` | Media types to exclude for images. | |
51+
| `vuln_report` | Generate vuln report using Grype. | |
2952

30-
### `output_path`
53+
## Example Usage
3154

32-
The path to store the SBOM. This is required.
55+
### Scan with a specific format
56+
57+
Use the `path` parameter, relative to the repository root:
58+
59+
```yaml
60+
- uses: scality/sbom@v1
61+
with:
62+
target: ./artifacts
63+
format: cyclonedx-json
64+
```
65+
66+
### Exclude mediatypes for container images
67+
68+
Images created with Oras for example have custom mediatype and are not usable
69+
by Skopeo, they have to be excluded.
70+
71+
```yaml
72+
- uses: scality/sbom@v1
73+
with:
74+
target: ./images
75+
exclude_mediatypes: "application/grafana-dashboard+json text/nginx-conf-template"
76+
```
3377

34-
## Example usage
78+
### Full example
3579

3680
```yaml
37-
uses: scality/sbom@v1
38-
with:
39-
ref: ${{ github.sha }}
40-
repo: 'your-repo-to-scan'
41-
input_path: 'path-to-your-repo'
42-
output_path: 'path-to-store-sbom'
81+
name: "Generate sbom"
82+
on:
83+
workflow_dispatch:
84+
workflow_call:
85+
jobs:
86+
generate-sbom:
87+
runs-on: ubuntu-22.04
88+
env:
89+
BASE_PATH: ${{ github.workspace }}/workdir
90+
SBOM_PATH: ${{ github.workspace }}/artifacts/sbom
91+
steps:
92+
- name: Create directories
93+
shell: bash
94+
run: |
95+
mkdir -p ${{ env.BASE_PATH }}/repo
96+
mkdir -p ${{ env.BASE_PATH }}/iso
97+
mkdir -p ${{ env.SBOM_PATH }}
98+
- name: Checkout repo for scanning
99+
uses: actions/checkout@v4
100+
with:
101+
fetch-depth: 0
102+
fetch-tags: true
103+
path: ${{ env.BASE_PATH }}/repo/myrepo
104+
- name: Generate sbom for repository
105+
uses: scality/sbom@v1.2.0
106+
with:
107+
target: ${{ env.BASE_PATH }}/repo/myrepo
108+
output-dir: ${{ env.SBOM_PATH }}
109+
- name: Get artifacts URL
110+
uses: scality/action-artifacts@v4
111+
id: artifacts
112+
with:
113+
method: setup
114+
url: https://artifactmanager.net
115+
user: ${{ secrets.ARTIFACTS_USER }}
116+
password: ${{ secrets.ARTIFACTS_PASSWORD }}
117+
- name: Donwload artifacts
118+
shell: bash
119+
env:
120+
ARTIFACTS_URL: ${{ steps.artifacts.outputs.link }}
121+
ARTIFACTS_USER: ${{ secrets.ARTIFACTS_USER }}
122+
ARTIFACTS_PASSWORD: ${{ secrets.ARTIFACTS_PASSWORD }}
123+
run: |
124+
echo "Downloading my.iso from $ARTIFACTS_URL"
125+
curl -sSfL -o ${{ env.BASE_PATH }}/iso/my.iso -u $ARTIFACTS_USER:$ARTIFACTS_PASSWORD $ARTIFACTS_URL/my.iso
126+
- name: Generate sbom for ISO
127+
uses: scality/sbom@v1.2.0
128+
with:
129+
target: ${{ env.BASE_PATH }}/iso/my.iso
130+
version: "1.0.0" # Make sure to replace this with the actual ISO version
131+
output-dir: ${{ env.SBOM_PATH }}
132+
- name: Generate archive
133+
shell: bash
134+
run: |
135+
cd ${{ env.SBOM_PATH }}
136+
tar -czf sbom_myproject.tar.gz *.json
137+
- name: Clean up
138+
shell: bash
139+
run: |
140+
rm -rf ${{ env.BASE_PATH }}/repo
141+
rm -rf ${{ env.BASE_PATH }}/iso
142+
rm -f ${{ env.SBOM_PATH }}/*.json
143+
- name: Upload artifacts
144+
if: always()
145+
uses: scality/action-artifacts@v4
146+
with:
147+
method: upload
148+
url: https://artifactmanager.net
149+
user: ${{ secrets.USER }}
150+
password: ${{ secrets.PASSWORD }}
151+
source: artifacts
43152
```
44153

45154
## References

0 commit comments

Comments
 (0)