gcpemu

module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0

README

gcpemu

A single Go binary that emulates a subset of Google Cloud's Products on a workstation or in CI, so the same OpenTofu modules, client SDKs and application code that target GCP run unmodified except for Endpoint overrides. See the SRS.

Status

Milestones M1 (core, IAM, Cloud Storage, Pub/Sub, Cloud DNS, Artifact Registry), M2 (compute networking, Cloud SQL, GKE, Cloud NAT) and M3 (Application Load Balancer, Cloud CDN, backend mTLS, Certificate Manager, Host mode) are implemented. The full SRS 11.2 Reference stack (steps 1–10) passes on linux/amd64 (make e2e).

Area Package Highlights
Core internal/… CLI, API gateway (REST + gRPC on one port), admin API, store (memory/bbolt), seed files, fault injection, request log
IAM services/iam Service accounts and keys, roles, policies with conditions, IAM v2 deny policies on projects, audit/enforce, OAuth2 token endpoint, IAM Credentials, metadata server, STS/WIF (OIDC exchange; AWS and SAML providers managed only), Service Usage (enabled APIs per project)
Cloud Storage services/gcs JSON + XML APIs, resumable uploads, generations/preconditions, checksums, V4 signed URLs, notifications, lifecycle, HMAC, legacy ACLs, managed folders with IAM
Pub/Sub services/pubsub gRPC + REST, streaming pull, ordering, DLQ, filters, push with OIDC, exactly-once, snapshots/seek, schemas
Secret Manager services/secrets gRPC + REST, global and regional secrets, versions and aliases, IAM, expiry and delayed destruction on the Emulator clock, Pub/Sub event notifications, managed rotation of Cloud SQL passwords
Cloud DNS services/dns Zones, record sets, changes, zone IAM policies; server policies (recorded); response policies applied to bound VPC networks; authoritative UDP/TCP server with forwarding
Artifact Registry services/ar Repositories API with Operations; OCI Distribution v1.1 registry with referrers; pull-through cache, remote and virtual repositories
Compute networking services/compute Networks, subnetworks, firewalls, routes, addresses, routers, zonal/regional/global NEGs, operations; servicenetworking; subnetworks realised as container networks; VPC peering (recorded)
Cloud NAT services/compute, services/nat Router NAT configs drive the NAT egress proxy container; drop/reject, logging, offline sink
Cloud SQL services/sql sqladmin v1beta4/v1 over real PostgreSQL 14–18 containers; connector (3307), IAM DB auth, authorized networks, private IP, backups, import/export, executeSql (Data API)
GKE services/gke container v1 (gRPC + REST) over real k3s clusters; node pools, IAM-backed kube auth, Workload Identity, private nodes via NAT, NEG sync, Ingress (gce) and Gateway API (gke-l7-global-external-managed, gke-l7-gxlb) controllers building load balancers, real-hostname Google APIs in pods; Connect gateway (connectgateway v1) to each cluster's Kubernetes API; Gateway API CRDs, the Secret Manager add-on (secrets-store-gke.csi.k8s.io) and SecretSync from cluster settings
Application Load Balancer services/lb Forwarding rules, proxies, URL maps, backend services/buckets, health checks, SSL certs/policies; in-process L7 proxy with frontend/backend mTLS, NEG and bucket backends, access logs; Cloud Armor policies, TCP/SSL/gRPC proxies and legacy health checks (recorded)
Cloud CDN services/cdn Cache modes, keys, TTLs, revalidation, negative caching, signed URLs/cookies, invalidation, LRU disk cache
Certificate Manager, Network Security services/certs Certificates (self-managed and managed via the local CA), maps, trust configs, DNS authorizations; backend authentication configs, server TLS policies

Quick start

make build
bin/gcpemu start --detach --services gcs,pubsub --seed seed.yaml
eval "$(bin/gcpemu env)"       # STORAGE_EMULATOR_HOST, PUBSUB_EMULATOR_HOST, GCE_METADATA_HOST, …
bin/gcpemu status
bin/gcpemu tofu-provider --project my-project   # provider "google" block with Endpoint overrides
                                                # (--beta adds a "google-beta" block)
bin/gcpemu console              # the Web console in the default browser
bin/gcpemu stop

Other commands: reset, logs [service] [--requests], time advance 24h, hosts, fault add|list|enable|disable|clear, snapshot save|restore|list|delete, export (the resources as a seed file), doctor, prune, version, admin openapi (the OpenAPI document of the /_emu/v1/ admin API, also served at /_emu/v1/openapi.yaml), and admin token.

State snapshots

gcpemu snapshot save NAME saves all of a running Instance's state, and snapshot restore NAME puts it back, undoing everything done since. A snapshot holds the control-plane store, GCS and Artifact Registry blobs, and a pg_dumpall of every Cloud SQL instance with its backup files. snapshot list and snapshot delete NAME manage them. Snapshots live in the instance dir under snapshots/, beside the data directory, so an Ephemeral Instance's snapshots outlive it and a later Instance of the same name restores them. That makes a snapshot a fast test fixture:

gcpemu start --detach --seed fixtures.yaml && gcpemu snapshot save clean
# ... run a test ...
gcpemu snapshot restore clean   # instead of re-seeding

Saving needs a quiet Instance: it fails while a Service is still starting, an Operation is running, a Cloud SQL instance is stopped, or clients keep changing state during the save. Restoring keeps configuration, Fault rules and the Emulator clock, which never goes back. A RUNNING GKE cluster keeps its Kubernetes objects and its cluster CA: its k3s datastore is saved, and its nodes rejoin and pull their images again. PersistentVolume contents are not saved, so volumes come back empty, and a cluster that is not RUNNING at save time comes back with a fresh data plane.

Windows

Download gcpemu-windows-amd64.exe or gcpemu-windows-arm64.exe from a release, check it against SHA256SUMS (certutil -hashfile gcpemu-windows-amd64.exe SHA256), and rename it to gcpemu.exe somewhere on PATH. No installer, zip or administrator rights are needed.

Natively, every Service runs in-process except Cloud SQL, GKE and Cloud NAT, which need a container runtime that native Windows can't use (ADR 0008). Docker Desktop's networks live inside its WSL2 VM, where the host can't route, so gcpemu.exe ignores the runtime even when DOCKER_HOST is set. With the default Service list it skips those three and logs that they need WSL2. Naming one of them in --services, or passing --host-mode, fails at start. For those, run the Linux binary inside WSL2. The load balancer runs natively, and Windows has no privileged ports, so a forwarding rule binds its own port directly.

State lives under %LOCALAPPDATA%\gcpemu\<instance> unless XDG_STATE_HOME or --data-dir says otherwise. Windows doesn't enforce file modes such as 0600, so the per-user ACL on that directory protects the CA key and the admin token.

gcpemu env prints bash by default, so from Git Bash run eval "$(gcpemu env)". From PowerShell, ask for PowerShell syntax (pwsh works too):

gcpemu env --shell powershell | Out-String | Invoke-Expression

Windows PowerShell 5.1 reads a program's output in the console's OEM code page, so if a path such as your profile folder has non-ASCII characters, run [Console]::OutputEncoding = [Text.Encoding]::UTF8 first. PowerShell 7 already reads UTF-8.

Binding beyond loopback

--bind (e.g. 0.0.0.0) exposes every listener beyond this host, with a warning, and is refused with IAM off unless --i-understand-this-is-insecure is passed. The admin API (/_emu/) and the Web console then need an admin token (docs/adr/0006-admin-token-guards-admin-api.md): a random one per start, or GCPEMU_ADMIN_TOKEN (at least 32 characters). gcpemu start prints the console URL with the token on stderr, and opening it swaps the token for a cookie; scripts send it in the X-Gcpemu-Admin-Token header. gcpemu commands on the same host read it from the instance directory, gcpemu admin token prints it, and gcpemu env exports it as GCPEMU_ADMIN_TOKEN. GET /_emu/v1/health and /ready stay open for probes, and the public GCP APIs are governed by IAM as usual.

