Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔦 Feature: support read-only and non-root docker containers #8347

Closed
1 task done
tcurdt opened this issue Apr 25, 2024 · 8 comments
Closed
1 task done

🔦 Feature: support read-only and non-root docker containers #8347

tcurdt opened this issue Apr 25, 2024 · 8 comments

Comments

@tcurdt
Copy link

tcurdt commented Apr 25, 2024

Please confirm if feature request does NOT exist already ?

  • I confirm there is no existing issue for this

Describe the usecase for the feature

For security reasons some companies require containers to be run as non-root and sometimes even in read-only mode. This usually is no bigger problem but nocodb seems to have a very unusual docker setup.

Setting this should work without bigger problems:

services:
  nocodb:
    container_name: nocodb
    image: nocodb/nocodb:latest
    read_only: true
    user: 65534:65534

Suggested Solution

TBH I am not quite sure why an un-tar would be necessary at container startup at runtime over build time.
If possible the image should be setup correctly at build time.

And if some folders need special permissions this here could be a work around:

ENV UID 65534
ENV GID 65534
RUN chown -R $UID:$GID /some/folder

Additional Context

No response

@salim-b
Copy link
Contributor

salim-b commented May 6, 2024

TBH I am not quite sure why an un-tar would be necessary at container startup at runtime over build time.

It is not. Simply removing the untar (also from the other start scripts)

if [ ! -f "$FILE" ]
then
tar -xzf /usr/src/appEntry/app.tar.gz -C /usr/src/app/
fi

and adding the following line to the Dockerfile at this position should suffice.

RUN tar -xzf /usr/src/appEntry/app.tar.gz -C /usr/src/app/ && rm -f /usr/src/appEntry/app.tar.gz

I wonder what @pranavxc thinks.

@pranavxc
Copy link
Member

pranavxc commented May 7, 2024

TBH I am not quite sure why an un-tar would be necessary at container startup at runtime over build time.

It is not. Simply removing the untar (also from the other start scripts)

if [ ! -f "$FILE" ]
then
tar -xzf /usr/src/appEntry/app.tar.gz -C /usr/src/app/
fi

and adding the following line to the Dockerfile at this position should suffice.

RUN tar -xzf /usr/src/appEntry/app.tar.gz -C /usr/src/app/ && rm -f /usr/src/appEntry/app.tar.gz

I wonder what @pranavxc thinks.

We are keeping our build as a compressed tar file to reduce the overall size, on the first run we are extracting the build and then proceeding. We will check how we can make it support read-only and non-root options.

@salim-b
Copy link
Contributor

salim-b commented May 7, 2024

@pranavxc Extracting on the first run is unfavorable in the case of a containerized app since the extraction is repeated on every container restart (unless /usr/src/appEntry lives on persistent storage), which delays startup. And by adding a tar archive in the container image to be extracted at run-time, you actually increase the storage requirements for the app at run-time.

I'm successfully using the above approach with the official Docker image, i.e.

FROM nocodb/nocodb:latest
RUN tar -xzf /usr/src/appEntry/app.tar.gz -C /usr/src/app/ && rm -f /usr/src/appEntry/app.tar.gz
COPY --link --chown=0:0 mystartup.sh /usr/src/appEntry/start.sh

(where mystartup.sh is the customized start-litestream.sh)

so I think it should work in general.

Would you welcome a PR?

@pranavxc
Copy link
Member

pranavxc commented May 8, 2024

@pranavxc Extracting on the first run is unfavorable in the case of a containerized app since the extraction is repeated on every container restart (unless /usr/src/appEntry lives on persistent storage), which delays startup. And by adding a tar archive in the container image to be extracted at run-time, you actually _in_crease the storage requirements for the app at run-time.

I'm successfully using the above approach with the official Docker image, i.e.

FROM nocodb/nocodb:latest
RUN tar -xzf /usr/src/appEntry/app.tar.gz -C /usr/src/app/ && rm -f /usr/src/appEntry/app.tar.gz
COPY --link --chown=0:0 mystartup.sh /usr/src/appEntry/start.sh

(where mystartup.sh is the customized start-litestream.sh)

so I think it should work in general.

Would you welcome a PR?

Your concerns make sense, I will have a look at the Dockerfile and get back to you. Skipping compressing will increase the overall image size slightly and other than that no issues are there but I will double-check.

@pranavxc
Copy link
Member

pranavxc commented May 8, 2024

@salim-b: I've reviewed it, and I suggest removing the compression part entirely from the Dockerfile and keeping the build in the extracted state. If you're interested in collaborating on this, please let me know, or I can handle this aspect. Regarding the non-root part, I'm concerned about existing users who have already mounted volumes if they migrate to the version where we're utilizing a non-root user.

@tcurdt
Copy link
Author

tcurdt commented May 8, 2024

Regarding the non-root part, I'm concerned about existing users who have already mounted volumes if they migrate to the version where we're utilizing a non-root user.

One way could be to just allow for easy non-root user usage. That way it's up to the user to migrate - if they want.

But I think with good upgrade instructions it would not be that bad either. In the end it's just a chown - which maybe could even be baked into the Dockerfile. And nocodb is still pre 1.0. In the long run it certainly would be better to run as non-root.

@salim-b
Copy link
Contributor

salim-b commented May 9, 2024

@pranavxc I've submitted #8439, please have a look.

@dstala dstala closed this as completed May 15, 2024
@dstala
Copy link
Member

dstala commented May 15, 2024

Please reopen this thread if you need further assistance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Closed
Development

No branches or pull requests

4 participants