← Cloud · GCP← Cloud · GCP
Cloud · GCPCloud · GCP19 Th7, 2026Jul 19, 202612 phút đọc10 min read

SecuritySecurity

Part of the Cloud knowledge base — GCP deep dive. Complements DevOps Roadmap.

Tổng quan

Bảo mật Google Cloud được xây trên defense in depthsecure by default. Dữ liệu được mã hóa lúc nghỉ (at rest) và khi truyền (in transit) một cách tự động, IAM chi phối mọi API call, và một tập dịch vụ nhiều lớp cho phép bạn thêm các kiểm soát mạnh hơn ở nơi cần: quản lý khóa (Cloud KMS), secrets (Secret Manager), truy cập app theo ngữ cảnh (Identity-Aware Proxy), dashboard tư thế bảo mật (Security Command Center), bảo vệ edge (Cloud Armor), ranh giới chống rò rỉ dữ liệu (VPC Service Controls), và enforce supply-chain (Binary Authorization).

Trang này tập trung vào lớp bảo vệ dữ liệu và bảo mật workload nằm trên IAM và networking (đã bàn ở các trang trước).

Mối quan tâmDịch vụ GCPTương đương AWS
Quản lý khóaCloud KMS / Cloud HSMAWS KMS / CloudHSM
SecretsSecret ManagerSecrets Manager / SSM Param Store
Proxy truy cập appIdentity-Aware Proxy (IAP)(ALB OIDC / Verified Access)
Posture & threat detectionSecurity Command CenterSecurity Hub + GuardDuty
WAF / DDoSCloud ArmorAWS WAF + Shield
Data perimeterVPC Service Controls(không có tương đương trực tiếp)
Cổng image/supply-chainBinary Authorization(Signer + admission policies)
Quy định/chủ quyềnAssured WorkloadsAWS GovCloud / control frameworks

Kiến thức nền tảng

Mã hóa mặc định at rest và in transit

Bạn chỉ thêm KMS khi cần kiểm soát khóa (chính sách rotation, cư trú theo vùng, thu hồi, audit).

Cloud KMS — key rings, keys, CMEK, envelope encryption

Cloud KMS là dịch vụ managed để tạo và dùng khóa mật mã.

CMEK (Customer-Managed Encryption Keys) thay KEK do Google quản lý bằng một khóa KMS bạn sở hữu cho một dịch vụ (BigQuery, GCS, Compute disk, Pub/Sub, v.v.). Bạn giữ quyền kiểm soát rotation và có thể disable/destroy khóa để làm dữ liệu không đọc được. CSEK (Customer-Supplied) đi xa hơn — bạn cung cấp raw key bytes và Google không bao giờ lưu — nhưng hiếm khi cần.

Envelope encryption là pattern: mã hóa dữ liệu cục bộ bằng DEK, rồi gọi KMS để mã hóa (bọc) DEK đó bằng KEK. Lưu DEK đã bọc cạnh ciphertext; giải mã bằng cách nhờ KMS unwrap DEK. Cách này giữ payload lớn khỏi đường request của KMS trong khi vẫn tập trung kiểm soát khóa.

# Tạo key ring và một symmetric key có rotation
gcloud kms keyrings create app-keyring --location=us-central1

gcloud kms keys create data-key \
  --location=us-central1 --keyring=app-keyring \
  --purpose=encryption \
  --rotation-period=90d --next-rotation-time=$(date -u -d '+90 days' +%Y-%m-%dT%H:%M:%SZ)

# Mã hóa / giải mã một file trực tiếp (payload nhỏ)
gcloud kms encrypt \
  --location=us-central1 --keyring=app-keyring --key=data-key \
  --plaintext-file=secret.txt --ciphertext-file=secret.enc

gcloud kms decrypt \
  --location=us-central1 --keyring=app-keyring --key=data-key \
  --ciphertext-file=secret.enc --plaintext-file=-

Secret Manager

