Skip to content

Commit 477e2c9

Browse files
author
Nicolas Marcq
committed
Run as non root by default #16
Support for K8S and Openshift
1 parent 1a509de commit 477e2c9

2 files changed

Lines changed: 37 additions & 34 deletions

File tree

Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
FROM node:14-alpine
1+
# BUILD
2+
# docker build \
3+
# --force-rm=true \
4+
# -f Dockerfile \
5+
# -t docker-http-https-echo .
26

3-
WORKDIR /app
7+
# RUN
8+
# docker run --rm -it \
9+
# -p 8080:8080 -p 8443:8443 \
10+
# docker-http-https-echo
411

5-
COPY . .
12+
FROM node:14-alpine
613

7-
ENV HTTP_PORT=80 HTTPS_PORT=443
14+
WORKDIR /app
15+
COPY . /app
16+
ENV HTTP_PORT=8080 HTTPS_PORT=8443
817

918
RUN npm install --production
10-
1119
RUN apk --no-cache add openssl && sh generate-cert.sh && rm -rf /var/cache/apk/*
1220

21+
RUN chmod -R 775 /app
1322
RUN chown -R node:node /app
1423

24+
USER 1000
25+
1526
CMD ["node", "./index.js"]

README.md

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
[![pulls](https://img.shields.io/docker/pulls/mendhak/http-https-echo.svg?style=for-the-badge&logo=docker)](https://hub.docker.com/r/mendhak/http-https-echo)
1+
[![pulls](https://img.shields.io/docker/pulls/mendhak/http-https-echo.svg?style=for-the-badge&logo=docker)](https://hub.docker.com/r/mendhak/http-https-echo)
22
[![Docker Build Status](https://img.shields.io/docker/build/mendhak/http-https-echo?color=darkgreen&label=build&style=for-the-badge)
33
![Docker Image Version (latest semver)](https://img.shields.io/docker/v/mendhak/http-https-echo?color=lightblue&label=latest&sort=semver&style=for-the-badge)](https://hub.docker.com/r/mendhak/http-https-echo)
44

55

66

7-
[`mendhak/http-https-echo`](https://hub.docker.com/r/mendhak/http-https-echo) is a Docker image that can echo various HTTP request properties back to client, as well as in the Docker container logs.
8-
You can use your own certificates, choose your ports, decode JWT headers and filter out certain paths.
7+
[`mendhak/http-https-echo`](https://hub.docker.com/r/mendhak/http-https-echo) is a Docker image that can echo various HTTP request properties back to client, as well as in the Docker container logs.
8+
You can use your own certificates, choose your ports, decode JWT headers and filter out certain paths.
99

1010
![browser](https://raw.githubusercontent.com/mendhak/docker-http-https-echo/master/screenshots/screenshot.png)
1111

12+
This image is executed as non root by default and is fully compliant with Kubernetes or Openshift deployment.
13+
1214
## Basic Usage
1315

1416
Run with Docker
1517

16-
docker run -p 8080:80 -p 8443:443 --rm -t mendhak/http-https-echo
18+
docker run -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo
1719

1820
Or run with Docker Compose
1921

@@ -26,9 +28,9 @@ Then, issue a request via your browser or curl, and watch the response, as well
2628

2729
## Choose your ports
2830

29-
You can choose a different internal port instead of 80 and 443 with the `HTTP_PORT` and `HTTPS_PORT` environment variables.
31+
You can choose a different internal port instead of 80 and 443 with the `HTTP_PORT` and `HTTPS_PORT` environment variables.
3032

31-
In this example I'm setting http to listen on 8888, and https to listen on 9999.
33+
In this example I'm setting http to listen on 8888, and https to listen on 9999.
3234

3335
docker run -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8080:8888 -p 8443:9999 --rm -t mendhak/http-https-echo
3436

@@ -37,7 +39,7 @@ With docker compose, this would be:
3739

3840
my-http-listener:
3941
image: mendhak/http-https-echo
40-
environment:
42+
environment:
4143
- HTTP_PORT=8888
4244
- HTTPS_PORT=9999
4345
ports:
@@ -52,8 +54,8 @@ Use volume mounting to substitute the certificate and private key with your own.
5254
my-http-listener:
5355
image: mendhak/http-https-echo
5456
ports:
55-
- "8080:80"
56-
- "8443:443"
57+
- "8080:8080"
58+
- "8443:8443"
5759
volumes:
5860
- /etc/ssl/certs/ssl-cert-snakeoil.pem:/app/fullchain.pem
5961
- /etc/ssl/private/ssl-cert-snakeoil.key:/app/privkey.pem
@@ -62,21 +64,21 @@ Use volume mounting to substitute the certificate and private key with your own.
6264

6365
## Decode JWT header
6466

65-
If you specify the header that contains the JWT, the echo output will contain the decoded JWT. Use the `JWT_HEADER` environment variable for this.
67+
If you specify the header that contains the JWT, the echo output will contain the decoded JWT. Use the `JWT_HEADER` environment variable for this.
6668

67-
docker run -e JWT_HEADER=Authentication -p 8080:80 -p 8443:443 --rm -it mendhak/http-https-echo
69+
docker run -e JWT_HEADER=Authentication -p 8080:8080 -p 8443:8443 --rm -it mendhak/http-https-echo
6870

6971

7072
Now make your request with `Authentication: eyJ...` header (it should also work with the `Authentication: Bearer eyJ...` schema too):
7173

7274
curl -k -H "Authentication: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" http://localhost:8080/
7375

74-
And in the output you should see a `jwt` section.
76+
And in the output you should see a `jwt` section.
7577

7678
## Do not log specific path
7779

78-
Set the environment variable `LOG_IGNORE_PATH` to a path you would like to exclude from verbose logging to stdout.
79-
This can help reduce noise from healthchecks in orchestration/infrastructure like Swarm, Kubernetes, ALBs, etc.
80+
Set the environment variable `LOG_IGNORE_PATH` to a path you would like to exclude from verbose logging to stdout.
81+
This can help reduce noise from healthchecks in orchestration/infrastructure like Swarm, Kubernetes, ALBs, etc.
8082

8183
docker run -e LOG_IGNORE_PATH=/ping -p 8080:80 -p 8443:443 --rm -t mendhak/http-https-echo
8284

@@ -88,19 +90,19 @@ With docker compose, this would be:
8890
environment:
8991
- LOG_IGNORE_PATH=/ping
9092
ports:
91-
- "8080:80"
92-
- "8443:443"
93+
- "8080:8080"
94+
- "8443:8443"
9395

9496

9597
## JSON payloads and JSON output
9698

97-
If you submit a JSON payload in the body of the request, with Content-Type: application/json, then the response will contain the escaped JSON as well.
99+
If you submit a JSON payload in the body of the request, with Content-Type: application/json, then the response will contain the escaped JSON as well.
98100

99101
For example,
100102

101103
curl -X POST -H "Content-Type: application/json" -d '{"a":"b"}' http://localhost:8080/
102104

103-
Will contain a `json` property in the response/output.
105+
Will contain a `json` property in the response/output.
104106

105107
...
106108
"xhr": false,
@@ -110,16 +112,6 @@ Will contain a `json` property in the response/output.
110112
}
111113
}
112114

113-
## Run as a non-root or rootless user
114-
115-
Set the `--user` to `node`, and change the internal ports to a high number.
116-
117-
docker run --user node -e HTTP_PORT=8080 -e HTTPS_PORT=8443 -p 8080:8080 -p 8443:8443 --rm mendhak/http-https-echo
118-
119-
Or use the sysctl flag, like so
120-
121-
docker run --user node --sysctl net.ipv4.ip_unprivileged_port_start=0 -p 8080:80 -p 8443:443 --rm mendhak/http-https-echo
122-
123115
## Output
124116

125117
#### Curl output
@@ -136,6 +128,6 @@ Or use the sysctl flag, like so
136128

137129
docker build -t mendhak/http-https-echo .
138130

139-
Run some tests to make sure features are working as expected.
131+
Run some tests to make sure features are working as expected.
140132

141133
./tests.sh

0 commit comments

Comments
 (0)