Chapters

Governance: keeping it fixed

Chapters 2 to 16 fixed Kadé's network one problem at a time. Every one of those fixes can be undone in a minute by someone with enough access: an external IP added "just to test", a firewall rule opened for a demo, a database switched back to a public IP. Governance is the set of tools that make the safe setup the only possible setup, and tell you quickly when something changes anyway.

Running it · chapter 24 of 26 · 10 min read

Why fixes drift back, and the two answers

A fix made by hand stays fixed only as long as nobody with access changes it. There are two kinds of answer, and a good setup uses both:

The fixed networkchapters 2 to 16as it should beConsole click"just to test"New projectdefault network againContractorold Owner accessPREVENTorg policiesfirewall policyIAM rolesVPC-SCrefusedwhat gets past preventionDrifted networka rule opened, an IPaddedDETECTaudit log alertsSecurity Command CenterAsset Inventory · drift planfound in minutesfixed again
#PreventDetect
1MeansThe risky change is refused when someone tries itThe change happens, and you find out quickly
2ToolsOrganization policies, hierarchical firewall policies, IAM roles, VPC Service ControlsAudit log alerts, Security Command Center, Cloud Asset Inventory, Firewall Insights
3StrengthNothing to clean up afterwardsCatches what prevention cannot express, and mistakes in the prevention itself
4RiskToo strict and it blocks real work; people look for ways around itToo noisy and alerts get ignored (chapter 16.2)

The resource hierarchy: where rules are set

Every GCP resource sits in a project, projects sit in folders, folders in the organization. IAM permissions and policies set high up are inherited by everything below. That is what makes governance possible: set a rule once on the folder, and every current and future project in it follows (chapter 5.2 used this for hierarchical firewall policies).

Organization kade.lkorg policies · IAM · firewall policyFolder productionstricter policies for live systemsFolder sandbox (example)looser, for experimentsProject kade-prodinherits both levels aboveProject kade-staginginherits both levels aboveProject dev-testsinherits org + sandboxinheriteddownward

Set a rule as high as it is true for everything below it. Stricter rules for live systems go on the production folder; experiments get their own folder.

Organization policies: how they work

An organization policy sets a constraint on a node of the hierarchy: "VMs in here may not have external IPs", "Cloud SQL in here may not have a public IP". It does not grant or remove anyone's access. It limits what anyone can create or configure, including Owners.

#Kind of constraintSettingsExample
1BooleanEnforced or notcompute.skipDefaultNetworkCreation: new projects get no default network
2ListAllowed values, denied values, or deny allrun.allowedIngress: only internal and internal-and-cloud-load-balancing
3CustomYour own condition on a resource's fields, for supported resource typesFor rules no built-in constraint expresses

Four behaviours decide whether a policy does what you expect. Each tab shows one:

Folder productionset: deny external IPs✕ external IPs refusedProject kade-prodnot set✕ inherited: refusedProject kade-stagingnot set✕ inherited: refused

Set once on the folder; every project, now and later, follows

The policy is set once, on the production folder. kade-prod and kade-staging have nothing set themselves, so they inherit it. A project created in the folder next year is covered the moment it exists.

Show as config
folders/production: compute.vmExternalIpAccess → denyAll
kade-prod:    (not set) → inherits denyAll
kade-staging: (not set) → inherits denyAll

The constraints that protect a network

These are the constraints that lock in this course's fixes. Pick an area; each card says what it blocks, which chapter's fix it protects, and Kadé's setting:

ConstraintTypeBlocksChapterKadé
compute.vmExternalIpAccesslistVMs with external IPs, except those listedch 3, 6.2deny all on production
compute.vmCanIpForwardlistVMs that can forward packets (routers, NAT VMs)ch 3, 4deny all
compute.requireOsLoginbooleanVMs without OS Loginch 6.2enforced on the org
compute.requireShieldedVmbooleanVMs without Shielded VM featuresch 12.2enforced on production
compute.disableSerialPortAccessbooleanSerial console access. Note: this also removes the break-glass path from chapter 6.1ch 6.1not set: Kadé keeps break-glass

Try it: which guardrail stops this?

Pick a risky change someone might make. The tool shows each layer it meets, in order, and which one refuses it, or which one at least notices:

  1. 1 · Org policySTOPS ITcompute.vmExternalIpAccess refuses it
  2. 2 · Hierarchical firewallnot reached
  3. 3 · IAM rolenot reached
  4. 4 · Detect (alert / SCC)not reached

Refused before it happened.

IAM for the network: who can change what

Organization policies limit what can exist. IAM decides who can change the things that are allowed. The basic roles are the problem:

