Skip to content

Commit 599d189

Browse files
committed
update for cve-report; new rl-deploy
1 parent df11c11 commit 599d189

File tree

5 files changed

+86
-29
lines changed

5 files changed

+86
-29
lines changed

Makefile

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ endif
1010

1111
VOLUMES := -v ./output:/output -v ./input:/input
1212
USER_GROUP := $(shell id -u):$(shell id -u )
13-
1413
COMMON_DOCKER := -i --rm -u $(USER_GROUP) --env-file=$(HOME)/.envfile_rl-scanner.docker
1514

1615
# IMAGE_NAME := rlsecure/scanner:latest
@@ -21,17 +20,45 @@ ARTIFACT_OK := vim
2120
ARTIFACT_ERR := eicarcom2.zip
2221

2322
LINE_LENGTH = 120
23+
PL_LINTERS = "eradicate,mccabe,pycodestyle,pyflakes,pylint"
24+
PL_IGNORE = C0114,C0115,C0116
25+
SCRIPTS = scripts/
2426

2527
IMAGE ?= reversinglabs/rl-scanner
2628
TAG ?= latest
2729

2830
.PHONY: build clean
2931

30-
all: clean prep format build testFail test_ok test_err clean
32+
all: clean prep build tests
33+
34+
clean:
35+
docker image prune -f
36+
-docker image rm $(IMAGE_NAME)
37+
rm -f eicarcom2.zip
38+
rm -rf .mypy_cache */.mypy_cache
3139

32-
prep:
40+
prep: format pycheck mypy
3341
wget 'https://www.eicar.org/download/eicar-com-2-2/?wpdmdl=8848&refresh=65d33af627b351708342006' --output-document 'eicarcom2.zip'
3442

