Skip to content

Commit 318715f

Browse files
committed
Merge branch 'master' of github.com:nginxinc/nginx-s3-gateway
2 parents 8482820 + 7c4fb24 commit 318715f

File tree

6 files changed

+136
-24
lines changed

6 files changed

+136
-24
lines changed

.github/workflows/main.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ jobs:
2121
- name: Install dependencies
2222
run: sudo apt-get install -y wait-for-it
2323
- name: Run tests - latest njs version
24-
run: ./test.sh latest-njs-oss
24+
run: ./test.sh --latest-njs --type oss
2525
- name: Run tests - stable njs version
26-
run: ./test.sh oss
26+
run: ./test.sh --type oss
27+
- name: Run tests - stable njs version - unprivileged process
28+
run: ./test.sh --unprivileged --type oss
29+
- name: Run tests - latest njs version - unprivileged process
30+
run: ./test.sh --latest-njs --unprivileged --type oss
2731

2832
build_and_deploy:
2933
runs-on: ubuntu-latest
@@ -41,9 +45,9 @@ jobs:
4145
- name: Install dependencies
4246
run: sudo apt-get install -y wait-for-it
4347
- name: Run tests - latest njs version
44-
run: ./test.sh latest-njs-oss
48+
run: ./test.sh --latest-njs --type oss
4549
- name: Run tests - stable njs version
46-
run: ./test.sh oss
50+
run: ./test.sh --type oss
4751
# latest-njs-oss image push [Github]
4852
- name: Tag container image for Push to github [latest-njs-oss date]
4953
run: docker tag nginx-s3-gateway:latest-njs-oss docker.pkg.github.com/$GITHUB_REPOSITORY/nginx-oss-s3-gateway:latest-njs-oss-${{ steps.date.outputs.date }}
@@ -53,6 +57,15 @@ jobs:
5357
run: docker push docker.pkg.github.com/$GITHUB_REPOSITORY/nginx-oss-s3-gateway:latest-njs-oss-${{ steps.date.outputs.date }}
5458
- name: Push container image to github [latest-njs-oss]
5559
run: docker push docker.pkg.github.com/$GITHUB_REPOSITORY/nginx-oss-s3-gateway:latest-njs-oss
60+
# unprivileged-oss image push [Github]
61+
- name: Tag container image for Push to github [unprivileged-oss date]
62+
run: docker tag nginx-s3-gateway:unprivileged-oss docker.pkg.github.com/$GITHUB_REPOSITORY/nginx-oss-s3-gateway:unprivileged-oss-${{ steps.date.outputs.date }}
63+
- name: Tag container image for Push to github [unprivileged-oss]
64+
run: docker tag nginx-s3-gateway:unprivileged-oss docker.pkg.github.com/$GITHUB_REPOSITORY/nginx-oss-s3-gateway:unprivileged-oss
65+
- name: Push container image to github [unprivileged-oss date]
66+
run: docker push docker.pkg.github.com/$GITHUB_REPOSITORY/nginx-oss-s3-gateway:unprivileged-oss-${{ steps.date.outputs.date }}
67+
- name: Push container image to github [unprivileged-oss]
68+
run: docker push docker.pkg.github.com/$GITHUB_REPOSITORY/nginx-oss-s3-gateway:unprivileged-oss
5669
# oss image push [Github]
5770
- name: Tag container image for Push to github [oss date]
5871
run: docker tag nginx-s3-gateway:latest docker.pkg.github.com/$GITHUB_REPOSITORY/nginx-oss-s3-gateway:latest-${{ steps.date.outputs.date }}
@@ -77,6 +90,15 @@ jobs:
7790
run: docker push nginxinc/nginx-s3-gateway:latest-njs-oss-${{ steps.date.outputs.date }}
7891
- name: Push container image to Docker Hub [latest-njs-oss]
7992
run: docker push nginxinc/nginx-s3-gateway:latest-njs-oss
93+
# unprivileged-oss image push [Docker Hub]
94+
- name: Tag container image for Push to Docker Hub [unprivileged-oss date]
95+
run: docker tag nginx-s3-gateway:unprivileged-oss nginxinc/nginx-s3-gateway:unprivileged-oss-${{ steps.date.outputs.date }}
96+
- name: Tag container image for Push to Docker Hub [unprivileged-oss]
97+
run: docker tag nginx-s3-gateway:unprivileged-oss nginxinc/nginx-s3-gateway:unprivileged-oss
98+
- name: Push container image to Docker Hub [unprivileged-oss date]
99+
run: docker push nginxinc/nginx-s3-gateway:unprivileged-oss-${{ steps.date.outputs.date }}
100+
- name: Push container image to Docker Hub [unprivileged-oss]
101+
run: docker push nginxinc/nginx-s3-gateway:unprivileged-oss
80102
# oss image push [Docker Hub]
81103
- name: Tag container image for Push to Docker Hub [oss date]
82104
run: docker tag nginx-s3-gateway:latest nginxinc/nginx-s3-gateway:latest-${{ steps.date.outputs.date }}