Web console

The API gateway serves the Web console at http://127.0.0.1:4510/console/; gcpemu console opens it. It calls only the public APIs and the admin API, and works offline. It acts as the default principal until you pick another user or service account in the header's principal switcher, so the views show what IAM allows that principal (try it with --iam-mode enforce). The choice is kept per browser and is not part of a shared link. --console=false turns it off; under CI=true it is off unless --console is passed. make build builds it when pnpm is on PATH (Node.js 24); without it the binary serves a "console not built" page. It reaches GKE clusters' Kubernetes objects and pod logs through the Connect gateway (/connectgateway/v1/projects/P/locations/L/gkeMemberships/CLUSTER/..., see docs/adr/0002-kubernetes-api-through-connect-gateway.md), which kubectl can use too. Its Cloud SQL query runner uses instances.executeSql (the Data API), so an instance needs settings.dataApiAccess set to ALLOW_DATA_API; statements run read-only unless unticked. Unlike Cloud SQL, the emulator lets executeSql name a built-in user without a password. Its Load Balancer view reads each forwarding rule's local listener from GET /_emu/v1/lb/listeners, and "test a URL" asks POST /_emu/v1/lb/route which route and backend of a URL map would serve a host, path and headers, without sending the request. Its traffic tab (/console/lb/traffic, filtered by ?host= and ?path=) traces each request live from the request log, whose lb entries carry the matched route, backend, network endpoint, cache status and backend latency; it shows the newest 500 that match. Its Cloud CDN view treats a backend service or bucket with enableCdn as an origin: adding, editing and removing one patches its cdnPolicy and enableCdn, and invalidation is urlMaps.invalidateCache. Each origin's cached entries and hit ratio come from GET /_emu/v1/cdn and GET /_emu/v1/cdn/entries, and "Purge all" is POST /_emu/v1/cdn/purge; hit and miss totals survive a purge and are cleared by gcpemu reset. Its Artifact Registry view lists repositories in every location by asking each one in turn, as the API lists one location at a time. Deleting a digest deletes the tags on it too (versions.delete with force). Pull commands name LOCATION-docker.pkg.dev when Host mode is ready and the registry port (127.0.0.1:5000/LOCATION-docker.pkg.dev/...) otherwise. Its Cloud DNS view edits record sets only through changes.create (an edit deletes and re-adds the record set in one change), and deleting a zone first deletes its record sets in one change. Its query box asks GET /_emu/v1/dns/query?name=N&type=T[&network=projects/P/global/networks/V], which sends the query to the Instance's DNS server, from the host or as a client on that VPC network, so private zones answer only on the networks they are bound to. Its Cloud NAT view edits a NAT gateway by patching its router's nats[] with the whole list; port usage is routers.getNatMappingInfo. Its translation log (/console/nat/translations, filtered by ?src=, ?dst= and ?outcome=) reads the request log's nat entries, which carry each connection's source, destination, workload and NAT IP and port. The offline sink switch is GET/PUT /_emu/v1/nat/sink; it lasts until the Instance stops. Its IAM view edits the policy of a Project, service account, bucket, topic, subscription, AR repository, secret, subnetwork or TLS policy through that resource's own setIamPolicy, carrying the etag it read. Its policy simulator gets a token for the chosen Principal from the OAuth2 refresh token grant (the emulator takes user:EMAIL or serviceAccount:EMAIL as the refresh token), calls the resource's testIamPermissions with it and revokes it. The IAM enforcement level is switched with PUT /_emu/v1/iam/enforcement until the Instance stops. Its audit view (/console/iam/audit, filtered by ?q= and ?status=missing|granted) lists GET /_emu/v1/iam/denials: every call IAM found the caller lacking a permission for, once per Principal, permission and resource, with the smallest predefined role that grants it and the Project owning the resource. Grant binds that role on that Project through its setIamPolicy. A call an IAM v2 deny policy refused is listed separately, naming the policy (denyPolicy) and no role, since no grant overrides a deny. The log lives in memory until the Instance stops or is reset; DELETE /_emu/v1/iam/denials clears it. Its Fault rules view (/console/faults, filtered by ?service= and ?q=) lists GET /_emu/v1/faults with each rule's hit count, adds rules with POST /_emu/v1/faults, and enables or disables one with PATCH /_emu/v1/faults/ID and {"disabled": true|false}, as gcpemu fault enable|disable ID do. A disabled rule keeps its hit count and does not fire; a seed file's rule may start with disabled: true. Its Request log view (/console/requests, filtered by ?service=, ?method=, ?principal=, ?status= and ?resource=) tails GET /_emu/v1/requests live, newest first, and keeps up to 100,000 rows in the browser. A status filter is a number (404), a class (5xx) or a code name (NOT_FOUND). Expanding an entry reads GET /_emu/v1/requests/ID, which adds the request and response bodies. The Instance keeps the first 16 KiB of each API call's bodies, and a unary gRPC message as protojson, for as long as the entry stays among the last 2,000 it logs. Its State view (/console/state) saves, restores and deletes State snapshots, resets the Instance, applies a seed file chosen or pasted into it (POST /_emu/v1/seed with the YAML as the body, whose relative paths resolve against the instance dir), and downloads the Instance's resources as a seed file (GET /_emu/v1/seed, as gcpemu export prints). An exported seed file holds Projects, each Service's resources and the Fault rules, with GCS object content inline; server-assigned fields and data plane contents (Postgres rows, Kubernetes objects, Pub/Sub messages) are left out.

Service endpoints

All Control plane APIs are served by the API gateway (default 127.0.0.1:4510), under /<api>/ (for example /pubsub/v1/…, /iam/v1/…) and at their native root paths where unambiguous (/storage/v1/, /dns/v1/, /compute/v1/, /sql/v1beta4/). Per-Service ports: GCS 4443, Pub/Sub 8085, registry 5000, DNS 5353 (UDP+TCP), metadata 8988, Cloud SQL host ports 54320+. gcpemu env also exports KUBECONFIG for GKE clusters. --port name=0 picks a free port for one listener and a bare --port 0 for all of them (LB and Cloud SQL host ports included); --port-range 20000-20999 draws those free ports from a range. The choices are written to <data-dir>/endpoints.json and printed by gcpemu env.

To reach a load balancer from another device (say, a phone on the LAN), pass --lb-bind <address> (repeatable; lbBind / GCPEMU_LB_BIND). Every forwarding rule is then also served on <address>:<its port>, while the admin API, the API gateway and every other Data plane stay on --bind. Nothing else is exposed, so --lb-bind doesn't need --i-understand-this-is-insecure. The emulator binds the port itself when it can. When the port is privileged (net.ipv4.ip_unprivileged_port_start above it), a labelled gcpemu-<id>-lb-lan container on the host network listens there and relays to the emulator. That fails on a VM runtime, whose host network is the VM's. On macOS no container is used: a forwarding rule on a port below 1024 listens on the wildcard address, which serves only loopback and --lb-bind addresses. If two forwarding rules share a port, only one gets the address. gcpemu status lists each rule's addresses as lb-lan:<name>, and gcpemu doctor checks the addresses before start and lists them while running.

