GCP — GitOps networking
Portfolio đầy đủ (hero, sections, diagram) — port first-class trong app, không iframe.
GCP Cloud EngineerEnterprise Landing Zone · Networking · Security · IaC
Thiết kế và vận hành enterprise GCP environments với landing zone, Shared VPC, Private Service Connect, VPC Service Controls và toàn bộ infrastructure-as-code bằng Terraform.
Tổng quan hệ thống GCP
Công nghệ sử dụng
| Service | Use Case | Config |
|---|---|---|
| GKE Autopilot | Production workloads | asia-southeast1 |
| Compute Engine | Bastion, build agents, legacy VMs | Spot VMs enabled |
| Cloud Run | Stateless microservices, APIs | VPC egress via PSC |
| Cloud Functions v2 | Event-driven, pub/sub triggers | Gen2 (Cloud Run backed) |
| Cloud Storage | Terraform state, artifacts, data lake | VPC-SC protected |
| Service | Use Case | Detail |
|---|---|---|
| Shared VPC | Centralized network governance | Host + 4 service projects |
| Cloud Load Balancing | Global L7 HTTPS, regional L4 TCP | GLB + ILB |
| Private Service Connect | Internal service endpoints | No transitive routing |
| Cloud Interconnect | On-prem hybrid connectivity | 2×10Gbps HA |
| Cloud DNS | Private zones + DNS peering | On-prem forwarding |
| Service | Role | Scope |
|---|---|---|
| IAM + Workload Identity | Identity & access management | Org + Project level |
| VPC Service Controls | Data exfiltration prevention | PROD perimeter |
| Cloud Armor | WAF + DDoS protection | GLB security policy |
| Identity-Aware Proxy | Zero-trust app access | Internal tools |
| Secret Manager | Secrets & credential management | CMEK encrypted |
| Tool | Role | Detail |
|---|---|---|
| Terraform | Infrastructure provisioning | Modules + remote GCS backend |
| Cloud Build | Terraform CI/CD pipeline | Trigger on PR → plan, merge → apply |
| GitHub Actions | App CI + Workload Identity | OIDC → no long-lived keys |
| Ansible | VM config management, OS hardening | Dynamic inventory via GCP plugin |
| Artifact Registry | Docker images, Terraform modules | VPC-SC + CMEK |
- GKE Autopilot
- Compute Engine
- Cloud Run
- Cloud Functions v2
- Batch
- Cloud Storage
- Cloud SQL (HA)
- Memorystore (Redis)
- BigQuery
- Pub/Sub
- IAM + Org Policy
- VPC Service Controls
- Cloud Armor
- Identity-Aware Proxy
- Secret Manager (CMEK)
- Cloud Monitoring
- Cloud Logging
- Cloud Trace
- Security Command Center
- Billing Export → BQ
Enterprise Landing Zone — Resource Hierarchy
Landing Zone là foundation trước khi deploy bất kỳ workload nào. Không có Landing Zone, mỗi team tự tạo project → billing không kiểm soát, IAM loạn, network flat, không audit trail.
Với Landing Zone: centralized governance, Org Policies làm guardrail, networking nhất quán, audit logs và billing budgets tự động — theo GCP Cloud Adoption Framework (Learn · Lead · Scale · Secure).
👥 Multi-Team IAM — Production-Ready Access Design (GCP)
sre@ → editor (scoped) security@ → viewer (all) dev@ → NO folder access
dev@ → editor (staging) data@ → viewer sre@ → owner (full)
disableSAKeyCreation · requireOsLogin · No primitive roles PROD
| Team | GKE PROD | Cloud SQL | GCS | BigQuery | VM / IAP | Secret Mgr |
|---|---|---|---|---|---|---|
| sre@ | container.admin → cluster-admin | cloudsql.admin (full DBA) | storage.admin all | bigquery.admin | osAdminLogin + MFA PROD | secretmanager.admin |
| dev@ | container.developer → ns-developer (own ns) | cloudsql.client · no DROP | objectCreator (app bucket) | ❌ | osLogin DEV only | secretAccessor /dev/* |
| data@ | container.viewer (data-ns) | cloudsql.viewer · SELECT only | objectViewer /data/ | dataViewer | ❌ Denied | ❌ Denied |
| security@ | container.viewer all ns | cloudsql.viewer read-only | objectViewer all | metadataViewer | Describe only | List (no value) |
| finops@ | ❌ | ❌ | getBucketTagging | ❌ | Describe (cost labels) | ❌ |
GCP Networking Deep Dive
Shared VPC tách network governance (host project quản subnets, firewall, routes) khỏi service projects gắn workload. Private Service Connect thay VPC peering cho kết nối dịch vụ nội bộ; Cloud NAT + Cloud Router cho egress có kiểm soát. Chi tiết Shared VPC và bảng so sánh với peering nằm ở mục Shared VPC Deep Dive.
🎯 GCP Interview Deep Dive — Hay Bị Hỏi
- GCP VPC là global — không attach IGW. Subnet có Private Google Access để reach GCP APIs mà không cần public IP.
- Inbound internet: GLB + public IP → forward vào private backend. Không có “public subnet” như AWS.
- Outbound từ instance có public IP: route 0.0.0.0/0 qua default internet gateway (ẩn, không cần config).
- Outbound từ instance không có public IP: phải dùng Cloud NAT.
- Attach vào Cloud Router (không attach vào subnet như AWS). Cloud Router là BGP speaker; Cloud NAT dùng Cloud Router để route.
- Auto-allocate external IPs hoặc reserved IP. SNAT: private IP → NAT external IP.
- GCP APIs không đi qua Cloud NAT — dùng Private Google Access hoặc PSC endpoint thay thế.
| Scenario | Dùng gì | Lý do |
|---|---|---|
| GKE + Cloud SQL + Cloud Run trong cùng org, cần share network | Shared VPC | Centralized firewall, subnet governance, Interconnect sharing |
| Expose Cloud SQL cho service project khác mà không share subnet | PSC | Managed service endpoint, CIDR isolation, cross-project OK |
| 2 VPC cần nói chuyện, không share host project | VPC Peering | Simple 2-way routing, không transitive, CIDR không overlap |
| GCP managed services (Secret Manager, GCS) từ private pod | PSC (all-APIs endpoint) | Không qua internet, không NAT, VPC-SC enforced |
| N projects cần reach on-prem qua 1 Interconnect | Shared VPC | Host project owns Cloud Router + Interconnect, service projects inherit |
Cloud SQL: bật audit/slow query flags → log tự động vào Cloud Logging → sink BigQuery hoặc Pub/Sub → ES. GKE: Fluentbit built-in (Autopilot) đưa stdout vào Cloud Logging; có thể thêm Vector/Alloy cho multi-sink tới Loki.
- Flags: cloudsql.enable_pgaudit, log_min_duration_statement, log_connections — log ship tự động tới Cloud Logging (không cần agent trên instance như RDS + CW agent).
- Log sink: Logging → BigQuery (phân tích SQL) hoặc Pub/Sub → Dataflow/Logstash → Elasticsearch.
- GKE Autopilot: Fluentbit DaemonSet đưa stdout/stderr vào Cloud Logging; label pod để filter.
- RabbitMQ / sidecar: log stdout → cùng pipeline; ES self-hosted qua sink + Pub/Sub nếu cần.
# Cloud SQL — audit + slow query
resource "google_sql_database_instance" "prod" {
settings {
database_flags {
name = "cloudsql.enable_pgaudit"
value = "on"
}
database_flags {
name = "log_min_duration_statement"
value = "1000"
}
database_flags {
name = "log_connections"
value = "on"
}
}
}
# Log sink → BigQuery
resource "google_logging_project_sink" "cloudsql_bq" {
name = "cloudsql-to-bigquery"
destination = "bigquery.googleapis.com/projects/${var.project}/datasets/audit_logs"
filter = "resource.type=cloudsql_database"
}
# Log sink → Pub/Sub → ES pipeline
resource "google_logging_project_sink" "to_pubsub" {
name = "logs-to-pubsub"
destination = "pubsub.googleapis.com/projects/${var.project}/topics/logs-export"
filter = "resource.type=k8s_container OR resource.type=cloudsql_database"
}GCP: Internet → Cloud Armor → GLB (HTTPS) → NEG (pod IP trực tiếp). Không cần Ingress controller riêng như AWS LBC — GLB là managed edge của GCP.
| Kiểu | Layer | Defense | Detect |
|---|---|---|---|
| DDoS volumetric | L3/L4 trước GLB | GCP DDoS Protection built-in (always-on). Cloud Armor Adaptive Protection — ML tạo rule khi anomaly. | Cloud Armor logs → Monitoring alert |
| SQLi / XSS | L7 qua GLB | Cloud Armor WAF: sqli-v33-stable, xss-v33-stable. Gắn policy vào backend service. | Cloud Armor sampled requests |
| Unauth access | GLB → backend | IAP — Google OIDC trước khi traffic tới pod; điều kiện domain/device. | IAP audit — rejected requests |
| Bypass GLB → pod | VPC firewall | Chỉ allow từ GLB health ranges (130.211.0.0/22, 35.191.0.0/16). deny-all-ingress priority thấp. NetworkPolicy deny-all trừ namespace ingress. | VPC Flow Logs → BigQuery |
| Malicious image | GKE admission | Binary Authorization + Artifact Analysis CVE. Kyverno chỉ cho phép image từ Artifact Registry. | SCC Container Threat Detection |
| Container escape | Node | GKE Autopilot hardened — COS, Shielded VM, gVisor tùy workload. Node SA tối thiểu. | SCC GKE Threat Detection → Pub/Sub |
| Data exfil | VPC-SC | VPC Service Controls — exfil BigQuery/GCS ra ngoài perimeter bị chặn dù IAM hợp lệ. | SCC anomalous access |
| Scenario | GCP solution | Tránh |
|---|---|---|
| GKE pod gọi GCP APIs (Secret Manager, GCS) không qua internet | PSC endpoint + Cloud DNS override *.googleapis.com | Cloud NAT ($/GB) cho Google APIs |
| N projects share subnet + firewall | Shared VPC (host owns network) | VPC Peering N², non-transitive |
| Expose Cloud SQL cho project khác, CIDR overlap | PSC (psc-cloudsql) | Peering (CIDR phải unique) |
| Internet → GKE private pod | GLB HTTPS + Cloud Armor + IAP | NodePort/LoadBalancer trực tiếp (bypass WAF) |
| Pull image Artifact Registry private | PSC + node SA artifactregistry.reader | Public registry không kiểm soát |
| On-prem → GCP bandwidth cao | Dedicated Interconnect + HA VPN standby | Chỉ HA VPN (latency biến thiên) |
| SSH không bastion public | IAP TCP tunneling (gcloud compute ssh --tunnel-through-iap) | Public IP + SSH |
| Cloud SQL credential không key file | Workload Identity → cloudsql.client | JSON key trên pod |
| Chống exfil khi IAM compromise | VPC Service Controls perimeter | Chỉ IAM (key theft bypass) |
| Multi-env không drift | Flux ResourceSet — 1 template, defaultValues theo env | Helm values copy-paste mỗi env |
GCP Security Deep Dive — Defense in Depth
Sơ đồ dưới mô tả thứ tự kiểm soát từ Internet vào workload: Cloud Armor trên GLB → IAP (zero-trust nội bộ) → VPC Service Controls + firewall → IAM / Workload Identity → Secret Manager + CMEK + Binary Authorization.
Terraform Modules — Resource Labeling Convention
Mọi Terraform module follow pattern labeling nhất quán: label derive từ basename(abspath(path.module)) — Cost breakdown chính xác theo team/product; terraform-module tự cập nhật khi rename folder.
locals {
default_labels = {
(basename(abspath(path.module))) = var.name
"terraform-module" = basename(abspath(path.module))
"product" = var.product
"team" = var.team
"environment" = var.environment
}
merged_labels = merge(local.default_labels, var.labels)
}VictoriaMetrics — Cluster → Operator Migration on GCP
- Nhiều file Helm values dev/staging/prod — drift khó phát hiện.
- vminsert/vmstorage/vmselect replica khác nhau từng env — dễ nhầm toán.
- Upgrade Helm tuần tự từng cluster — sequence sai có thể split-brain vmstorage.
- Scrape rules trong ConfigMap thủ công — không validation, khó review diff.
- Metric GCP (Cloud SQL, Cloud Run, Pub/Sub) scrape riêng — maintenance ~8h/tháng.
- VMCluster CRD — operator quản lifecycle, rolling upgrade zero-downtime.
- VMServiceScrape / VMPodScrape — discover theo label K8s, schema validated.
- VMRule trong Git — alert validated khi apply, drift được operator sửa.
- VMAgent với WIF — không file SA key; Flux ResourceSet giữ parity mọi env.
- Vận hành giảm mạnh (~45 phút/tháng vs ~8 giờ) khi chuẩn hóa GitOps.
| Component | AWS (EKS) | GCP (GKE Autopilot) | Lý do khác nhau |
|---|---|---|---|
| vmstorage disk | gp3 · EBS | premium-rwo · PD-SSD | Autopilot chỉ RWO; premium-rwo đủ IOPS cho write-heavy vmstorage. |
| VMAgent identity | IRSA — annotation EKS → IAM role | WIF — annotation iam.gke.io/gcp-service-account | Cùng pattern không key file; binding Terraform workloadIdentityUser. |
| VMAgent queue | S3 persistent queue | GCS persistent queue | remoteWrite.persistentQueue hỗ trợ cả S3 và GCS. |
| GCP-managed metrics | CloudWatch exporter | Stackdriver exporter + monitoring.viewer | Rate limit API — thường interval 60s trong VMServiceScrape. |
| Grafana access | ALB + ACM + Cognito/OIDC | ILB L7 + IAP + Google OIDC | IAP thay lớp auth edge (BeyondCorp) trước Grafana. |
| Security findings | Security Hub → SNS → Alertmanager | SCC Premium → Pub/Sub → webhook | Cùng flow cảnh báo; khác dịch vụ quản lý. |
| Billing alerts | Cost Explorer → CloudWatch alarm | Billing Export → BigQuery + VMRule | Dữ liệu chi phí đầy đủ trong BQ; có thể alert metric billing qua VMRule. |
Wiki HTML có thêm sơ đồ VMCluster full (~1020×620) và pipeline Vector/Fluentbit — không nhúng nguyên văn để giữ bundle nhẹ; bảng và bullet phía trên giữ đúng semantics (Tier A).
Secrets Management — OpenBao/Vault + ESO trên GCP
Secret Manager đủ cho static secrets và WIF-native. OpenBao/Vault khi cần dynamic secrets, cross-cloud, policy chi tiết hơn IAM. External Secrets Operator là bridge chuẩn từ store → Kubernetes Secret.
| Tiêu chí | GCP Secret Manager | OpenBao / Vault | ESO |
|---|---|---|---|
| Dynamic secrets | Chỉ static | Cloud SQL, IAM, PKI — TTL từng lease | Phụ thuộc backend |
| WIF / GKE auth | Native — annotation | K8s auth method | Dùng WIF cho SM backend |
| Secret versioning | Có rollback | KV v2 versioned | remoteRef.version |
| Cross-cloud | GCP only | Gom nhiều cloud / on-prem | Multi-store |
| Audit trail | Cloud Audit Logs | Vault audit log | Events trên ExternalSecret |
| Emergency revoke | Disable version | lease revoke-prefix | N/A |
| Cost / Ops | Managed, per-call | Self-hosted — vận hành HA | Open-source operator |
Wiki có sơ đồ OpenBao + ESO + SM trên GKE; ở đây giữ bảng so sánh và luồng vận hành tương đương Tier A.
GCP Workload Identity Federation — Deep Dive
Workload Identity bind Kubernetes ServiceAccount với GCP Service Account qua OIDC: metadata server trên node intercept, exchange token qua Cloud STS — không cần JSON key trên pod.
| AWS IRSA | AWS Pod Identity | GCP WIF | |
|---|---|---|---|
| Intercept | Webhook inject token | Agent DaemonSet IMDS | GKE Metadata Server |
| Token exchange | STS AssumeRoleWithWebIdentity | EKS → STS | Cloud STS token exchange |
| Trust config | IAM trust OIDC | pod_identity_association | IAM binding workloadIdentityUser |
| SA annotation | eks.amazonaws.com/role-arn | Không cần | iam.gke.io/gcp-service-account |
| DaemonSet needed | Không | eks-pod-identity-agent | Built-in GKE (metadata server) |
| Token TTL | 24h projected | 1h | 1h |
Wiki HTML có thêm flow runtime (metadata server → STS → GCP API) và các bước Terraform setup — có thể mở file gốc khi cần chi tiết từng bước; bảng trên bao phủ semantics chính (Tier A).