#RoleCan change the network?Use
1roles/ownereverything, including IAM itselfOne or two break-glass accounts, not daily work
2roles/editoralmost everything: firewall rules, routes, IPsAvoid. It is the usual way "a developer opened port 22" happens
3roles/compute.networkAdminNetworks, subnets, routes, load balancers, NAT, VPN. Not firewall rules or certificatesWhoever builds the network
4roles/compute.securityAdminFirewall rules, firewall policies, SSL certificates and policiesWhoever owns security. Kept separate on purpose
5roles/compute.networkViewerRead onlyDevelopers who need to see, not change
6roles/compute.networkUserUse a (shared) subnet when creating resourcesService projects in a Shared VPC (chapter 14)
7roles/dns.admin, roles/compute.loadBalancerAdminOnly their own areaNarrow jobs
Network Admin and Security Admin are split so that the person who builds a path is not automatically the person who opens the firewall on it. In a one-person team both land on the same person, but the habit of using narrow roles still keeps everyone else out.
WHO CAN CHANGE WHAT, AFTER THE CLEAN-UPkade-platform@ groupon folder productionNetwork Admin + Security AdminDevelopersread onlyNetwork ViewerCI service accountwrites from reviewed codeNetwork Admin + Security AdminBreak-glass (2 accounts)used only in emergencies, alertedOwnerWhat each can changesubnets, routes, LB, NAT, VPNnetworkAdminfirewall rules, SSL policiessecurityAdminlook at everythingnetworkVieweranything, incl. IAMowner
#HabitWhy
1Grant to groups, not peoplekade-platform@kade.lk holds the roles; people join and leave the group. One place to see and remove access
2Grant high, narrowlyNetwork roles on the folder cover staging too; developer roles on single projects
3Time-limit special accessAn IAM condition with an expiry date for a contractor or an incident (chapter 6.1 did this for IAP)
4Remove what is unusedThe IAM Recommender lists permissions not used in 90 days
5No service account keysA leaked key file works from anywhere. Workload identity and attached service accounts need no keys; the constraint iam.disableServiceAccountKeyCreation enforces it

VPC Service Controls: a perimeter around Google APIs

Firewall rules protect traffic to your VMs. They cannot protect Google APIs such as Cloud Storage or BigQuery: those are reached over Google's public endpoints, and IAM alone decides who can call them. If credentials leak, the attacker can download Kadé's data from anywhere. VPC Service Controls draws a perimeter around projects, so their protected APIs only answer requests from inside the perimeter, and data can only be copied to projects inside it.

service perimeter · kade-prodkade-workerinside kade-prodCloud Storagekade-prod bucketsBigQuerysales data

Allowed: both sides inside, IAM decides as usual

kade-worker, inside kade-prod, reads a product photo from Cloud Storage. Both the caller and the bucket are inside the perimeter, so the request is checked by IAM as usual and allowed.

Show as config
perimeter kade-prod-perimeter: projects kade-prod
restricted services: storage.googleapis.com, sqladmin.googleapis.com, bigquery.googleapis.com
#PieceJob
1Service perimeterA set of projects and the APIs protected for them
2Access levelA rule for letting in requests from outside: the office IP range, or company-managed devices
3Ingress and egress rulesNarrow exceptions: "this outside service account may read this bucket"
4restricted.googleapis.comThe private API addresses that only serve perimeter-supported APIs (chapter 9)
5Dry-run perimeterLogs what would be blocked without blocking it. Always run it for a few weeks first
VPC Service Controls adds work and breaks things that are not planned for (third-party tools reading your buckets, a CI system outside GCP). It earns its place when the data is sensitive: payments, personal data. Kadé starts with a dry-run perimeter around kade-prod.

Detect: finding what changed, and what is already wrong

#ToolAnswersCost
1Audit logs + log-based alert"Someone just changed a firewall rule, route or external IP." Admin Activity logs are always on (chapter 16.1); an alert on them tells you within minutesFree logs; a small metric
2Security Command Center"What is risky right now?" Findings such as an open firewall, an SSH port open to the internet, a public IP on a VM, a public Cloud SQL instance, flow logs disabledStandard tier included; Premium adds more detectors
3Cloud Asset Inventory"Show me every external IP, every firewall rule from 0.0.0.0/0, every Owner, across the organization." One search instead of project-by-project clickingIncluded
4Firewall Insights, Network AnalyzerUnused and overly broad rules; misconfigurations (chapter 16.2)Included
5IAM Recommender, Policy Analyzer"Who can change firewall rules in kade-prod, and through which role?"Included

The network written down: infrastructure as code

The strongest answer to "what should the network look like?" is a file. With Terraform (or a similar tool), the network from this course is described in code, kept in Git, reviewed before it changes, and applied by a CI job. A console change then shows up as drift: the next plan says "the real firewall differs from the code".