Dockerfile.unprivileged

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This container images makes the necessary modifications in the
2+
# inherited image (which could be OSS NGINX or NGINX Plus) in order
3+
# to allow running NGINX S3 Gateway as a non root user.
4+
# Steps are based on the official unprivileged container:
5+
# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/Dockerfile-debian.template
6+
FROM nginx-s3-gateway
7+
8+
# Implement changes required to run NGINX as an unprivileged user
9+
RUN sed -i "/^server {/a \ listen 8080;" /etc/nginx/templates/default.conf.template \
10+
&& sed -i '/user nginx;/d' /etc/nginx/nginx.conf \
11+
&& sed -i 's,/var/run/nginx.pid,/tmp/nginx.pid,' /etc/nginx/nginx.conf \
12+
&& sed -i "/^http {/a \ proxy_temp_path /tmp/proxy_temp;\n client_body_temp_path /tmp/client_temp;\n fastcgi_temp_path /tmp/fastcgi_temp;\n uwsgi_temp_path /tmp/uwsgi_temp;\n scgi_temp_path /tmp/scgi_temp;\n" /etc/nginx/nginx.conf \
13+
# Nginx user must own the cache and etc directory to write cache and tweak the nginx config
14+
&& chown -R nginx:0 /var/cache/nginx \
15+
&& chmod -R g+w /var/cache/nginx \
16+
&& chown -R nginx:0 /etc/nginx \
17+
&& chmod -R g+w /etc/nginx
18+
19+
EXPOSE 8080
20+
21+
USER nginx

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Dockerfile.buildkit.plus Dockerfile with the same configuration as Docke
7070
with support for hiding secrets using Docker's Buildkit
7171
Dockerfile.latest-njs Dockerfile that inherits from the last build of the gateway and
7272
then builds and installs the latest version of njs from source
73+
Dockerfile.latest-unpriviledged Dockerfiles that inherits from the last build of the gateway and
74+
makes the necessary modifications to allow running the container
75+
as a non root, unpriviledged user.
7376
settings.example Docker env file example
7477
standalone_ubuntu_oss_install.sh install script that will install the gateway as a Systemd service
7578
test.sh test launcher

