Skip to content

Commit

Permalink
chore: Implement security fixes (#683)
Browse files Browse the repository at this point in the history
* chore: Update Dockerfile to use non-root user

* fix(anta): Update regexp syntax for better readability

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* fix(anta): Update regexp syntax for better readability

---------

Co-authored-by: Matthieu Tâche <mtache@arista.com>
  • Loading branch information
titom73 and mtache authored May 17, 2024
1 parent 838ec40 commit 1c04244
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ RUN pip install --upgrade pip
WORKDIR /local
COPY . /local

ENV PYTHONPATH=/local
ENV PATH=$PATH:/root/.local/bin
RUN python -m venv /opt/venv

RUN pip --no-cache-dir install --user .

ENV PATH="/opt/venv/bin:$PATH"

RUN apk add --no-cache build-base # Add build-base package
RUN pip --no-cache-dir install "." &&\
pip --no-cache-dir install ".[cli]"

# ----------------------------------- #

### BASE

FROM python:${PYTHON_VER}-${IMG_OPTION} AS BASE

# Add a system user
RUN adduser --system anta

# Opencontainer labels
# Labels version and revision will be updating
# during the CI with accurate information
Expand All @@ -40,7 +47,12 @@ LABEL "org.opencontainers.image.title"="anta" \
"org.opencontainers.image.revision"="dev" \
"org.opencontainers.image.version"="dev"

COPY --from=BUILDER /root/.local/ /root/.local
ENV PATH=$PATH:/root/.local/bin
# Copy artifacts from builder
COPY --from=BUILDER /opt/venv /opt/venv

# Define PATH and default user
ENV PATH="/opt/venv/bin:$PATH"

USER anta

ENTRYPOINT [ "/root/.local/bin/anta" ]
ENTRYPOINT [ "/opt/venv/bin/anta" ]
2 changes: 1 addition & 1 deletion anta/cli/exec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def collect_commands(
async def collect(dev: AntaDevice, command: str, outformat: Literal["json", "text"]) -> None:
outdir = Path() / root_dir / dev.name / outformat
outdir.mkdir(parents=True, exist_ok=True)
safe_command = re.sub(r"(/|\|$)", "_", command)
safe_command = re.sub(r"[\\\/\s]", "_", command)
c = AntaCommand(command=command, ofmt=outformat)
await dev.collect(c)
if not c.collected:
Expand Down

0 comments on commit 1c04244

Please sign in to comment.