Skip to content

Commit 9b1b9a8

Browse files
authored
Merge pull request codefresh-io#19 from codefresh-io/add-twistlock-scan-from-steelcase
adding twistlock scanning plugin from Steelcase
2 parents 1acdf9b + 83c3316 commit 9b1b9a8

File tree

6 files changed

+463
-0
lines changed

6 files changed

+463
-0
lines changed

stable/twistlock-scan/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM ubuntu:xenial
2+
3+
ENV LANG C.UTF-8
4+
5+
RUN { \
6+
echo '#!/bin/sh'; \
7+
echo 'set -e'; \
8+
echo; \
9+
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
10+
} > /usr/local/bin/docker-java-home && \
11+
chmod +x /usr/local/bin/docker-java-home
12+
13+
RUN apt-get update && apt-get install -y --no-install-recommends \
14+
bzip2 \
15+
unzip \
16+
xz-utils \
17+
apt-transport-https \
18+
ca-certificates \
19+
curl \
20+
software-properties-common \
21+
python3-openssl && \
22+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
23+
add-apt-repository \
24+
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
25+
$(lsb_release -cs) \
26+
stable" && \
27+
apt-get update && apt-get install -y --no-install-recommends \
28+
docker-ce=17.09.0~ce-0~ubuntu && \
29+
apt-get install -y \
30+
openjdk-8-jre \
31+
; \
32+
rm -rf /var/lib/apt/lists/*; \
33+
\
34+
[ "$JAVA_HOME" = "$(docker-java-home)" ]; \
35+
\
36+
update-alternatives --get-selections | awk -v home="$JAVA_HOME" 'index($3, home) == 1 { $2 = "manual"; print | "update-alternatives --set-selections" }'; \
37+
update-alternatives --query java | grep -q 'Status: manual' && \
38+
mkdir /packages && \
39+
curl -o /packages/twistcli https://cdn.twistlock.com/support/twistcli && \
40+
curl -o /packages/nexus-iq-cli-1.38.0-02.jar https://download.sonatype.com/clm/scanner/nexus-iq-cli-1.38.0-02.jar
41+
42+
COPY scripts /scripts
43+
44+
RUN chmod +x -R /packages
45+
RUN chmod +x -R /scripts
46+
47+
WORKDIR /scripts
48+
49+
ENTRYPOINT ["/usr/bin/python3"]
50+
CMD [""]

stable/twistlock-scan/LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
© 2017 Steelcase Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

stable/twistlock-scan/README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Security Scanning Tools [![Codefresh build status]( https://g.codefresh.io/api/badges/build?repoOwner=SC-TechDev&repoName=docker-security-scanner&branch=master&pipelineName=docker-security-scanner&accountName=sctechdevservice&type=cf-1)]( https://g.codefresh.io/repositories/SC-TechDev/docker-security-scanner/builds?filter=trigger:build;branch:master;service:59e62c5410e3d100019e7f3d~docker-security-scanner)
2+
3+
Docker image which invokes security script using TwistCLI (Nexus coming soon)
4+
5+
### Prerequisites:
6+
7+
Codefresh Subscription (Dedicated Infrastructure) - https://codefresh.io/
8+
9+
Twistlock Subscription - https://www.twistlock.com/
10+
11+
### Documentation:
12+
13+
Twistlock CLI: https://twistlock.desk.com/customer/en/portal/articles/2875595-twistcli?b_id=16619
14+
15+
Nexus IQ CLI: TBD
16+
17+
## Script Library
18+
19+
### twistlock.py
20+
21+
Executes TwistCLI to scan Docker image given.
22+
23+
### options
24+
25+
To use an ENVIRONMENT VARIABLE you need to add the variables to your Codefresh Pipeline and also to your codefresh.yaml.
26+
27+
28+
Example `codefresh.yml` build is below with required ENVIRONMENT VARIABLES in place.
29+
30+
31+
| ENVIRONMENT VARIABLE | SCRIPT ARGUMENT | DEFAULT | TYPE | REQUIRED | DESCRIPTION |
32+
|----------------------------|--------------------------------------|----------|---------|----------|---------------------------------------------------------------------------------------------------------------------------------|
33+
| CF_METADATA | [ -c, --cf_metadata ] | null | boolean | No | In combination with TL_UPLOAD stores Twistlock Report URL in TL_REPORT_URL var for Codefresh metadata annotation |
34+
| TL_CONSOLE_HOSTNAME | [ -C, --tl_console_hostname ] | null | string | Yes | hostname/ip |
35+
| TL_CONSOLE_PORT | [ -P, --tl_console_port ] | null | string | Yes | port |
36+
| TL_CONSOLE_USERNAME | [ -U, --tl_console_username ] | null | string | Yes | username |
37+
| TL_CONSOLE_PASSWORD | [ -X, --tl_console_password ] | null | string | Yes | password |
38+
| TL_ONLY | [ -Z, --tl_only ] | null | boolean | Yes | Twistlock Console Only (Required for now Nexus TBD) |
39+
| TL_TLS_ENABLED | [ -T, --tl_tls_enabled ] | null | boolean | No | enable TLS |
40+
| TL_HASH | [ -H, --tl_hash ] | [ sha1 ] | string | No | [ md5, sha1, sha256 ] hashing algorithm |
41+
| TL_UPLOAD | [ -R, --tl_upload ] | null | boolean | No | ( ignores all options below if set and only returns report url ) uploads report to Twistlock to be used later via Twistlock API |
42+
| TL_DETAILS | [ -D, --tl_details ] | null | boolean | No | prints an itemized list of each vulnerability found by the scanner |
43+
| TL_ONLY_FIXED | [ -O, --tl_only_fixed ] | null | boolean | No | reports just the vulnerabilites that have fixes available |
44+
| TL_COMPLIANCE_THRESHOLD | [ -M, --tl_compliance_threshold ] | null | string | No | [ low, medium, high ] sets the the minimal severity compliance issue that returns a fail exit code |
45+
| TL_VULNERABILITY_THRESHOLD | [ -V, --tl_vulnerability_threshold ] | null | string | No | [ low, medium, high, critical ] sets the minimal severity vulnerability that returns a fail exit code |
46+
47+
### codefresh.yml
48+
49+
Codefresh Build Step to execute Twistlock scan.
50+
All `${{var}}` variables must be put into Codefresh Build Parameters
51+
codefresh.yml
52+
```console
53+
buildimage:
54+
type: build
55+
title: Build Runtime Image
56+
dockerfile: Dockerfile
57+
image_name: # Image you're building/scanning [repository/image]
58+
tag: latest-cf-build-candidate
59+
60+
nexus_iq_scan_build_stage:
61+
type: composition
62+
composition:
63+
version: '2'
64+
services:
65+
imagebuild:
66+
image: ${{buildimage}}
67+
command: sh -c "exit 0"
68+
labels:
69+
build.image.id: ${{CF_BUILD_ID}}
70+
composition_candidates:
71+
scan_service:
72+
image: sctechdev/docker-security-scanner
73+
environment:
74+
- TL_CONSOLE_HOSTNAME=${{TL_CONSOLE_HOSTNAME}}
75+
- TL_CONSOLE_PORT=${{TL_CONSOLE_PORT}}
76+
- TL_CONSOLE_USERNAME=${{TL_CONSOLE_USERNAME}}
77+
- TL_CONSOLE_PASSWORD=${{TL_CONSOLE_PASSWORD}}
78+
- TL_ONLY=${{TL_ONLY}}
79+
command: twistlock.py -i "$$(docker inspect $$(docker inspect $$(docker ps -aqf label=build.image.id=${{CF_BUILD_ID}}) -f {{.Config.Image}}) -f {{.Id}} | sed 's/sha256://g')"
80+
depends_on:
81+
- imagebuild
82+
volumes:
83+
- /var/run/docker.sock:/var/run/docker.sock
84+
- /var/lib/docker:/var/lib/docker
85+
# Everything below this line is Optional for CF_METADATA
86+
- '${{CF_VOLUME_NAME}}:/codefresh/volume'
87+
add_flow_volume_to_composition: true
88+
89+
export:
90+
title: "Exporting variables..."
91+
image: alpine
92+
commands:
93+
- echo "Exporting variables..."
94+
95+
set_metadata:
96+
title: "Setting metadata on image..."
97+
image: alpine
98+
commands:
99+
- echo "Setting metadata on image..."
100+
on_finish:
101+
metadata:
102+
set:
103+
- '${{build_step.imageId}}':
104+
- TwistlockSecurityReport: ${{TL_REPORT_URL}}
105+
```

stable/twistlock-scan/codefresh.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: '1.0'
2+
3+
steps:
4+
5+
buildimage:
6+
type: build
7+
description: image build step
8+
dockerfile: Dockerfile
9+
image_name: sctechdev/docker-security-scanner
10+
tag: latest-cf-build-candidate
11+
12+
push_image:
13+
type: push
14+
candidate: ${{buildimage}}
15+
tag: latest
16+
when:
17+
branch:
18+
only:
19+
- master
20+
push_image1:
21+
type: push
22+
candidate: ${{buildimage}}
23+
tag: ${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}
24+
25+
push_image_nexus_latest:
26+
title: Push to Nexus Repo (latest)
27+
type: push
28+
candidate: ${{buildimage}}
29+
tag: latest
30+
registry: sonatype-docker-internal
31+
when:
32+
branch:
33+
only:
34+
- master
35+
36+
push_image_neuxs_gitbranch_gitsha:
37+
title: Push to Nexus Repo (gitbranch + gitsha)
38+
type: push
39+
candidate: ${{buildimage}}
40+
tag: ${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}
41+
registry: sonatype-docker-internal

stable/twistlock-scan/plugin.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
image: docker.io/sctechdev/docker-security-scanner
2+
tag: master-c81e6d4
3+
version: 2.2
4+
description: Execute Twistlock image scan as build step
5+
keywords:
6+
- Twistlock 2.2
7+
home: https://hub.docker.com/r/sctechdev/docker-security-scanner/
8+
sources:
9+
- https://github.com/SC-TechDev/docker-security-scanner
10+
maintainers:
11+
- name: Dustin Van Buskirk
12+
email: dev@vanbuskirk.me
13+
- name: Varun Tagore
14+
email: rondevops@gmail.com
15+
icon: A URL to an SVG or PNG image to be used as an icon (optional)
16+
envs:
17+
- name: CF_METADATA
18+
type: required
19+
description: Boolean; combination with TL_UPLOAD stores Twistlock Report URL in TL_REPORT_URL var for Codefresh metadata annotation
20+
- name: TL_CONSOLE_HOSTNAME
21+
type: required
22+
description: Hostname or IP of Twistlock Console
23+
- name: TL_CONSOLE_PORT
24+
type: required
25+
description: Port of Twistlock Console
26+
- name: TL_CONSOLE_USERNAME
27+
type: required
28+
description: Username of Twistlock Console
29+
- name: TL_CONSOLE_PASSWORD
30+
type: required
31+
description: Password of Twistlock Console User
32+
- name: TL_ONLY
33+
type: required
34+
description: Twistlock Console Scan Only (No Nexus)
35+
- name: TL_TLS_ENABLED
36+
type: optional
37+
description: Boolean; Enable TLS connection to Twistlock Console
38+
- name: TL_HASH
39+
type: optional
40+
description: Hashing Algorithm to use
41+
- name: TL_UPLOAD
42+
type: optional
43+
description: Upload report to Twistlock Console and return URL (Overrides all other options only returns URL)
44+
- name: TL_DETAILS
45+
type: optional
46+
description: Prints an itemized list of each vulnerability found by the scanner
47+
- name: TL_ONLY_FIXED
48+
type: optional
49+
description: reports just the vulnerabilites that have fixes available
50+
- name: TL_COMPLIANCE_THRESHOLD
51+
type: optional
52+
description: [ low, medium, high ] sets the the minimal severity compliance issue that returns a fail exit code
53+
- name: TL_VULNERABILITY_THRESHOLD
54+
type: optional
55+
description: [ low, medium, high, critical ] sets the minimal severity vulnerability that returns a fail exit code
56+
volumes:
57+
- name: /var/run/docker.sock:/var/run/docker.sock
58+
required: true
59+
description: Docker socket for DIND
60+
- name: /var/lib/docker:/var/lib/docker
61+
required: true
62+
description: Docker lib access for DIND
63+
- name: '${{CF_VOLUME_NAME}}:/codefresh/volume'
64+
required: false
65+
description: Volume required if setting Docker image metadata using Codefresh

0 commit comments

Comments
 (0)