Secret Manager lưu API key, mật khẩu, chứng chỉ và các secret khác với versioning, kiểm soát truy cập IAM, audit logging, CMEK tùy chọn, chính sách replication tự động (automatic hoặc user-managed regions), và thông báo rotation qua Pub/Sub.

# Tạo secret và thêm một version
printf 's3cr3t-value' | gcloud secrets create db-password \
  --replication-policy=automatic --data-file=-

# Cấp một service account quyền đọc đúng secret này
gcloud secrets add-iam-policy-binding db-password \
  --member="serviceAccount:app@PROJECT.iam.gserviceaccount.com" \
  --role="roles/secretmanager.secretAccessor"

# Truy cập version mới nhất lúc runtime
gcloud secrets versions access latest --secret=db-password

Cloud Run, GKE và Compute có thể mount secret dưới dạng file hoặc inject vào biến môi trường, nên app không bao giờ nhúng credential.

Identity-Aware Proxy (IAP)

IAP enforce kiểm soát truy cập theo ngữ cảnh trước ứng dụng và VM — mô hình zero-trust nơi truy cập được xác thực và ủy quyền theo từng request thay vì dựa vào vị trí mạng (VPN).

# Tunnel SSH tới một VM private qua IAP (không cần external IP)
gcloud compute ssh my-vm --zone=us-central1-a --tunnel-through-iap

Security Command Center (SCC)

SCC là dashboard bảo mật và rủi ro trung tâm — kiểm kê tài sản, phát hiện misconfiguration và lỗ hổng, cùng threat detection.

Khía cạnhStandardPremium / Enterprise
GiáMiễn phíTrả phí (per-org / theo usage)
Security Health AnalyticsQuét misconfig cơ bảnĐầy đủ, liên tục
Web Security ScannerHạn chếĐầy đủ (managed scans)
Event Threat DetectionCó (threat từ logs)
Container/VM Threat Detection
Attack path simulationCó (Premium/Enterprise)
Báo cáo compliance (CIS, PCI, v.v.)
SIEM/SOAR (Enterprise)Tích hợp Chronicle

Dùng Standard cho khả năng hiển thị nền tảng; Premium/Enterprise cho threat detection chủ động, mapping compliance và phân tích attack-path.

Cloud Armor (WAF / DDoS)

Cloud ArmorWAF và bảo vệ DDoS của Google tại edge của global load balancer.

gcloud compute security-policies create web-waf --description="Edge WAF"
# Chặn một quốc gia và bật preconfigured rule SQLi
gcloud compute security-policies rules create 1000 \
  --security-policy=web-waf \
  --expression="origin.region_code == 'KP'" --action=deny-403
gcloud compute security-policies rules create 2000 \
  --security-policy=web-waf \
  --expression="evaluatePreconfiguredExpr('sqli-v33-stable')" --action=deny-403

VPC Service Controls

VPC Service Controls (VPC-SC) tạo một service perimeter quanh các managed Google API (BigQuery, GCS, v.v.) để ngăn rò rỉ dữ liệu (exfiltration). Ngay cả một caller có IAM credential hợp lệ cũng không thể chuyển dữ liệu ra ngoài perimeter — giảm thiểu rò rỉ do đánh cắp credential và insider.

Binary Authorization

Binary Authorization là một cổng lúc deploy cho GKE và Cloud Run, đảm bảo chỉ container image tin cậy, đã attest được chạy. Một policy yêu cầu image được ký bởi các attestor tin cậy (ví dụ được build bởi CI của bạn, đã scan, đã pass test). Image không ký hoặc chưa xác minh bị chặn. Kết hợp với scan lỗ hổng Artifact Analysis, nó enforce một chuỗi cung ứng phần mềm kiểm chứng được.

Assured Workloads (tóm tắt)

Assured Workloads áp dụng kiểm soát compliance (cư trú dữ liệu, truy cập nhân sự, quản lý khóa) lên một folder project để đáp ứng các quy chế như FedRAMP, CJIS, IL4/IL5, HIPAA và yêu cầu chủ quyền theo vùng — mà không phải đấu dây thủ công từng kiểm soát. Hữu ích cho workload thuộc lĩnh vực quy định/khu vực công và sovereign-cloud.

Khái niệm chính

CMEK vs CSEK vs khóa do Google quản lý

Mô hìnhAi giữ/rotate khóaDùng khi
Google-managed (mặc định)GoogleCần mã hóa nhưng không cần kiểm soát khóa
CMEK (KMS)Bạn, trong Cloud KMSCompliance yêu cầu kiểm soát/rotation/thu hồi
CSEKBạn cung cấp raw bytes; Google không lưuYêu cầu khóa không bao giờ rời khỏi bạn
EKM (external)Đối tác ngoài / HSM on-premKhóa phải nằm hoàn toàn ngoài Google

Secret Manager vs KMS

Chúng giải quyết vấn đề khác nhau: KMS quản lý khóa dùng để mã hóa/giải mã/ký; Secret Manager lưu giá trị secret (và dùng mã hóa bên dưới). Lưu mật khẩu trong Secret Manager; dùng KMS để CMEK-mã hóa một database. Đừng đặt raw application secret trực tiếp vào KMS.

Zero-trust access

IAP + Access Context Manager + VPC-SC cùng nhau hiện thực BeyondCorp zero-trust: truy cập app theo identity và ngữ cảnh, không dựa vào vị trí mạng, và một data perimeter quanh các dịch vụ. Điều này thay thế mô hình cũ “mạng nội bộ tin cậy + VPN”.

Best Practices

  1. Dựa vào mã hóa mặc định; chỉ thêm CMEK ở nơi compliance đòi hỏi kiểm soát. Lý do: mọi thứ đã được mã hóa AES-256 at rest — CMEK thêm overhead vận hành và nên dành cho dữ liệu cần đảm bảo rotation/thu hồi.

  2. Lưu mọi secret trong Secret Manager, không bao giờ trong code, image hay file env trong git. Lý do: credential hard-code là vector rò rỉ hàng đầu; Secret Manager thêm versioning, IAM, audit và rotation.

  3. Cấp secretAccessor theo từng secret cho service account theo từng workload. Lý do: least privilege giới hạn một workload bị xâm phạm chỉ đúng những secret nó cần, không phải cả project.

  4. Bật automatic key rotation trong KMS. Lý do: rotation định kỳ giới hạn blast radius của một key version bị xâm phạm và được nhiều khung compliance yêu cầu.

  5. Tách nhiệm vụ quanh KMS bằng các IAM role riêng biệt. Lý do: tách cryptoKeyEncrypterDecrypter (dùng) khỏi cloudkms.admin (quản lý) để không identity nào vừa dùng vừa hủy được khóa.

  6. Dùng envelope encryption cho dữ liệu ứng dụng lớn. Lý do: mã hóa dữ liệu khối lượng lớn cục bộ bằng DEK và chỉ gọi KMS để wrap/unwrap — tránh giới hạn rate của KMS và giữ payload khỏi đường của key-service.

  7. Đặt IAP trước app nội bộ và SSH/RDP; bỏ public IP. Lý do: xác thực theo ngữ cảnh, theo request qua IAP loại bỏ bastion và cổng quản trị phơi ra internet.

  8. Bật Security Command Center và triage finding liên tục. Lý do: SCC phơi bày misconfiguration và threat khắp org; Premium thêm threat chủ động và attack-path cho môi trường rủi ro cao.

  9. Đặt một policy Cloud Armor với OWASP CRS trước các HTTPS load balancer public. Lý do: WAF edge + bảo vệ DDoS chặn các tấn công web phổ biến và flood khối lượng trước khi tới backend.

  10. Thêm rate limiting và Adaptive Protection trong Cloud Armor. Lý do: throttling và phát hiện L7 DDoS dựa trên ML phòng chống lạm dụng và flood tầng ứng dụng mà ACL đơn giản bỏ lỡ.

  11. Bọc các dịch vụ dữ liệu nhạy cảm trong một VPC Service Controls perimeter (dry-run trước). Lý do: ngăn exfiltration ngay cả với credential đánh cắp hợp lệ; dry-run xác thực rule trước khi bạn liều chặn traffic hợp pháp.

  12. Enforce Binary Authorization trên GKE/Cloud Run production. Lý do: chỉ image đã ký, đã attest, đã scan mới deploy — bịt khe supply-chain nơi một image độc hại hay có lỗ hổng lọt vào prod.

  13. Bật scan lỗ hổng Artifact Analysis trên mọi registry. Lý do: scan CVE liên tục các image nuôi Binary Authorization và phơi bày dependency có lỗ hổng trước khi deploy.

  14. Bật data-access audit logs cho các dịch vụ nhạy cảm. Lý do: admin-activity logs bật mặc định, nhưng data-access logs (ai đọc gì) là opt-in và thiết yếu cho điều tra và compliance.

  15. Dùng Assured Workloads cho workload thuộc lĩnh vực quy định/chủ quyền. Lý do: nó enforce kiểm soát cư trú, nhân sự và khóa như guardrail thay vì dựa vào cấu hình thủ công dễ sai.

  16. Áp organization policy constraints làm guardrail. Lý do: org policy (ví dụ tắt tạo service account key, giới hạn location tài nguyên, yêu cầu CMEK, tắt external IP) ngăn cấu hình rủi ro khắp org trước khi chúng xảy ra.

