Skip to content

Commit

Permalink
Use authbind to bind privileged ports
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Aug 5, 2018
1 parent e2f5d90 commit b148f11
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)

# Set default base image dynamically for each arch
BASEIMAGE?=quay.io/kubernetes-ingress-controller/nginx-$(ARCH):0.55
BASEIMAGE?=quay.io/kubernetes-ingress-controller/nginx-$(ARCH):0.57

ifeq ($(ARCH),arm)
QEMUARCH=arm
Expand Down
5 changes: 3 additions & 2 deletions build/go-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if [ "$missing" = true ];then
exit 1
fi

E2E_IMAGE=quay.io/kubernetes-ingress-controller/e2e:v07282018-45ba1672c
E2E_IMAGE=quay.io/kubernetes-ingress-controller/e2e:v08042018-e2f5d90

DOCKER_OPTS=${DOCKER_OPTS:-""}

Expand Down Expand Up @@ -75,6 +75,7 @@ docker run \
-v ${PWD}/bin/${ARCH}:/go/bin/linux_${ARCH} \
-w /go/src/${PKG} \
--env-file .env \
${E2E_IMAGE} ${FLAGS}
--entrypoint ${FLAGS} \
${E2E_IMAGE}

rm .env
2 changes: 1 addition & 1 deletion cmd/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func main() {

mc, err := metric.NewCollector(conf.ListenPorts.Status, reg)
if err != nil {
glog.Fatalf("Error creating prometheus collectos: %v", err)
glog.Fatalf("Error creating prometheus collector: %v", err)
}
mc.Start()

Expand Down
5 changes: 4 additions & 1 deletion internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,10 @@ func configureDynamically(pcfg *ingress.Configuration, port int) error {
backends := make([]*ingress.Backend, len(pcfg.Backends))

for i, backend := range pcfg.Backends {
service := &apiv1.Service{Spec: backend.Service.Spec}
var service *apiv1.Service
if backend.Service != nil {
service = &apiv1.Service{Spec: backend.Service.Spec}
}
luaBackend := &ingress.Backend{
Name: backend.Name,
Port: backend.Port,
Expand Down
6 changes: 3 additions & 3 deletions internal/ingress/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func nginxExecCommand(args ...string) *exec.Cmd {
ngx = defBinary
}

cmdArgs := []string{"-c", cfgPath}
cmdArgs := []string{"--deep", ngx, "-c", cfgPath}
cmdArgs = append(cmdArgs, args...)
return exec.Command(ngx, cmdArgs...)
return exec.Command("authbind", cmdArgs...)
}

func nginxTestCommand(cfg string) *exec.Cmd {
Expand All @@ -91,5 +91,5 @@ func nginxTestCommand(cfg string) *exec.Cmd {
ngx = defBinary
}

return exec.Command(ngx, "-c", cfg, "-t")
return exec.Command("authbind", "--deep", ngx, "-c", cfg, "-t")
}
2 changes: 1 addition & 1 deletion internal/ingress/metric/collectors/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewController(pod, namespace, class string) *Controller {
prometheus.GaugeOpts{
Namespace: PrometheusNamespace,
Name: "config_last_reload_successful",
Help: "Whether the last configuration reload attemp was successful",
Help: "Whether the last configuration reload attempt was successful",
ConstLabels: constLabels,
}),
configSuccessTime: prometheus.NewGauge(
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/metric/collectors/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func TestControllerCounters(t *testing.T) {
const metadata = `
# HELP nginx_ingress_controller_config_last_reload_successful Whether the last configuration reload attemp was successful
# HELP nginx_ingress_controller_config_last_reload_successful Whether the last configuration reload attempt was successful
# TYPE nginx_ingress_controller_config_last_reload_successful gauge
# HELP nginx_ingress_controller_success Cumulative number of Ingress controller reload operations
# TYPE nginx_ingress_controller_success counter
Expand Down
9 changes: 8 additions & 1 deletion internal/ingress/metric/collectors/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"net"
"os"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -95,7 +96,13 @@ var (
// NewSocketCollector creates a new SocketCollector instance using
// the ingresss watch namespace and class used by the controller
func NewSocketCollector(pod, namespace, class string) (*SocketCollector, error) {
listener, err := net.Listen("unix", "/tmp/prometheus-nginx.socket")
socket := "/tmp/prometheus-nginx.socket"
listener, err := net.Listen("unix", socket)
if err != nil {
return nil, err
}

err = os.Chmod(socket, 0777)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func IsIPV6(ip _net.IP) bool {

// IsPortAvailable checks if a TCP port is available or not
func IsPortAvailable(p int) bool {
ln, err := _net.Listen("tcp", fmt.Sprintf(":%v", p))
conn, err := _net.Dial("tcp", fmt.Sprintf(":%v", p))
if err != nil {
return false
return true
}
ln.Close()
return true
defer conn.Close()
return false
}

// IsIPv6Enabled checks if IPV6 is enabled or not
Expand Down
11 changes: 6 additions & 5 deletions rootfs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ WORKDIR /etc/nginx

RUN clean-install \
diffutils \
libcap2-bin \
dumb-init

COPY . /

# Fix permission during the build to avoid issues at runtime
# with volumes (custom templates)
RUN bash -eux -c ' \
RUN bash -eu -c ' \
writeDirs=( \
/etc/nginx/template \
/etc/ingress-controller/ssl \
Expand All @@ -41,9 +40,11 @@ RUN bash -eux -c ' \
chown -R www-data.www-data ${dir}; \
done' \
&& chown www-data.www-data /etc/nginx/nginx.conf \
&& chown www-data.www-data /etc/nginx/opentracing.json \
&& chown www-data.www-data /etc/nginx
&& chown www-data.www-data /etc/nginx/opentracing.json

ENTRYPOINT ["/entrypoint.sh"]
# Create symlinks to redirect nginx logs to stdout and stderr docker log collector
# This only works if nginx is started with CMD or ENTRYPOINT
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log

CMD ["/nginx-ingress-controller"]
49 changes: 0 additions & 49 deletions rootfs/entrypoint.sh

This file was deleted.

1 change: 1 addition & 0 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ http {
client_body_temp_path /tmp/client-body;
fastcgi_temp_path /tmp/fastcgi-temp;
proxy_temp_path /tmp/proxy-temp;
ajp_temp_path /tmp/ajp-temp;

client_header_buffer_size {{ $cfg.ClientHeaderBufferSize }};
client_header_timeout {{ $cfg.ClientHeaderTimeout }}s;
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ func (f *Framework) AfterEach() {
By("Waiting for test namespace to no longer exist")
err := DeleteKubeNamespace(f.KubeClientSet, f.IngressController.Namespace)
Expect(err).NotTo(HaveOccurred())

if CurrentGinkgoTestDescription().Failed {
log, err := f.NginxLogs()
Expect(err).ToNot(HaveOccurred())
By("Dumping NGINX logs after a failure running a test")
Logf("%v", log)
}
}

// IngressNginxDescribe wrapper function for ginkgo describe. Adds namespacing.
Expand Down
8 changes: 8 additions & 0 deletions test/manifests/ingress-controller/mandatory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
securityContext:
capabilities:
drop:
- ALL
add:
- NET_BIND_SERVICE
# www-data -> 33
runAsUser: 33
ports:
- name: http
containerPort: 80
Expand Down

0 comments on commit b148f11

Please sign in to comment.