mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-08-10 08:27:25 +00:00
fix(content): harden install and security guidance
This commit is contained in:
@@ -20,7 +20,9 @@ Trivy 是由 Aqua Security 开发的开源漏洞扫描器,以其轻量级、
|
||||
|
||||
```bash
|
||||
# 安装 Trivy
|
||||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
||||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh -o install-trivy.sh
|
||||
less install-trivy.sh # 先审阅脚本内容
|
||||
sudo sh install-trivy.sh -b /usr/local/bin
|
||||
|
||||
# 扫描本地镜像
|
||||
trivy image nginx:latest
|
||||
@@ -58,7 +60,9 @@ Grype 由 Anchore 开发,支持更广泛的软件包管理器和语言。
|
||||
|
||||
```bash
|
||||
# 安装 Grype
|
||||
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
|
||||
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh -o install-grype.sh
|
||||
less install-grype.sh
|
||||
sudo sh install-grype.sh -b /usr/local/bin
|
||||
|
||||
# 扫描镜像
|
||||
grype docker:nginx:latest
|
||||
@@ -130,7 +134,9 @@ Syft 是 Anchore 推出的专业 SBOM 生成工具。
|
||||
**安装:**
|
||||
|
||||
```bash
|
||||
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
|
||||
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh -o install-syft.sh
|
||||
less install-syft.sh
|
||||
sudo sh install-syft.sh -b /usr/local/bin
|
||||
```
|
||||
**生成 SBOM:**
|
||||
|
||||
@@ -319,22 +325,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends curl \
|
||||
|
||||
#### 2. 构建时扫描
|
||||
|
||||
在 Dockerfile 中集成安全扫描:
|
||||
在 CI/CD 构建阶段集成安全扫描,避免在 Dockerfile 里从分支 URL 下载并执行远程安装脚本:
|
||||
|
||||
```dockerfile
|
||||
FROM golang:1.26-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
||||
# 使用 Trivy 扫描源代码
|
||||
RUN apk add --no-cache curl && \
|
||||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin && \
|
||||
trivy fs . --exit-code 1 --severity HIGH,CRITICAL
|
||||
|
||||
RUN go build -o app .
|
||||
|
||||
FROM alpine:3.17@sha256:abcd1234...(请替换为实际完整的 64 位摘要哈希)
|
||||
COPY --from=builder /app/app /app
|
||||
```bash
|
||||
docker run --rm \
|
||||
-v "$PWD:/work" \
|
||||
-w /work \
|
||||
aquasec/trivy:latest \
|
||||
fs . --exit-code 1 --severity HIGH,CRITICAL
|
||||
```
|
||||
|
||||
#### 3. 运行时镜像扫描策略
|
||||
|
||||
Reference in New Issue
Block a user