Tài liệu tham khảo

Part of the Cloud knowledge base — GCP deep dive. Complements DevOps Roadmap.

Overview

Google Cloud security is built on defense in depth and secure by default. Data is encrypted at rest and in transit automatically, IAM governs every API call, and a layered set of services lets you add stronger controls where you need them: managed keys (Cloud KMS), secrets (Secret Manager), context-aware access to apps (Identity-Aware Proxy), a security posture dashboard (Security Command Center), edge protection (Cloud Armor), data-exfiltration boundaries (VPC Service Controls), and supply-chain enforcement (Binary Authorization).

This page focuses on the data-protection and workload-security layer that sits on top of IAM and networking (covered in earlier pages).

ConcernGCP serviceAWS equivalent
Key managementCloud KMS / Cloud HSMAWS KMS / CloudHSM
SecretsSecret ManagerSecrets Manager / SSM Param Store
App access proxyIdentity-Aware Proxy (IAP)(ALB OIDC / Verified Access)
Posture & threat detectionSecurity Command CenterSecurity Hub + GuardDuty
WAF / DDoSCloud ArmorAWS WAF + Shield
Data perimeterVPC Service Controls(no direct equivalent)
Image/supply-chain gateBinary Authorization(Signer + admission policies)
Regulated/sovereignAssured WorkloadsAWS GovCloud / control frameworks

Fundamentals

Default encryption at rest and in transit

You only add KMS when you need control over the keys (rotation policy, region residency, revocation, audit).

Cloud KMS — key rings, keys, CMEK, envelope encryption

Cloud KMS is a managed service to create and use cryptographic keys.

CMEK (Customer-Managed Encryption Keys) replaces the Google-managed KEK with a KMS key you own for a service (BigQuery, GCS, Compute disks, Pub/Sub, etc.). You keep control over rotation and can disable/destroy the key to render data unreadable. CSEK (Customer-Supplied) goes further — you provide raw key bytes and Google never stores them — but is rarely needed.

Envelope encryption is the pattern: encrypt data locally with a DEK, then call KMS to encrypt (wrap) that DEK with a KEK. Store the wrapped DEK next to the ciphertext; decrypt by asking KMS to unwrap the DEK. This keeps large payloads off the KMS request path while centralizing key control.

# Create a key ring and a rotating symmetric key
gcloud kms keyrings create app-keyring --location=us-central1

