mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
Improve security of dockerfiles
* Verify checksum of downloaded rust target riscv32imac-unknown-xous_*.zip * Pin base image to a sha256 digest * Quote build arg to prevent shell injection attacks * Run cargo --locked to make sure builds follow Cargo.lock * Use --proto '=https' for curl to only allow HTTPS protocol to prevent downgrade attacks * Create non-root user to run cargo commands and build artifacts
This commit is contained in:
parent
a16c176bab
commit
0959ea80db
4 changed files with 40 additions and 17 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
target/
|
||||||
|
build/
|
||||||
*.uf2
|
*.uf2
|
||||||
.direnv
|
.direnv
|
||||||
.github
|
.github
|
||||||
|
|
@ -6,3 +8,5 @@
|
||||||
.gitattributes
|
.gitattributes
|
||||||
.gitignore
|
.gitignore
|
||||||
*.nix
|
*.nix
|
||||||
|
*~
|
||||||
|
*.swp
|
||||||
|
|
|
||||||
6
.github/workflows/docker.yml
vendored
6
.github/workflows/docker.yml
vendored
|
|
@ -11,6 +11,7 @@ on:
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: ghcr.io
|
||||||
IMAGE_PREFIX: ${{ github.repository }}
|
IMAGE_PREFIX: ${{ github.repository }}
|
||||||
|
RUST_IMAGE_SHA256: f7a4434bddc5865c07ec0e2804fcde20e9898a2b4c12cac53b22310550a8d6f5
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-apps-dabao:
|
build-apps-dabao:
|
||||||
|
|
@ -60,6 +61,7 @@ jobs:
|
||||||
type=sha,prefix=sha-
|
type=sha,prefix=sha-
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
|
|
||||||
- name: Build dabao ${{ matrix.app }} app firmware (uf2 files)
|
- name: Build dabao ${{ matrix.app }} app firmware (uf2 files)
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
|
|
@ -67,6 +69,7 @@ jobs:
|
||||||
file: ./apps-dabao/Dockerfile
|
file: ./apps-dabao/Dockerfile
|
||||||
build-args: |
|
build-args: |
|
||||||
app=${{ matrix.app }}
|
app=${{ matrix.app }}
|
||||||
|
IMG_SHA256=${{ env.RUST_IMAGE_SHA256 }}
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
@ -126,11 +129,14 @@ jobs:
|
||||||
type=sha,prefix=sha-
|
type=sha,prefix=sha-
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
|
|
||||||
- name: Build bao1x boot1 firmware (uf2 files)
|
- name: Build bao1x boot1 firmware (uf2 files)
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./bao1x-boot/Dockerfile
|
file: ./bao1x-boot/Dockerfile
|
||||||
|
build-args: |
|
||||||
|
IMG_SHA256=${{ env.RUST_IMAGE_SHA256 }}
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
FROM rust:1.92-slim AS toolchain
|
|
||||||
ARG RUST_VERSION="1.92.0"
|
ARG RUST_VERSION="1.92.0"
|
||||||
|
ARG IMG_SHA256=""
|
||||||
|
FROM rust:${RUST_VERSION}-slim-bullseye${IMG_SHA256:+@sha256:${IMG_SHA256}} AS toolchain
|
||||||
|
|
||||||
ARG EXTRA="1"
|
ARG EXTRA="1"
|
||||||
|
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
|
|
@ -10,19 +12,25 @@ RUN set -eux; \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& download_url="https://github.com/betrusted-io/rust/releases/download"; \
|
&& download_url="https://github.com/betrusted-io/rust/releases/download"; \
|
||||||
zipfile="riscv32imac-unknown-xous_${RUST_VERSION}.zip"; \
|
zipfile="riscv32imac-unknown-xous_${RUST_VERSION}.zip"; \
|
||||||
curl -L -O "${download_url}/${RUST_VERSION}.${EXTRA}/${zipfile}"; \
|
curl --proto '=https' --tlsv1.2 -fsSL -O "${download_url}/${RUST_VERSION}.${EXTRA}/${zipfile}"; \
|
||||||
|
sha256="fc7e7210444ee33c96956c4015eeafe96a588c12d68385ad763a4d1f3c6ec811"; \
|
||||||
|
echo "${sha256} *${zipfile}" | sha256sum --strict --check -; \
|
||||||
unzip "${zipfile}" -d "$(rustc --print sysroot)"; \
|
unzip "${zipfile}" -d "$(rustc --print sysroot)"; \
|
||||||
rm "${zipfile}"
|
rm "${zipfile}"
|
||||||
|
|
||||||
RUN rustup target add riscv32imac-unknown-none-elf
|
RUN rustup target add riscv32imac-unknown-none-elf
|
||||||
|
|
||||||
|
|
||||||
FROM toolchain AS builder
|
FROM toolchain AS builder
|
||||||
ARG app="helloworld"
|
ARG app="helloworld"
|
||||||
WORKDIR /usr/src/xous-core
|
RUN useradd --create-home --uid 1000 baozi
|
||||||
COPY . .
|
USER baozi
|
||||||
RUN --mount=type=cache,target=/root/.cargo/registry cargo xtask dabao ${app}
|
WORKDIR /home/baozi/xous-core
|
||||||
|
COPY --chown=baozi:baozi . .
|
||||||
|
RUN --mount=type=cache,target=/home/baozi/.cargo/registry,uid=1000,gid=1000 cargo --locked xtask dabao "${app}"
|
||||||
|
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=builder /usr/src/xous-core/target/riscv32imac-unknown-xous-elf/release/apps.uf2 /
|
COPY --from=builder /home/baozi/xous-core/target/riscv32imac-unknown-xous-elf/release/apps.uf2 /
|
||||||
COPY --from=builder /usr/src/xous-core/target/riscv32imac-unknown-xous-elf/release/loader.uf2 /
|
COPY --from=builder /home/baozi/xous-core/target/riscv32imac-unknown-xous-elf/release/loader.uf2 /
|
||||||
COPY --from=builder /usr/src/xous-core/target/riscv32imac-unknown-xous-elf/release/xous.uf2 /
|
COPY --from=builder /home/baozi/xous-core/target/riscv32imac-unknown-xous-elf/release/xous.uf2 /
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
FROM rust:1.92-slim AS toolchain
|
|
||||||
|
|
||||||
ARG RUST_VERSION="1.92.0"
|
ARG RUST_VERSION="1.92.0"
|
||||||
|
ARG IMG_SHA256=""
|
||||||
|
FROM rust:${RUST_VERSION}-slim-bullseye${IMG_SHA256:+@sha256:${IMG_SHA256}} AS toolchain
|
||||||
|
|
||||||
ARG EXTRA="1"
|
ARG EXTRA="1"
|
||||||
|
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
|
|
@ -11,7 +12,9 @@ RUN set -eux; \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& download_url="https://github.com/betrusted-io/rust/releases/download"; \
|
&& download_url="https://github.com/betrusted-io/rust/releases/download"; \
|
||||||
zipfile="riscv32imac-unknown-xous_${RUST_VERSION}.zip"; \
|
zipfile="riscv32imac-unknown-xous_${RUST_VERSION}.zip"; \
|
||||||
curl -L -O "${download_url}/${RUST_VERSION}.${EXTRA}/${zipfile}"; \
|
curl --proto '=https' --tlsv1.2 -fsSL -O "${download_url}/${RUST_VERSION}.${EXTRA}/${zipfile}"; \
|
||||||
|
sha256="fc7e7210444ee33c96956c4015eeafe96a588c12d68385ad763a4d1f3c6ec811"; \
|
||||||
|
echo "${sha256} *${zipfile}" | sha256sum --strict --check -; \
|
||||||
unzip "${zipfile}" -d "$(rustc --print sysroot)"; \
|
unzip "${zipfile}" -d "$(rustc --print sysroot)"; \
|
||||||
rm "${zipfile}"
|
rm "${zipfile}"
|
||||||
|
|
||||||
|
|
@ -19,12 +22,14 @@ RUN rustup target add riscv32imac-unknown-none-elf
|
||||||
|
|
||||||
|
|
||||||
FROM toolchain AS builder
|
FROM toolchain AS builder
|
||||||
WORKDIR /usr/src/xous-core
|
RUN useradd --create-home --uid 1000 baozi
|
||||||
COPY . .
|
USER baozi
|
||||||
RUN --mount=type=cache,target=/root/.cargo/registry cargo xtask bao1x-alt-boot1
|
WORKDIR /home/baozi/xous-core
|
||||||
RUN --mount=type=cache,target=/root/.cargo/registry cargo xtask bao1x-boot1
|
COPY --chown=baozi:baozi . .
|
||||||
|
RUN --mount=type=cache,target=/home/baozi/.cargo/registry,uid=1000,gid=1000 cargo --locked xtask bao1x-alt-boot1
|
||||||
|
RUN --mount=type=cache,target=/home/baozi/.cargo/registry,uid=1000,gid=1000 cargo --locked xtask bao1x-boot1
|
||||||
|
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=builder /usr/src/xous-core/target/riscv32imac-unknown-none-elf/release/bao1x-boot1.uf2 /
|
COPY --from=builder /home/baozi/xous-core/target/riscv32imac-unknown-none-elf/release/bao1x-boot1.uf2 /
|
||||||
COPY --from=builder /usr/src/xous-core/target/riscv32imac-unknown-none-elf/release/bao1x-alt-boot1.uf2 /
|
COPY --from=builder /home/baozi/xous-core/target/riscv32imac-unknown-none-elf/release/bao1x-alt-boot1.uf2 /
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue