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

Cut down feed ingress vulnerabilities #230

Merged
merged 7 commits into from
Feb 8, 2021
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
Expand Up @@ -5,3 +5,4 @@
*.iws
build/
vendor/
nginx/fake/fake_graceful_nginx
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ addons:

language: go

sudo: required

go:
- 1.13

services:
- docker

before_install:
- wget https://github.com/aquasecurity/trivy/releases/download/v0.15.0/trivy_0.15.0_Linux-64bit.tar.gz
- sudo tar -C /usr/local/bin -zxf trivy_0.15.0_Linux-64bit.tar.gz

install:
- make setup

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v4.1.0
* Switch feed-ingress base image to alpine to reduce the number of vulnerabilities

# v4.0.0
* Support latest backend config for nginx upstream module
* Support setting keepalive_requests and keepalive_timeout for nginx upstream module
Expand Down
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ files := $(shell find . -path ./vendor -prune -o -name '*.go' -print)
build_time := $(shell date -u)
ldflags := -X "github.com/sky-uk/feed/feed-ingress/cmd.version=$(version)" -X "github.com/sky-uk/feed/feed-ingress/cmd.buildTime=$(build_time)"

.PHONY: all format test build vet lint copy docker release checkformat check clean fakenginx
os := $(shell uname)
ifeq ("$(os)", "Linux")
GOOS = linux
else ifeq ("$(os)", "Darwin")
GOOS = darwin
endif
GOARCH ?= amd64

.PHONY: all format test build vet lint copy docker release checkformat check clean fakenginx check-vulnerabilities

all : format check build
check : vet lint test
travis : checkformat check docker
travis : checkformat check docker check-vulnerabilities

setup:
@echo "== setup"
Expand All @@ -29,7 +37,7 @@ format :

build :
@echo "== build"
@go install -v ./feed-ingress/... ./feed-dns/...
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go install -v ./feed-ingress/... ./feed-dns/...

unformatted = $(shell goimports -l $(files))

Expand Down Expand Up @@ -90,3 +98,7 @@ else
docker push $(image_prefix)-dns:$(git_tag)
docker push $(image_prefix)-dns:latest
endif

check-vulnerabilities:
@echo "== Checking for vulnerabilities in the docker image"
trivy image --exit-code=1 --severity="HIGH,CRITICAL" $(image_prefix)-ingress:latest
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ To enable OpenTracing, you will need to provide the following options:

```bash
# Define the path to the OpenTracing vendor plugin
--nginx-opentracing-plugin-path=/usr/local/lib/libjaegertracing_plugin.linux_amd64.so
--nginx-opentracing-plugin-path=/usr/local/lib64/libjaegertracing.so
# Define the path to the config for the vendor plugin
--nginx-opentracing-config-path=/etc/jaeger-nginx-config.json
```
Expand Down
19 changes: 7 additions & 12 deletions docker/ingress/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
FROM debian:stretch-slim
FROM alpine:3.13

# Install useful diagnostic packages
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install --no-install-suggests --no-install-recommends -y \
libcap2-bin \
RUN apk add --no-cache \
libcap \
curl \
ca-certificates \
dnsutils \
vim-tiny \
bind-tools \
vim \
lsof \
iproute2 \
&& apt-get clean -y \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* /tmp/*
iproute2

# Install NGINX

Expand All @@ -35,7 +30,7 @@ RUN /tmp/build-nginx.sh
RUN setcap "cap_net_bind_service=+ep" /usr/sbin/nginx

# Setup feed controller
RUN useradd -s /sbin/nologin feed
RUN adduser --shell /sbin/nologin --disabled-password feed
RUN mkdir -p /nginx /var/cache/nginx
RUN chown -R feed:feed /nginx /var/cache/nginx

Expand Down
50 changes: 32 additions & 18 deletions docker/ingress/build-nginx.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/bin/bash
#!/usr/bin/env sh

set -ex

apt-get update
apt-get install --no-install-suggests --no-install-recommends -y \
build-essential \
cmake automake autogen autoconf libtool \
libc6 libc6-dev \
libpcre3 libpcre3-dev libpcrecpp0v5 \
zlib1g zlib1g-dev \
libaio1 libaio-dev \
sudo libssl-dev
# From https://github.com/nginxinc/docker-nginx/blob/master/mainline/alpine/Dockerfile
# Build dependencies
apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
make \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
libedit-dev \
mercurial \
bash \
alpine-sdk \
findutils \
cmake

# Runtime dependencies
apk add --no-cache pcre

echo "--- Downloading NGINX and modules"
mkdir /tmp/nginx
Expand All @@ -27,12 +41,13 @@ opentracing_nginx_tarball="nginx-opentracing-${OPENTRACING_NGINX_VERSION}.tar.gz
opentracing_cpp_tarball="opentracing-cpp-${OPENTRACING_CPP_VERSION}.tar.gz"
jaeger_tarball="jaeger-client-cpp-${JAEGER_VERSION}.tar.gz"

# 2 spaces required between hash and filename
touch hashes
echo "${NGINX_SHA256} ${nginx_tarball}" >> hashes
echo "${VTS_SHA256} ${vts_tarball}" >> hashes
echo "${OPENTRACING_NGINX_SHA256} ${opentracing_nginx_tarball}" >> hashes
echo "${OPENTRACING_CPP_SHA256} ${opentracing_cpp_tarball}" >> hashes
echo "${JAEGER_SHA256} ${jaeger_tarball}" >> hashes
echo "${NGINX_SHA256} ${nginx_tarball}" >> hashes
echo "${VTS_SHA256} ${vts_tarball}" >> hashes
echo "${OPENTRACING_NGINX_SHA256} ${opentracing_nginx_tarball}" >> hashes
echo "${OPENTRACING_CPP_SHA256} ${opentracing_cpp_tarball}" >> hashes
echo "${JAEGER_SHA256} ${jaeger_tarball}" >> hashes
if ! sha256sum -c hashes; then
echo "sha256 hashes do not match downloaded files"
exit 1
Expand Down Expand Up @@ -110,6 +125,5 @@ mkdir -p /nginx/modules
cp objs/ngx_http_opentracing_module.so /nginx/modules/

echo "--- Cleaning up"
apt-get purge -y build-essential ca-certificates libc6-dev libpcre3-dev zlib1g-dev libaio-dev gcc-5 cmake automake autogen autoconf libtool
apt-get clean -y
rm -rf /var/lib/apt/lists/* /tmp/* /root/.hunter
apk del .build-deps
rm -rf /tmp/* /root/.hunter