gcloud kms keys create data-key \
  --location=us-central1 --keyring=app-keyring \
  --purpose=encryption \
  --rotation-period=90d --next-rotation-time=$(date -u -d '+90 days' +%Y-%m-%dT%H:%M:%SZ)

# Encrypt / decrypt a file directly (small payloads)
gcloud kms encrypt \
  --location=us-central1 --keyring=app-keyring --key=data-key \
  --plaintext-file=secret.txt --ciphertext-file=secret.enc

gcloud kms decrypt \
  --location=us-central1 --keyring=app-keyring --key=data-key \
  --ciphertext-file=secret.enc --plaintext-file=-

Secret Manager

Secret Manager stores API keys, passwords, certificates, and other secrets with versioning, IAM access control, audit logging, optional CMEK, automatic replication policy (automatic or user-managed regions), and rotation notifications via Pub/Sub.

# Create a secret and add a version
printf 's3cr3t-value' | gcloud secrets create db-password \
  --replication-policy=automatic --data-file=-

# Grant a service account read access to just this secret
gcloud secrets add-iam-policy-binding db-password \
  --member="serviceAccount:app@PROJECT.iam.gserviceaccount.com" \
  --role="roles/secretmanager.secretAccessor"

# Access the latest version at runtime
gcloud secrets versions access latest --secret=db-password

Cloud Run, GKE, and Compute can mount secrets as files or inject them as environment variables, so apps never embed credentials.

Identity-Aware Proxy (IAP)

IAP enforces context-aware access control in front of applications and VMs — a zero-trust model where access is authenticated and authorized per-request instead of relying on network position (VPN).

# Tunnel SSH to a private VM through IAP (no external IP needed)
gcloud compute ssh my-vm --zone=us-central1-a --tunnel-through-iap

Security Command Center (SCC)

SCC is the central security and risk dashboard — asset inventory, misconfiguration and vulnerability findings, and threat detection.

AspectStandardPremium / Enterprise
PriceFreePaid (per-org / usage)
Security Health AnalyticsBasic misconfig scansFull, continuous
Web Security ScannerLimitedFull (managed scans)
Event Threat DetectionYes (log-based threats)
Container/VM Threat DetectionYes
Attack path simulationYes (Premium/Enterprise)
Compliance reports (CIS, PCI, etc.)Yes
SIEM/SOAR (Enterprise)Chronicle integration

Use Standard for baseline visibility; Premium/Enterprise for active threat detection, compliance mapping, and attack-path analysis.

Cloud Armor (WAF / DDoS)

Cloud Armor is Google’s WAF and DDoS protection at the global load-balancer edge.

gcloud compute security-policies create web-waf --description="Edge WAF"
# Block a country and enable the SQLi preconfigured rule
gcloud compute security-policies rules create 1000 \
  --security-policy=web-waf \
  --expression="origin.region_code == 'KP'" --action=deny-403
gcloud compute security-policies rules create 2000 \
  --security-policy=web-waf \
  --expression="evaluatePreconfiguredExpr('sqli-v33-stable')" --action=deny-403

VPC Service Controls

VPC Service Controls (VPC-SC) create a service perimeter around managed Google APIs (BigQuery, GCS, etc.) to prevent data exfiltration. Even a caller with valid IAM credentials cannot move data outside the perimeter — mitigating stolen-credential and insider exfiltration.

Binary Authorization

Binary Authorization is a deploy-time gate for GKE and Cloud Run that ensures only trusted, attested container images run. A policy requires images to be signed by trusted attestors (e.g., built by your CI, scanned, passed tests). Unsigned or unverified images are blocked. Combined with Artifact Analysis vulnerability scanning, it enforces a verifiable software supply chain.

Assured Workloads (brief)

Assured Workloads applies compliance controls (data residency, personnel access, key management) to a folder of projects to meet regimes like FedRAMP, CJIS, IL4/IL5, HIPAA, and regional sovereignty requirements — without you manually wiring each control. Useful for regulated/public-sector and sovereign-cloud workloads.

