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

fix-attrs broken in v2.2.0.1 #329

Closed
b-m-f opened this issue Feb 14, 2021 · 24 comments
Closed

fix-attrs broken in v2.2.0.1 #329

b-m-f opened this issue Feb 14, 2021 · 24 comments

Comments

@b-m-f
Copy link

b-m-f commented Feb 14, 2021

I am using the fix-attrs.d directory to change permissions on a file that is mounted into the container at launch.

This worked fine in 2.1.0.2 but breaks in 2.2.0.1.

Working in 2.1.0.2
https://github.com/b-m-f/WirtBot/runs/1894909984#step:3:1813

Breaking with 2.2.0.1
https://github.com/b-m-f/WirtBot/runs/1898569667?check_suite_focus=true#step:3:2244

@b-m-f
Copy link
Author

b-m-f commented Feb 14, 2021

Let me know if there is any more info I can provide to help :)

The only suspect I could make out is this change: 3e7bc9f

@jprjr
Copy link
Member

jprjr commented Feb 15, 2021

Can you come up with a small example? I can't seem to get it to fail

@b-m-f
Copy link
Author

b-m-f commented Feb 16, 2021

Hi @jprjr ,

I have created a reproduction at https://github.com/b-m-f/s6-overlay-bug-reproduction . It is based on the nginx example from the README.

Simply clone and run docker-compose up. It should fail with:

s6-bug-test    | [fix-attrs.d] 01-fix-mounted: applying...
s6-bug-test    | [fix-attrs.d] 01-fix-mounted: exited 1.

Versions:
Docker version 20.10.3
docker-compose version 1.28.2

@rakheshster
Copy link

FWIW I too encountered this issue with my containers today. Upgraded to the latest 2.2.0.3 and that didn't help either.

Docker version 20.10.2, build 2291f61
docker-compose version 1.27.4, build 40524192

@andrewzah
Copy link

fix-attrs.d just hangs for me. on 2.2.0.1 and 2.2.0.3

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...

@timothydlister
Copy link

timothydlister commented Mar 12, 2021

Not sure if this will help anyone but I had this problem when using the s6-overlay package in the Alpine repository. When I installed using a release from this repo, the problem went away.

@dermotbradley
Copy link
Contributor

dermotbradley commented Mar 12, 2021 via email

@timothydlister
Copy link

On Friday, March 12, 2021, 6:03:03 PM GMT, Timothy Lister @.***> wrote: Not sure if this will help anyone but I had this problem when using the package in the Alpine repository. When I installed using a release from this repo, the problem went away.
Hi there, Alpine maintainer for s6-overlay here. Which Alpine release was this with? Edge? v3.13.0/v3.13.1/v3.13.2? Which version of the s6-overlay package? Which version of s6-overlay? Alpine Edge has the current release of s6-overlay packaged whereas v3.13.x has an older version, likewise the version of the other s6 packages differ between Edge and v3.13.x. Dermot

Hi there,

I just reran my test to make sure, from my dockerfile:

FROM alpine:3.13
RUN apk add --no-cache s6-overlay
...
ENTRYPOINT ["/init"]

Shows when run:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...

From inside 3.13:

/ # apk info s6-overlay
WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/main: No such file or directory
WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/community: No such file or directory
s6-overlay-2.1.0.0-r1 description:
s6 overlay for containers

s6-overlay-2.1.0.0-r1 webpage:
https://github.com/just-containers/s6-overlay/

Trying with alpine:edge gives:

export: fatal: unable to exec /etc/s6/init/init-stage1: Permission denied

@dermotbradley
Copy link
Contributor

dermotbradley commented Mar 12, 2021 via email

@dermotbradley
Copy link
Contributor

@timothydlister

I've figured out the problem with the Alpine Edge package for s6-overlay and raised a MR for a new package release to resolve it in Edge, https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/19251. I'm not part of the core Alpine and so can't do the merge myself - hopefully it will be merged in the next few hours and then the revised package will be rolled out to the repository mirrors, however it might take a day or two with it being the weekend.

