서명된 쿠버네티스 아티팩트 검증하기

서명된 쿠버네티스 아티팩트 검증하기 (Verify Signed Kubernetes Artifacts)

기능 상태: Kubernetes v1.26부터 Beta.

출처: 문서

본문

시작하기 전에 (Before you begin)

다음 도구가 설치돼 있어야 해요.

  • cosign (설치 가이드)
  • curl (주로 운영 체제에서 제공)
  • jq (jq 다운로드)

바이너리 서명 검증하기 (Verifying binary signatures)

쿠버네티스 릴리스 과정은 cosign의 keyless signing을 사용해 모든 바이너리 아티팩트(tarball, SPDX 파일, 독립 바이너리)에 서명해요. 특정 바이너리를 검증하려면 그것을 서명과 인증서와 함께 검색해요.

URL=https://dl.k8s.io/release/v1.37.0/bin/linux/amd64
BINARY=kubectl

FILES=(
    "$BINARY"
    "$BINARY.sig"
    "$BINARY.cert"
)

for FILE in "${FILES[@]}"; do
    curl -sSfL --retry 3 --retry-delay 3 "$URL/$FILE" -o "$FILE"
done

그런 다음 cosign verify-blob을 사용해 blob을 검증해요.

cosign verify-blob "$BINARY" \
  --signature "$BINARY".sig \
  --certificate "$BINARY".cert \
  --certificate-identity [email protected] \
  --certificate-oidc-issuer https://accounts.google.com

참고: Cosign 2.0은 --certificate-identity--certificate-oidc-issuer 옵션을 요구해요. keyless signing에 대해 더 알아보려면 Keyless Signatures를 참고하세요. 이전 버전의 Cosign은 COSIGN_EXPERIMENTAL=1을 설정해야 했어요. 추가 정보는 sigstore Blog를 참고하세요.

이미지 서명 검증하기 (Verifying image signatures)

서명된 이미지의 전체 목록은 Releases를 참고하세요. 이 목록에서 이미지 하나를 골라 cosign verify 명령으로 서명을 검증해요.

cosign verify registry.k8s.io/kube-apiserver-amd64:v1.37.0 \
  --certificate-identity [email protected] \
  --certificate-oidc-issuer https://accounts.google.com \
  | jq .

모든 컨트롤 플레인 컴포넌트의 이미지 검증하기 (Verifying images for all control plane components)

최신 안정 버전(v1.37.0)에 대해 서명된 모든 컨트롤 플레인 이미지를 검증하려면 다음 명령을 실행하세요.

curl -Ls "https://sbom.k8s.io/$(curl -Ls https://dl.k8s.io/release/stable.txt)/release" \
  | grep "SPDXID: SPDXRef-Package-registry.k8s.io" \
  | grep -v sha256 | cut -d- -f3- | sed 's/-/\//' | sed 's/-v1/:v1/' \
  | sort > images.txt
input=images.txt
while IFS= read -r image
do
  cosign verify "$image" \
    --certificate-identity [email protected] \
    --certificate-oidc-issuer https://accounts.google.com \
    | jq .
done < "$input"

이미지를 검증한 후, 다음 예시처럼 Pod 매니페스트에서 다이제스트로 이미지를 지정할 수 있어요.

registry-url/image-name@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2

자세한 내용은 이미지 풀 정책(Image Pull Policy) 섹션을 참고하세요.

승인 컨트롤러로 이미지 서명 검증하기 (Verifying Image Signatures with Admission Controller)

컨트롤 플레인이 아닌 이미지(예: conformance 이미지)의 경우, sigstore policy-controller 승인 컨트롤러를 사용해 배포 시점에 서명을 검증할 수도 있어요.

policy-controller를 시작하는 데 유용한 자료는 다음과 같아요.

  • Installation
  • Configuration Options

소프트웨어 자재 명세서(SBOM) 검증하기 (Verify the Software Bill Of Materials)

sigstore 인증서와 서명, 또는 해당 SHA 파일을 사용해 쿠버네티스 소프트웨어 자재 명세서(SBOM)를 검증할 수 있어요.

# Retrieve the latest available Kubernetes release version
VERSION=$(curl -Ls https://dl.k8s.io/release/stable.txt)

# Verify the SHA512 sum
curl -Ls "https://sbom.k8s.io/$VERSION/release" -o "$VERSION.spdx"
echo "$(curl -Ls "https://sbom.k8s.io/$VERSION/release.sha512") $VERSION.spdx" | sha512sum --check

# Verify the SHA256 sum
echo "$(curl -Ls "https://sbom.k8s.io/$VERSION/release.sha256") $VERSION.spdx" | sha256sum --check

# Retrieve sigstore signature and certificate
curl -Ls "https://sbom.k8s.io/$VERSION/release.sig" -o "$VERSION.spdx.sig"
curl -Ls "https://sbom.k8s.io/$VERSION/release.cert" -o "$VERSION.spdx.cert"

# Verify the sigstore signature
cosign verify-blob \
    --certificate "$VERSION.spdx.cert" \
    --signature "$VERSION.spdx.sig" \
    --certificate-identity [email protected] \
    --certificate-oidc-issuer https://accounts.google.com \
    "$VERSION.spdx"

더 알아보기 (Learn more)