Key Concepts

CMEK vs CSEK vs Google-managed keys

ModelWho holds/rotates the keyUse when
Google-managed (default)GoogleYou need encryption but not key control
CMEK (KMS)You, in Cloud KMSCompliance requires control/rotation/revocation
CSEKYou supply raw bytes; Google doesn’t storeStrict key-never-leaves-you mandates
EKM (external)External partner / on-prem HSMKeys must live outside Google entirely

Secret Manager vs KMS

They solve different problems: KMS manages keys used to encrypt/decrypt/sign; Secret Manager stores secret values (and uses encryption under the hood). Store a password in Secret Manager; use KMS to CMEK-encrypt a database. Don’t put raw application secrets directly in KMS.

Zero-trust access

IAP + Access Context Manager + VPC-SC together implement BeyondCorp zero-trust: identity- and context-aware access to apps, no reliance on network location, and a data perimeter around services. This replaces the old “trusted internal network + VPN” model.

Best Practices

  1. Rely on default encryption; add CMEK only where compliance demands control. Rationale: everything is already AES-256 encrypted at rest — CMEK adds operational overhead and should be reserved for data needing rotation/revocation guarantees.

  2. Store every secret in Secret Manager, never in code, images, or env files in git. Rationale: hard-coded credentials are the top leak vector; Secret Manager adds versioning, IAM, audit, and rotation.

  3. Grant secretAccessor per-secret to per-workload service accounts. Rationale: least privilege limits a compromised workload to the exact secrets it needs, not the whole project.

  4. Enable automatic key rotation in KMS. Rationale: periodic rotation limits the blast radius of a compromised key version and is required by many compliance frameworks.

  5. Separate duties around KMS with distinct IAM roles. Rationale: split cryptoKeyEncrypterDecrypter (use) from cloudkms.admin (manage) so no single identity can both use and destroy keys.

  6. Use envelope encryption for large application data. Rationale: encrypt bulk data locally with DEKs and only call KMS to wrap/unwrap them — avoids KMS rate limits and keeps payloads off the key-service path.

  7. Front internal apps and SSH/RDP with IAP; remove public IPs. Rationale: context-aware, per-request auth via IAP eliminates bastions and internet-exposed management ports.

  8. Turn on Security Command Center and triage findings continuously. Rationale: SCC surfaces misconfigurations and threats across the org; Premium adds active threat and attack-path detection for high-risk environments.

  9. Put a Cloud Armor policy with the OWASP CRS in front of public HTTPS load balancers. Rationale: edge WAF + DDoS protection blocks common web attacks and volumetric floods before they reach your backends.

  10. Add rate limiting and Adaptive Protection in Cloud Armor. Rationale: throttling and ML-based L7 DDoS detection defend against abuse and application-layer floods that simple ACLs miss.

  11. Wrap sensitive data services in a VPC Service Controls perimeter (dry-run first). Rationale: prevents exfiltration even with valid stolen credentials; dry-run validates rules before you risk blocking legitimate traffic.

  12. Enforce Binary Authorization on GKE/Cloud Run production. Rationale: only signed, attested, scanned images deploy — closing the supply-chain gap where a malicious or vulnerable image reaches prod.

  13. Enable Artifact Analysis vulnerability scanning on all registries. Rationale: continuous CVE scanning of images feeds Binary Authorization and surfaces vulnerable dependencies before deploy.

  14. Enable data-access audit logs for sensitive services. Rationale: admin-activity logs are on by default, but data-access logs (who read what) are opt-in and essential for investigations and compliance.

  15. Use Assured Workloads for regulated/sovereign workloads. Rationale: it enforces residency, personnel, and key controls as guardrails rather than relying on manual, error-prone configuration.

  16. Apply organization policy constraints as guardrails. Rationale: org policies (e.g., disable service account key creation, restrict resource locations, require CMEK, disable external IPs) prevent risky configurations org-wide before they happen.

References