In the meantime you could modify your Dockerfile for Alpine Edge to do the chmod and mkdir commands after the "apk add" for s6-overlay as a workaround.

I haven't looked at the older package for Alpine 3.13 yet but its probably the same issue.

I've raised #334 regarding the s6-overlay Source Code tarfile i'm using for the packaging.

@cnt0
Copy link

cnt0 commented Mar 18, 2021

looks like I can reproduce this issue with s6-overlay package from alpine:3.13.

FROM alpine:3.13
RUN apk add --no-cache s6-overlay
ENTRYPOINT ["/init"]

just hangs. @dermotbradley can you please fix this as well?

@dermotbradley
Copy link
Contributor

dermotbradley commented Mar 19, 2021

looks like I can reproduce this issue with s6-overlay package from alpine:3.13.

FROM alpine:3.13
RUN apk add --no-cache s6-overlay
ENTRYPOINT ["/init"]

just hangs. @dermotbradley can you please fix this as well?

Hi. The issue I fixed in Alpine Edge was a packaging mistake which caused the "export: fatal: unable to exec /etc/s6/init/init-stage1: Permission denied" error that @timothydlister saw. This packaging issue was not present in s6-overlay for Alpine 3.13 (I only introduced the, now corrected, mistake in Edge).

As the original problem report for this ticket was observed on Debian then I don't believe the underlying issue is Alpine-specific.

@andrewzah
Copy link

This happens on debian, alpine, and centos for me. I build it from source, so I don't think it's a packaging issue.

@dermotbradley
Copy link
Contributor

This happens on debian, alpine, and centos for me. I build it from source, so I don't think it's a packaging issue.

I found some time to look at the underlying issue and its not a packaging issue.

Using the reproduction repo of @b-m-f which is Ubuntu based I saw the same error. However the fix is simple - the "fix-mounted" file in that repo simply needs a newline added and it works! I also created an Alpine 3.13-based version of this "reproducer" and it failed in the same way until I added a newline to that file and then it also worked.

@mustanggb
Copy link

mustanggb commented Mar 24, 2021

Think I just encountered this as well in docker with alpine 3.13 and s6-overlay 1.22.1.0

Dockerfile

FROM alpine:3.13

ADD https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-nobin.tar.gz /tmp/
RUN apk add --no-cache s6 s6-portable-utils && \
    tar -xzC / -f /tmp/s6-overlay-nobin.tar.gz && \
    rm /tmp/s6-overlay-nobin.tar.gz

ENTRYPOINT /init

Gets stuck on...

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...

Switching to alpine 3.12 and it works fine again.


EDIT:

Okay so it looks like this could be expected due to compatibility with dependencies, possibly execline.
So alpine 3.12 has execline 2.6.0.2, whereas alpine 3.13 has execline 2.7.0.0 it and looks like this doesn't work with either s6-overlay 1.22.1.0 (as I tried originally) or 2.1.0.0 (as packaged by @dermotbradley), but manually installing 2.2.0.3 and it does appear to work again (still testing).

@dermotbradley Maybe consider updating your s6-overlay package in 3.13 to 2.2.x.x

@dermotbradley
Copy link
Contributor

@mustanggb

ADD https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-nobin.tar.gz /tmp/

