콘텐츠로 이동

Enable experimental features (keyless signing)

플랫폼명령어
Ubuntu/Debianwget https://github.com/sigstore/cosign/releases/latest/download/cosign_amd64.deb && sudo dpkg -i cosign_amd64.deb
RHEL/Fedora/CentOSwget https://github.com/sigstore/cosign/releases/latest/download/cosign-amd64.rpm && sudo rpm -ivh cosign-amd64.rpm
macOS (Homebrew)brew install cosign
macOS (Binary)curl -LO https://github.com/sigstore/cosign/releases/latest/download/cosign-darwin-amd64 && sudo mv cosign-darwin-amd64 /usr/local/bin/cosign && sudo chmod +x /usr/local/bin/cosign
macOS (Apple Silicon)curl -LO https://github.com/sigstore/cosign/releases/latest/download/cosign-darwin-arm64 && sudo mv cosign-darwin-arm64 /usr/local/bin/cosign && sudo chmod +x /usr/local/bin/cosign
Windows (Scoop)scoop install cosign
Windows (Chocolatey)choco install cosign
Windows (winget)winget install sigstore.cosign
Linux (Generic Binary)curl -LO https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64 && sudo mv cosign-linux-amd64 /usr/local/bin/cosign && sudo chmod +x /usr/local/bin/cosign
Arch Linuxyay -S cosign
Containerdocker run --rm gcr.io/projectsigstore/cosign:latest version
Verify Installationcosign version
명령어설명
cosign versioncosign 버전 정보 표시
cosign help사용 가능한 모든 명령어와 옵션 표시
cosign generate-key-pair새로운 키 페어 (cosign.key와 cosign.pub)를 생성하세요
cosign generate-key-pair --output-key-prefix mykey사용자 지정 접두사로 키 쌍 생성
cosign sign --key cosign.key IMAGE_URI개인 키로 컨테이너 이미지에 서명하기
cosign sign IMAGE_URIOIDC를 사용하여 키 없는 모드로 이미지 서명하기
cosign verify --key cosign.pub IMAGE_URI공개 키로 이미지 서명 확인
cosign verify IMAGE_URI키 없는 서명 확인
cosign sign --key cosign.key -a key=value IMAGE_URI사용자 지정 주석으로 이미지에 서명
cosign verify --key cosign.pub -a key=value IMAGE_URI서명 확인 및 주석 확인
cosign triangulate IMAGE_URI이미지의 서명 위치 찾기
cosign download signature IMAGE_URI이미지의 서명 다운로드
cosign download attestation IMAGE_URI이미지에 대한 증명서 다운로드
cosign copy SOURCE_IMAGE DEST_IMAGE서명이 있는 이미지를 새 위치로 복사하기
cosign sign --key cosign.key IMAGE1 IMAGE2 IMAGE3한 번에 여러 이미지에 서명하기
cosign verify --key cosign.pub IMAGE_URI --output jsonJSON으로 출력 검증 결과
cosign sign --key cosign.key gcr.io/project/image@sha256:abc123...특정 이미지 다이제스트 서명
cosign public-key --key cosign.key개인 키에서 공개 키 추출
cosign initializecosign의 신뢰 루트 초기화
cosign tree IMAGE_URI이미지의 서명 및 증명 트리 표시
명령어설명
cosign generate-key-pair --kms gcpkms://projects/PROJECT/locations/LOCATION/keyRings/RING/cryptoKeys/KEYGoogle Cloud KMS에서 키 쌍 생성
cosign generate-key-pair --kms awskms://arn:aws:kms:region:account:key/key-idAWS KMS에서 키 쌍 생성
cosign generate-key-pair --kms azurekms://vault.vault.azure.net/keys/keyname/versionAzure Key Vault에서 키 쌍 생성
cosign generate-key-pair --kms hashivault://transit/keys/cosignHashiCorp Vault에서 키 쌍 생성하기
cosign attest --key cosign.key --predicate predicate.json IMAGE_URI이미지에 증명서 첨부
cosign attest --key cosign.key --type slsaprovenance --predicate provenance.json IMAGE_URISLSA 출처 증명 첨부
cosign attest --key cosign.key --type vuln --predicate scan-results.json IMAGE_URI취약성 스캔 증명서 첨부
cosign attest --key cosign.key --type spdx --predicate sbom.spdx.json IMAGE_URISBOM 증명 첨부
cosign verify-attestation --key cosign.pub IMAGE_URI이미지의 증명서를 확인하세요
cosign verify-attestation --key cosign.pub --type slsaprovenance IMAGE_URI특정 증명 유형 확인
cosign verify-attestation --key cosign.pub --policy policy.cue IMAGE_URICUE 정책에 대해 증명 확인
cosign sign-blob --key cosign.key --output-signature file.sig file.txt임의의 파일 서명 (비컨테이너)
cosign verify-blob --key cosign.pub --signature file.sig file.txtBlob 서명 확인
cosign sign --key cosign.key --timestamp-server-url http://timestamp.server IMAGE_URIRFC3161 타임스탬프로 서명
cosign verify --certificate-identity user@example.com --certificate-oidc-issuer https://accounts.google.com IMAGE_URIID 없는 서명 확인
cosign verify --key cosign.pub --rekor-url https://rekor.sigstore.dev IMAGE_URIRekor 투명성 로그로 검증
cosign verify --key cosign.pub --insecure-ignore-tlog IMAGE_URI투명성 로그를 확인하지 않고 검증하기
cosign copy --platform linux/amd64 SOURCE_IMAGE DEST_IMAGE특정 플랫폼용 이미지 복사
cosign copy --sig-only SOURCE_IMAGE DEST_IMAGE서명만 복사 (이미지 제외)
cosign manifest verify --key cosign.pub IMAGE_URI이미지 매니페스트 서명 확인
cosign upload blob --signature file.sig --payload file.txtRekor 투명성 로그에 서명 업로드
cosign sign --key cosign.key -r gcr.io/myproject/myimage재귀적으로 모든 태그에 서명하기
cosign verify --key cosign.pub --certificate-chain chain.pem IMAGE_URI인증서 체인으로 확인
cosign attach signature --signature sig.json IMAGE_URI이미지에 수동으로 서명 첨부
cosign attach attestation --attestation att.json IMAGE_URI이미지에 증명서를 수동으로 첨부
# Enable experimental features (keyless signing)
export COSIGN_EXPERIMENTAL=1

