apisix-docker icon indicating copy to clipboard operation
apisix-docker copied to clipboard

feature request/security: avoid container running root

Open vmaillot opened this issue 3 years ago • 9 comments

Hey there,

In advance, thanks for your time and help.

Context

I was trying to make Apisix run in a OpenShift cluster but without having root running the container. To do so I am using the official upstream Helm chart. I was able to run everything but the Apisix deployment without root. A work around is to use the SCC as anyuid on the service account running the application to let the application run as user root (0). Obviously in a perfect world we do not want that.

That is why I am asking if that would be possible to make the application run as a non-root user. When trying this solution with the help of the Helm chart, and without setting up the SCC I am getting this error below:

/usr/local/openresty/luajit/bin/luajit ./apisix/cli/apisix.lua init failed to update nginx.conf: failed to open file: /usr/local/apisi/conf/nginx.conf, error info:/usr/local/apisix/conf/nginx.conf: Permission denied

The error makes total sense, as the generated nginx configuration has those permissions:

bash-5.1# ls -la /usr/local/apisix/conf/nginx.conf
-rw-r--r--    1 root     root         11422 Jul  5 10:49 /usr/local/apisix/conf/nginx.conf

Solutions

The first easy solution would be to add write access to the group root on this file as every container is started with the root group (0) on OpenShift. The nginx configuration seems to be generated somehow, maybe it would be doable to add the write permission to the group on the fly?

The second one is a bit more tricky and might require more work but would simply follows the Best practices for writing Dockerfiles. Again maybe we have a application limitation, but I think that should be feasible!

Please let me know if something is unclear or not understood here.

Thanks for evaluating this proposition of a new feature to gain a bit of flexibility and security while running Apisix.

vmaillot avatar Jul 06 '22 15:07 vmaillot

The first easy solution would be to add write access to the group root on this file as every container is started with the root group (0) on OpenShift. The nginx configuration seems to be generated somehow, maybe it would be doable to add the write permission to the group on the fly?

Yes, the nginx.conf is generated when APISIX just starts. We may add the write and execute permission for the path /usr/local/apisix/conf.

tokers avatar Jul 07 '22 01:07 tokers

Yes, the nginx.conf is generated when APISIX just starts. We may add the write and execute permission for the path /usr/local/apisix/conf.

Right, your suggestion is nice and it would be awesome if you could implement this feature. Thanks for your effort here!

vmaillot avatar Jul 07 '22 07:07 vmaillot

Yes, the nginx.conf is generated when APISIX just starts. We may add the write and execute permission for the path /usr/local/apisix/conf.

we can do this in Dockerfile?

tzssangglass avatar Jul 08 '22 03:07 tzssangglass

Yes, the nginx.conf is generated when APISIX just starts. We may add the write and execute permission for the path /usr/local/apisix/conf.

we can do this in Dockerfile?

I think so.

tokers avatar Jul 10 '22 09:07 tokers

This issue has been marked as stale due to 30 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Aug 09 '22 10:08 github-actions[bot]

@tzssangglass @tokers any news?

vmaillot avatar Aug 09 '22 10:08 vmaillot

someone work on this:https://github.com/apache/apisix-docker/search?q=root+is%3Apr&type=issues, but no one seems to be pushing it to master eventually.

tzssangglass avatar Aug 09 '22 15:08 tzssangglass

Any new status on that?

vmaillot avatar Sep 05 '22 12:09 vmaillot

This issue has been marked as stale due to 30 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Oct 08 '22 10:10 github-actions[bot]

ping :}

vmaillot avatar Oct 10 '22 07:10 vmaillot

someone work on this:https://github.com/apache/apisix-docker/search?q=root+is%3Apr&type=issues, but no one seems to be pushing it to master eventually.

@vmaillot Is this OK for you?

tokers avatar Oct 10 '22 09:10 tokers

someone work on this:https://github.com/apache/apisix-docker/search?q=root+is%3Apr&type=issues, but no one seems to be pushing it to master eventually.

