Use authbind to bind privileged ports
This commit is contained in:
parent
e2f5d9066e
commit
b148f113ae
14 changed files with 48 additions and 69 deletions
2
Makefile
2
Makefile
|
@ -61,7 +61,7 @@ IMAGE = $(REGISTRY)/$(IMGNAME)
|
||||||
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
|
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
|
||||||
|
|
||||||
# Set default base image dynamically for each 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)
|
ifeq ($(ARCH),arm)
|
||||||
QEMUARCH=arm
|
QEMUARCH=arm
|
||||||
|
|
|
@ -40,7 +40,7 @@ if [ "$missing" = true ];then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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:-""}
|
DOCKER_OPTS=${DOCKER_OPTS:-""}
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ docker run \
|
||||||
-v ${PWD}/bin/${ARCH}:/go/bin/linux_${ARCH} \
|
-v ${PWD}/bin/${ARCH}:/go/bin/linux_${ARCH} \
|
||||||
-w /go/src/${PKG} \
|
-w /go/src/${PKG} \
|
||||||
--env-file .env \
|
--env-file .env \
|
||||||
${E2E_IMAGE} ${FLAGS}
|
--entrypoint ${FLAGS} \
|
||||||
|
${E2E_IMAGE}
|
||||||
|
|
||||||
rm .env
|
rm .env
|
||||||
|
|
|
@ -125,7 +125,7 @@ func main() {
|
||||||
|
|
||||||
mc, err := metric.NewCollector(conf.ListenPorts.Status, reg)
|
mc, err := metric.NewCollector(conf.ListenPorts.Status, reg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Error creating prometheus collectos: %v", err)
|
glog.Fatalf("Error creating prometheus collector: %v", err)
|
||||||
}
|
}
|
||||||
mc.Start()
|
mc.Start()
|
||||||
|
|
||||||
|
|
|
@ -741,7 +741,10 @@ func configureDynamically(pcfg *ingress.Configuration, port int) error {
|
||||||
backends := make([]*ingress.Backend, len(pcfg.Backends))
|
backends := make([]*ingress.Backend, len(pcfg.Backends))
|
||||||
|
|
||||||
for i, backend := range 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{
|
luaBackend := &ingress.Backend{
|
||||||
Name: backend.Name,
|
Name: backend.Name,
|
||||||
Port: backend.Port,
|
Port: backend.Port,
|
||||||
|
|
|
@ -80,9 +80,9 @@ func nginxExecCommand(args ...string) *exec.Cmd {
|
||||||
ngx = defBinary
|
ngx = defBinary
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs := []string{"-c", cfgPath}
|
cmdArgs := []string{"--deep", ngx, "-c", cfgPath}
|
||||||
cmdArgs = append(cmdArgs, args...)
|
cmdArgs = append(cmdArgs, args...)
|
||||||
return exec.Command(ngx, cmdArgs...)
|
return exec.Command("authbind", cmdArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func nginxTestCommand(cfg string) *exec.Cmd {
|
func nginxTestCommand(cfg string) *exec.Cmd {
|
||||||
|
@ -91,5 +91,5 @@ func nginxTestCommand(cfg string) *exec.Cmd {
|
||||||
ngx = defBinary
|
ngx = defBinary
|
||||||
}
|
}
|
||||||
|
|
||||||
return exec.Command(ngx, "-c", cfg, "-t")
|
return exec.Command("authbind", "--deep", ngx, "-c", cfg, "-t")
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ func NewController(pod, namespace, class string) *Controller {
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Namespace: PrometheusNamespace,
|
Namespace: PrometheusNamespace,
|
||||||
Name: "config_last_reload_successful",
|
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,
|
ConstLabels: constLabels,
|
||||||
}),
|
}),
|
||||||
configSuccessTime: prometheus.NewGauge(
|
configSuccessTime: prometheus.NewGauge(
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
func TestControllerCounters(t *testing.T) {
|
func TestControllerCounters(t *testing.T) {
|
||||||
const metadata = `
|
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
|
# TYPE nginx_ingress_controller_config_last_reload_successful gauge
|
||||||
# HELP nginx_ingress_controller_success Cumulative number of Ingress controller reload operations
|
# HELP nginx_ingress_controller_success Cumulative number of Ingress controller reload operations
|
||||||
# TYPE nginx_ingress_controller_success counter
|
# TYPE nginx_ingress_controller_success counter
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -95,7 +96,13 @@ var (
|
||||||
// NewSocketCollector creates a new SocketCollector instance using
|
// NewSocketCollector creates a new SocketCollector instance using
|
||||||
// the ingresss watch namespace and class used by the controller
|
// the ingresss watch namespace and class used by the controller
|
||||||
func NewSocketCollector(pod, namespace, class string) (*SocketCollector, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,13 @@ func IsIPV6(ip _net.IP) bool {
|
||||||
|
|
||||||
// IsPortAvailable checks if a TCP port is available or not
|
// IsPortAvailable checks if a TCP port is available or not
|
||||||
func IsPortAvailable(p int) bool {
|
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 {
|
if err != nil {
|
||||||
return false
|
|
||||||
}
|
|
||||||
ln.Close()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// IsIPv6Enabled checks if IPV6 is enabled or not
|
// IsIPv6Enabled checks if IPV6 is enabled or not
|
||||||
func IsIPv6Enabled() bool {
|
func IsIPv6Enabled() bool {
|
||||||
|
|
|
@ -20,14 +20,13 @@ WORKDIR /etc/nginx
|
||||||
|
|
||||||
RUN clean-install \
|
RUN clean-install \
|
||||||
diffutils \
|
diffutils \
|
||||||
libcap2-bin \
|
|
||||||
dumb-init
|
dumb-init
|
||||||
|
|
||||||
COPY . /
|
COPY . /
|
||||||
|
|
||||||
# Fix permission during the build to avoid issues at runtime
|
# Fix permission during the build to avoid issues at runtime
|
||||||
# with volumes (custom templates)
|
# with volumes (custom templates)
|
||||||
RUN bash -eux -c ' \
|
RUN bash -eu -c ' \
|
||||||
writeDirs=( \
|
writeDirs=( \
|
||||||
/etc/nginx/template \
|
/etc/nginx/template \
|
||||||
/etc/ingress-controller/ssl \
|
/etc/ingress-controller/ssl \
|
||||||
|
@ -41,9 +40,11 @@ RUN bash -eux -c ' \
|
||||||
chown -R www-data.www-data ${dir}; \
|
chown -R www-data.www-data ${dir}; \
|
||||||
done' \
|
done' \
|
||||||
&& chown www-data.www-data /etc/nginx/nginx.conf \
|
&& 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/opentracing.json
|
||||||
&& chown www-data.www-data /etc/nginx
|
|
||||||
|
|
||||||
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"]
|
CMD ["/nginx-ingress-controller"]
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
#!/usr/bin/dumb-init /bin/bash
|
|
||||||
|
|
||||||
# Copyright 2017 The Kubernetes Authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo 0 > /tmp/nginx.pid
|
|
||||||
# fix directory permissions
|
|
||||||
writeDirs=( \
|
|
||||||
/var/log
|
|
||||||
/var/log/nginx
|
|
||||||
/tmp
|
|
||||||
);
|
|
||||||
for dir in "${writeDirs[@]}";do
|
|
||||||
mkdir -p ${dir};
|
|
||||||
chown -R www-data.www-data ${dir};
|
|
||||||
done
|
|
||||||
|
|
||||||
ln -sf /dev/stdout /var/log/nginx/access.log
|
|
||||||
ln -sf /dev/stderr /var/log/nginx/error.log
|
|
||||||
chown www-data.www-data /var/log/nginx/*
|
|
||||||
|
|
||||||
echo "Testing if setcap is supported..."
|
|
||||||
if setcap cap_net_bind_service=+ep /usr/sbin/nginx; then
|
|
||||||
echo "setcap is supported. Setting cap_net_bind_service=+ep to allow binding port lower than 1024 as non-root"
|
|
||||||
setcap cap_net_bind_service=+ep /usr/sbin/nginx
|
|
||||||
setcap -v cap_net_bind_service=+ep /usr/sbin/nginx
|
|
||||||
setcap cap_net_bind_service=+ep /nginx-ingress-controller
|
|
||||||
setcap -v cap_net_bind_service=+ep /nginx-ingress-controller
|
|
||||||
|
|
||||||
echo "Droping root privileges and running as user..."
|
|
||||||
su-exec www-data:www-data "$@"
|
|
||||||
else
|
|
||||||
echo "WARNING!!!: setcap is not supported. Running as root"
|
|
||||||
echo "Please check https://github.com/moby/moby/issues/1070"
|
|
||||||
"$@"
|
|
||||||
fi
|
|
|
@ -131,6 +131,7 @@ http {
|
||||||
client_body_temp_path /tmp/client-body;
|
client_body_temp_path /tmp/client-body;
|
||||||
fastcgi_temp_path /tmp/fastcgi-temp;
|
fastcgi_temp_path /tmp/fastcgi-temp;
|
||||||
proxy_temp_path /tmp/proxy-temp;
|
proxy_temp_path /tmp/proxy-temp;
|
||||||
|
ajp_temp_path /tmp/ajp-temp;
|
||||||
|
|
||||||
client_header_buffer_size {{ $cfg.ClientHeaderBufferSize }};
|
client_header_buffer_size {{ $cfg.ClientHeaderBufferSize }};
|
||||||
client_header_timeout {{ $cfg.ClientHeaderTimeout }}s;
|
client_header_timeout {{ $cfg.ClientHeaderTimeout }}s;
|
||||||
|
|
|
@ -133,6 +133,13 @@ func (f *Framework) AfterEach() {
|
||||||
By("Waiting for test namespace to no longer exist")
|
By("Waiting for test namespace to no longer exist")
|
||||||
err := DeleteKubeNamespace(f.KubeClientSet, f.IngressController.Namespace)
|
err := DeleteKubeNamespace(f.KubeClientSet, f.IngressController.Namespace)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
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.
|
// IngressNginxDescribe wrapper function for ginkgo describe. Adds namespacing.
|
||||||
|
|
|
@ -260,6 +260,14 @@ spec:
|
||||||
valueFrom:
|
valueFrom:
|
||||||
fieldRef:
|
fieldRef:
|
||||||
fieldPath: metadata.namespace
|
fieldPath: metadata.namespace
|
||||||
|
securityContext:
|
||||||
|
capabilities:
|
||||||
|
drop:
|
||||||
|
- ALL
|
||||||
|
add:
|
||||||
|
- NET_BIND_SERVICE
|
||||||
|
# www-data -> 33
|
||||||
|
runAsUser: 33
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
containerPort: 80
|
containerPort: 80
|
||||||
|
|
Loading…
Reference in a new issue