Skip to content

Chương 45: Cloud Build & Artifact Registry — CI/CD Pipeline

Tại sao quan trọng trong production

Một bộ công cụ CI/CD mạnh mẽ và bảo mật là nền tảng của mọi hệ thống production hiện đại. Trong GCP, Cloud BuildArtifact Registry cùng tạo thành xương sống của supply chain security — từ việc biên dịch code đến việc lưu trữ và triển khai artifacts an toàn.

Khi bạn scale lên hàng ngàn deployments mỗi ngày, hai câu hỏi trở nên critical:

  1. Bạn có thể chứng minh artifacts của mình được xây dựng như thế nào? — SLSA provenance, build attestation
  2. Bạn có thể ngăn chặn artifacts không được phép được triển khai? — Binary Authorization, vulnerability scanning

Nếu không hiểu rõ cơ chế của Cloud Build workers, cách service accounts được khởi tạo, hay cách Artifact Registry tracks vulnerabilities, bạn sẽ gặp:

  • Security gaps: Builds chạy với quá nhiều permissions, hoặc không thể verify build provenance
  • Performance bottlenecks: Build caching không được tối ưu, leading to 10–20min builds thay vì 2–3 phút
  • Supply chain attacks: Malicious artifacts slip through vì vulnerability scanning không được kích hoạt đúng cách
  • Deployment disasters: Không có audit trail khi xảy ra incident

Chương này sẽ dạy bạn cách hệ thống hoạt động bên trong, không phải là tutorial "làm theo bước X, Y, Z". Mục tiêu là bạn sẽ có mental model chính xác để design CI/CD pipeline an toàn, hiệu quả, và scalable trên GCP.


Các chủ đề trong chương này

1. Cloud Build: Execution Model & Architecture

Cách Cloud Build thực sự vận hành: build steps, workers, ephemeral execution environment, build network isolation. Tại sao mỗi build chạy trong một Docker container, cách state được chia sẻ giữa các steps, và những ràng buộc thực tế mà bạn cần biết.

2. Service Accounts & Security: Least Privilege

Default Cloud Build service account có quá nhiều permissions. Cách thiết kế service account strategy để implement least privilege: custom service accounts, IAM roles, cách bind service account đến build steps cụ thể, và những tập hợp permissions tối thiểu cho các use case thông dụng.

3. Private Worker Pools: Network Isolation & VPC Integration

Khi bạn không muốn builds của mình chạy trên shared Google infrastructure, private worker pools là câu trả lời. Architecture của private pools, cách chúng peer với customer VPC, tại sao no public IP là critical security control, và những trade-offs giữa default pools vs private pools.

4. Build Triggers & Configuration Management

Cách kích hoạt builds: Cloud Source Repos, GitHub, GitLab, webhooks, scheduled builds. Cầu trúc cloudbuild.yaml schema, substitution variables (built-in vs custom), cách interpolation hoạt động, và những gotchas khi làm việc với complex build pipelines.

5. Artifact Registry: Architecture & Repository Types

Artifact Registry là nơi tất cả artifacts của bạn được lưu trữ. Repository types (Docker, Maven, npm, Python, generic), regional storage architecture, cost optimization, cách quản lý repositories theo team/environment, và integration với Cloud Build.

6. Container Vulnerability Scanning & SBOM

Cách Artifact Analysis scans container images: on-push scanning, continuous monitoring, cách SBOM (Software Bill of Materials) được generate và sử dụng, cleanup policies để xoá artifacts cũ, protection rules để ngăn deletion của critical images.

7. Build Provenance & SLSA Attestation

Cloud Build sinh ra SLSA-compliant build provenance — metadata cryptographically signed về build environment, inputs, outputs, và builder identity. Cách provenance được generate, verify, và dùng để implement supply chain security gates.

8. Binary Authorization & Deployment Gates

Cách Binary Authorization blocks deployment của container images nếu chúng không được xây dựng bởi Cloud Build hoặc không pass vulnerability checks. Cloud Deploy: managed delivery service, canary deployments, blue-green strategy, approval gates, cách tích hợp tất cả lại với nhau.

9. Organization Policies & Supply Chain Security

Cách lock-down CI/CD pipeline ở organization level: allowedIntegrations org policy, những integrations nào mà Cloud Build có thể kết nối (GitHub, GitLab, Bitbucket), tại sao control này critical, và những best practices cho supply chain security.


Điều kiện tiên quyết

Bạn nên quen thuộc với:

  • Container fundamentals: Docker images, registries, layer architecture
  • CI/CD concepts: Build pipelines, artifact versioning, deployment strategies
  • GCP fundamentals (từ Chương 1): Resource hierarchy, IAM, service accounts
  • Cloud Storage & GCS: Làm thế nào artifacts được lưu trữ và truy cập

Nếu bạn chưa làm quen với Kubernetes, nên dành thời gian để understand Chương 5 (GKE Control Plane) vì Cloud Deploy integratio tightly với GKE.


Cách đọc chương này

Đây là một chương self-contained — bạn có thể bắt đầu từ bất kỳ section nào. Tuy nhiên, strongly recommend đọc theo thứ tự:

  1. Start với Cloud Build architecture (01) để hiểu execution model
  2. Tiếp đến service accounts (02) để hiểu security boundaries
  3. Sau đó triggers & configuration (04) để hiểu cách define pipelines
  4. Rồi Artifact Registry (05-06) để hiểu artifact storage & scanning
  5. Cuối cùng provenance & Binary Authorization (07-08) để thấy full picture của supply chain security

Private worker pools (03) có thể skip nếu bạn chỉ dùng default pools, nhưng nếu bạn có strict network policies, nó là must-read.


Key takeaways (cuối chương)

Sau khi đọc xong, bạn sẽ hiểu:

Cloud Build không phải "chỉ là một tool chạy Docker commands" — nó là một distributed build system với ephemeral execution, network isolation, và cryptographic provenance
Service accounts không nên được treat casually — phải implement least privilege, bind cụ thể từng step
Private pools có trade-off rõ ràng giữa security, cost, và complexity — biết khi nào nên dùng
Artifact Registry không chỉ store images — nó actively scans, generates SBOM, và enforces cleanup policies
Supply chain security là multi-layer: SLSA provenance + Binary Authorization + org policies, không phải chỉ một cái
Scaled CI/CD không về "làm builds chạy nhanh" mà về "có thể audit, verify, và reproduce mỗi deployment"


Organization của chapter

chapter-45-cloud-build-artifact-registry/
├── index.md (file này)
├── 01-cloud-build-architecture.md
├── 02-service-accounts-security.md
├── 03-private-worker-pools.md
├── 04-build-configuration.md
├── 05-artifact-registry-architecture.md
├── 06-vulnerability-scanning-sbom.md
├── 07-build-provenance-attestation.md
├── 08-cloud-deploy-delivery.md
└── 09-supply-chain-security-policies.md

References