To manage GKE clusters and push images from another machine (say, Argo CD and BuildKit in another cluster on the LAN), pass --gke-bind <address> and --ar-bind <address> (both repeatable; gkeBind / GCPEMU_GKE_BIND, arBind / GCPEMU_AR_BIND). As with --lb-bind, the admin API and every other listener stay on --bind, and neither flag needs --i-understand-this-is-insecure (docs/adr/0011-lan-binding-requires-credentials.md).

  • --gke-bind: each cluster's Kubernetes API is also served on <address>:<a port of its own>, kept across restarts, and the API server's certificate covers the address. <data-dir>/kubeconfig-lan points at the first address with the cluster's admin client certificate, and GET /container/_emu/kubeconfig?cluster=…&lan=true (or lan=<address>) returns the same for one cluster. Service account tokens and emulator IAM access tokens work too. Anonymous requests are refused, and an unknown bearer token no longer maps to the default principal at any IAM enforcement level, on loopback as well.
  • --ar-bind: the registry is also served on <address>:<the registry's port>, falling back to a free port when that one is taken. It serves TLS with a certificate from the instance CA, so clients trust <data-dir>/ca.pem (for docker, as /etc/docker/certs.d/<address>:<port>/ca.crt). Every request needs credentials, whatever the IAM enforcement level: docker login -u oauth2accesstoken -p <access token>, or -u _json_key with a service account key for a long-lived one such as BuildKit's. IAM permissions are then checked as on loopback. Clients are challenged for Basic credentials, because crane and ko refuse a token realm on a private IP address.

gcpemu status lists the addresses as gke-lan:<context> and ar-lan.

Container runtime

Cloud SQL, GKE and Cloud NAT need Docker Engine (>= 24) or Podman (>= 4.9, Docker-compatible socket), and on Windows they need WSL2 (see "Windows" above). On macOS, Docker Desktop, OrbStack, Colima and Podman machine work too. The emulator uses DOCKER_HOST first, then the Docker context (DOCKER_CONTEXT, or the current context in ~/.docker/config.json), then the first well-known socket that responds. If DOCKER_HOST or a context other than default names a runtime that doesn't respond, start fails rather than using another one, so gcpemu and docker always agree. gcpemu doctor shows the runtime it picked and why. Everything the emulator creates is labelled gcpemu.instance=<id> and gcpemu.dir=<data dir>; containers are removed on stop, and with --data-dir the volumes holding Postgres and Kubernetes state are kept so resources survive a restart. When a data dir is deleted, or a run crashes and never starts again, nothing reclaims its objects: gcpemu doctor warns about such abandoned Instance IDs, and gcpemu prune lists their containers, networks and volumes and removes them once you confirm (--yes skips the question). An ID with a running container is never touched.

On a VM runtime, host clients reach Cloud SQL instances, forwarding rules and GKE LoadBalancer Services on loopback addresses: a 127.0.0.x of their own each. A GKE cluster's endpoint is 127.0.0.1 and a port the emulator serves, so gcloud container clusters get-credentials writes a kubeconfig that works from the host. Linux and Windows route all of 127.0.0.0/8 to loopback, so they need no loopback aliases, but macOS has only 127.0.0.1, so there only one Cloud SQL instance is reachable and forwarding rules and LoadBalancer Services share 127.0.0.1: each on its own port, or a free one when an earlier one holds it, as gcpemu env shows. That needs no container runtime. sudo gcpemu loopback install adds 127.0.0.2–127.0.0.254 to lo0 and installs a LaunchDaemon that adds them again at boot; sudo gcpemu loopback uninstall removes both. gcpemu doctor reports whether they are present.

When a subnetwork's range overlaps another network on the host, its container network runs on a free range instead and keeps the subnetwork's addresses on a VLAN of each container's interface (a Translated network, ADR 0004). That needs VLAN (8021q) support in the runtime's kernel, which on macOS is the VM's kernel. Without it, only the Translated network fails, with an error naming the runtime; give the subnetwork a range that doesn't overlap, and everything else keeps working.

Runtime VLAN (8021q) support
Docker Desktop not yet checked
Colima not yet checked
OrbStack not yet checked
Podman machine not yet checked

The emulator copies a static linux gcpemu binary into containers as a Sidecar agent, for the runtime's architecture. On a linux host of that architecture it's its own executable. Otherwise it uses GCPEMU_AGENT_BINARY, then gcpemu-linux-<arch> next to the executable, then the copy cached in the instance directory under agent/<version>/linux-<arch>/. A release build (vX.Y.Z) with none of these copies it out of the published image of the same version (ghcr.io, then Docker Hub) and caches it. A dev build needs make agent instead. A binary for the wrong architecture fails the start with an error naming both.

Cloud NAT knobs: natReject / GCPEMU_NAT_REJECT=true rejects uncovered egress immediately instead of timing out; with --offline (or the offline sink switched on from the Web console), NAT-allowed egress hits a sink that records the attempt and returns natSinkResponse (GCPEMU_NAT_SINK_RESPONSE, default 503:gcpemu offline: egress blocked). Each workload a NAT serves gets a block of minPortsPerVm ports (default 64, 32 with dynamic port allocation) on ports 1024-65535 of the NAT's IPs, in address order; AUTO_ONLY NATs gain IPs as workloads join, and on MANUAL_ONLY a workload that doesn't fit gets no ports, so its egress is dropped and getRouterStatus reports minExtraNatIpsNeeded. NAT IPs are emulated: the NAT egress proxy translates onto the workload's port block on its own external address, reusing a port per destination; endpoint-independent mapping caps a workload's concurrent connections at its block, and dynamic port allocation lets it grow to maxPortsPerVm. Mapping info, status and NAT logs name the NAT IP the block stands for. GCPEMU_GKE_MAX_NODES caps nodes per instance (default 5). LoadBalancer Services are given node addresses on the cluster's VPC by k3s's built-in service load balancer (servicelb), the emulator's in-cluster L4 allocator (FR-GKE-009). On a VM runtime, or when the cluster's subnetwork is a Translated network, the host can't reach node addresses, so the emulator serves them instead: on a loopback address, reported as the Service's ingress and by gcpemu env as GCPEMU_GKE_<CLUSTER>_<NAMESPACE>_<SERVICE>_<PORT>, and relayed to the Service's node port. Only TCP ports are served. When the emulator itself runs in a container, see "Container image".

Pods reach an external load balancer by its public address, as on GCP: the emulated DNS answers them with the forwarding rule's own IP (host clients still get the local listener), and the lb-edge container serves those IPs on the external network. Nodes with external IPs route them to it directly, and the backend sees the node's address; private nodes go through Cloud NAT, so they need one, and the backend sees the NAT's address (ADR 0007).

Real hostnames: GKE pods and host mode

The emulator includes a Google front end (Service endpoint frontend, a dynamic port unless you pass --port frontend=N). It terminates TLS for the real hostnames the API gateway serves (storage.googleapis.com, pubsub.googleapis.com, sqladmin.googleapis.com, iamcredentials.googleapis.com, oauth2.googleapis.com, …) and for every LOCATION-docker.pkg.dev. Certificates come from the instance CA (<data-dir>/ca.pem). It then passes HTTP/1.1, HTTP/2 and gRPC through to the emulator unchanged. APIs the emulator doesn't serve (logging.googleapis.com, …) are never redirected.

GKE pods use real hostnames automatically. Each node answers DNS for the served names with 169.254.169.254 and relays port 443 there to the Google front end. A mutating admission webhook mounts a bundle of the host's system roots plus the emulator CA at /etc/ssl/certs/ca-certificates.crt and /etc/gcpemu/certs/. It also sets SSL_CERT_FILE, REQUESTS_CA_BUNDLE, NODE_EXTRA_CA_CERTS and GCE_METADATA_HOST. Unmodified Go, Python, Java and Node clients get Workload Identity tokens from the metadata server and reach the emulated Services without any Endpoint override. To opt a namespace or a pod out, label it gcpemu.dev/inject=disabled; kube-system is always skipped. Nodes also trust the CA in their own system store.

Host mode (gcpemu start --host-mode, Linux only: elsewhere start refuses it) does the same for host processes without root. It starts a labelled container (gcpemu-<id>-hostmode) that the host reaches at its container IP. The container serves HTTPS on :443, plain HTTP on :80 and DNS on :53, answering the served names with its own IP. It forwards other googleapis.com/pkg.dev names to your real upstream resolvers and everything else to the emulated Cloud DNS. gcpemu env prints the IP as GCPEMU_HOST_MODE_IP and writes setup steps to stderr. There are two ways to send the names there:

