Skip to content
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

sast-jobs dockerfile/readme #12

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SQ-*
12 changes: 12 additions & 0 deletions sast-job/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# syntax = docker/dockerfile:1.6

FROM python:3.8-slim

ENV PYTHONDONTWRITEBYTECODE 1
WORKDIR /app

RUN apt-get update -y && apt-get install --no-install-recommends -y curl python3-pip nodejs npm && pip3 install requests bs4 lxml

COPY sq-job.py .

CMD ["python3", "sq-job.py"]
9 changes: 9 additions & 0 deletions sast-job/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
REPO=accuknox
IMGNAME=sastjob
IMGTAG=latest
IMG=${REPO}/${IMGNAME}:${IMGTAG}
build:
docker buildx build -t ${IMG} .

push:
docker push ${IMG}
15 changes: 15 additions & 0 deletions sast-job/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#

```
docker run --rm -it -e SQ_URL=http://35.188.10.229:9000 -e SQ_AUTH_TOKEN=<AUTH-TOKEN> -e SQ_PROJECTS="^nimbus$" -e REPORT_PATH=/app/data/ -v $PWD:/app/data/ accuknox/sastjob:latest
```

Configuration
| Var | Sample Value | Description |
|----------------|---------------------------|------------------------------------|
| SQ_URL* | http://35.188.10.229:9000 | SonarQube server URL |
| SQ_AUTH_TOKEN* | squ_token | SonarQube user authn token |
| SQ_PROJECTS | "^nimbus$" | Scan the given projects/components |
| REPORT_PATH | /app/data/ | Path to keep the report json files |

> * are mandatory configuration options
6 changes: 4 additions & 2 deletions sast-job/sq-job.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def prereq():
Install NodeJS which is needed to run SonarQube.
"""
try:
return ""
return "" # Everything installed using Dockerfile
subprocess.run(
"curl -sL https://s3.amazonaws.com/scripts.accuknox.com/nodesource_setup.sh -o /tmp/nodesource_setup.sh",
shell=True,
Expand Down Expand Up @@ -199,7 +199,8 @@ def _get_results(key, auth_token=None, sonar_url=None, branch=None):
results += "]}"

# Write results to file
issues_file = os.path.join(f"{SCANNED_FILE_DIR}", "SQ-{}.json".format(time.time()))
issues_file = os.path.join(f"{SCANNED_FILE_DIR}", "SQ-{}.json".format(key))
#issues_file = os.path.join(f"{SCANNED_FILE_DIR}", "SQ-{}.json".format(time.time()))
with open(issues_file, "w") as f:
f.write(results)

Expand Down Expand Up @@ -638,6 +639,7 @@ def get_all_results_main_branch(
sq_url = os.environ.get("SQ_URL", "")
sq_auth_token = os.environ.get('SQ_AUTH_TOKEN', "")
sq_projects = os.environ.get('SQ_PROJECTS', ".*")
SCANNED_FILE_DIR = os.environ.get('REPORT_PATH', "./")

if sq_url == "" or sq_auth_token == "":
log.error("SQ_URL or SQ_AUTH_TOKEN env var not specified")
Expand Down