Skip to content

Commit

Permalink
Fix netlink and capabilities (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsravn authored Apr 3, 2018
1 parent b7e46cc commit 3b069d1
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 51 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v1.9.2
* Bug fix for merlin attacher - fix netlink and capabilities for feed-ingress.

# v1.9.1
* Introduced flag to set the amount of memory allocated to the vhost statistics module (default: 1 MiB)

Expand Down
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 19 additions & 20 deletions docker/ingress/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM phusion/baseimage:0.9.22
FROM debian:stretch-slim

# 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 \
curl \
ca-certificates \
dnsutils \
vim-tiny \
lsof \
Expand All @@ -12,33 +15,29 @@ RUN apt-get update \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* /tmp/*

# Install nginx
ENV NGINX_VERSION 1.12.2
ENV NGINX_SHA256 305f379da1d5fb5aefa79e45c829852ca6983c7cd2a79328f8e084a324cf0416
ENV VTS_VERSION 0.1.15
ENV VTS_SHA256 5112a054b1b1edb4c0042a9a840ef45f22abb3c05c68174e28ebf483164fb7e1

COPY build-nginx.sh /tmp
RUN /bin/bash /tmp/build-nginx.sh

COPY feed-ingress /
COPY nginx.tmpl /nginx/
RUN chown nginx:nginx /nginx/nginx.tmpl
RUN chmod 755 /tmp/build-nginx.sh
RUN /tmp/build-nginx.sh
# For binding to privileged ports in nginx.
RUN setcap "cap_net_bind_service=+ep" /usr/sbin/nginx

ADD logrotate.config /etc/logrotate.d/nginx
RUN chmod 600 /etc/logrotate.d/nginx
# Setup feed controller
RUN useradd -s /sbin/nologin feed
RUN mkdir -p /nginx /var/cache/nginx
RUN chown -R feed:feed /nginx /var/cache/nginx

ADD logrotate.cron /etc/cron.d/nginx
RUN chmod 600 /etc/cron.d/nginx

# Defer execution as the log dir may be mounted when running
ADD log-dir-ownership.sh /etc/my_init.d/log-dir-ownership.sh
COPY feed-ingress /
# For binding VIP for merlin.
RUN setcap "cap_net_admin=+ep" /feed-ingress

# Let feed shutdown gracefully by giving it plenty of time to stop.
# Give children processes 5 minutes to timeout
ENV KILL_PROCESS_TIMEOUT=300
# Give all other processes (such as those which have been forked) 5 minutes to timeout
ENV KILL_ALL_PROCESSES_TIMEOUT=300
COPY nginx.tmpl /nginx/
RUN chown feed:feed /nginx/nginx.tmpl

ENTRYPOINT ["/sbin/my_init", "--quiet", "--", "/sbin/setuser", "nginx", \
"/feed-ingress", "-nginx-workdir", "/nginx"]
USER feed
ENTRYPOINT ["/feed-ingress", "-nginx-workdir", "/nginx"]
9 changes: 1 addition & 8 deletions docker/ingress/build-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

set -ex

useradd -s /sbin/nologin nginx
mkdir -p /nginx /var/cache/nginx
chown -R nginx:nginx /nginx /var/cache/nginx

apt-get update
apt-get install --no-install-suggests --no-install-recommends -y \
build-essential \
Expand All @@ -15,9 +11,6 @@ apt-get install --no-install-suggests --no-install-recommends -y \
libaio1 libaio-dev \
sudo libssl-dev

# allow nginx user to manage interfaces and arp configuration
echo "%nginx ALL=NOPASSWD: /sbin/ip, /usr/bin/tee" >> /etc/sudoers

echo "--- Downloading nginx and modules"
mkdir /tmp/nginx
cd /tmp/nginx
Expand Down Expand Up @@ -70,6 +63,6 @@ make
make install

echo "--- Cleaning up"
apt-get purge -y build-essential libc6-dev libpcre3-dev zlib1g-dev libaio-dev gcc-5 cpp-5
apt-get purge -y build-essential ca-certificates libc6-dev libpcre3-dev zlib1g-dev libaio-dev gcc-5
apt-get clean -y
rm -rf /var/lib/apt/lists/* /tmp/*
6 changes: 0 additions & 6 deletions docker/ingress/log-dir-ownership.sh

This file was deleted.

12 changes: 0 additions & 12 deletions docker/ingress/logrotate.config

This file was deleted.

3 changes: 0 additions & 3 deletions docker/ingress/logrotate.cron

This file was deleted.

4 changes: 4 additions & 0 deletions merlin/merlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,7 @@ func (u *updater) removeVIP() error {
}
return u.nl.removeVIP(u.VIPInterface, u.VIP)
}

func (u *updater) String() string {
return "merlin attacher"
}
8 changes: 7 additions & 1 deletion merlin/netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package merlin
import (
"fmt"

"strings"

"github.com/vishvananda/netlink"
)

Expand All @@ -15,6 +17,10 @@ type netlinkWrapper interface {
type netlinkWrapperImpl struct{}

func (i *netlinkWrapperImpl) handleVIP(vipInterface, vip string, fn func(netlink.Link, *netlink.Addr) error) error {
if !strings.Contains(vip, "/") {
// Doesn't contain a network, add /32.
vip = vip + "/32"
}
ipNet, err := netlink.ParseIPNet(vip)
if err != nil {
return fmt.Errorf("unable to parse VIP %s: %v", vip, err)
Expand All @@ -23,7 +29,7 @@ func (i *netlinkWrapperImpl) handleVIP(vipInterface, vip string, fn func(netlink
if err != nil {
return fmt.Errorf("unable to add/remove VIP on %s: %v", vipInterface, err)
}
if err := fn(lnk, &netlink.Addr{IPNet: ipNet, Label: "feed-vip"}); err != nil {
if err := fn(lnk, &netlink.Addr{IPNet: ipNet}); err != nil {
return fmt.Errorf("unable to add/remove VIP %s to %s: %v", vip, vipInterface, err)
}
return nil
Expand Down

0 comments on commit 3b069d1

Please sign in to comment.