Skip to content

Commit 418b189

Browse files
committed
cli 2.2.0
1 parent 599d189 commit 418b189

File tree

32 files changed

+848
-114
lines changed

32 files changed

+848
-114
lines changed

.gitignore

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
dist
2-
rl-deploy
31
__pycache__
4-
input/
5-
output/
6-
tmp/
7-
eicarcom2.zip
2+
.mypy_cache/
3+
tests/*/report/
4+
tests/repro/store/
5+
tests/repro/report_base/
6+
tests/repro/report_repro_fail/
7+
tests/repro/report_repro_ok/
8+
OLD/

BUILD.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# rl-secure Docker image (rl-scanner)
2+
3+
This repository contains configurations used to create `rl-scanner` Docker images. To improve performance and reduce traffic, this image uses the cached install feature provided by the `rl-deploy` tool.
4+
5+
## Prerequisites
6+
7+
To create a cached installation file, you have to make sure that your license information is valid.
8+
9+
License information must be provided using the following environment variables:
10+
11+
| Environment variable | Description |
12+
| :--------- | :------ |
13+
| `RLSECURE_ENCODED_LICENSE` | Required. The `rl-secure` license file as a Base64-encoded string. Encode the contents of your license file, and provide the resulting string with this variable. |
14+
| `RLSECURE_SITE_KEY` | Required. The `rl-secure` license site key. The site key is a string generated by ReversingLabs and sent to users with the license file. |
15+
16+
17+
## Building the image
18+
19+
The `make` system is used to perform builds.
20+
21+
To build an image, you can use one of the following build targets:
22+
23+
| Target name | Description |
24+
| :--------- | :------ |
25+
| `build-with-cache` | Generated image will use the installation cache mechanism. This will result in faster execution, since the scanner functionality will use a local cached installation instead of downloading updates from the ReversingLabs server. |
26+
| `build-without-cache` | Generated image will contain only the scanner functionality. On each execution, the `rl-secure` tool will be downloaded from the ReversingLabs server. |
27+
28+
29+
To locally build the scanner image, use the command:
30+
31+
```
32+
make build-with-cache IMAGE_NAME="my-rl-scanner"
33+
```
34+
35+
This will create an image with a tag `my-rl-scanner` using your local Docker instance.
36+
37+
Note that in order to make the `build-with-cache` target, you would need to provide the license information using the environment variables.
38+
39+
40+
## Testing the image
41+
42+
To test the functionality of the image, you can use the `make` target named `test`.
43+
44+
In order to perform the test, it is expected that the environment variables `RLSECURE_ENCODED_LICENSE` and `RLSECURE_SITE_KEY` are set appropriately.
45+
46+
You can test the generated image with the following command:
47+
48+
```
49+
make test IMAGE_NAME="my-rl-scanner"
50+
```
51+
52+
## Release image
53+
54+
Documentation for using the generated image can be found [in the README](README.md).

Dockerfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

Dockerfile.cache

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# syntax=docker/dockerfile:1
2+
3+
ARG CACHE_PATH=/tmp/rl-secure.cache
4+
5+
FROM rockylinux:9-minimal
6+
ARG CACHE_PATH
7+
COPY scripts/* /opt/rl-scanner/
8+
RUN --mount=type=secret,id=rlsecure_license --mount=type=secret,id=rlsecure_sitekey <<EORUN
9+
set -e
10+
echo ${CACHE_PATH}
11+
microdnf upgrade -y
12+
microdnf install -y --nodocs python3-pip
13+
pip3 install --no-cache-dir rl-deploy
14+
microdnf clean all
15+
rl-deploy cache \
16+
--no-tracking \
17+
--location=${CACHE_PATH} \
18+
--encoded-key=$(cat /run/secrets/rlsecure_license) \
19+
--site-key=$(cat /run/secrets/rlsecure_sitekey)
20+
21+
chmod 755 /opt/rl-scanner/entrypoint /opt/rl-scanner/rl-scan /opt/rl-scanner/rl-prune
22+
EORUN
23+
ENV PATH="/opt/rl-scanner:${PATH}"
24+
ENTRYPOINT [ "/opt/rl-scanner/entrypoint" ]

Dockerfile.no_cache

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM rockylinux:9-minimal
4+
COPY scripts/* /opt/rl-scanner/
5+
RUN <<EORUN
6+
set -e
7+
microdnf upgrade -y
8+
microdnf install -y --nodocs python3-pip
9+
pip3 install --no-cache-dir rl-deploy
10+
microdnf clean all
11+
12+
chmod 755 /opt/rl-scanner/entrypoint /opt/rl-scanner/rl-scan /opt/rl-scanner/rl-prune
13+
EORUN
14+
ENV PATH="/opt/rl-scanner:${PATH}"
15+
ENTRYPOINT [ "/opt/rl-scanner/entrypoint" ]

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) 2023 ReversingLabs
3+
Copyright (c) 2024 ReversingLabs
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: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,74 @@
1-
# the envfile has the 2 required environment variables:
2-
# RLSECURE_SITE_KEY=
1+
# Makefile expects 2 required environment variables for
2+
# build-with-cache and test targets:
33
# RLSECURE_ENCODED_LICENSE=
4+
# RLSECURE_SITE_KEY=
45

5-
ifdef DOCKER_TAG
6-
BUILD_VERSION := $(DOCKER_TAG)
7-
else
8-
BUILD_VERSION=latest
6+
ifeq ($(strip $(RLSECURE_ENCODED_LICENSE)),)
7+
$(error mandatory RLSECURE_ENCODED_LICENSE not set!)
98
endif
109

11-
VOLUMES := -v ./output:/output -v ./input:/input
12-
USER_GROUP := $(shell id -u):$(shell id -u )
13-
COMMON_DOCKER := -i --rm -u $(USER_GROUP) --env-file=$(HOME)/.envfile_rl-scanner.docker
14-
15-
# IMAGE_NAME := rlsecure/scanner:latest
16-
IMAGE_BASE := reversinglabs/rl-scanner
17-
IMAGE_NAME := $(IMAGE_BASE):$(BUILD_VERSION)
18-
19-
ARTIFACT_OK := vim
20-
ARTIFACT_ERR := eicarcom2.zip
10+
ifeq ($(strip $(RLSECURE_SITE_KEY)),)
11+
$(error mandatory RLSECURE_SITE_KEY not set!)
12+
endif
2113

14+
IMAGE_NAME ?= reversinglabs/rl-scanner:test
2215
LINE_LENGTH = 120
2316
PL_LINTERS = "eradicate,mccabe,pycodestyle,pyflakes,pylint"
2417
PL_IGNORE = C0114,C0115,C0116
2518
SCRIPTS = scripts/
2619

27-
IMAGE ?= reversinglabs/rl-scanner
28-
TAG ?= latest
2920

30-
.PHONY: build clean
21+
.PHONY: build-without-cache build-with-cache push clean format pycheck test test.%
3122

32-
all: clean prep build tests
23+
all: clean prep build test
3324

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
25+
prep: format pylama mypy
26+
27+
build: build-with-cache
28+
29+
build-without-cache:
30+
docker buildx build . -f Dockerfile.no_cache \
31+
--no-cache \
32+
-t $(IMAGE_NAME)
3933

40-
prep: format pycheck mypy
41-
wget 'https://www.eicar.org/download/eicar-com-2-2/?wpdmdl=8848&refresh=65d33af627b351708342006' --output-document 'eicarcom2.zip'
34+
# --build-arg CACHE_PATH=/tmp/rl-secure.cache
35+
build-with-cache:
36+
docker buildx build . -f Dockerfile.cache \
37+
--no-cache \
38+
--secret id=rlsecure_license,env=RLSECURE_ENCODED_LICENSE \
39+
--secret id=rlsecure_sitekey,env=RLSECURE_SITE_KEY \
40+
-t $(IMAGE_NAME)
4241

43-
format: $(SCRIPTS)
42+
clean:
43+
-docker rmi $(IMAGE_NAME)
44+
rm -rf ./tests/*/report/
45+
rm -rf ./tests/repro/store/
46+
rm -rf ./tests/repro/report_base/
47+
rm -rf ./tests/repro/report_repro_fail/
48+
rm -rf ./tests/repro/report_repro_ok/
49+
50+
format:
4451
black \
4552
--line-length $(LINE_LENGTH) \
4653
$(SCRIPTS)/*
4754

48-
pycheck: $(SCRIPTS)
55+
pylama:
4956
pylama \
5057
--max-line-length $(LINE_LENGTH) \
5158
--linters $(PL_LINTERS) \
5259
--ignore $(PL_IGNORE) \
5360
$(SCRIPTS)
5461

55-
mypy: $(SCRIPTS)
62+
mypy:
5663
mypy \
5764
--strict \
5865
--no-incremental \
5966
$(SCRIPTS)
6067

6168

62-
# build a new docker image from the Dockerfile generated
63-
build:
64-
mkdir -p tmp
65-
docker build -t $(IMAGE_NAME) -f Dockerfile .
66-
docker image ls $(IMAGE_NAME) | tee ./tmp/image_ls.txt
67-
docker image inspect $(IMAGE_NAME) --format '{{ .Config.Labels }}'
68-
docker image inspect $(IMAGE_NAME) --format '{{ .RepoTags }}'
69-
70-
tests: testFail test_ok test_err
71-
72-
testFail:
73-
# we know that specifying no arguments should print usage() and fail
74-
-docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) # will fail but we will ignore that
75-
# we know that specifying no arguments to rl-scan should print usage() and fail
76-
-docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) rl-scan # will fail but we will ignore that
77-
78-
test_ok:
79-
rm -rf output input
80-
mkdir -m 777 -p input output
81-
cp /bin/$(ARTIFACT_OK) ./input/$(ARTIFACT_OK)
82-
docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) \
83-
rl-scan --package-path=/input/$(ARTIFACT_OK) --report-path=/output --report-format all
84-
ls -laR input output >./tmp/list_in_out_ok.txt
85-
cat output/report.rl.json | jq -r . >tmp/test_ok.json
86-
87-
test_err:
88-
rm -rf output input
89-
mkdir -m 777 -p input output
90-
curl -o $(ARTIFACT_ERR) -sS https://secure.eicar.org/$(ARTIFACT_ERR)
91-
cp $(ARTIFACT_ERR) ./input/$(ARTIFACT_ERR)
92-
# 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
93-
-docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) \
94-
rl-scan --package-path=/input/$(ARTIFACT_ERR) --report-path=/output --report-format all
95-
ls -laR input output >./tmp/list_in_out_err.txt
96-
cat output/report.rl.json | jq -r . >tmp/test_err.json
69+
all-tests := $(addprefix test., $(notdir $(wildcard tests/*)))
70+
71+
test.%: tests/%/run.sh
72+
cd $(dir $<) && ./run.sh "$(IMAGE_NAME)"
9773

74+
test: $(all-tests)

0 commit comments

Comments
 (0)