# Set custom Rekor transparency log URL
export REKOR_URL=https://rekor.sigstore.dev

# Set custom Fulcio certificate authority URL
export FULCIO_URL=https://fulcio.sigstore.dev

# Set custom OIDC issuer for keyless signing
export COSIGN_OIDC_ISSUER=https://oauth2.sigstore.dev/auth

# Set custom OIDC client ID
export COSIGN_OIDC_CLIENT_ID=sigstore

# Set Docker registry credentials
export COSIGN_REPOSITORY=registry.example.com/signatures

# Set password for private key (CI/CD use)
export COSIGN_PASSWORD=your-password-here

# Skip TUF root verification (not recommended for production)
export COSIGN_EXPERIMENTAL_SKIP_TUF=1

# Set custom Docker config location
export DOCKER_CONFIG=/path/to/.docker
```## 고급 사용법
```cue
// policy.cue - Example attestation policy
predicateType: "https://slsa.dev/provenance/v0.2"

predicate: {
  buildType: "https://cloudbuild.googleapis.com/CloudBuildYaml@v1"
  builder: id: =~"^https://cloudbuild.googleapis.com/"
  
  invocation: {
    configSource: {
      repository: =~"^https://github.com/myorg/"
    }
  }
}
```## 구성
```cue
// vuln-policy.cue - Require no critical vulnerabilities
predicateType: "https://cosign.sigstore.dev/attestation/vuln/v1"

predicate: {
  scanner: {
    name: "trivy"
  }
  
  metadata: {
    scanFinishedOn: string
  }
  
  // No critical vulnerabilities allowed
  scanner: result: {
    criticalCount: 0
  }
}
```### 환경 변수
```yaml
# .github/workflows/sign.yml
name: Sign Container Image
on: [push]

permissions:
  contents: read
  id-token: write  # Required for keyless signing
  packages: write

jobs:
  sign:
    runs-on: ubuntu-latest
    steps:
      - name: Install Cosign
        uses: sigstore/cosign-installer@v3
        
      - name: Login to Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
          
      - name: Build Image
        run: docker build -t ghcr.io/${{ github.repository }}:latest .
        
      - name: Push Image
        run: docker push ghcr.io/${{ github.repository }}:latest
        
      - name: Sign Image (Keyless)
        run: |
          cosign sign --yes ghcr.io/${{ github.repository }}:latest
# Generate key pair (will prompt for password)
cosign generate-key-pair

# Build your container image
docker build -t myregistry.io/myapp:v1.0 .

# Push image to registry
docker push myregistry.io/myapp:v1.0

# Sign the image
cosign sign --key cosign.key myregistry.io/myapp:v1.0

# Verify the signature
cosign verify --key cosign.pub myregistry.io/myapp:v1.0

# Verify and extract payload
cosign verify --key cosign.pub myregistry.io/myapp:v1.0 | jq .
```### CUE 정책 파일 예시
```bash
# Enable experimental mode for keyless signing
export COSIGN_EXPERIMENTAL=1

# Sign image (will open browser for OIDC authentication)
cosign sign myregistry.io/myapp:v1.0

# In CI/CD (GitHub Actions), use --yes flag
cosign sign --yes myregistry.io/myapp:v1.0

# Verify keyless signature with identity
cosign verify \
  --certificate-identity user@example.com \
  --certificate-oidc-issuer https://github.com/login/oauth \
  myregistry.io/myapp:v1.0

