Skip to content

Commit

Permalink
chore(ci): added docker security scan and a linter (#496)
Browse files Browse the repository at this point in the history
* chore(ci): add the snyk docker image scan

* chore(dep): bump all base images to most recent LTS

* chore(dep): bump all base images to most recent LTS

* chore(ci): add hadolint

* chore(security): common practice is swaying towards do upgrades in images

* fix(ci): revert the rhel base image upgrade

* Update alpine/Dockerfile

* pin the hadolint scanner
  • Loading branch information
hutchic authored Sep 7, 2021
1 parent ac56188 commit f368fe4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: generic

services:
- docker
dist: bionic

env:
matrix:
Expand All @@ -10,6 +8,11 @@ env:
- BASE="ubuntu" KONG_DOCKER_TAG="kong-ubuntu" PACKAGE_TYPE="deb"
- BASE="rhel" KONG_DOCKER_TAG="kong-rhel" PACKAGE_TYPE="rpm"

before_install:
- curl -fsSL https://get.docker.com -o get-docker.sh
- sh ./get-docker.sh
- echo "$DOCKER_KEY" | docker login -u "$DOCKER_USER" --password-stdin

before_script:
- if [ "$TRAVIS_SECURE_ENV_VARS" = "true" ]; then echo "$DOCKER_KEY" | docker login -u "$DOCKER_USER" --password-stdin; else echo "no docker credentials to log in, watch for the rate-limit"; fi
- sudo apt-get install figlet
Expand Down
3 changes: 3 additions & 0 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ENV ASSET $ASSET

ARG EE_PORTS

# hadolint ignore=DL3010
COPY kong.tar.gz /tmp/kong.tar.gz

ARG KONG_VERSION=2.5.0
Expand All @@ -19,6 +20,7 @@ ENV KONG_AMD64_SHA $KONG_AMD64_SHA
ARG KONG_ARM64_SHA="131964ce443f2d08dc98191fcc442867f2dee2f741ccee9cc519bb99c765f3cf"
ENV KONG_ARM64_SHA $KONG_ARM64_SHA

# hadolint ignore=DL3018
RUN set -eux; \
arch="$(apk --print-arch)"; \
case "${arch}" in \
Expand All @@ -36,6 +38,7 @@ RUN set -eux; \
&& mv /kong/usr/local/* /usr/local \
&& mv /kong/etc/* /etc \
&& rm -rf /kong \
&& apk upgrade \
&& apk add --no-cache libstdc++ libgcc openssl pcre perl tzdata libcap zip bash zlib zlib-dev git ca-certificates \
&& adduser -S kong \
&& addgroup -S kong \
Expand Down
6 changes: 4 additions & 2 deletions centos/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM centos:7
FROM centos:8
LABEL maintainer="Kong <[email protected]>"

ARG ASSET=ce
Expand All @@ -13,12 +13,14 @@ ENV KONG_VERSION $KONG_VERSION

ARG KONG_SHA256="87b789aed871991b92d264b02ceca3c66246c825c28dd71e73faac7293e43fa2"

# hadolint ignore=DL3033
RUN set -ex; \
if [ "$ASSET" = "ce" ] ; then \
curl -fL https://download.konghq.com/gateway-${KONG_VERSION%%.*}.x-centos-7/Packages/k/kong-$KONG_VERSION.el7.amd64.rpm -o /tmp/kong.rpm \
&& echo "$KONG_SHA256 /tmp/kong.rpm" | sha256sum -c -; \
fi; \
yum install -y -q unzip shadow-utils git \
yum update -y \
&& yum install -y -q unzip shadow-utils git \
&& yum clean all -q \
&& rm -fr /var/cache/yum/* /tmp/yum_save*.yumtx /root/.pki \
# Please update the centos install docs if the below line is changed so that
Expand Down
5 changes: 5 additions & 0 deletions hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ignored:
- DL3008
- DL3027
- SC2046
- DL4006
7 changes: 5 additions & 2 deletions tests/01-image.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
function run_test {
tinitialize "Docker-Kong test suite" "${BASH_SOURCE[0]}"

docker run -i --rm -v $PWD/hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint:2.7.0 < $BASE/Dockerfile

if [[ ! -z "${SNYK_SCAN_TOKEN}" ]]; then
docker scan --accept-license --login --token "${SNYK_SCAN_TOKEN}"
docker scan --accept-license --exclude-base --severity=high --file $BASE/Dockerfile kong-$BASE
fi

# Test the proper version was buid
tchapter "test $BASE image"
Expand All @@ -23,8 +28,6 @@ function run_test {
fi
popd



# Docker swarm test
ttest "Docker swarm test"

Expand Down
4 changes: 3 additions & 1 deletion ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:xenial
FROM ubuntu:focal

ARG ASSET=ce
ENV ASSET $ASSET
Expand All @@ -10,8 +10,10 @@ COPY kong.deb /tmp/kong.deb
ARG KONG_VERSION=2.5.0
ENV KONG_VERSION $KONG_VERSION

# hadolint ignore=DL3015
RUN set -ex \
&& apt-get update \
&& apt-get upgrade -y \
&& if [ "$ASSET" = "ce" ] ; then \
apt-get install -y curl \
&& curl -fL https://download.konghq.com/gateway-${KONG_VERSION%%.*}.x-ubuntu-$(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2)/pool/all/k/kong/kong_${KONG_VERSION}_$(dpkg --print-architecture).deb -o /tmp/kong.deb \
Expand Down

0 comments on commit f368fe4

Please sign in to comment.