# per-domain DNS routing with systemd-resolved (lasts until the bridge restarts)
sudo resolvectl dns <bridge-if> <ip> && sudo resolvectl domain <bridge-if> ~googleapis.com ~pkg.dev
# or a static /etc/hosts block (remove it when done)
gcpemu hosts | sudo tee -a /etc/hosts

Then trust the CA system-wide with gcpemu ca install. On Linux it also adds the CA to Docker's and containerd's per-registry trust for every LOCATION-docker.pkg.dev, and, with certutil (libnss3-tools), to the browser NSS databases: Chrome's ~/.pki/nssdb and every native, snap and flatpak Firefox profile. Colima and Podman machine keep their own registry trust inside their VM, so for them ca install prints the command to run there; Docker Desktop and OrbStack use the macOS keychain. gcpemu ca rotate replaces it in those databases, and gcpemu doctor reports where it is trusted. Or trust it per shell with eval "$(gcpemu env --trust)". That sets SSL_CERT_FILE to <data-dir>/ca-bundle.pem, which holds the system roots (on Windows, exported from the ROOT certificate store) plus the emulator CA. gcpemu env always exports GCPEMU_CA_FILE. To test without changing the host, use curl --resolve storage.googleapis.com:443:<ip> --cacert "$GCPEMU_CA_FILE" …, or give Go clients a net.Resolver that dials <ip>:53.

Configuration

Flags > GCPEMU_* env vars > gcpemu.yaml > defaults. CI=true implies --ephemeral, JSON logs and no Web console. The IAM enforcement level is audit by default (--iam-mode off|audit|enforce); PUT /_emu/v1/iam/enforcement with {"level":"enforce"} switches it while the Instance runs. IAM v2 deny policies (google_iam_deny_policy, /iam/v2/policies/…/denypolicies) are checked before any allow policy and bind every Principal they name, the Default principal included; internal calls with no Principal are exempt. Under audit a denied call is logged and allowed. Denial conditions on request.time and resource.* are evaluated; conditions on resource tags are refused, since the emulator has no tags.

Seed files

Top-level keys are projects, faults and Service IDs (iam, compute, gcs, pubsub, dns, ar, sql, gke). Each Service documents its section in its seed.go.

Go tests
inst := emutest.Start(t, []string{"gcs", "pubsub"})
inst.Setenv(t) // client env vars for this test
GitHub Actions
- uses: linuxuser586/gcpemu/setup-gcpemu@v0
  with:
    services: gcs,pubsub,sql
    seed: test/emu-seed.yaml

This installs the release binary after checking it against SHA256SUMS, and starts the instance once the seed has been applied. It exports gcpemu env to later steps. When the job fails, it uploads the logs, request log, resource dump and kubeconfig as an artifact. See setup-gcpemu/README.md. Releases are published from vX.Y.Z tags, and each one moves its major tag. Until v1.0.0 that tag is @v0; pin @v0.1.0 for an exact release.

Container image

Each release is also a multi-arch (amd64, arm64) distroless image, running as a non-root user, at docker.io/linuxuser586/gcpemu and ghcr.io/linuxuser586/gcpemu. It is tagged X.Y.Z, X.Y, X and latest; a prerelease gets only its exact version.

docker run -d --name gcpemu -p 4510:4510 -p 4443:4443 -p 8085:8085 \
  -v gcpemu:/data linuxuser586/gcpemu:0
docker exec gcpemu /gcpemu status

The image binds 0.0.0.0 at IAM enforcement level audit, keeps state in /data (mount a volume to keep it across containers, or set GCPEMU_EPHEMERAL=true), and reports healthy once every Service is ready (gcpemu status --ready). Because it is not bound to loopback, the admin API and the Web console need the admin token (see "Binding beyond loopback"): docker logs gcpemu shows the console URL with it, docker exec gcpemu /gcpemu admin token prints it, and -e GCPEMU_ADMIN_TOKEN=... sets it. Load balancer forwarding rules listen on their own ports, so publish those with extra -p flags.

Cloud SQL, GKE and Cloud NAT start containers of their own, so they need the host's Docker socket (Docker-outside-of-Docker). Without the socket the image starts every other Service and logs which it skipped. With it, the emulator stays unprivileged and non-root; it needs only the socket's group:

docker run -d --name gcpemu -p 4510:4510 -p 4443:4443 -p 8085:8085 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  --group-add "$(stat -c %g /var/run/docker.sock)" \
  linuxuser586/gcpemu:0 start --ephemeral

