Skip to content

Commit

Permalink
add nonroot user to docker image (#6627)
Browse files Browse the repository at this point in the history
* add nonroot docker image

* sign drone

* back to one image

* space
  • Loading branch information
captncraig authored Mar 11, 2024
1 parent 70ea877 commit b827bad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ web/ui/node_modules/
web/ui/build/
packaging/windows/LICENSE
packaging/windows/agent-windows-amd64.exe
cmd/grafana-agent/Dockerfile
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ DOCKER_FLAGS += --platform=$(DOCKER_PLATFORM)
endif

.PHONY: images agent-image agentctl-image operator-image
images: agent-image agentctl-image operator-image
images: agent-image agentctl-image operator-image agent-boringcrypto-image

agent-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(AGENT_IMAGE) -f cmd/grafana-agent/Dockerfile .
Expand Down
9 changes: 9 additions & 0 deletions cmd/grafana-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ RUN --mount=type=cache,target=/root/.cache/go-build \

FROM public.ecr.aws/ubuntu/ubuntu:mantic

#Username and uid for grafana-agent user
ARG UID=473
ARG USERNAME="grafana-agent"

LABEL org.opencontainers.image.source="https://github.com/grafana/agent"

# Install dependencies needed at runtime.
Expand All @@ -44,6 +48,11 @@ EOF
COPY --from=build /src/agent/build/grafana-agent /bin/grafana-agent
COPY cmd/grafana-agent/agent-local-config.yaml /etc/agent/agent.yaml

# Create grafana-agent user in container, but do not set it as default
RUN groupadd --gid $UID $USERNAME
RUN useradd -m -u $UID -g $UID $USERNAME
RUN chown -R $USERNAME:$USERNAME /etc/agent
RUN chown -R $USERNAME:$USERNAME /bin/grafana-agent

ENTRYPOINT ["/bin/grafana-agent"]
ENV AGENT_DEPLOY_MODE=docker
Expand Down
4 changes: 0 additions & 4 deletions tools/ci/docker-containers
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ else
BRANCH_TAG=$VERSION
fi


# Build all of our images.

export BUILD_PLATFORMS=linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
export BUILD_PLATFORMS_BORINGCRYPTO=linux/amd64,linux/arm64


case "$TARGET_CONTAINER" in
agent)
docker buildx build --push \
Expand All @@ -80,8 +78,6 @@ case "$TARGET_CONTAINER" in
.
;;



agentctl)
docker buildx build --push \
--platform $BUILD_PLATFORMS \
Expand Down

0 comments on commit b827bad

Please sign in to comment.