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

Container won't start #76

Closed
Whalee110 opened this issue Oct 9, 2023 · 43 comments
Closed

Container won't start #76

Whalee110 opened this issue Oct 9, 2023 · 43 comments

Comments

@Whalee110
Copy link

I am attempting to deploy portainer stack with docker compose and it keeps failing to "initialise"

The error I get is below but I can't see any error in the compose.

Secrets saved.
Settings saved.
Config plugin initialization completed.
Database plugin initialization completed.
Life cycle plugin initialization completed.
Starting migrations...
Applying initial database script...
Attempt to apply initial...
FastifyError [Error]: A callback for 'onReady' hook timed out. You may have forgotten to call 'done' function or to resolve a Promise
at exit (/app/node_modules/fastify/lib/hooks.js:97:37)
at manageTimeout (/app/node_modules/fastify/lib/hooks.js:124:11)
at _encapsulateThreeParam (/app/node_modules/avvio/boot.js:562:7)
at Boot.timeoutCall (/app/node_modules/avvio/boot.js:458:5)
at Boot.callWithCbOrNextTick (/app/node_modules/avvio/boot.js:440:19)
at Task.release (/app/node_modules/fastq/queue.js:149:16)
at worked (/app/node_modules/fastq/queue.js:201:10)
at Boot.timeoutCb (/app/node_modules/avvio/boot.js:467:7)
at /app/node_modules/fastify/lib/hooks.js:146:9
at _encapsulateThreeParam (/app/node_modules/avvio/boot.js:562:7) {
code: 'FST_ERR_HOOK_TIMEOUT',
statusCode: 500,
cause: AvvioError [Error]: Plugin did not start in time: 'bound _encapsulateThreeParam'. You may have forgotten to call 'done' function or to resolve a Promise
at Timeout._onTimeout (/app/node_modules/avvio/boot.js:451:21)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
code: 'AVV_ERR_READY_TIMEOUT',
fn: [Function: bound _encapsulateThreeParam]
}
}

@AlexSciFier
Copy link
Owner

Hi can you send me the architecture of the machine running the container and your docker-compose file?

@Whalee110
Copy link
Author

Hey Alex,

Belows is my compose file and system info extract. Let me know If I can provide any better info thanks :)

Compose:
version: "3.9"
services:
neonlink:
image: alexscifier/neonlink
container_name: NAS_Neonlink
mem_limit: 2g
cpu_shares: 768
security_opt:
- no-new-privileges:true
restart: on-failure:5
volumes:
- /volume1/docker/neonlink/data:/app/data
- /volume1/docker/neonlink/media:/app/public/static/media/background
networks:
NAS_IPLan:
ipv4_address: 10.0.13.**

networks:
NAS_IPLan:
external: true
name: macvlan

System Info:
Sorry iffy getting it because it's on a Synology NAS.
CPU: Intel Celeron J3455, 1.5ghz, 4 cores
16 gb ram
DSM 7.2-64570 Update 3
DS918+

@AlexSciFier
Copy link
Owner

Thank you, try to run container with default docker-compose

@Whalee110
Copy link
Author

Same error occurs. Waiting for the container to restart the follow up error is:

Config plugin initialization completed.
Database plugin initialization completed.
Life cycle plugin initialization completed.
TypeError: Cannot read properties of undefined (reading 'version')
at getDatabaseVersion (file:///app/db/sqlite/database.js:23:14)
at SqliteManager.migrate (file:///app/db/sqlite/database.js:109:21)
at Object. (file:///app/plugins/010-database.js:63:27)
at /app/node_modules/fastify/lib/hooks.js:160:24
at _encapsulateThreeParam (/app/node_modules/avvio/boot.js:562:7)
at Boot.timeoutCall (/app/node_modules/avvio/boot.js:458:5)
at Boot.callWithCbOrNextTick (/app/node_modules/avvio/boot.js:440:19)
at Task.release (/app/node_modules/fastq/queue.js:149:16)
at worked (/app/node_modules/fastq/queue.js:201:10)
at Boot.timeoutCb (/app/node_modules/avvio/boot.js:467:7)
Starting migrations...

If that helps

@AlexSciFier
Copy link
Owner

It seems that database files was created but it's corrupted.
Delete all files in /volume1/docker/neonlink/data that was created and make a clean reinstall with default docker-compose.

@Whalee110
Copy link
Author

Yeah I did this, Originally I tried various locations and the including root based on the default compose. The above error was after it created the new one and failed, I just left out the already posted errors.

I will try using docker project instead of portainer

@julichan
Copy link

julichan commented Oct 11, 2023

Hello,
Looking at the logs, the problem seems to come on database initialization of a specific version of the application. I have resolved several of such problems when we improved the code.
We would have to check the code to confirm but i'd check the database initialization method called by fastify's synchroneous onReady call to make sure all paths ends with either the done function or an exception. It's a hook we created in the plugin. I'll check that.
@Whalee110, did you try to install the latest release?

@julichan
Copy link

Ok after taking a look, the hook is asynchroneous so my theory does not apply. The done method cannot be used in this case and this may be a real timeout. Perhaps we should try to increase the timeout period but this feels strange. The database initialization has nothing that take long.

@julichan
Copy link

julichan commented Oct 11, 2023

Oh, i just saw the second set of logs with (reading 'version')
at getDatabaseVersion (file:///app/db/sqlite/database.js:23:14)
It seems the database contains a migrations table but no version data. The should have ended with an exception other than the timeout thought.
@Whalee110, It is possible the two logs come from different versions of the app? Can you check that when you call docker-compose, it updates the image and does not use the one already stored in your docker cache?

@Whalee110
Copy link
Author

@julichan the second set of logs come because the container stops but has "always-restart" on so when it restarts the database already exists.

I tried again making sure to delete the image from the cache but no luck.

@Whalee110
Copy link
Author

Okay so I have an unraid machine and figured out how to get compose running on it.

Secrets saved.
NAS_Neonlink | Settings saved.
NAS_Neonlink | Config plugin initialization completed.
NAS_Neonlink | Database plugin initialization completed.
NAS_Neonlink | Life cycle plugin initialization completed.
NAS_Neonlink | Starting migrations...
NAS_Neonlink | Applying initial database script...
NAS_Neonlink | Attempt to apply initial...
NAS_Neonlink | Updating version number to 6...
NAS_Neonlink | Migrations completed.
NAS_Neonlink | Application initialized.
NAS_Neonlink | Server started listening on http://0.0.0.0:3333

No issues using the exact same compose script. I did get a warning about kernel version but doesn't appear to impact it. So there must be something on Synology NAS side that is causing issues.

@Whalee110
Copy link
Author

I took the db that was created within unraid and put in the folder I was referencing on portainer and this times it started up correctly.

Starting migrations...
Config plugin initialization completed.
Database plugin initialization completed.
Life cycle plugin initialization completed.
Starting migrations...
Found database version 6
Found 0 applicable migration files.
Migrations completed.
Application initialized.
Server started listening on http://0.0.0.0:3333

@julichan
Copy link

julichan commented Oct 14, 2023

@Whalee110, thanks for the information, can you tell me what synology model and dsm version you have because it s working on my latest one but i havent tried on others. I know they have either kernel 3.10 or 4.x. docker isn't well supported with kernel 3.10 lately.

Edit: you already provided this info:
DSM 7.2-64570 Update 3
DS918+

Can you get the kernel version?

@julichan
Copy link

julichan commented Oct 14, 2023

I looked around google a little bit and I don't see a problem aside from a performance issue in this case.
@AlexSciFier, it could be a problem if this occured during a database upgrade. do you think we could increase the timeout with fastify instance creation parameter pluginTimeout to avoid this kind of problem and perhaps even parameterise it with a default value in docker?
Another solution would be to handle database initialization outside the fastify plugin system althrough it would not be great for the architecture.

Edit: according to this, we can disable the timeout.

@AlexSciFier
Copy link
Owner

@julichan Yes, i think we can make a env variable. I'll make a PR.

AlexSciFier added a commit that referenced this issue Oct 14, 2023
Fix for #76 Container won't start on Synology NAS
@AlexSciFier
Copy link
Owner

@Whalee110 ok, Should be fixed in 1.4.11. Change FASTIFY_PLUGIN_TIMEOUT parameter to 0 in docker-compose file

@julichan
Copy link

julichan commented Oct 14, 2023

I just looked at your changes. If we keep the default to 10000, it won't change much. I'd set it to 120000 to feel very safe. This is what they fo with plugin fastify-mongodb. But anyway, we would need a test from @Whalee110 first to confirm this would fix things up.

@Whalee110
Copy link
Author

Whalee110 commented Oct 15, 2023

@julichan I think the kernel version is 4.4.302+
The full output of uname -a
4.4.302+ #64570 SMP Thu Jul 20 00:07:29 CST 2023 x86_64 GNU/Linux synology_apollolake_918+

I removed everything and re-created the stack repulling image and the below is the output.

tarting migrations...
Setting umask to 022
Creating database and backgrounds directories
User set by docker; running Neonlink as 1000:1000
Secrets saved.
Settings saved.
Config plugin initialization completed.
Database plugin initialization completed.
Life cycle plugin initialization completed.
Starting migrations...
Applying initial database script...
Attempt to apply initial...
FastifyError [Error]: A callback for 'onReady' hook timed out. You may have forgotten to call 'done' function or to resolve a Promise
    at exit (/app/node_modules/fastify/lib/hooks.js:97:37)
    at manageTimeout (/app/node_modules/fastify/lib/hooks.js:124:11)
    at _encapsulateThreeParam (/app/node_modules/avvio/boot.js:562:7)
    at Boot.timeoutCall (/app/node_modules/avvio/boot.js:458:5)
    at Boot.callWithCbOrNextTick (/app/node_modules/avvio/boot.js:440:19)
    at Task.release (/app/node_modules/fastq/queue.js:149:16)
    at worked (/app/node_modules/fastq/queue.js:201:10)
    at Boot.timeoutCb (/app/node_modules/avvio/boot.js:467:7)
    at /app/node_modules/fastify/lib/hooks.js:146:9
    at _encapsulateThreeParam (/app/node_modules/avvio/boot.js:562:7) {
  code: 'FST_ERR_HOOK_TIMEOUT',
  statusCode: 500,
  cause: AvvioError [Error]: Plugin did not start in time: 'bound _encapsulateThreeParam'. You may have forgotten to call 'done' function or to resolve a Promise
      at Timeout._onTimeout (/app/node_modules/avvio/boot.js:451:21)
      at listOnTimeout (node:internal/timers:569:17)
      at process.processTimers (node:internal/timers:512:7) {
    code: 'AVV_ERR_READY_TIMEOUT',
    fn: [Function: bound _encapsulateThreeParam]
  }
}
Setting umask to 022
Creating database and backgrounds directories
User set by docker; running Neonlink as 1000:1000
Config plugin initialization completed.
Database plugin initialization completed.
Life cycle plugin initialization completed.
Starting migrations...
TypeError: Cannot read properties of undefined (reading 'version')
    at getDatabaseVersion (file:///app/db/sqlite/database.js:23:14)
    at SqliteManager.migrate (file:///app/db/sqlite/database.js:109:21)
    at Object.<anonymous> (file:///app/plugins/010-database.js:63:27)
    at /app/node_modules/fastify/lib/hooks.js:160:24
    at _encapsulateThreeParam (/app/node_modules/avvio/boot.js:562:7)
    at Boot.timeoutCall (/app/node_modules/avvio/boot.js:458:5)
    at Boot.callWithCbOrNextTick (/app/node_modules/avvio/boot.js:440:19)
    at Task.release (/app/node_modules/fastq/queue.js:149:16)
    at worked (/app/node_modules/fastq/queue.js:201:10)
    at Boot.timeoutCb (/app/node_modules/avvio/boot.js:467:7)

The compose file used is:

version: "3.9"
services:
  neonlink:
    image: alexscifier/neonlink
    container_name: NAS_Neonlink
    mem_limit: 2g
    cpu_shares: 768
    security_opt:
      - no-new-privileges:true
    restart: on-failure:5
    volumes:
      - /volume1/docker/neonlink/data:/app/data
      - /volume1/docker/neonlink/media:/app/public/static/media/background
    envrioment:
      - FASTIFY_PLUGIN_TIMEOUT=0
    networks:
      NAS_IPLan:
        ipv4_address: 192.168.20.1

networks:
  NAS_IPLan:
    external: true
    name: macvlan

In portainer I had an enviroment variable FASTIFY_PLUGIN_TIMEOUT with value set to 0

@AlexSciFier
Copy link
Owner

@Whalee110 try to run with FASTIFY_PLUGIN_TIMEOUT=15000 or higher

@Whalee110
Copy link
Author

I ended up doing 15000, 30000, 100000 and 360000.

No change same output.

Setting umask to 022
Creating database and backgrounds directories
User set by docker; running Neonlink as 1026:100
Secrets saved.
Settings saved.
Config plugin initialization completed.
Database plugin initialization completed.
Life cycle plugin initialization completed.
Starting migrations...
Applying initial database script...
Attempt to apply initial...
FastifyError [Error]: A callback for 'onReady' hook timed out. You may have forgotten to call 'done' function or to resolve a Promise
 at exit (/app/node_modules/fastify/lib/hooks.js:97:37)
 at manageTimeout (/app/node_modules/fastify/lib/hooks.js:124:11)
 at _encapsulateThreeParam (/app/node_modules/avvio/boot.js:562:7)
 at Boot.timeoutCall (/app/node_modules/avvio/boot.js:458:5)
 at Boot.callWithCbOrNextTick (/app/node_modules/avvio/boot.js:440:19)
 at Task.release (/app/node_modules/fastq/queue.js:149:16)
 at worked (/app/node_modules/fastq/queue.js:201:10)
 at Boot.timeoutCb (/app/node_modules/avvio/boot.js:467:7)
 at /app/node_modules/fastify/lib/hooks.js:146:9
 at _encapsulateThreeParam (/app/node_modules/avvio/boot.js:562:7) {
code: 'FST_ERR_HOOK_TIMEOUT',
statusCode: 500,
cause: AvvioError [Error]: Plugin did not start in time: 'bound _encapsulateThreeParam'. You may have forgotten to call 'done' function or to resolve a Promise
   at Timeout._onTimeout (/app/node_modules/avvio/boot.js:451:21)
   at listOnTimeout (node:internal/timers:569:17)
   at process.processTimers (node:internal/timers:512:7) {
 code: 'AVV_ERR_READY_TIMEOUT',
 fn: [Function: bound _encapsulateThreeParam]
}
}

Are there any commands i can run to see more detail that can help?

@julichan
Copy link

julichan commented Oct 15, 2023

@Whalee110, did the value change the timing in which the error occured? If not, it would mean the parameter pluginTimeout doesn't work for hooks or because of the autoloader...

There are only 2 awaited function at this point: await import and await migrationPlugin, neither should take so long without a reason. The await import could be because the initial script file is locked against read but it's only inside the container and there is no other usage case in neonlink code. For the second, there is only a set of queries to create new tables that should barely take a few ms to an already opened database.

@AlexSciFier, We could add a log between the two to ensure the migrationplugin loaded from import to be aware which of the function is timing out but i'm not sure knowing that will be so helpful. Also, since the app work with an initialized database, i don't think the second function is timing out due to a hidden error but we could add logs in the foreach of the "initial" migrationplugin script.

@Whalee110, do you have an anti virus on your dsm that could be locking files? This is far fetched reason though as the related files are so small.

From what i've read, we could also try the following:

  • if the pluginTimeout doesn't work because of the autoloader, we could load the three plugins manually. (Yes i read someone saying that in a bug)
  • if pluginTimeout doesn't work with onReady hooks, move the migration out of the hook?
  • otherwise initialize the database outside the plugin system in a synchroneous manner.

This is from the least to the most costly solutions i see but without knowing actual reason for the crash, it's too much for a bug.

Would also monitoring the performance of the initialization code be possible/useful?

Do you have any other idea @AlexSciFier ?

@Whalee110
Copy link
Author

It appeared to be a bit longer but that just could be normal variance as it wasn't huge.

I don't believe I have any anti virus enabled - Later today I will go through and disable some of the "security" I put on it for now.

Is it trying to connect to any external addresses? I do have a DNS level Ad block if that impacts it that I will also try disabling.

I'll try doing it exclusively through SSH with docker run to see if it provides any additional information.

@julichan
Copy link

julichan commented Oct 15, 2023

@Whalee110, no need to go as far as disabling your dns level securities. Initialization steps doesn't connect anywhere. Only anti virus like app may affect it although i very much doubt it.
I also have a lot of securities on my dsm enabled and run in no problem so i doubt the nas settings change anything.

@AlexSciFier
Copy link
Owner

@Whalee110 try to run container without binding volumes. If the container starts without errors, then the problem is in the file system and not in the application.

@Whalee110
Copy link
Author

Whalee110 commented Oct 16, 2023

Same error

I was unsure about the umask 022 so I ran on both again to see, but it does look like it's just the version where the logs vary
NAS

Creating database and backgrounds directories
User set by docker; running Neonlink as 1000:1000
Config plugin initialization completed.
Database plugin initialization completed.
Life cycle plugin initialization completed.
Starting migrations...
TypeError: Cannot read properties of undefined (reading 'version')  ```

Unraid

``` NAS_Neonlink  | Setting umask to 022
NAS_Neonlink  | Creating database and backgrounds directories
NAS_Neonlink  | User set by docker; running Neonlink as 1000:1000
NAS_Neonlink  | Config plugin initialization completed.
NAS_Neonlink  | Database plugin initialization completed.
NAS_Neonlink  | Life cycle plugin initialization completed.
NAS_Neonlink  | Starting migrations...
NAS_Neonlink  | Found database version 6
NAS_Neonlink  | Found 0 applicable migration files.
NAS_Neonlink  | Migrations completed.
NAS_Neonlink  | Application initialized.
NAS_Neonlink  | Server started listening on http://0.0.0.0:3333 ```

@AlexSciFier
Copy link
Owner

To be clear, you are running the container without this section?

volumes:
    - ./data:/app/data
    - ./background:/app/public/static/media/background

Because judging by your logs, the application is trying to open a database file that should not exist.
Without this section, the container will store all files within itself. Accordingly, we exclude all file system errors.

@WarHawk8080
Copy link

I had to stop container, then chown the entire directory to the GID/UID of the user from the docker-compose.yml
When it created the directory structure...it made the /data and /background directories as root...not as running user

@Whalee110
Copy link
Author

I manually create directories beforehand to ensure permissions are set, but regardless even with no mapped drives the same error occurs. On a Synology discord where I first got a sample of the compose they mentioned it needing an additional line so I will be waiting to test that once they provide the updated compose.

@AlexSciFier Yeah sorry, those logs were comparing the startup of the device that is fine and the one that fails.
This was the compose used

version: "3.9"
services:
  neonlink:
    image: alexscifier/neonlink:latest
    container_name: NAS_Neonlink
    mem_limit: 2g
    cpu_shares: 768
    security_opt:
      - no-new-privileges:true
    restart: on-failure:5

    networks:
      NAS_IPLan:
        ipv4_address: 192.168.20.1

networks:
  NAS_IPLan:
    external: true
    name: macvlan

@julichan
Copy link

julichan commented Oct 18, 2023

Hello @Whalee110,

I did not have time to test on my older server but here is my compose you may adapt to yours that works on my ds923+. Please take note that some feature don't work with synology docker. Try the following:

  • security_opt doesn't work on all dsm so try to remove it. Through it should with your kernel if you have the latest package of "Container Manager"
  • I also have a custom dockerfile for custom user. you may want to add a non root user.
  • Change the docker-compose version of your compose file, there are difference in each versions. that's especially valid before 3.5, i did not check beyond that.
  • I use the btrfs file system and every volume is created as folders before hand via ansible. you can simulate by creating folders manually.
  • I use several networks for personal purpose but you only need one and that should not affect your problem.

Dockerfile:

ARG IMAGE_NAME=alexscifier/neonlink
ARG IMAGE_TAG=latest

FROM ${IMAGE_NAME}:${IMAGE_TAG}
LABEL maintainer="Julichan"

USER root

RUN apk --no-cache add shadow \
  && groupmod -g "1000" -o node \
  && usermod -u "1000" -o node \
  && chown -R node:node .

USER node

docker-compose.yml

version: '3.5'

networks:
  internal:
    name: internal-neonlink
    driver: bridge
  dockernet:
    name: dockernet
    external: true

services:  
  server:
    restart: unless-stopped
    build: 
      context: ./server/build
      network: host
    user: "1000:1000"
    image: "alexscifier/neonlink:latest-custimized"
    container_name: "neonlink-server"
    networks:
      internal:
      dockernet:
        ipv4_address: 172.18.2.1
    volumes:
    - /etc/localtime:/etc/localtime:ro
    - /volume2/docker/neonlink/server/data:/app/data
    - /volume2/docker/neonlink/server/data/backgrounds:/app/public/static/media/background
    environment:
    - TZ=Europe/Paris
    - PORT=8080

@AlexSciFier
Copy link
Owner

I tried to fix user permission error by running container as root and change user in docker-entrypoint.sh in #83. What do you think about this @julichan?

@julichan
Copy link

julichan commented Oct 18, 2023

@AlexSciFier, it seems good but i'd need to test gosu myself to have a good idea. However i tried many methods in the past and i have one conscen about this method. There are many phases in docker that result in different states: build, container creation and container running. Each state should have its own access right. I believe the root command should never be accessible beyond build because it leaves potential opening for root escalation by reusage of those tools in a non-root container. So i always override the dockerfile and dockerfile entrypoint when i see such tools in images.
So my advice: Never allow to create/run a container in root mode.do what you have to do in the image (dockerfile). Create a dockerfile to override the behaviour of the image if necessary. A web interface with security holes can lead to root escalation on the server even through docker even if there was no known case so far.
Ps: i know i did not remove su-exec or gosu in neonlink case but it was all done in rush and u know the reason... XD
Ps2: you may consider that neonlink doesn't contain sensible data and isn't that much of a treat but security with docker is far more complex than any other app. Users tends to use root or a single user to all their images. Just the possibility of a hole in a container that can be accessed publicly could give access to another container i don't know how with sensible data or to another security hole. That's why you must be especially hard on security with docker.
Ps3: hackers are smarter and smarter nowadays, they'd definitely make use of any information you give them so even a list of sites you access is sensible information if the target of an attack is a specific person.

@AlexSciFier
Copy link
Owner

AlexSciFier commented Oct 18, 2023

@julichan

Ps: i know i did not remove su-exec or gosu in neonlink case but it was all done in rush and u know the reason... XD

No, i added it after server code update

Ok so, the actual fix for permission error, i think, is to leave as it is right now.

  • Before run container, create folders with user you need.
  • Add user parameter with same user as in folder owner in docker-compose file.

With this i don't need docker-entrypoint script.

@damomato
Copy link

Not sure if related, but just now I also had problems with my container starting due to permission issues. Once I added in the user parameter and changed 1000 to my user ID it started up no problem. I usually use PUID or UID to set that but I guess not the case here.

The discussion in this issue helped me figure that out so thanks!

@Whalee110
Copy link
Author

Apologies for no update, the forum I am with the person that said they had a fix for it has yet to respond.

I've tried the compose provided by Julichan but no difference in outcome.

@Whalee110
Copy link
Author

It works!

The person provided their code, I had to change it to 0 but it looks like using portainer environment option didn't apply it correctly. Apologies for missing that, I'm learning how to use docker compose currently so didn't realise :/

This is the compose that worked:

version: "3.9"
services:
  neonlink:
    image: alexscifier/neonlink:latest
    container_name: NeonLink
    hostname: neonlink
    mem_limit: 1g
    cpu_shares: 768
    security_opt:
      - no-new-privileges:true
    read_only: true
    user: 1026:100
    ports:
      - 6433:3333
    volumes:
      - /volume1/docker/neonlink/data:/app/data:rw
      - /volume1/docker/neonlink/background:/app/public/static/media/background:rw
    environment:
      FASTIFY_PLUGIN_TIMEOUT: 0
      PUID: 1026
      PGID: 100
      UMASK: 22
    restart: on-failure:5

@julichan
Copy link

Alright so my worries were well founded. We should increase the value to at least 120000 by default for now since it could occur during a db upgrade resulting to a loss of data.

@julichan
Copy link

julichan commented Oct 22, 2023

@Whalee110 in your compose file, you use a synology existing user (1026 is usually the first created user id). I imagine that is an user with administrative privileges. You'd better make sure neonlink is not accessible outside of your private network.
In docker they always recomend to use a non existing user with an id starting from 1000.

@Whalee110
Copy link
Author

@julichan oh I see, my presumption this is done to avoid "permissions issues" but I just copy it from others I see. If that is potentially security risk then I think maybe I should read up on compose a bit more to avoid more like it haha. Thank you for the info!

@julichan
Copy link

julichan commented Oct 23, 2023

@Whalee110, this is allowed because there are important uses cases. For exemple, if you have a an app that manage your documents in docker and u want your documents accessible from a user stand point of the file system, you'll use a volume that can be read/write by your host user. But in that case, you usually create a user on your host that is only allowed to do things in thag part of the file system for secuirity reasons. Limited host access will prevent ability to hack.
You would use ACL right system for that as it overrides the basic linux right system and allows multiple files and folder ownership to enforce further security.
But oh you know, all this is just the same kind of security mistake we have everywhere which can lead to host privilege escalation. While there are no known case yet with docker, there is an incredible known amount of mistakes with databases that lead to this.
Docker works like this: it creates a process for every container you have. That container use the host kernel and share it with whatever is the image. At this point, you may take a ubuntu or alpine or other os image, the ilage doesn't contain a kernel but a set of installed packages. But it's different in that it makes use a of kernel feature that's powerful: running the process as a host inexistant user and that's a very powerful isolation.
The images that doesn't allow you to run your docker process with user other than root and give you environment variables to define a user totally break that security advantage as they makes the use of root priviledge to imporsonate any user but still have complete host access...
In the case of neonlink, we store files that are meant to be used only by neonlink. That means there is no need for host access at all. You can set the ownership of your neonlink folders and files to the user/group 1000 which is noone on Synology as well as for your container and it should work well.

@AlexSciFier
Copy link
Owner

It works!

The person provided their code, I had to change it to 0 but it looks like using portainer environment option didn't apply it correctly. Apologies for missing that, I'm learning how to use docker compose currently so didn't realise :/

This is the compose that worked:

version: "3.9"
services:
  neonlink:
    image: alexscifier/neonlink:latest
    container_name: NeonLink
    hostname: neonlink
    mem_limit: 1g
    cpu_shares: 768
    security_opt:
      - no-new-privileges:true
    read_only: true
    user: 1026:100
    ports:
      - 6433:3333
    volumes:
      - /volume1/docker/neonlink/data:/app/data:rw
      - /volume1/docker/neonlink/background:/app/public/static/media/background:rw
    environment:
      FASTIFY_PLUGIN_TIMEOUT: 0
      PUID: 1026
      PGID: 100
      UMASK: 22
    restart: on-failure:5

@Whalee110 What version did you use? If it's 1.4.12 than you don't need PUID, PGID and UMASK variables. I removed it in this version. Now if you want to change user in docker you need to use default user parameter in docker-compose file.

@Whalee110
Copy link
Author

@AlexSciFier yeah that's the way I do in my compose this was just the one the person got working from a synology discord. I think it was 1.4.11 at the time I did it.

@julichan Oh I see. I knew why you'd want certain users similar with the "no new priv" tag, but I was unsure as to when you'd want to make it what user. Your explanation helped alot there! ty I have also created a user that can only access docker folder for future instead of my admin account :)

@AlexSciFier
Copy link
Owner

@Whalee110 If the problem is resolved, can I close the issue?

@Whalee110
Copy link
Author

Yup thank you for your help!

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

No branches or pull requests

5 participants