# Verify in GitHub Actions workflow
cosign verify \
  --certificate-identity https://github.com/myorg/myrepo/.github/workflows/build.yml@refs/heads/main \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  myregistry.io/myapp:v1.0
# Generate SBOM using syft
syft myregistry.io/myapp:v1.0 -o spdx-json > sbom.spdx.json

# Attach SBOM as attestation
cosign attest --key cosign.key \
  --type spdx \
  --predicate sbom.spdx.json \
  myregistry.io/myapp:v1.0

# Verify attestation
cosign verify-attestation --key cosign.pub \
  --type spdx \
  myregistry.io/myapp:v1.0

# Download and view SBOM
cosign verify-attestation --key cosign.pub \
  --type spdx \
  myregistry.io/myapp:v1.0 | jq -r '.payload' | base64 -d | jq .
```### 취약점 스캔을 위한 증명 정책
```bash
# Generate key in Google Cloud KMS
cosign generate-key-pair --kms gcpkms://projects/my-project/locations/us-central1/keyRings/cosign/cryptoKeys/signing-key

# Sign image using KMS key
cosign sign --key gcpkms://projects/my-project/locations/us-central1/keyRings/cosign/cryptoKeys/signing-key \
  myregistry.io/myapp:v1.0

# Get public key from KMS
cosign public-key --key gcpkms://projects/my-project/locations/us-central1/keyRings/cosign/cryptoKeys/signing-key > cosign.pub

# Verify using public key
cosign verify --key cosign.pub myregistry.io/myapp:v1.0

# AWS KMS example
cosign sign --key awskms://arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012 \
  myregistry.io/myapp:v1.0
# Create vulnerability scan
trivy image --format json --output scan-results.json myregistry.io/myapp:v1.0

# Attach scan results as attestation
cosign attest --key cosign.key \
  --type vuln \
  --predicate scan-results.json \
  myregistry.io/myapp:v1.0

# Create policy file
cat > vuln-policy.cue <<EOF
predicateType: "https://cosign.sigstore.dev/attestation/vuln/v1"
predicate: {
  scanner: {
    name: "trivy"
  }
}
EOF

# Verify against policy
cosign verify-attestation --key cosign.pub \
  --type vuln \
  --policy vuln-policy.cue \
  myregistry.io/myapp:v1.0

# If policy passes, deploy image
kubectl set image deployment/myapp myapp=myregistry.io/myapp:v1.0
```### GitHub Actions 통합
`@sha256:...`
`--insecure-ignore-tlog`## 일반적인 사용 사례
`--certificate-identity`### 사용 사례 1: 키 페어로 컨테이너 이미지 서명 및 검증
`--certificate-oidc-issuer`

| 문제 | 솔루션 |
|-------|----------|
| **Error: "private key password incorrect"** | Ensure you're using the correct password for your private key. Set `COSIGN_PASSWORD` environment variable for non-interactive use: `export COSIGN_PASSWORD=your-password` |
| **Error: "no matching signatures"** | The image may not be signed, or you're using the wrong public key. Verify with `cosign triangulate IMAGE_URI` to check if signatures exist, and ensure you're using the correct public key. |
| **Error: "UNAUTHORIZED: authentication required"** | You need to authenticate to the registry first. Run `docker login` or use `cosign login` with appropriate credentials before signing or verifying. |
| **Keyless signing fails with "no provider found"** | Enable experimental mode with `export COSIGN_EXPERIMENTAL=1` and ensure you have internet access to reach Fulcio and Rekor services. |
| **Error: "failed to verify certificate identity"** | When verifying keyless signatures, you must specify both `--certificate-identity` and `--certificate-oidc-issuer` flags matching the signer's identity. |
| **Signatures not found after copying image** | Use `cosign copy` instead of `docker tag` or `crane copy` to ensure signatures are copied along with the image. Regular Docker commands don't copy OCI artifacts. |
| **Error: "tlog entry not found"** | The signature may not have been uploaded to Rekor transparency log. Use `--insecure-ignore-tlog` flag only in air-gapped environments or re-sign the image. |
| **Verification fails in air-gapped environment** | Initialize cosign with TUF root: `cosign initialize --mirror https://your-mirror --root root.json`, or use `--insecure-ignore-tlog` and `--insecure-ignore-sct` flags (not recommended for production). |
| **Error: "image is a manifest list"** | Sign the specific platform image instead of the manifest list, or use `cosign sign --recursive` to sign all images in the manifest list. |
| **Attestation verification fails with policy** | Check your CUE policy syntax with `cue vet policy.cue`. Ensure the predicateType matches exactly. Use `cosign verify-attestation --output json` to inspect actual attestation structure. |
| **Error: "failed to get public key from KMS"** | Verify your cloud credentials are configured (`gcloud auth`, `aws configure`, `az login`) and you have permissions to access the KMS key. Check the KMS key URI format is correct. |### 사용 사례 2: GitHub Actions를 사용한 키리스 서명
`--attachment-tag-prefix`