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 user 10001 is part of root group? #35179

Open
0x6f677548 opened this issue Sep 13, 2024 · 6 comments
Open

container user 10001 is part of root group? #35179

0x6f677548 opened this issue Sep 13, 2024 · 6 comments

Comments

@0x6f677548
Copy link

Component(s)

cmd/otelcontribcol

Describe the issue you're reporting

dockerfile

It seems to me that the container is running with a user 10001 part of the 0 (root) group.

I suggest something like:

ARG USER_UID=10001
ARG USER_GID=10001
USER ${USER_UID}:${USER_GID}

Am I missing something?

@0x6f677548 0x6f677548 added the needs triage New item requiring triage label Sep 13, 2024
@rogercoll
Copy link
Contributor

Nice catch! Do you know how we could verify the GID of the user from that image? (Being based on scratch makes debugging hard)

But based on dockerfile documentation:

When the user doesn't have a primary group then the image (or the next instructions) will be run with the root group.

And if we want to follow security best-practices:

Consider an explicit UID/GID.
Users and groups in an image are assigned a non-deterministic UID/GID in that the "next" UID/GID is assigned regardless of image rebuilds. So, if it’s critical, you should assign an explicit UID/GID.

We should also bring your suggestion to the repository used to publicly release the images https://github.com/open-telemetry/opentelemetry-collector-releases

@0x6f677548
Copy link
Author

0x6f677548 commented Sep 16, 2024

Yes, it is running as group 0. Just confirmed by running id inside the container shell:

~ $ id
uid=10001 gid=0 groups=0

One could use an alpine image to debug it, but if you want to confirm it on a scratch, here's my suggestion:

FROM alpine:latest AS builder

# Install a statically linked shell and the necessary binaries
RUN apk add --no-cache busybox-static
RUN apk add --no-cache coreutils acl attr

FROM otel/opentelemetry-collector-contrib:latest AS prep

FROM scratch

# Copy the shell executable from the builder stage
COPY --from=builder /bin/busybox.static /bin/sh
# Copy id binary from the builder stage
COPY --from=builder /usr/bin/id /bin/id

# Copy required shared libraries
COPY --from=builder /lib/ld-musl-x86_64.so.1 /lib/ld-musl-x86_64.so.1
COPY --from=builder /lib/libc.musl-x86_64.so.1 /lib/libc.musl-x86_64.so.1
COPY --from=builder /lib/libcrypto.so.3 /lib/
COPY --from=builder /lib/libacl.so.1 /lib/
COPY --from=builder /lib/libattr.so.1 /lib/
COPY --from=builder /lib/libutmps.so.0.1 /lib/
COPY --from=builder /lib/libskarnet.so.2.14 /lib/
COPY --from=builder /lib/libutmps.so.0.1 /lib/

COPY --from=prep /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=prep otelcol-contrib /otelcol-contrib

ARG USER_UID=10001
USER ${USER_UID}



# copy the config file to the /etc folder
COPY otel_collector.config.yaml /etc/otel_collector.config.yaml

EXPOSE 4317 55680 55679
ENTRYPOINT ["/otelcol-contrib"]
CMD ["--config", "/etc/otel_collector.config.yaml"]

Let me know if I can help somehow.

@0x6f677548
Copy link
Author

We should also bring your suggestion to the repository used to publicly release the images https://github.com/open-telemetry/opentelemetry-collector-releases

missed this comment. Sure - I'll create the issue over there also. thanks

@0x6f677548
Copy link
Author

Alternative steps to reproduce:
open-telemetry/opentelemetry-collector-releases#662 (comment)

@ChrsMark ChrsMark removed the needs triage New item requiring triage label Sep 18, 2024
@ChrsMark
Copy link
Member

@open-telemetry/collector-contrib-maintainers this looks like a valid suggestion and should be changed along with open-telemetry/opentelemetry-collector-releases#662.

@rogercoll
Copy link
Contributor

Fixing it in #36170

mx-psi pushed a commit that referenced this issue Nov 8, 2024
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Sets a specific GID for the build container's image.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
#35179

<!--Describe what testing was performed and which tests were added.-->
#### Testing

(Manual)

```
$ make docker-otelcontribcol
// create a sample config.yaml file
$ docker run -v .:/etc/otel/ otelcontribcol
$ ps -o user,group,pid,comm -ax | rg otelcontribcol
10001    10001    1903287 otelcontribcol
```

Without the changes:
```
$ ps -o user,group,pid,comm -ax | rg otelcontribcol
root     root     1940536 otelcontribcol
```

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->
pull bot pushed a commit to abaguas/opentelemetry-collector-contrib that referenced this issue Nov 8, 2024
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Sets a specific GID for the build container's image.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
open-telemetry#35179

<!--Describe what testing was performed and which tests were added.-->
#### Testing

(Manual)

```
$ make docker-otelcontribcol
// create a sample config.yaml file
$ docker run -v .:/etc/otel/ otelcontribcol
$ ps -o user,group,pid,comm -ax | rg otelcontribcol
10001    10001    1903287 otelcontribcol
```

Without the changes:
```
$ ps -o user,group,pid,comm -ax | rg otelcontribcol
root     root     1940536 otelcontribcol
```

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->
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

3 participants