@vmaillot Is this OK for you?

well, can't this be pushed to master somehow?

vmaillot avatar Oct 10 '22 09:10 vmaillot

hi, i will do it @vmaillot

Hazel6869 avatar Oct 10 '22 09:10 Hazel6869

hi, i will do it @vmaillot

hey @Hazel6869 thanks a lot! it is much appreciated

vmaillot avatar Oct 10 '22 09:10 vmaillot

This issue has been marked as stale due to 30 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Nov 10 '22 10:11 github-actions[bot]

@Hazel6869 any progress on your side regarding #371?

vmaillot avatar Nov 11 '22 09:11 vmaillot

@vmaillot I'm testing. sorry~ I want to know which image is you used,
image

Hazel6869 avatar Nov 28 '22 08:11 Hazel6869

@vmaillot I'm testing. sorry~ I want to know which image is you used, image

hey @Hazel6869 sorry for the late reply, but i would suggest to go with alpine : D lightweight ftw!

vmaillot avatar Dec 06 '22 09:12 vmaillot

APISIX has stopped maintaining the alpine image, it is recommended that you use debian.

soulbird avatar Dec 07 '22 01:12 soulbird

@vmaillot sorry, APISIX has stopped maintaining the alpine image, it is recommended that you use debian. how do you think.

Hazel6869 avatar Dec 13 '22 09:12 Hazel6869

@vmaillot sorry, APISIX has stopped maintaining the alpine image, it is recommended that you use debian. how do you think.

@Hazel6869 debian would be totally fine! thanks for checking

vmaillot avatar Dec 13 '22 09:12 vmaillot

@vmaillot OK, I will use debian, I have time today, I will fix it.

Hazel6869 avatar Dec 14 '22 01:12 Hazel6869

Does this change need to be applied to centos based image? and also, this may required some more docs, non root user can not bind ports under 1024, unless use securityContext.runAsUser to override the default user.

fengxsong avatar Jan 05 '23 11:01 fengxsong

Finally, I found cause that I can't bind ports 80 and 443. Release 3.1.0 is the first release that contain this change, right? This affect helm chart too. Have to add securityContext.runAsUser=0 (run as root).

ankworld avatar Jan 16 '23 21:01 ankworld

Finally, I found cause that I can't bind ports 80 and 443. Release 3.1.0 is the first release that contain this change, right? This affect helm chart too. Have to add securityContext.runAsUser=0 (run as root).

@Hazel6869 Please take a look when you have time.

tokers avatar Jan 17 '23 01:01 tokers

From an Helm chart point of view, why did you guys reverted to use 2.15.1-debian image?

Thanks for your time and help!

vmaillot avatar Jan 26 '23 15:01 vmaillot

Chart 1.x is for Apisix v3. Chart 0.x is for Apisix V2.

ankworld avatar Jan 26 '23 16:01 ankworld

@ankworld The helm chart version 0.12.3 contains / referencing the apisix 3.1.0-debian image. So the question above was valid. https://github.com/apache/apisix-helm-chart/blob/apisix-0.12.3/charts/apisix/values.yaml#L84

This was fixed in the chart 0.13.0: https://github.com/apache/apisix-helm-chart/blob/apisix-0.13.0/charts/apisix/values.yaml#L84

Also this means that that the non-root (current thread tema) changes are no incorporated in the 0.x chart version (apisix container image 2.x) only in the chart 1.x (apisix:3.1.0-debian)

mkocsis-tg avatar Jan 29 '23 16:01 mkocsis-tg

From an Helm chart point of view, why did you guys reverted to use 2.15.1-debian image?

Thanks for your time and help! @vmaillot Hi,I don't understand, does the current change meet your needs?

Hazel6869 avatar Jan 30 '23 02:01 Hazel6869

This issue has been marked as stale due to 30 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Mar 01 '23 10:03 github-actions[bot]