43+
format: $(SCRIPTS)
44+
black \
45+
--line-length $(LINE_LENGTH) \
46+
$(SCRIPTS)/*
47+
48+
pycheck: $(SCRIPTS)
49+
pylama \
50+
--max-line-length $(LINE_LENGTH) \
51+
--linters $(PL_LINTERS) \
52+
--ignore $(PL_IGNORE) \
53+
$(SCRIPTS)
54+
55+
mypy: $(SCRIPTS)
56+
mypy \
57+
--strict \
58+
--no-incremental \
59+
$(SCRIPTS)
60+
61+
3562
# build a new docker image from the Dockerfile generated
3663
build:
3764
mkdir -p tmp
@@ -40,6 +67,8 @@ build:
4067
docker image inspect $(IMAGE_NAME) --format '{{ .Config.Labels }}'
4168
docker image inspect $(IMAGE_NAME) --format '{{ .RepoTags }}'
4269

70+
tests: testFail test_ok test_err
71+
4372
testFail:
4473
# we know that specifying no arguments should print usage() and fail
4574
-docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) # will fail but we will ignore that
@@ -50,7 +79,8 @@ test_ok:
5079
rm -rf output input
5180
mkdir -m 777 -p input output
5281
cp /bin/$(ARTIFACT_OK) ./input/$(ARTIFACT_OK)
53-
docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) rl-scan --package-path=/input/$(ARTIFACT_OK) --report-path=/output
82+
docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) \
83+
rl-scan --package-path=/input/$(ARTIFACT_OK) --report-path=/output --report-format all
5484
ls -laR input output >./tmp/list_in_out_ok.txt
5585
cat output/report.rl.json | jq -r . >tmp/test_ok.json
5686

@@ -60,16 +90,8 @@ test_err:
6090
curl -o $(ARTIFACT_ERR) -sS https://secure.eicar.org/$(ARTIFACT_ERR)
6191
cp $(ARTIFACT_ERR) ./input/$(ARTIFACT_ERR)
6292
# as we are now scanning a item that makes the scan fail (non zero exit code) we have to ignore the error in the makefile
63-
-docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) rl-scan --package-path=/input/$(ARTIFACT_ERR) --report-path=/output
93+
-docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) \
94+
rl-scan --package-path=/input/$(ARTIFACT_ERR) --report-path=/output --report-format all
6495
ls -laR input output >./tmp/list_in_out_err.txt
6596
cat output/report.rl.json | jq -r . >tmp/test_err.json
6697

67-
clean:
68-
docker image prune -f
69-
-docker image rm $(IMAGE_NAME)
70-
rm -f eicarcom2.zip
71-
rm -rf .mypy_cache */.mypy_cache
72-
73-
format:
74-
black --line-length $(LINE_LENGTH) scripts/*
75-

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ docker run --rm \
186186

187187
To perform a build reproducibility check, we need two build artifacts of a package version.
188188

189-
Assuming there is already an existing package store with a previously scanned package version `project/[email protected]`, we perform a reproducibility check by scanning another build artifact of the same package version with the specially crafted project URL `project/[email protected]?build=repro`.
189+
Assuming there is already an existing package store with a previously scanned package version `project/[email protected]`, we perform a reproducibility check by scanning another build artifact of the same package version with the specially crafted project URL `project/[email protected]?build=repro`.
190190

191191
The previously scanned artifact for the package version is used as the reference against which the artifact we're scanning will be compared.
192192
The `build=repro` qualifier indicates our intention to perform a reproducibility build check.
@@ -220,7 +220,7 @@ The `rl-scan` helper tool supports the following parameters.
220220
| :--------- | :------ |
221221
| `--package-path` | Required. Path to the package file you want to scan. The specified package file must exist in the **package source** directory mounted to the container. |
222222
| `--report-path` | Required. Path to the location where you want to store analysis reports. The specified path must exist in the **reports destination** directory mounted to the container. |
223-
| `--report-format` | Required. A comma-separated list of report formats to generate. Supported values: `cyclonedx`, `sarif`, `spdx`, `rl-html`, `rl-json`, `all` |
223+
| `--report-format` | Required. A comma-separated list of report formats to generate. Supported values: `cyclonedx`, `sarif`, `spdx`, `rl-html`, `rl-json`, `rl-checks`, `rl-cve`, `all` |
224224
| `--rl-store` | Optional. Path to existing rl-secure package store that is to be used for scan. |
225225
| `--purl` | Optional. Package URL used for scan (format `[pkg:namespace/]<project></package><@version>`). |
226226
| `--diff-with` | Optional. Package version that will be used as a base for difference report. |

scripts/cimessages.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
)
77

88

9-
class Messages:
9+
class Messages: # pylint: disable=too-few-public-methods
1010
@classmethod
1111
def create(cls, name: str) -> Any:
1212
if name == "teamcity":
@@ -48,8 +48,7 @@ def escape(msg: str) -> str:
4848
if isinstance(msg, dict):
4949
msg_content: List[str] = [f"{k}='{escape(v)}'" for k, v in msg.items()]
5050
return f"##teamcity[{name} {' '.join(msg_content)}]"
51-
else:
52-
return f"##teamcity[{name} '{escape(msg)}']"
51+
return f"##teamcity[{name} '{escape(msg)}']"
5352

5453
def block_start(self, msg: str) -> None:
5554
print(TeamCityMesages.service_message("progressStart", msg), flush=True)

scripts/rl-scan

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import argparse
55
import os
66
import sys
77
import glob
8-
from urllib.parse import urlsplit, parse_qs
8+
from urllib.parse import (
9+
urlsplit,
10+
parse_qs,
11+
)
912

1013
import rlsecure
1114
from cimessages import Messages
15+
from typing import (
16+
List,
17+
)
1218

1319

1420
def __expand_specs(specs: str) -> str:
@@ -20,7 +26,20 @@ def __expand_specs(specs: str) -> str:
2026
return files[0]
2127

2228

29+
ReportFormatLIst: List[str] = [
30+
"cyclonedx",
31+
"sarif",
32+
"spdx",
33+
"rl-html",
34+
"rl-json",
35+
"rl-checks",
36+
"rl-cve",
37+
"all",
38+
]
39+
40+
2341
def main() -> int:
42+
reportList = ", ".join(ReportFormatLIst)
2443
parser = argparse.ArgumentParser(
2544
formatter_class=argparse.RawDescriptionHelpFormatter,
2645
prog="rl-scan",
@@ -78,7 +97,7 @@ def main() -> int:
7897
parser.add_argument(
7998
"--report-format",
8099
default="all",
81-
help="A comma-separated list of report formats to generate. Supported values: cyclonedx, sarif, spdx, rl-html, rl-json, rl-checks, all",
100+
help=f"A comma-separated list of report formats to generate. Supported values: {reportList}",
82101
)
83102
parser.add_argument(
84103
"--message-reporter",

scripts/rlsecure.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
import glob
44
import shutil
55
import subprocess
6-
from distutils.dir_util import copy_tree
6+
7+
# from distutils.dir_util import copy_tree
78
from pathlib import Path
8-
from urllib.parse import urlsplit, parse_qs, urlunsplit, urlencode, SplitResult
9+
from urllib.parse import (
10+
urlsplit,
11+
parse_qs,
12+
urlunsplit,
13+
urlencode,
14+
SplitResult,
15+
)
916
from typing import (
1017
Optional,
1118
Any,
@@ -23,7 +30,7 @@ def __is_empty_dir(path: str) -> bool:
2330

2431
def __run(*args: Any, **kwargs: Any) -> Any:
2532
try:
26-
return subprocess.run(*args, **kwargs)
33+
return subprocess.run(*args, **kwargs) # pylint: disable=subprocess-run-check
2734
except subprocess.CalledProcessError as ex:
2835
raise RuntimeError(f'Command "{" ".join(*args)}" returned non-zero exit code ({ex.returncode})') from ex
2936
except Exception as ex:
@@ -64,7 +71,7 @@ def install(stream: Optional[str] = None) -> None:
6471

6572

6673
def use_store(store_path: str) -> None:
67-
global __RLSTORE
74+
global __RLSTORE # pylint: disable=global-statement
6875
__RLSTORE = store_path
6976
if not os.path.isdir(__RLSTORE):
7077
raise RuntimeError(f"'{__RLSTORE}' is not a directory")
@@ -120,7 +127,7 @@ def prune(
120127
__run(cmd, check=True)
121128

122129

123-
class ScanResult:
130+
class ScanResult: # pylint: disable=too-few-public-methods
124131
def __init__(self, passed: bool, msg: str) -> None:
125132
self.passed = passed
126133
self.msg = msg
@@ -161,7 +168,11 @@ def generate_report(
161168

162169
# copy report to desired location
163170
os.makedirs(rpt_path, exist_ok=True)
164-
copy_tree(__RLREPORT_LOCATION, rpt_path)
171+
shutil.copytree(
172+
src=__RLREPORT_LOCATION,
173+
dst=rpt_path,
174+
dirs_exist_ok=True,
175+
)
165176

166177
# collect scan results
167178
if not is_repro:
@@ -184,12 +195,18 @@ def generate_report(
184195
return ScanResult(False, msg.group(1) if msg is not None else "rl-secure analysis: failed")
185196
else:
186197
# repro scan
187-
def make_base_purl(purl):
198+
def make_base_purl(purl: str) -> str:
188199
elements = urlsplit(purl)
189200
query = parse_qs(elements.query)
190201
del query["build"]
191202
return urlunsplit(
192-
SplitResult(elements.scheme, elements.netloc, elements.path, urlencode(query), elements.fragment)
203+
SplitResult(
204+
elements.scheme,
205+
elements.netloc,
206+
elements.path,
207+
urlencode(query),
208+
elements.fragment,
209+
)
193210
)
194211

195212
base_purl = make_base_purl(purl)

0 commit comments

Comments
 (0)