Skip to content

Commit

Permalink
make sure pomerium is running as non-root inside a container (pomeriu…
Browse files Browse the repository at this point in the history
  • Loading branch information
wasaga authored Jul 6, 2022
1 parent 150b51f commit f86eed8
Show file tree
Hide file tree
Showing 28 changed files with 190 additions and 203 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ repos:
args: ["lint"]
types: ["go"]
pass_filenames: false
fail_fast: true
- id: deployment
name: deployment
fail_fast: true
language: system
entry: make
args: ["deployment"]
types: ["yaml"]
pass_filenames: false
2 changes: 1 addition & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ARG ARCH
FROM gcr.io/distroless/base:nonroot-${TARGETARCH:-amd64}
WORKDIR /pomerium
COPY pomerium* /bin/
ENTRYPOINT [ "/bin/pomerium-ingress" ]
ENTRYPOINT [ "/bin/pomerium-ingress" ]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ dev-install:
@echo "==> $@"
@echo "deleting pods..."
@kubectl delete --force --selector app.kubernetes.io/name=pomerium pods || true
@$(KUSTOMIZE) build config/dev | kubectl apply --filename -
@$(KUSTOMIZE) build config/dev/local | kubectl apply --filename -
@stern -n pomerium --selector app.kubernetes.io/name=pomerium

.PHONY: dev-gen-secrets
Expand Down
16 changes: 0 additions & 16 deletions apis/ingress/v1/zz_generated.deepcopy.go

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

28 changes: 18 additions & 10 deletions cmd/all_in_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import (
type allCmdOptions struct {
ingressControllerOpts
debug bool
// MetricsBindAddress must be externally accessible host:port
MetricsBindAddress string `validate:"required,hostname_port"`
// metricsBindAddress must be externally accessible host:port
metricsBindAddress string `validate:"required,hostname_port"`
serverAddr string `validate:"required,hostname_port"`
httpRedirectAddr string `validate:"required,hostname_port"`
}

type allCmdParam struct {
Expand All @@ -40,9 +42,10 @@ type allCmdParam struct {
updateStatusFromService string
dumpConfigDiff bool

metricsBindAddress string
// bootstrapMetricsAddr for bootstrap configuration controller metrics
bootstrapMetricsAddr string
ingressMetricsAddr string
// ingressMetricsAddr for ingress+settings reconciliation controller metrics
ingressMetricsAddr string

cfg config.Config
}
Expand Down Expand Up @@ -72,7 +75,10 @@ func (s *allCmd) setupFlags() error {
if err := flags.MarkHidden("debug"); err != nil {
return err
}
flags.StringVar(&s.MetricsBindAddress, metricsBindAddress, "", "host:port for aggregate metrics")
flags.StringVar(&s.metricsBindAddress, metricsBindAddress, "", "host:port for aggregate metrics. host is mandatory")
flags.StringVar(&s.serverAddr, "server-addr", ":8443", "the address the HTTPS server would bind to")
flags.StringVar(&s.httpRedirectAddr, "http-redirect-addr", ":8080", "the address HTTP redirect would bind to")

s.ingressControllerOpts.setupFlags(flags)
return viperWalk(flags)
}
Expand Down Expand Up @@ -117,9 +123,8 @@ func (s *allCmdOptions) getParam() (*allCmdParam, error) {
ingressOpts: opts,
updateStatusFromService: s.UpdateStatusFromService,
dumpConfigDiff: s.debug,
metricsBindAddress: s.MetricsBindAddress,
}
if err := p.makeBootstrapConfig(); err != nil {
if err := p.makeBootstrapConfig(*s); err != nil {
return nil, fmt.Errorf("bootstrap: %w", err)
}

Expand All @@ -144,9 +149,12 @@ func (s *allCmdParam) run(ctx context.Context) error {
return eg.Wait()
}

func (s *allCmdParam) makeBootstrapConfig() error {
func (s *allCmdParam) makeBootstrapConfig(opt allCmdOptions) error {
s.cfg.Options = config.NewDefaultOptions()

s.cfg.Options.Addr = opt.serverAddr
s.cfg.Options.HTTPRedirectAddr = opt.httpRedirectAddr

ports, err := netutil.AllocatePorts(7)
if err != nil {
return fmt.Errorf("allocating ports: %w", err)
Expand All @@ -157,6 +165,8 @@ func (s *allCmdParam) makeBootstrapConfig() error {
s.bootstrapMetricsAddr = fmt.Sprintf("localhost:%s", ports[5])
s.ingressMetricsAddr = fmt.Sprintf("localhost:%s", ports[6])

s.cfg.Options.MetricsAddr = opt.metricsBindAddress

s.cfg.MetricsScrapeEndpoints = []config.MetricsScrapeEndpoint{
{
Name: "bootstrap",
Expand All @@ -182,8 +192,6 @@ func (s *allCmdParam) makeBootstrapConfig() error {
},
}

s.cfg.Options.MetricsAddr = ":9090"

return nil
}

Expand Down
54 changes: 0 additions & 54 deletions config/pomerium/deployment.yaml

This file was deleted.

24 changes: 24 additions & 0 deletions config/pomerium/deployment/args.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pomerium
spec:
template:
spec:
containers:
- name: pomerium
args:
- all-in-one
- --global-settings=$(POMERIUM_NAMESPACE)/settings
- --update-status-from-service=$(POMERIUM_NAMESPACE)/pomerium-proxy
- --metrics-bind-address=$(POD_IP):9090
env:
- name: POMERIUM_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
12 changes: 12 additions & 0 deletions config/pomerium/deployment/base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pomerium
spec:
replicas: 1
template:
spec:
containers:
- name: pomerium
serviceAccountName: pomerium-controller
terminationGracePeriodSeconds: 10
File renamed without changes.
12 changes: 12 additions & 0 deletions config/pomerium/deployment/image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pomerium
spec:
replicas: 1
template:
spec:
containers:
- name: pomerium
image: pomerium/ingress-controller:main
imagePullPolicy: IfNotPresent
10 changes: 10 additions & 0 deletions config/pomerium/deployment/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resources:
- base.yaml
patchesStrategicMerge:
- args.yaml
- image.yaml
- ports.yaml
- resources.yaml
- no-root.yaml
- readonly-root-fs.yaml
#- healthchecks.yaml
16 changes: 16 additions & 0 deletions config/pomerium/deployment/no-root.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pomerium
spec:
template:
spec:
securityContext:
runAsNonRoot: true
containers:
- name: pomerium
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsGroup: 1000
runAsUser: 1000
19 changes: 19 additions & 0 deletions config/pomerium/deployment/ports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pomerium
spec:
template:
spec:
containers:
- name: pomerium
ports:
- containerPort: 8443
name: https
protocol: TCP
- name: http
containerPort: 8080
protocol: TCP
- name: metrics
containerPort: 9090
protocol: TCP
22 changes: 22 additions & 0 deletions config/pomerium/deployment/readonly-root-fs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pomerium
spec:
template:
spec:
nodeSelector:
kubernetes.io/os: linux
containers:
- name: pomerium
securityContext:
readOnlyRootFilesystem: true
env:
- name: TMPDIR
value: "/tmp"
volumeMounts:
- mountPath: "/tmp"
name: tmp
volumes:
- name: tmp
emptyDir: {}
16 changes: 16 additions & 0 deletions config/pomerium/deployment/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pomerium
spec:
template:
spec:
containers:
- name: pomerium
resources:
limits:
cpu: 5000m
memory: 1Gi
requests:
cpu: 300m
memory: 200Mi
10 changes: 3 additions & 7 deletions config/pomerium/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#
resources:
- namespace.yaml
- deployment.yaml
- service_proxy.yaml
- service_metrics.yaml
- service_account.yaml
- role.yaml
- role_binding.yaml
- ingressclass.yaml
- ./ingressclass.yaml
- ./deployment
- ./service
4 changes: 4 additions & 0 deletions config/pomerium/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
- role.yaml
- role_binding.yaml
- service_account.yaml
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions config/pomerium/service/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
- proxy.yaml
- metrics.yaml
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ spec:
protocol: TCP
name: https
- name: http
targetPort: 80
targetPort: http
protocol: TCP
port: 80
Loading

0 comments on commit f86eed8

Please sign in to comment.