Change in Gitpull requestReviewa second pair of eyesCI: terraform planshows the exact diffCI: terraform applyonly writer in kade-prodGCPkade-vpc, rules, LB…Console changesomeone opens port 22Daily drift plan"firewall rule differs from code"detected next morning, or by the audit log alert in minutes
#RuleWhy
1Only the CI service account holds network write roles in kade-prodPeople change the network by changing code, which gets reviewed
2Humans keep Network Viewer, plus a break-glass group for emergenciesIncidents still need hands; every use of break-glass is visible in the audit log
3A scheduled plan (daily) reports driftCatches changes made outside the pipeline
4Start by importing what existsRewriting a working network from scratch is a risk of its own; import, then improve
Infrastructure as code is a subject of its own. For this course, the point is the governance one: a written, reviewed description of the network is what turns "is this right?" from memory into a diff.

Rollout plan

In order of protection gained per hour spent, for a platform starting with Owners everywhere and no policies:

  1. 1.Day 1

    about an hour

    • Remove the freelancer and unused Owners
    • Two break-glass Owners; everyone else to narrow roles via a group
    • Alert on firewall, route and address changes
  2. 2.Week 1

    a few hours

    • Find violations with Asset Inventory and fix them
    • Org: skip default network, require OS Login
    • Folder: no external IPs, no public Cloud SQL, Cloud Run ingress
  3. 3.Month 1

    spread out

    • Security Command Center findings reviewed weekly
    • No service account keys
    • Dry-run VPC Service Controls perimeter
  4. 4.Later

    when stable

    • Import the network into Terraform; CI as the only writer
    • Enforce the VPC-SC perimeter after a clean dry run
    • Custom constraints for gaps

Back to Kadé

Commands in this chapter

Commands 1 to 5 are read-only. Commands 6 to 8 change the organization; run them with the organization or folder ID, after dry run.

What policy actually applies to a project?

  • What it shows: The effective policy for one constraint on kade-prod, after inheritance and merging.
  • What to look for: enforce: true or the allowed and denied values you expect. If it is empty, nothing above sets it.
gcloud org-policies describe compute.vmExternalIpAccess --project=kade-prod --effective

List the policies set on the folder

  • What it shows: Every constraint with a policy set directly on the production folder.
  • What to look for: The constraints from section 11's table.
gcloud org-policies list --folder=FOLDER_ID

Find every external IP in the organization

  • What it shows: Reserved and in-use external addresses across all projects.
  • What to look for: Anything besides the load balancer and NAT IPs. Fix these before enforcing vmExternalIpAccess.
gcloud asset search-all-resources --scope=organizations/ORG_ID \  --asset-types=compute.googleapis.com/Address --query="addressType:EXTERNAL" \  --format="table(displayName,project,location,additionalAttributes.address)"

Who holds Owner or Editor?

  • What it shows: Every IAM binding granting the basic roles, anywhere in the organization.
  • What to look for: Individual users and former contractors. The goal is two break-glass Owners and no Editors.
gcloud asset search-all-iam-policies --scope=organizations/ORG_ID \  --query="policy:(roles/owner OR roles/editor)" --format="table(resource,policy.bindings.role,policy.bindings.members)"

Who can change firewall rules in kade-prod?

  • What it shows: Every identity that holds the permission to update firewall rules, and through which role and level.
  • What to look for: Only the platform group and the CI service account.
gcloud asset analyze-iam-policy --organization=ORG_ID \  --full-resource-name=//cloudresourcemanager.googleapis.com/projects/kade-prod \  --permissions=compute.firewalls.update

Block external IPs on VMs in the folder, dry run first (changes the organization)

  • What it shows: A policy file with a dry-run spec only: violations are logged, nothing is blocked. Move the rules to spec to enforce.
  • What to look for: Dry-run violations in the audit logs for a week; zero means it is safe to enforce. Dry run is not available for every constraint; where it is not, preview with the Policy Simulator in the console, and fix what command 3 found first.
cat > no-external-ip.yaml <<'EOF'name: folders/FOLDER_ID/policies/compute.vmExternalIpAccessdryRunSpec:  rules:  - denyAll: trueEOFgcloud org-policies set-policy no-external-ip.yaml

Require OS Login and skip default networks, organization-wide (changes the organization)

  • What it shows: Two boolean constraints enforced on the organization.
  • What to look for: Command 1 on any project shows enforce: true. A new test project has no default network.
gcloud org-policies set-policy require-oslogin.yaml        # constraints/compute.requireOsLogin, enforce: truegcloud org-policies set-policy skip-default-network.yaml   # constraints/compute.skipDefaultNetworkCreation, enforce: true

Alert on network changes (changes the project)

  • What it shows: A log-based metric counting changes to firewall rules, routes, addresses and security policies, for an alert to watch (chapter 16.2).
  • What to look for: The counter rising when you change a test rule; the alert's notification arriving.
gcloud logging metrics create kade_network_changes \  --description="Changes to firewall rules, routes, addresses, security policies" \  --log-filter='logName:"cloudaudit.googleapis.com%2Factivity" AND    (protoPayload.methodName:("compute.firewalls." OR "compute.routes." OR     "compute.addresses." OR "compute.securityPolicies."))'

Spotted a mistake, or something unclear? Suggest an edit on GitHub