You used this repo's "nobin" tarfile which only contains the s6-overlay specific files. If using this file fails but then using the same version of the "amd64" tarfile (obviously not then using "apk add" for the s6/s6-portable-utils packages) from this repo does work then that points to a version compatibility issue with the OS' (in this case Alpine's) versions of s6/execline/etc packages.

@dermotbradley Maybe consider updating your s6-overlay package in 3.13 to 2.2.x.x

I have replied to the Alpine gitlab issue you raised about this issue. I don't want to fill up this repo's issue with Alpine-specific discussions so we can talk further about it in that Gitlab issue.

Fundamentally when execline 2.7.0.0 came it out it changed some behaviour that then had to be fixed in s6-overlay (#317, #319), then when execline 2.8.0.0 came out it also changed some behaviour that required other s6-overlay changes (#335).

In general there is always likely to be some sort of time delay from whenever newer versions of s6 utilities are released and then when s6-overlay is updated to handle any changes (if needed).

@cnt0
Copy link

cnt0 commented Mar 25, 2021

Fundamentally when execline 2.7.0.0 came it out it changed some behaviour that then had to be fixed in s6-overlay

ah yes. Looks like this comment describes the exact problem I faced. This is the commit which fixes that. Guys, can you please reference such important issues in commit messages? It would've been so much easier to get the full picture in this case,,,

@pvizeli
Copy link

pvizeli commented Mar 26, 2021

I have the same issue on 2.2.x.x like:
https://github.com/b-m-f/s6-overlay-bug-reproduction

I use alpine/debian/ubuntu with the tarfile from this repository:
https://github.com/home-assistant/docker-base

@jprjr
Copy link
Member

jprjr commented Mar 26, 2021 via email

@jprjr
Copy link
Member

jprjr commented Mar 26, 2021

Here's some notes

fix-attrs has two places that uses forstdin.

There's a chunk that tests if a file is a directory, calls s6-ls, then loops over the contents of that -

forbacktickx is really just pipeline { stuff } forstdin

If something is an empty directory, s6-ls returns no output.

Before execline 2.7.0.0, forstdin would accept empty input and just not run the loop. Now, the input is empty, it exits 1.

The other place is

- this is where it reads the contents of a file from the fix-attrs.d.

Previously, if a file did not end in a newline character (like in the repo @b-m-f created), forstdin would still return the line. Now, if the file does not end in a newline character, forstdin exits 1.

@jprjr
Copy link
Member

jprjr commented Apr 10, 2021

I've been reviewing this, and I think the only real fix is to rewrite fix-attrs from scratch. That difference in behavior with the latest execline makes updating fix-attrs particularly difficult.

In most other cases, I was able to replace forstdin with elglob and loop over that. But fix-attrs has the feature of traversing hidden files, so elglob just won't really work. I don't know if I can write a glob pattern that will match regular files and hidden files, while also excluding the . and .. entries. s6-ls can do it, but then we're back at the original problem of empty directories - s6-ls will return empty output, so forstdin returns 1.

I think the better solution is to just write a custom program in C and include it as a static binary.

algitbot pushed a commit to alpinelinux/aports that referenced this issue Jul 24, 2021
Upstream development appears to have stopped several months ago. Recent
s6-overlay versions do not work correctly with recent execline versions
(which are separately packaged for Alpine by skarnet).

For more information see
just-containers/s6-overlay#329

Closes #12547.

If/when upstream resolves compatibility with general s6/execline packages
then I will restart maintaining this package.

For now the only solution for end-users is to download and use upstream's
arch-specific binary tarfiles at
https://github.com/just-containers/s6-overlay/releases which contain
versions of s6/execline binaries that upstream has tested with s6-overlay.
jprjr added a commit that referenced this issue Nov 23, 2021
Replaces forstdin with custom fork that allows
for emtpy files and lines missing the newline.

See #329
jprjr added a commit that referenced this issue Nov 23, 2021
Replaces forstdin with custom fork that allows
for emtpy files and lines missing the newline.

See #329
jprjr added a commit that referenced this issue Nov 23, 2021
Replaces forstdin with custom fork that allows
for emtpy files and lines missing the newline.

See #329
@jprjr
Copy link
Member

jprjr commented Nov 23, 2021

Hi all, I believe I've come up with a fix for this and could use help testing.

I've made a fork of forstdin that re-enables some of the old behavior (reading in 0 bytes of input is fine, missing a final newline is also fine), and made a branch of s6-overlay that uses the fork.

Here is a n example Dockerfile for installing the from the latest build off the issue-329 branch:

FROM ubuntu
RUN apt-get update && apt-get install -y unzip curl

RUN curl -R -L -o /tmp/dist.zip \
  https://nightly.link/just-containers/s6-overlay/workflows/all/issue-329/dist.zip

RUN cd /tmp && unzip dist.zip && chmod +x s6-overlay-amd64-installer && /tmp/s6-overlay-amd64-installer /
ENTRYPOINT ["/init"]

If anybody out there can try this out and see if it fixes their issue, that would be a huge help!

@ByJacob
Copy link

ByJacob commented Dec 11, 2021

Works for me. Use newest php:apache for base.

v2.2.0.3

app_1  | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
app_1  | [s6-init] ensuring user provided files have correct perms...exited 0.
app_1  | [fix-attrs.d] applying ownership & permissions fixes...
app_1  | [fix-attrs.d] 01-fix-index.php: applying... 
app_1  | [fix-attrs.d] 01-fix-index.php: exited 1.
app_1  | [fix-attrs.d] 02-fix-www-catalog: applying... 
app_1  | [fix-attrs.d] 02-fix-www-catalog: exited 1.
app_1  | [fix-attrs.d] done.
app_1  | [cont-init.d] executing container initialization scripts...
app_1  | [cont-init.d] done.
app_1  | [services.d] starting services
app_1  | [services.d] done.

issue-329 version

app_1  | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
app_1  | [s6-init] ensuring user provided files have correct perms...exited 0.
app_1  | [fix-attrs.d] applying ownership & permissions fixes...
app_1  | [fix-attrs.d] 01-fix-index.php: applying... 
app_1  | [fix-attrs.d] 01-fix-index.php: exited 0.
app_1  | [fix-attrs.d] 02-fix-www-catalog: applying... 
app_1  | [fix-attrs.d] 02-fix-www-catalog: exited 0.
app_1  | [fix-attrs.d] done.
app_1  | [cont-init.d] executing container initialization scripts...
app_1  | [cont-init.d] done.
app_1  | [services.d] starting services
app_1  | [services.d] done.

file 01-fix-index.php

/var/www/html/index.php true www-data 0600 0700

file 02-fix-www-catalog

/var/www/html true www-data:www-data 0644 0755

But when have bad file (example 01, wrong username) and use variable S6_BEHAVIOUR_IF_STAGE2_FAILS=2 execution continues

app_1  | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
app_1  | [s6-init] ensuring user provided files have correct perms...exited 0.
app_1  | [fix-attrs.d] applying ownership & permissions fixes...
app_1  | [fix-attrs.d] 01-fix-index.php: applying... 
app_1  | s6-envuidgid: fatal: unknown user: www-data2
app_1  | [fix-attrs.d] 01-fix-index.php: exited 1.
app_1  | [fix-attrs.d] 02-fix-www-catalog: applying... 
app_1  | [fix-attrs.d] 02-fix-www-catalog: exited 0.
app_1  | [fix-attrs.d] done.
app_1  | [cont-init.d] executing container initialization scripts...
app_1  | [cont-init.d] done.
app_1  | [services.d] starting services
app_1  | [services.d] done.

PromoFaux added a commit to edgd1er/docker-pi-hole that referenced this issue Jan 17, 2022
@skarnet
Copy link
Contributor

skarnet commented Jan 20, 2022

Version 3.0.0.0 of s6-overlay is out, which should hopefully fix all these outstanding issues.
Please note that fix-attrs is deprecated; it's difficult to make work with USER containers, and a much better policy is to set appropriate ownership and permissions from outside the container, at the time when your filesystems are mounted or in your Dockerfile. It is still supported for now, though; I hope the new version of s6-overlay will work for you.
Closing this; please reopen if not fixed.

@skarnet skarnet closed this as completed Jan 20, 2022
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