docs/getting_started.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ docker run --env-file ./settings --publish 80:80 --name nginx-s3-gateway \
148148
nginx-s3-gateway:oss
149149
```
150150

151+
In the same way, if you want to use NGINX OSS container image as a non-root, unpriviledged user,
152+
you can build it as follows:
153+
```
154+
docker build --file Dockerfile.latest-unpriviledged --tag nginx-s3-gateway --tag nginx-s3-gateway:latest-unpriviledged-oss .
155+
```
156+
And run the image binding the container port 8080 to 80 in the host like:
157+
```
158+
docker run --env-file ./settings --publish 80:8080 --name nginx-s3-gateway \
159+
nginx-s3-gateway:latest-unpriviledged-oss
160+
```
161+
151162
### Building the NGINX Plus Container Image
152163

153164
In order to build the NGINX Plus container image, copy your NGINX Plus

test.sh

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#
1818

1919
set -o errexit # abort on nonzero exit status
20-
set -o nounset # abort on unbound variable
2120
set -o pipefail # don't hide errors within pipes
2221

2322
nginx_server_proto="http"
@@ -41,28 +40,71 @@ e() {
4140
>&2 echo "$1"
4241
}
4342

44-
45-
if [ $# -eq 0 ]; then
43+
usage() { e "Usage: $0 [--latest-njs <default:false>] [--unprivileged <default:false>] [--type <default:oss|plus>" 1>&2; exit 1; }
44+
45+
for arg in "$@"; do
46+
shift
47+
case "$arg" in
48+
'--help') set -- "$@" '-h' ;;
49+
'--latest-njs') set -- "$@" '-j' ;;
50+
'--unprivileged') set -- "$@" '-u' ;;
51+
'--type') set -- "$@" '-t' ;;
52+
*) set -- "$@" "$arg" ;;
53+
esac
54+
done
55+
56+
while getopts "hjut:" arg; do
57+
case "${arg}" in
58+
j)
59+
njs_latest="1"
60+
;;
61+
u)
62+
unprivileged="1"
63+
;;
64+
t)
65+
nginx_type="${OPTARG}"
66+
;;
67+
*)
68+
usage
69+
;;
70+
esac
71+
done
72+
shift $((OPTIND-1))
73+
74+
startup_message=""
75+
76+
if [ -z "${nginx_type}" ]; then
4677
nginx_type="oss"
47-
njs_latest=0
48-
p "No argument specified - defaulting to NGINX OSS. Valid arguments: oss, plus, latest-njs-oss, latest-njs-plus"
78+
startup_message="Starting NGINX ${nginx_type} (default)"
79+
elif ! { [ ${nginx_type} == "oss" ] || [ ${nginx_type} == "plus" ]; }; then
80+
e "Invalid NGINX type: ${nginx_type} - must be either 'oss' or 'plus'"
81+
usage
4982
else
50-
if [[ "${1}" == *plus ]]; then
51-
nginx_type="plus"
52-
p "Testing with NGINX Plus"
53-
else
54-
nginx_type="oss"
55-
p "Testing with NGINX OSS"
56-
fi
83+
startup_message="Starting NGINX ${nginx_type}"
84+
fi
5785

58-
if [[ "${1}" == latest-njs-* ]]; then
59-
p "Testing with latest development version of NJS"
60-
njs_latest=1
61-
else
62-
njs_latest=0
63-
fi
86+
if [ -z "${njs_latest}" ]; then
87+
njs_latest="0"
88+
startup_message="${startup_message} with the release NJS module (default)"
89+
elif [ ${njs_latest} -eq 1 ]; then
90+
startup_message="${startup_message} with the latest NJS module"
91+
else
92+
startup_message="${startup_message} with the release NJS module"
6493
fi
6594

95+
if [ -z "${unprivileged}" ]; then
96+
unprivileged="0"
97+
startup_message="${startup_message} in privileged mode (default)"
98+
elif [ ${unprivileged} -eq 1 ]; then
99+
startup_message="${startup_message} in unprivileged mode"
100+
else
101+
startup_message="${startup_message} in privileged mode"
102+
fi
103+
104+
e "${startup_message}"
105+
106+
set -o nounset # abort on unbound variable
107+
66108
docker_cmd="$(command -v docker)"
67109
if ! [ -x "${docker_cmd}" ]; then
68110
e "required dependency not found: docker not found in the path or not executable"
@@ -102,7 +144,14 @@ if [ "${nginx_type}" = "plus" ]; then
102144
fi
103145

104146
compose() {
105-
"${docker_compose_cmd}" -f "${test_compose_config}" -p "${test_compose_project}" "$@"
147+
# Hint to docker-compose the internal port to map for the container
148+
if [ ${unprivileged} -eq 1 ]; then
149+
export NGINX_INTERNAL_PORT=8080
150+
else
151+
export NGINX_INTERNAL_PORT=80
152+
fi
153+
154+
"${docker_compose_cmd}" -f "${test_compose_config}" -p "${test_compose_project}" "$@"
106155
}
107156

108157
integration_test() {
@@ -208,6 +257,12 @@ if [ ${njs_latest} -eq 1 ]; then
208257
--tag nginx-s3-gateway --tag nginx-s3-gateway:latest-njs-${nginx_type} .
209258
fi
210259

260+
if [ ${unprivileged} -eq 1 ]; then
261+
p "Layering in unprivileged build"
262+
docker build -f Dockerfile.unprivileged \
263+
--tag nginx-s3-gateway --tag nginx-s3-gateway:unprivileged-${nginx_type} .
264+
fi
265+
211266
### UNIT TESTS
212267

213268
p "Running unit tests in Docker image"

test/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
condition: service_healthy
1010
image: "nginx-s3-gateway"
1111
ports:
12-
- "8989:80/tcp"
12+
- "8989:${NGINX_INTERNAL_PORT-80}/tcp"
1313
links:
1414
- "minio"
1515
restart: "no"

0 commit comments

Comments
 (0)