The emulator finds its own container and joins the networks it creates (taking each subnetwork's reserved second-to-last address), so it works on a normal bridge or compose network as well as with --network host. Privileged GKE nodes get their privilege from the Docker daemon, not from the emulator's container. From the host:

  • Cloud SQL instances are published on 127.0.0.1 (GCPEMU_SQL_* ports, as on the host). The Cloud SQL Auth Proxy and connectors dial the instance IPs on the emulator's bridge networks, which a Linux host reaches directly (Docker Desktop does not).
  • GET /container/_emu/kubeconfig?cluster=projects/P/locations/L/clusters/C returns a kubeconfig whose server is the cluster's API published on 127.0.0.1; the Connect gateway (/connectgateway/v1/...) works through the API gateway port.
  • A GKE LoadBalancer Service's ingress is a node address that a Linux host reaches directly: servicelb's on an ordinary network, and on a Translated network every Ready node's Fallback-range address, served by the cluster itself (gcpemu env prints the first). On a VM runtime, see below.
  • Use --ephemeral (or a volume on /data): stopping an ephemeral instance removes all of its containers, networks and volumes, while a persistent one keeps them for its next start.

On a VM runtime (Docker Desktop, OrbStack, Colima, Podman machine) the host can't route to container addresses inside the VM, so the emulator serves each GKE LoadBalancer Service on a port its own container publishes (ADR 0012). Start it with --port-range and publish that range on the same container and host ports:

docker run -d --name gcpemu -p 127.0.0.1:4510:4510 -p 127.0.0.1:20000-20019:20000-20019 \
  -v /var/run/docker.sock:/var/run/docker.sock --group-add 0 \
  linuxuser586/gcpemu:0 start --ephemeral --port-range 20000-20019

A Service takes its own port when the container publishes it at the same host port (-p 127.0.0.1:8080:8080), and otherwise a free port of the range. Its ingress is the host IP of that binding (127.0.0.1), and the port appears only in gcpemu env (GCPEMU_GKE_<CLUSTER>_<NAMESPACE>_<SERVICE>_<PORT>) and the Web console. Only TCP ports are served. When no published port is free, the Service has no ingress and the emulator logs a warning saying what to publish. The Google front end's dynamic port stays out of the range here, so the range is left for Services.

The emulator guesses from the runtime's info that it is on a VM runtime: Docker Desktop and OrbStack are recognized. Set GCPEMU_VM_RUNTIME=true (or --vm-runtime true) on Colima and Podman machine, or false to keep node addresses; the default is auto. docker exec gcpemu /gcpemu doctor prints the decision, warns when no --port-range port is published, and flags clusters last started under the other decision; restarting the emulator recreates their servers with the current one. On Docker Desktop the socket belongs to root inside the VM, hence --group-add 0.

As a GitHub Actions service container (the job waits for the health check):

services:
  gcpemu:
    image: linuxuser586/gcpemu:0
    ports: ["4510:4510", "4443:4443", "8085:8085"]
env:
  STORAGE_EMULATOR_HOST: http://localhost:4443
  PUBSUB_EMULATOR_HOST: localhost:8085
Reference stack (SRS 11.2)

e2e/ holds the Reference stack, the final acceptance test of the whole emulator: one OpenTofu root module (e2e/stack/), a Go API (e2e/app/) and TestReferenceStack, which drives them against an in-process emulator at IAM enforcement level enforce:

  1. tofu apply creates a VPC and subnet (pod/service ranges), Cloud Router + NAT, a private GKE cluster with Workload Identity and a node pool, an Artifact Registry repo, buckets (static assets, uploads with a Pub/Sub notification), a topic with an OIDC push subscription, Cloud SQL Postgres 16 on a private IP with an IAM service account user, the example.test. zone and a global external ALB with Cloud CDN (backend bucket, NEG backend service with backend mTLS, managed certificate, HTTP→HTTPS redirect); a plan right after must be empty;
  2. the app is built for amd64 and arm64 FROM scratch and pushed to AR, Istio is installed from its Helm charts (its ingress gateway requires the LB's client certificate), the app is deployed and a second apply (api_neg_name) adds the ingress gateway's GKE NEG to the load balancer;
  3. https://app.example.test/ (emulated DNS, emulator CA; Go client and curl) serves the bucket's page and the second request reports X-Cache-Status: hit;
  4. /api/health goes LB → Istio → app; a client without the LB certificate is refused;
  5. /api/work writes to GCS, inserts into Cloud SQL (Go connector, IAM auth) and publishes, using Workload Identity and no Endpoint override;
  6. the bucket notification and the message arrive by push with a verified OIDC token; the pod then calls https://app.example.test/api/health itself, through Cloud NAT;
  7. the pod reaches the internet through Cloud NAT, and neither the internet nor the load balancer after nat_enabled=false;
  8. app_storage_access=false makes step 5 fail with PERMISSION_DENIED;
  9. urlMaps.invalidateCache on /* makes the next request a miss;
  10. tofu destroy leaves no containers (gcpemu status lists the instance's containers).
make e2e                          # = GCPEMU_NET_TESTS=1 go test -tags e2e ./e2e -run TestReferenceStack -timeout 30m -v
GCPEMU_NET_TESTS=0 make e2e       # offline-ish: steps 1, 3, 9 and 10 only

It needs a container runtime and tofu on PATH; tofu init downloads the google and tls providers. Steps 2 and 4–8 download Helm and the Istio release for its charts (both pinned and checksum-verified) and the Istio images and reach https://example.com/, so they only run with GCPEMU_NET_TESTS=1. Downloads are cached in $GCPEMU_E2E_CACHE (default <user cache dir>/gcpemu-e2e). The run must finish within 10 minutes (GCPEMU_E2E_BUDGET overrides); it prints per-step timings. With emulator_gateway empty the module targets real GCP (set project and domain).

Client compatibility (SRS 7.1)

make compat runs the real clients against a detached instance with only Endpoint overrides: gcloud (storage, pubsub, secrets, iam, dns, compute load balancing and NAT, artifacts, sql, container), kubectl through gke-gcloud-auth-plugin, Helm, Docker, crane, ko, psql, the Cloud SQL Auth Proxy v2 (including automatic IAM authentication) and dig. gcloud (with the gke-gcloud-auth-plugin component), kubectl, dig and Docker come from PATH; Helm, crane, ko and the Auth Proxy are downloaded at pinned, checksum-verified versions.

gcloud runs behind the same Escape guard as the OpenTofu acceptance (below), with NO_PROXY covering loopback, because gcloud, unlike Go, proxies loopback too. A gcloud request with no CLOUDSDK_API_ENDPOINT_OVERRIDES_* covering it fails the step and names the missing variable. gcloud's universe descriptor fetch from storage.gcpemu.invalid is not counted as an escape. The gcloud/escape-guard subtest lists Pub/Sub topics without the pubsub override, and fails unless the guard refuses pubsub.gcpemu.invalid. The other clients run without the guard: they either stay on loopback or reach the internet on purpose.

OpenTofu acceptance (SRS 11.1, IF-001)

make tofu applies each module in compat/tofu/ (one per service area: IAM, Storage, Pub/Sub, DNS, VPC networking, load balancing and CDN, Certificate Manager, Cloud SQL, GKE, Artifact Registry), plans again expecting no changes, destroys it and checks the state is empty. It does this with the google and google-beta providers, each at the latest release of the current and the previous minor (looked up in the OpenTofu registry), against a detached instance whose provider block is gcpemu tofu-provider output. GCPEMU_TOFU_PROVIDERS narrows the matrix (google-beta, google@8.6.0, google@8.6.0,google-beta@8.5.0) and GCPEMU_TOFU_MODULES the modules (lb,dns). The resource types each module must declare are listed in compat/tofu_test.go; that list is the supported surface. It needs tofu on PATH and, for Cloud SQL and GKE, a container runtime.

tofu plan, apply and destroy run behind an Escape guard: HTTPS_PROXY and HTTP_PROXY point at an in-test proxy that refuses every request that would leave the machine. Each refused host fails the module, and the error names it. The instance listens on loopback, which Go never proxies and NO_PROXY exempts. tofu init runs without the guard so it can still download providers. An escape-guard subtest per provider plans a data source whose dns_custom_endpoint is removed from the provider block, and fails unless the guard refuses dns.gcpemu.invalid. The Reference stack's OpenTofu runs use the same guard.

gcpemu tofu-provider --beta also prints a provider "google-beta" block for modules that use provider = google-beta. It has the same Endpoint overrides, except that container's is /container/v1beta1/. It is opt-in because a google-beta block makes OpenTofu require the hashicorp/google-beta provider.

Both blocks set universe_domain = "gcpemu.invalid". Without it, the provider looks up the caller's email at openidconnect.googleapis.com every time it is configured. No Endpoint override covers that URL, so each run calls Google, or stalls for about 10 minutes when there is no DNS. An API that the block gives no Endpoint override is addressed as <api>.gcpemu.invalid, which never resolves, so the call fails instead of reaching Google. Providers older than 7.2 still make the lookup. Upgrade them, or set HTTPS_PROXY to an address that refuses connections.

Pointing gcloud at an instance needs nothing beyond eval "$(gcpemu env)" plus a token: for example echo owner > /tmp/tok; export CLOUDSDK_AUTH_ACCESS_TOKEN_FILE=/tmp/tok. Registry clients log in to $GCPEMU_REGISTRY as oauth2accesstoken with gcloud auth print-access-token.

gcpemu env also sets CLOUDSDK_CORE_UNIVERSE_DOMAIN=gcpemu.invalid, in Host mode too. A gcloud API with no CLOUDSDK_API_ENDPOINT_OVERRIDES_<API> then goes to <api>.gcpemu.invalid, which never resolves, so the command fails instead of reaching Google. gcloud also refuses credentials stored for Google (gcloud auth login, or a key from real Google) with a universe mismatch error, so they are never sent to the instance; use the token file above, or a key the emulator issued. Outside Google's universe gcloud behaves differently in a few places:

  • gcloud compute images list and gcloud compute instances create without --image* flags fail looking up the universe descriptor at storage.gcpemu.invalid. Pass --no-standard-images, or --image-family with --image-project.
  • gcloud storage buckets create requires --location.

gcpemu env --no-universe leaves that variable out, for a shell that also points gcloud at Google with stored credentials.

For the client libraries, gcpemu env sets GOOGLE_CLOUD_UNIVERSE_DOMAIN=gcpemu.invalid (which --no-universe keeps). A Go client, or a generated gRPC client such as Pub/Sub in Python or Node, then sends an API with no endpoint override to <api>.gcpemu.invalid instead of Google. The Python and Node Cloud Storage clients ignore the variable, so they still need STORAGE_EMULATOR_HOST.

gcpemu env also sets GOOGLE_API_USE_MTLS_ENDPOINT=never, which --no-universe keeps. In always mode, or when a client certificate is found, a Go client dials a hard-coded <api>.mtls.googleapis.com, which the universe does not change. If you set GOOGLE_API_USE_MTLS_ENDPOINT=always after eval "$(gcpemu env)", a Go client for an API with no endpoint override reaches Google. The Python client libraries refuse mTLS outside Google's universe, so they fail instead. The Node client libraries build the mTLS host from the universe, so in always mode they stay on the unresolvable <api>.gcpemu.invalid, and with GOOGLE_API_USE_CLIENT_CERTIFICATE=true they refuse mTLS outside Google's universe.

Service-account keys the emulator issues say "universe_domain": "gcpemu.invalid". A Go client that loads one needs GOOGLE_CLOUD_UNIVERSE_DOMAIN=gcpemu.invalid, even outside a gcpemu env shell; without it the first request fails with a universe mismatch. With it, Go clients sign their own JWTs from the key instead of calling its token_uri, which the instance also accepts. Some clients compare the key with Google's universe whatever the variable says:

  • Python Cloud Storage with credentials passed explicitly: pass client_options={"universe_domain": "gcpemu.invalid"}.
  • Node Pub/Sub, including with PUBSUB_EMULATOR_HOST: pass universeDomain: 'gcpemu.invalid' with emulatorMode: true, since any universeDomain otherwise turns emulator mode off.
  • An OpenTofu provider "google" block that loads a key: set universe_domain = "gcpemu.invalid", as the gcpemu tofu-provider blocks do.

The metadata server that gcpemu env points host processes at is in the Invalid universe too. Python google-auth otherwise looks up each account's Regional Access Boundary at iamcredentials.googleapis.com, which no Endpoint override covers (ADR 0009). ADC through it needs nothing else, except that Python Cloud Storage with those credentials passed explicitly needs the same client_options as an emulator key. In GKE pods the metadata server stays in Google's universe, and the instance answers the lookup. On a machine where someone ran gcloud auth application-default login, ADC uses a key instead, as below.

Credentials the instance did not issue, such as a key from real Google or gcloud's application-default login, send their token requests to oauth2.googleapis.com. Go HTTP clients, Python Cloud Storage with credentials passed explicitly and the Node REST fallback fetch a token before they check the universe, so that request reaches Google even when every API has an endpoint override. ADC finds gcloud's application_default_credentials.json before the metadata server, so when it exists and GOOGLE_APPLICATION_CREDENTIALS is unset, gcpemu env exports GOOGLE_APPLICATION_CREDENTIALS pointing at an emulator key for the metadata server's service account (ADR 0010). It never overrides a GOOGLE_APPLICATION_CREDENTIALS you set, but it warns, as gcpemu doctor does, when that file is not in the Invalid universe. In host mode those token requests reach the instance instead, which refuses a refresh token Google issued (one starting 1//, or sent with gcloud's application-default client ID) with 400 invalid_grant rather than taking it as the default Principal.

The Cloud SQL Auth Proxy v2 puts a static --token in Google's universe, so in a gcpemu env shell it refuses the token with a universe mismatch. Its --universe-domain cannot go with --sqladmin-api-endpoint, so run it with GOOGLE_CLOUD_UNIVERSE_DOMAIN= or with --credentials-file and an emulator key.

Development

make agent         # the Sidecar agent, bin/gcpemu-linux-<arch> (needed off linux)
make vet race      # gofmt, vet, tests with -race
make release       # static binaries for linux/darwin/windows × amd64/arm64, with the Web console
make cross         # the same binaries without building the console (no Node.js)

The Makefile needs GNU make (3.81 or later) and a POSIX shell. macOS ships both. On Windows, run it from Git Bash with GNU make (winget install ezwinports.make); make build writes bin/gcpemu.exe there, and make race needs a C compiler for cgo.

The Web console (console/) is Vite + React + TypeScript; console/embed.go embeds its dist/. With Node.js 24 and pnpm:

bin/gcpemu start                       # in one terminal
cd console && pnpm install && pnpm dev # /console/ with hot reload; other paths go to the API gateway
                                       # (GCPEMU_GATEWAY, default 127.0.0.1:4510)
pnpm lint && pnpm typecheck && pnpm test
pnpm gen:api                           # after editing internal/admin/openapi.yaml
make console-e2e                       # Playwright on Chromium, Firefox and WebKit

Each Service is an isolated package implementing emu.Service (internal/emu/emu.go); cross-service contracts live in internal/emu/xservice.go.

API route tables and field-behaviour validation (REQUIRED, OUTPUT_ONLY, IMMUTABLE) are generated into internal/apidef from the googleapis commit pinned in internal/apidef/apis.yaml and from the discovery documents of the google.golang.org/api version in go.mod. gRPC services get REST through internal/transcode, and the API gateway checks every gRPC request against the generated tables. After a version bump, regenerate:

make generate                     # after go get google.golang.org/api@... or editing apis.yaml
make generate GOOGLEAPIS=latest   # move the googleapis pin to master, then regenerate
go test ./internal/apidef         # TestDrift: the pin and the Go modules must agree

Annotations a real API doesn't enforce go in the relax lists of apis.yaml, each with its reason.

Licensed under Apache-2.0.

Directories

Path Synopsis
cmd
gcpemu command
Command gcpemu is a local emulator for Google Cloud services.
Command gcpemu is a local emulator for Google Cloud services.
Package compat is the client compatibility suite (SRS 7.1, IF-003 to IF-006 and IF-009): the real gcloud, kubectl with gke-gcloud-auth-plugin, Helm, Docker, crane, ko, psql, the Cloud SQL Auth Proxy v2 and dig run against a detached gcpemu instance with only endpoint configuration.
Package compat is the client compatibility suite (SRS 7.1, IF-003 to IF-006 and IF-009): the real gcloud, kubectl with gke-gcloud-auth-plugin, Helm, Docker, crane, ko, psql, the Cloud SQL Auth Proxy v2 and dig run against a detached gcpemu instance with only endpoint configuration.
Package console embeds the Web console's built bundle (FR-UI-001).
Package console embeds the Web console's built bundle (FR-UI-001).
e2e
Package e2e holds the SRS 11.2 reference stack acceptance test: one OpenTofu root module (stack/), a Go API (app/) and the test that drives them against an in-process emulator.
Package e2e holds the SRS 11.2 reference stack acceptance test: one OpenTofu root module (stack/), a Go API (app/) and the test that drives them against an in-process emulator.
app command
Command app is the Go API of the SRS 11.2 reference stack.
Command app is the Go API of the SRS 11.2 reference stack.
Package emutest starts an in-process gcpemu instance for Go tests (FR-CI-009).
Package emutest starts an in-process gcpemu instance for Go tests (FR-CI-009).
internal
admin
Package admin holds the OpenAPI description of the /_emu/v1/ admin API (SRS 7.3), embedded in the binary for `gcpemu admin openapi`.
Package admin holds the OpenAPI description of the /_emu/v1/ admin API (SRS 7.3), embedded in the binary for `gcpemu admin openapi`.
agent
Package agent runs gcpemu helper processes inside containers the emulator launches (GKE node metadata proxy, Cloud SQL server-side proxy).
Package agent runs gcpemu helper processes inside containers the emulator launches (GKE node metadata proxy, Cloud SQL server-side proxy).
apidef
Package apidef holds the API surface generated from Google's published definitions (NFR-MNT-001): the google.api.http routes and field behaviours (AIP-203) of the gRPC APIs, read from googleapis at the commit pinned in apis.yaml, and the methods and field annotations of the discovery (JSON/REST) APIs, read from the discovery documents vendored in the google.golang.org/api module pinned in go.mod.
Package apidef holds the API surface generated from Google's published definitions (NFR-MNT-001): the google.api.http routes and field behaviours (AIP-203) of the gRPC APIs, read from googleapis at the commit pinned in apis.yaml, and the methods and field annotations of the discovery (JSON/REST) APIs, read from the discovery documents vendored in the google.golang.org/api module pinned in go.mod.
apidef/internal/apigen command
Command apigen generates internal/apidef's route and field-behaviour tables (NFR-MNT-001) from Google's published API definitions:
Command apigen generates internal/apidef's route and field-behaviour tables (NFR-MNT-001) from Google's published API definitions:
apierr
Package apierr models GCP API errors and renders them as the JSON error envelope used by REST APIs and as google.rpc.Status for gRPC (FR-CORE-025).
Package apierr models GCP API errors and renders them as the JSON error envelope used by REST APIs and as google.rpc.Status for gRPC (FR-CORE-025).
ca
Package ca is the emulator's local certificate authority (Section 7.4).
Package ca is the emulator's local certificate authority (Section 7.4).
cli
Package cli implements the gcpemu command line (FR-CORE-001..007).
Package cli implements the gcpemu command line (FR-CORE-001..007).
clock
Package clock provides the emulator's clock: real by default, a fake advanceable clock under --deterministic or `gcpemu time advance` (NFR-REL-002).
Package clock provides the emulator's clock: real by default, a fake advanceable clock under --deterministic or `gcpemu time advance` (NFR-REL-002).
config
Package config loads emulator configuration with the precedence flags > env (GCPEMU_*) > gcpemu.yaml > defaults (FR-CORE-010).
Package config loads emulator configuration with the precedence flags > env (GCPEMU_*) > gcpemu.yaml > defaults (FR-CORE-010).
emu
Package emu defines the contract between the emulator core and service modules (NFR-MNT-002) and the shared environment they run in.
Package emu defines the contract between the emulator core and service modules (NFR-MNT-002) and the shared environment they run in.
escapeguard
Package escapeguard is the Escape guard (see CONTEXT.md): a proxy that OpenTofu and gcloud runs in the acceptance tests go through, so that an Escaped request fails the test, naming the host, instead of reaching Google.
Package escapeguard is the Escape guard (see CONTEXT.md): a proxy that OpenTofu and gcloud runs in the acceptance tests go through, so that an Escaped request fails the test, naming the host, instead of reaching Google.
events
Package events is the Instance's change feed, served as server-sent events at /_emu/v1/events (FR-CORE-045, FR-UI-006): resource changes, Operation progress, Request log entries and IAM denials.
Package events is the Instance's change feed, served as server-sent events at /_emu/v1/events (FR-CORE-045, FR-UI-006): resource changes, Operation progress, Request log entries and IAM denials.
fault
Package fault implements fault injection rules (FR-CORE-060): inject an error code, latency or a dropped connection by service, method, resource pattern and probability or count.
Package fault implements fault injection rules (FR-CORE-060): inject an error code, latency or a dropped connection by service, method, resource pattern and probability or count.
frontend
Package frontend is the emulator's "Google front end": a TLS terminator that lets unmodified clients reach emulated services by their real hostnames (storage.googleapis.com, pubsub.googleapis.com, LOCATION-docker.pkg.dev, ...) over HTTPS, HTTP/2 and gRPC (FR-INT-007, FR-CORE-043).
Package frontend is the emulator's "Google front end": a TLS terminator that lets unmodified clients reach emulated services by their real hostnames (storage.googleapis.com, pubsub.googleapis.com, LOCATION-docker.pkg.dev, ...) over HTTPS, HTTP/2 and gRPC (FR-INT-007, FR-CORE-043).
gateway
Package gateway is the control-plane gateway (FR-CORE-040): one listener serving every API over HTTP/1.1 REST and gRPC (h2c), routing by path prefix and Host, authenticating callers and recording the request log.
Package gateway is the control-plane gateway (FR-CORE-040): one listener serving every API over HTTP/1.1 REST and gRPC (h2c), routing by path prefix and Host, authenticating callers and recording the request log.
hostmode
Package hostmode implements host mode (FR-CORE-043): host processes reach emulated services by their real hostnames (storage.googleapis.com, LOCATION-docker.pkg.dev, ...) once the local CA is trusted.
Package hostmode implements host mode (FR-CORE-043): host processes reach emulated services by their real hostnames (storage.googleapis.com, LOCATION-docker.pkg.dev, ...) once the local CA is trusted.
instance
Package instance assembles and runs one emulator instance: state store, gateway, admin API and the selected services.
Package instance assembles and runs one emulator instance: state store, gateway, admin API and the selected services.
locations
Package locations embeds the real Google Cloud regions and zones (FR-CORE-021) so every service validates locations the same way.
Package locations embeds the real Google Cloud regions and zones (FR-CORE-021) so every service validates locations the same way.
loopback
Package loopback reports whether the host has loopback addresses beyond 127.0.0.1 (ADR 0005).
Package loopback reports whether the host has loopback addresses beyond 127.0.0.1 (ADR 0005).
lro
Package lro implements google.longrunning Operations for services whose mutations are long-running in GCP (FR-CORE-023).
Package lro implements google.longrunning Operations for services whose mutations are long-running in GCP (FR-CORE-023).
netplane
Package netplane connects the emulator process to the container networks it creates (Section 3.3).
Package netplane connects the emulator process to the container networks it creates (Section 3.3).
project
Package project implements project identity (FR-CORE-020): any project ID is accepted, and its number is derived deterministically from the ID.
Package project implements project identity (FR-CORE-020): any project ID is accepted, and its number is derived deterministically from the ID.
reqlog
Package reqlog records every API call and data-plane request as a structured entry (FR-CORE-061) and keeps the most recent ones in memory for the admin API (FR-CORE-045).
Package reqlog records every API call and data-plane request as a structured entry (FR-CORE-061) and keeps the most recent ones in memory for the admin API (FR-CORE-045).
runtime
Package runtime is the container runtime driver (Section 3.1): a small client for the Docker Engine API, which Docker Engine and Podman (its Docker-compatible socket) both serve.
Package runtime is the container runtime driver (Section 3.1): a small client for the Docker Engine API, which Docker Engine and Podman (its Docker-compatible socket) both serve.
store
Package store is the control-plane state store (FR-CORE-032): a small transactional, namespaced key-value interface with an in-memory implementation for --ephemeral and a bbolt (pure Go) one for --data-dir.
Package store is the control-plane state store (FR-CORE-032): a small transactional, namespaced key-value interface with an in-memory implementation for --ephemeral and a bbolt (pure Go) one for --data-dir.
transcode
Package transcode serves the REST surface of gRPC services: it maps the google.api.http bindings generated into internal/apidef onto the services' gRPC implementations (AIP-127), validating each request's field behaviours on the way in.
Package transcode serves the REST surface of gRPC services: it maps the google.api.http bindings generated into internal/apidef onto the services' gRPC implementations (AIP-127), validating each request's field behaviours on the way in.
trust
Package trust builds CA bundles that combine the host's system roots with the emulator's local CA (Section 7.4), for clients that read a single bundle file: SSL_CERT_FILE from `gcpemu env --trust` (FR-CORE-004) and the bundle injected into GKE pods (FR-INT-007).
Package trust builds CA bundles that combine the host's system roots with the emulator's local CA (Section 7.4), for clients that read a single bundle file: SSL_CERT_FILE from `gcpemu env --trust` (FR-CORE-004) and the bundle injected into GKE pods (FR-INT-007).
vmrelay
Package vmrelay implements the VM relay (ADR 0005).
Package vmrelay implements the VM relay (ADR 0005).
webconsole
Package webconsole serves the Web console's bundle on the gateway under /console (FR-UI-002).
Package webconsole serves the Web console's bundle on the gateway under /console (FR-UI-002).
Package services lists the service modules compiled into gcpemu.
Package services lists the service modules compiled into gcpemu.
ar
Package ar emulates Artifact Registry (SRS 5.3): the artifactregistry v1 control plane over gRPC and REST on the gateway, and an OCI Distribution v1.1 registry on its own port (default 5000).
Package ar emulates Artifact Registry (SRS 5.3): the artifactregistry v1 control plane over gRPC and REST on the gateway, and an OCI Distribution v1.1 registry on its own port (default 5000).
cdn
Package cdn emulates Cloud CDN (SRS 5.9): the HTTP cache the load balancer puts in front of CDN-enabled backend services and backend buckets.
Package cdn emulates Cloud CDN (SRS 5.9): the HTTP cache the load balancer puts in front of CDN-enabled backend services and backend buckets.
certs
Package certs emulates Certificate Manager (certificatemanager.googleapis.com v1) and the Network Security API (networksecurity.googleapis.com v1: backend authentication configs, server and client TLS policies) and provides emu.CertManager, the view of those resources the load balancer data plane consumes (FR-LB-004, FR-LB-006, FR-LB-009).
Package certs emulates Certificate Manager (certificatemanager.googleapis.com v1) and the Network Security API (networksecurity.googleapis.com v1: backend authentication configs, server and client TLS policies) and provides emu.CertManager, the view of those resources the load balancer data plane consumes (FR-LB-004, FR-LB-006, FR-LB-009).
compute
Package compute emulates the parts of compute.googleapis.com v1 the other services build on (SRS 1.2 supporting resources, 3.3, 5.10): regions and zones, projects.get, VPC networks, subnetworks, firewalls, routes, addresses, Cloud Routers with Cloud NAT (FR-NAT-001), network endpoint groups (zonal for FR-GKE-008, regional and global), VPC Network Peering (recorded) and compute Operations (FR-CORE-023), plus the minimal servicenetworking.googleapis.com API that binds private services access ranges to a VPC.
Package compute emulates the parts of compute.googleapis.com v1 the other services build on (SRS 1.2 supporting resources, 3.3, 5.10): regions and zones, projects.get, VPC networks, subnetworks, firewalls, routes, addresses, Cloud Routers with Cloud NAT (FR-NAT-001), network endpoint groups (zonal for FR-GKE-008, regional and global), VPC Network Peering (recorded) and compute Operations (FR-CORE-023), plus the minimal servicenetworking.googleapis.com API that binds private services access ranges to a VPC.
dns
Package dns emulates Cloud DNS (SRS 5.2): the dns.googleapis.com v1 REST control plane (managed zones, record sets, changes; FR-DNS-001/002; zone IAM policies, FR-IAM-003; server and response policies, FR-DNS-006) and an authoritative DNS data plane on UDP and TCP that answers from the stored zones and response policies and forwards other names to the host resolver (FR-DNS-003/004).
Package dns emulates Cloud DNS (SRS 5.2): the dns.googleapis.com v1 REST control plane (managed zones, record sets, changes; FR-DNS-001/002; zone IAM policies, FR-IAM-003; server and response policies, FR-DNS-006) and an authoritative DNS data plane on UDP and TCP that answers from the stored zones and response policies and forwards other names to the host resolver (FR-DNS-003/004).
gcs
Package gcs emulates Cloud Storage (SRS 5.4): the JSON API v1 (buckets, objects, uploads, notifications, IAM, HMAC keys, legacy ACLs, managed folders), the XML API subset used by the official clients for reads and by S3-style tools, V4 signed URLs and POST policies, Pub/Sub notifications and lifecycle rules.
Package gcs emulates Cloud Storage (SRS 5.4): the JSON API v1 (buckets, objects, uploads, notifications, IAM, HMAC keys, legacy ACLs, managed folders), the XML API subset used by the official clients for reads and by S3-style tools, V4 signed URLs and POST policies, Pub/Sub notifications and lifecycle rules.
gke
Package gke emulates Google Kubernetes Engine (SRS 5.7): the container.googleapis.com v1 API over gRPC and REST on the gateway, backed by real k3s clusters running in the host's container runtime.
Package gke emulates Google Kubernetes Engine (SRS 5.7): the container.googleapis.com v1 API over gRPC and REST on the gateway, backed by real k3s clusters running in the host's container runtime.
iam
Package iam emulates Identity and Access Management (SRS 5.1): service accounts and keys, predefined and custom roles, IAM policies on projects and resources with a shared policy evaluator, OAuth2 token issuance, the IAM Credentials API, IAM v2 deny policies and a GCE-compatible metadata server.
Package iam emulates Identity and Access Management (SRS 5.1): service accounts and keys, predefined and custom roles, IAM policies on projects and resources with a shared policy evaluator, OAuth2 token issuance, the IAM Credentials API, IAM v2 deny policies and a GCE-compatible metadata server.
lb
Package lb emulates the Application Load Balancer (SRS 5.8): the compute v1 load-balancing collections (forwarding rules, target HTTP(S) proxies, URL maps, backend services and buckets, health checks, SSL certificates and SSL policies, global and regional; FR-LB-001) served on the compute API, and a real in-process L7 proxy per forwarding rule wired exactly as GCP wires them: forwarding rule → target proxy → URL map → backend service or bucket → NEG endpoints (FR-LB-002..010).
Package lb emulates the Application Load Balancer (SRS 5.8): the compute v1 load-balancing collections (forwarding rules, target HTTP(S) proxies, URL maps, backend services and buckets, health checks, SSL certificates and SSL policies, global and regional; FR-LB-001) served on the compute API, and a real in-process L7 proxy per forwarding rule wired exactly as GCP wires them: forwarding rule → target proxy → URL map → backend service or bucket → NEG endpoints (FR-LB-002..010).
lb/urlmap
Package urlmap is the load balancer's URL map routing engine (FR-LB-003): a pure library that compiles a compute v1 UrlMap and selects, for a request, the backend (service or bucket), redirect, URL rewrite and header actions exactly as GCP's Application Load Balancers do:
Package urlmap is the load balancer's URL map routing engine (FR-LB-003): a pure library that compiles a compute v1 UrlMap and selects, for a request, the backend (service or bucket), redirect, URL rewrite and header actions exactly as GCP's Application Load Balancers do:
nat
Package nat is the Cloud NAT service module (SRS 5.10).
Package nat is the Cloud NAT service module (SRS 5.10).
pubsub
Package pubsub emulates Cloud Pub/Sub (SRS 5.5): topics, subscriptions, publish, pull, streaming pull and push delivery, ordering, dead-letter topics, filters, exactly-once delivery, snapshots, seek and schemas.
Package pubsub emulates Cloud Pub/Sub (SRS 5.5): topics, subscriptions, publish, pull, streaming pull and push delivery, ordering, dead-letter topics, filters, exactly-once delivery, snapshots, seek and schemas.
secrets
Package secrets emulates Secret Manager (secretmanager.googleapis.com v1) over gRPC and REST on the gateway: global and regional secrets, versions and their payloads, version aliases, expiry, delayed version destruction, rotation notifications to Pub/Sub topics, managed rotation of Cloud SQL credentials, and secret IAM policies.
Package secrets emulates Secret Manager (secretmanager.googleapis.com v1) over gRPC and REST on the gateway: global and regional secrets, versions and their payloads, version aliases, expiry, delayed version destruction, rotation notifications to Pub/Sub topics, managed rotation of Cloud SQL credentials, and secret IAM policies.
sql
Package sql emulates Cloud SQL for PostgreSQL (SRS 5.6).
Package sql emulates Cloud SQL for PostgreSQL (SRS 5.6).
sql/internal/genflags command
Command genflags generates Cloud SQL for PostgreSQL's database flag allow-list (FR-SQL-003) from Google's documentation:
Command genflags generates Cloud SQL for PostgreSQL's database flag allow-list (FR-SQL-003) from Google's documentation:
sql/proxy
Package proxy is the Cloud SQL in-container agent (FR-SQL-004..007).
Package proxy is the Cloud SQL in-container agent (FR-SQL-004..007).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL