# Allow non-root users to write to stdout/stderr

**URL:** <https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993>\
**Category:** Questions / Help\
**Created:** [October 30, 2021, 11:46pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993 "2021-10-30T23:46:52Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![md1](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@md1](https://community.fly.io/u/md1)\
**Post date:** [October 30, 2021, 11:46pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/1 "2021-10-30T23:46:52Z")

</div>

Hi, could you please allow non-root users to write to /dev/stdout and /dev/stderr in your default image?

The most common PHP/nginx docker base image (trafex/php-nginx) works fine in Docker but can’t deploy to Fly because of permission issues.

---

<div class="post-metadata">

**Author:** ![sudhir.j](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/sudhir.j/32/39775_2.png) [@sudhir.j](https://community.fly.io/u/sudhir.j)\
**Post date:** [November 1, 2021, 9:47am UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/2 "2021-11-01T09:47:49Z")

</div>

Hi @md1, I could be missing something, but isn’t this explicit in the permissions setup on [docker-php-nginx/Dockerfile at master · TrafeX/docker-php-nginx · GitHub](https://github.com/TrafeX/docker-php-nginx/blob/master/Dockerfile) ? From what I know it seems like permission needs to be added in there for `nobody` to write to `/dev/stdout` and `/dev/stderr`. Will check if I’m missing something, but it might be easier to raise an issue or ask on the base image repo.

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [November 1, 2021, 5:43pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/3 "2021-11-01T17:43:21Z")

</div>

We create a pipe for the main process’s stdout and another one for stderr. Those are owned by the same user and group we use to start the process.

@md1 Can you share your Dockerfile and your nginx config?

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [November 2, 2021, 1:47pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/5 "2021-11-02T13:47:29Z")

</div>

As far as I can tell, your app logged a few lines, the error seems to be elsewhere?

```auto
2021-10-31 01:39:01,449 INFO supervisord started with pid 510
2021-10-31 01:39:02,451 INFO spawned: 'nginx' with pid 516
2021-10-31 01:39:02,453 INFO spawnerr: can't find command 'php-fpm8'
2021-10-31 01:39:02,590 INFO gave up: php-fpm entered FATAL state, too many start retries too quickly
2021-10-31 01:39:03,592 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

```

It wouldn’t have been able to log these lines if it couldn’t write to /dev/stdout or /dev/stderr.

---

<div class="post-metadata">

**Author:** ![md1](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@md1](https://community.fly.io/u/md1)\
**Post date:** [November 6, 2021, 9:25pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/6 "2021-11-06T21:25:24Z")

</div>

You can repo the error with `FROM trafex/php-nginx:latest`

---

<div class="post-metadata">

**Author:** ![md1](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@md1](https://community.fly.io/u/md1)\
**Post date:** [November 6, 2021, 9:32pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/7 "2021-11-06T21:32:27Z")

</div>

> [@jerome](#):
>
> As far as I can tell, your app logged a few lines, the error seems to be elsewhere?

I’m not sure which app you are looking at, but yes I broke tons of unrelated stuff trying to get it working.

As you mentioned in your other post, you create the pipes as the user running the main process. If you set the permissions properly it should also allow other processes spawned as lower privilege users to also write to stdout/stderr.

Everything works fine in Docker, so it does appear to be an issue specific to the fly runtime.

---

<div class="post-metadata">

**Author:** ![sudhir.j](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/sudhir.j/32/39775_2.png) [@sudhir.j](https://community.fly.io/u/sudhir.j)\
**Post date:** [November 7, 2021, 5:22am UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/8 "2021-11-07T05:22:53Z")

</div>

@md1 I’ve managed to replicate the problem as you’ve suggested with just the latest image, but we still don’t know the exact cause.

All the other images that are running on Fly are writing to stdout/stderr, even the ones spawned as `nobody`. Even in this case the EACCES error itself is being written there correctly, which is why we’re able to see it at all.

Will try to figure out what’s going on, I’m basically trying to adjust the permissions on every directory used one at a time to see what’s special about this, but no luck so far.

---

<div class="post-metadata">

**Author:** ![md1](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@md1](https://community.fly.io/u/md1)\
**Post date:** [November 9, 2021, 1:18am UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/9 "2021-11-09T01:18:34Z")

</div>

Thanks for confirming I am not crazy!

I’ll continue to try and debug on my end, but I would appreciate any assistance in figuring out what is unique to Fly that breaks the universe.

---

<div class="post-metadata">

**Author:** ![md1](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@md1](https://community.fly.io/u/md1)\
**Post date:** [November 23, 2021, 4:51am UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/10 "2021-11-23T04:51:35Z")

</div>

Any idea what might be going on here? @sudhir.j

---

<div class="post-metadata">

**Author:** ![sudhir.j](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/sudhir.j/32/39775_2.png) [@sudhir.j](https://community.fly.io/u/sudhir.j)\
**Post date:** [November 23, 2021, 9:10am UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/11 "2021-11-23T09:10:57Z")

</div>

Not yet. I wasn’t able to figure it out with the default Dockerfile. If you’re ok with modifying the Dockerfile I’d suggest removing the switch to the `nobody` user, that should help a bit, but all the surrounding files will need to be checked as well.

---

<div class="post-metadata">

**Author:** ![ross](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/ross/32/48220_2.png) [@ross](https://community.fly.io/u/ross)\
**Post date:** [May 29, 2022, 5:34pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/12 "2022-05-29T17:34:28Z")

</div>

@sudhir.j I’m curious if you ever found a solution, or a better alternative Dockerfile to use? I’m running into the same permissions issues with trafex/docker-php-nginx, even after mucking around with permissions on different files.

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [May 29, 2022, 9:16pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/13 "2022-05-29T21:16:17Z")

</div>

> [@ross](#):
>
> I’m curious if you ever found a solution, or a better alternative Dockerfile to use?

I don’t quite see Sudhir around anymore.

Anyways, see: [Permissions Error Attempting To Read From stdout - #2 by greg](https://community.fly.io/t/permissions-error-attempting-to-read-from-stdout/5172/2)

It could be `supervisord` (which [`docker-php-nginx`](https://github.com/TrafeX/docker-php-nginx/blob/master/Dockerfile) uses as a process supervisor) that’s mucking with your log output?

---

<div class="post-metadata">

**Author:** ![greg](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/greg/32/2119_2.png) [@greg](https://community.fly.io/u/greg)\
**Post date:** [May 29, 2022, 10:24pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/14 "2022-05-29T22:24:25Z")

</div>

Yeah, building on that from @ignoramous my answer was in turn based on Fly’s own example for how to run multiple processes. This one:

> **[Running Multiple Processes Inside A Fly.io App](https://fly.io/docs/app-guides/multiple-processes/#use-supervisord)**
>
> Documentation and guides from the team at Fly.io.

As I recall … it only worked when the user was root. As per the Fly example. _But_ in the docker-php-nginx `Dockerfile` they _don’t_ use root. And hence that could explain the permission issue.

---

<div class="post-metadata">

**Author:** ![ross](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/ross/32/48220_2.png) [@ross](https://community.fly.io/u/ross)\
**Post date:** [May 29, 2022, 10:49pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/15 "2022-05-29T22:49:25Z")

</div>

Ahh, that makes sense. I modified the Dockerfile to use hivemind instead (as suggested [in the docs](https://fly.io/docs/app-guides/multiple-processes/#use-a-procfile-manager) you linked) and that seems to have done the trick!

The end result looks something like this, and works just fine as the `nobody` user from trafex/php-nginx:

```nohighlight
FROM trafex/php-nginx:2.6.0

# ...

RUN curl -fsSL https://github.com/DarthSim/hivemind/releases/download/v1.1.0/hivemind-v1.1.0-linux-amd64.gz | gunzip -c > /usr/local/bin/hivemind && chmod +x /usr/local/bin/hivemind

# ...

ENTRYPOINT ["hivemind", "/path/to/Procfile"]

```

---

<div class="post-metadata">

**Author:** ![Alex21](https://avatars.discourse-cdn.com/v4/letter/a/5e9695/32.png) [@Alex21](https://community.fly.io/u/Alex21)\
**Post date:** [January 26, 2023, 5:59pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/16 "2023-01-26T17:59:17Z")

</div>

I ran into this issue as well, and wrote up the specifics with what I’m encountering in [Container (non-root) user can't write to /dev/stdout or /dev/stderr](https://community.fly.io/t/container-non-root-user-cant-write-to-dev-stdout-or-dev-stderr/10375). What’s weird there is:

```auto
echo "hi"

```

works, but:

```auto
echo "hi" >> /dev/stdout

```

fails with a permission denied, which contradicts the comment in [Allow non-root users to write to stdout/stderr - #5 by jerome](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/5).

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [January 26, 2023, 10:18pm UTC](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/17 "2023-01-26T22:18:24Z")

</div>

> [@Alex21](#):
>
> but:
> 
> ```auto
> echo "hi" >> /dev/stdout
> 
> ```
> 
> fails with a permission denied, which contradicts the comment in [Allow non-root users to write to stdout/stderr - #5 by jerome](https://community.fly.io/t/allow-non-root-users-to-write-to-stdout-stderr/2993/5).

Actual _files_ backing `stdin`/`out`/`err` for entrypoint (main / server) process are _pipes_ ([code](https://github.com/superfly/init-snapshot/blob/48cf36ff7ac6229df66bf1de2b1e2b1c233b2e51/src/bin/init/main.rs#L706-L707)) owned by `run-as` _user_.

```auto
# from fly ssh console; where 520 is the entrypoint-pid (server process)
# fd/1 is stdout
ls -lhtr /proc/520/fd/1
l-wx------ 1 <run-as> <run-as> 64 Jan 26 21:58 /proc/520/fd/1 -> pipe:[4403]
...

```

I not am really sure, but I believe the reason why writing to `/dev/stdout` from `fly ssh` (interactive shell) doesn’t work is because the _char device_ `/dev/pts/1` is owned by `root` with no world permissions even if the _link_ `/proc/<entrypoint-pid>/fd/1` is owned by `USER` (shell-user) one is running the interactive shell as.

```auto
# from fly ssh console; su <shell-user>
ls -lhtr /dev/pts/0 
...
crw--w---- 1 root tty 136, 0 Jan 26 22:15 /dev/pts/0
...
ls -lhtr /proc/self/fd/1
lrwx------ 1 <shell-user> <shell-user> 64 Jan 26 22:15 /proc/self/fd/1 -> /dev/pts/0

```
