1. Introduction
Last Updated: 2026-11-06
Content Delivery Networks (CDNs) improve user performance by caching frequently accessed content closer to the end users, terminating connections closer to the clients, re-using connections to the origin, and through adoption of modern networking protocols and customizations.
Media CDN, GCP's global edge network for streaming media, provides many built-in or "core" capabilities.The core capabilities are intended to address the most common use cases, but you may also have requirements that aren't addressed by this core feature set.
Service Extensions for Media CDN, sometimes also referred as Edge Programmability, allows you to run your own code at the edge to customize the behavior of Media CDN. This unlocks additional use cases ranging from normalizing cache key, custom token authentication and token revocation, additional custom log fields, A/B testing, and custom error page.
What you'll build
In this codelab, we will walk through the steps to deploy an edge compute-enabled CDN delivery environment with Media CDN (CDN) + Service Extensions (Edge Programmability) + Cloud Storage (origin source for Media CDN).

What you'll learn
- How to set up Media CDN with a Cloud Storage bucket as an origin
- How to create a Service Extensions plugin with custom HTTP authentication and associate it with Media CDN
- How to validate that the Service Extensions plugin is working as expected
- (Optional) How to manage Service Extensions plugins, including updating, referencing, rolling back, and deleting a specific plugin version
What you'll need
- Basic Networking and knowledge of HTTP
- Basic Unix/Linux command line knowledge
2. Before you begin
Request for Media CDN Allowlist
Before getting started, you will need to ensure your project has been added to the private preview allowlist for Media CDN.
- To request access to Media CDN, please contact your Google Account Team to create an access request on your behalf for Media CDN.
3. Setup and Requirements
Start Cloud Shell
While Google Cloud can be operated remotely from your laptop, in this codelab you will be using Google Cloud Shell, a command line environment running in the Cloud.
From the GCP Console click the Cloud Shell icon on the top right toolbar:

It should only take a few moments to provision and connect to the environment. When it is finished, you should see something like this:

This virtual machine is loaded with all the development tools you'll need. It offers a persistent 5GB home directory, and runs on Google Cloud, greatly enhancing network performance and authentication. All of your work in this lab can be done with simply a browser.
Before you begin
IAM Roles & Access
The Identity and Access Management (IAM) permissions required to create Media CDN, Service Extensions, Cloud Storage, and Artifact Registry resources are the following:
- roles/networkservices.edgeCacheAdmin
- roles/networkservices.serviceExtensionsAdmin
- roles/storage.admin
- roles/artifactregistry.admin
Inside Cloud Shell, make sure that your project_id, project_num, location, and repository environment variables are set up.
gcloud config list project gcloud config set project [YOUR-PROJECT-NAME] export PROJECT_ID=[YOUR-PROJECT-NAME] export PROJECT_NUM=[YOUR-PROJECT-NUMBER] export LOCATION=us-central1 export REPOSITORY=service-extension-$PROJECT_ID
Enable APIs
Enable Media CDN & Service Extensions APIs through the commands below
gcloud services enable networkservices.googleapis.com gcloud services enable edgecache.googleapis.com gcloud services enable artifactregistry.googleapis.com
4. Create a Cloud Storage Bucket
Media CDN content can originate from locations such as a Cloud Storage bucket, a third-party storage location, or any publicly accessible HTTP(S) endpoint.
In this codelab, we'll store content in a Cloud Storage bucket.
We will use the gcloud storage buckets create command to create the bucket
gcloud storage buckets create gs://mediacdn-bucket-$PROJECT_ID --location=$LOCATION
Optionally, you can create a Cloud Storage bucket using the Google Cloud console as follows:
- In the Google Cloud console, go to the Cloud Storage page.
- Click the CREATE button.
- Enter a name for the bucket (e.g., "mediacdn-bucket-$PROJECT_ID").
- Leave the remaining settings as default.
- Click the CREATE button.

5. Upload a test object to the Cloud Storage Bucket
Now we will upload an object into the Cloud Storage bucket.
- Create a file in Cloud Shell and upload it to the bucket using gcloud storage:
echo media-cdn-service-extensions-test > file.txt gcloud storage cp file.txt gs://mediacdn-bucket-$PROJECT_ID
- Grant Media CDN access to the bucket:
gcloud storage buckets add-iam-policy-binding gs://mediacdn-bucket-$PROJECT_ID \
--member="serviceAccount:service-$PROJECT_NUM@gcp-sa-mediaedgefill.iam.gserviceaccount.com" \
--role="roles/storage.legacyObjectReader"
6. Configure Media CDN
Next, we will create a Media CDN deployment configuration.
Each Media CDN configuration consists of two main resources:
- EdgeCacheService: Handles client-facing configuration (TLS, IP addressing), routing, CDN configuration (cache modes, TTLs, signing), and security policies.
- EdgeCacheOrigin: Handles per-origin configuration for HTTP-based origins, as well as retry conditions when content is unreachable or unavailable.
Configure an Edge Cache Origin
Let's create an origin pointing to the Cloud Storage bucket you created.
- In the Google Cloud console, go to the Media CDN page.
- Click the ORIGINS tab.
- Click CREATE ORIGIN.
- Enter ‘cloud-storage-origin' as the name for the EdgeCacheOrigin resource.
- Under Origin address:
- Select ‘Select a Google Cloud Storage bucket'.
- Click BROWSE to choose the Cloud Storage bucket named ‘mediacdn-bucket-$PROJECT_ID'.
- Click SELECT.
- Leave the remaining settings as default.
- Click CREATE ORIGIN.

The newly created EdgeCacheOrigin resource appears in the list of origins in your project on the Origins page.
Configure an Edge Cache Service
- In the Google Cloud console, go to the Media CDN page.
- Click the SERVICES tab.
- Click CREATE SERVICE.
- Enter a name for your service (e.g., ‘media-cdn'), and then click Next.

- In the Routing section, click ADD HOST RULE.
- Enter "*" in the Hosts field.

- Click ADD ROUTE RULE.
- For Priority, specify "1".
- Click ADD A MATCH CONDITION. For Path match, select "Prefix match" as the Match type, enter "/" in the Path match field, and then click Done.
- Select Fetch from an Origin under Primary action, and then select the origin that you configured in the drop down list.

- Click ADVANCED CONFIGURATIONS to extend more configuration options.
- In Route action, click ADD AN ITEM. Then, do the following:
- For Type, select "CDN policy".
- For Cache mode, select "Force cache all".
- Leave the remaining settings as default.
- Click Done.
- Click Save.

- Click CREATE SERVICE.
The newly created EdgeCacheService resource appears on the Services page in the list of services in your project.
Retrieve the Media CDN IP Address and Test
- In the Google Cloud console, go to the Media CDN page.
- Go to Media CDN
- Click the Services tab.
- For your service, see the Addresses column.

To test that your service is correctly configured to cache content, use the curl command-line tool to issue requests and check the responses.
curl -svo /dev/null "http://MEDIA_CDN_IP_ADDRESS/file.txt"
The command should produce output similar to the following:
< HTTP/2 200 OK ... media-cdn-service-extensions-test ...
Now you have successfully created a Media CDN deployment with Cloud Storage as an origin.
7. Configure Artifact Registry for Service Extensions
Before creating a Service Extensions plugin, we need to configure Artifact Registry. Artifact Registry is Google Cloud's universal package manager for managing build artifacts. Proxy-Wasm plugins are published to Artifact Registry, after which they can be deployed to your Media CDN environment.
We will use the gcloud artifacts repositories create command to create the repository:
gcloud artifacts repositories create service-extension-$PROJECT_ID \
--repository-format=docker \
--location=$LOCATION \
--description="Repo for Service Extension" \
--async
Optionally, you can create a repository using the Google Cloud console as follows:
- In the Google Cloud console, go to the Artifact Registry page.
- Click the + CREATE REPOSITORY button.
- Enter a Name for the repository (e.g., ‘service-extension-$PROJECT_ID').
- Set Format to ‘Docker', Mode to ‘Standard', Location Type to ‘Region', and select ‘us-central1 (Iowa)'.
- Click the CREATE button.

The newly created Artifact Registry repository resource should appear on the Repositories page.
Once the repository resource has been created, run the following command in Cloud Shell to configure your Docker client to push and pull packages using this repository:
gcloud auth configure-docker $LOCATION-docker.pkg.dev
Output:
... Adding credentials for: us-central1-docker.pkg.dev Docker configuration file updated.
8. Configure Service Extensions on Media CDN
Now, we will demonstrate how to write and build a Service Extensions (Proxy-Wasm) plugin that can be deployed to Media CDN, using the Rust programming language.
In this example, we will create a Proxy-Wasm plugin that verifies each HTTP request contains an Authorization header with the value "secret". If the request does not contain this header, the plugin will generate an HTTP 403 Forbidden response.
A quick refresher on Service Extensions resources: CdnEdgeExtension, WasmPlugin, and WasmPluginVersion.
- A
CdnEdgeExtensionresource attaches directly to your Media CDN EdgeCacheService deployment and runs one or more extension chains (extensionChains). Each extension chain defines Common Expression Language (CEL) match conditions (matchCondition.celExpression) and can contain WasmPlugin resources. - A
WasmPluginresource points to a main-version corresponding to the activeWasmPluginVersion. - A
WasmPluginVersionreferences a container image stored in Artifact Registry. As you update your Proxy-Wasm plugins, you create different WasmPluginVersion resources.
Please refer to the diagram below to better understand the relationship between these resources.

Write and build a Service Extensions plugin
- Install the Rust toolchain by following the instructions at https://www.rust-lang.org/tools/install.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Next, add Wasm support to your Rust toolchain by running the following command:
rustup target add wasm32-wasip1
- Create a Rust package called my-wasm-plugin:
cargo new --lib my-wasm-plugin
Output:
Creating library `my-wasm-plugin` package note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
- Enter the directory my-wasm-plugin and verify that a
Cargo.tomlfile and asrcdirectory were created:
cd my-wasm-plugin ls
Output:
Cargo.toml src
- Next, open the
Cargo.tomlfile to configure your Rust package. Add the following configuration under[dependencies]:
proxy-wasm = "0.2"
log = "0.4"
[lib]
crate-type = ["cdylib"]
[profile.release]
lto = true
opt-level = 3
codegen-units = 1
panic = "abort"
strip = "debuginfo"
- After your edits, the
Cargo.tomlfile should look similar to this:
[package]
name = "my-wasm-plugin"
version = "0.1.0"
edition = "2021"
[dependencies]
proxy-wasm = "0.2"
log = "0.4"
[lib]
crate-type = ["cdylib"]
[profile.release]
lto = true
opt-level = 3
codegen-units = 1
panic = "abort"
strip = "debuginfo"
- Edit the
lib.rsin thesrcdirectory with the following content.
use log::info;
use proxy_wasm::traits::*;
use proxy_wasm::types::*;
proxy_wasm::main! { {
proxy_wasm::set_log_level(LogLevel::Trace);
proxy_wasm::set_http_context(|_, _| -> Box<dyn HttpContext> { Box::new(DemoPlugin) });
} }
struct DemoPlugin;
impl HttpContext for DemoPlugin {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
if self.get_http_request_header("Authorization") == Some(String::from("secret")) {
info!("Access granted.");
Action::Continue
} else {
self.send_http_response(403, vec![], Some(b"Access forbidden.\n"));
Action::Pause
}
}
}
impl Context for DemoPlugin {}
Alternatively, you can and save it as lib.rs under the src directory.
- After configuring the
Cargo.tomlmanifest file and writing your Proxy-Wasm source code inlib.rs, build your Proxy-Wasm plugin by running the following command inside themy-wasm-plugindirectory:
cargo build --release --target wasm32-wasip1
Once the build completes successfully, you will see a message as shown below:
... Compiling my-wasm-plugin v0.1.0 Finished `release` [optimized] target(s) in 3.74s
Let's also inspect the target directory to verify the build output files:
ls ./target
You will see the output as shown below:
CACHEDIR.TAG release wasm32-wasip1
Publish a Proxy-Wasm plugin to Artifact Registry
Now, we will publish our Proxy-Wasm plugin to the Artifact Registry repository created earlier so it can be deployed to Media CDN.
We first package the Proxy-Wasm plugin into a container image.
- Create a file named
Dockerfilein themy-wasm-plugindirectory with the following contents:
FROM scratch
COPY target/wasm32-wasip1/release/my_wasm_plugin.wasm plugin.wasm
- Next, build the container image:
docker build --no-cache --platform wasm -t my-wasm-plugin .
(non-x86 processors only) Next, build the container image:
docker build --no-cache --platform wasm --provenance=false -t my-wasm-plugin .
Output
[+] Building 0.2s (5/5) FINISHED docker:default ...
- Next, publish (push) your Proxy-Wasm plugin to Artifact Registry. We will tag the container image with the ‘prod' tag.
docker tag my-wasm-plugin $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/my-wasm-plugin:prod
Now, push the tagged ‘prod' container image to your Artifact Registry repository:
docker push $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/my-wasm-plugin:prod
Output:
The push refers to repository ... 8564ddd9910a: Pushed prod: digest: sha256:f3ae4e392eb45393bfd9c200cf8c0c261762f7f39dde5c7cd4b9a8951c6f2812 size: 523
Let's verify that the container image for the Proxy-Wasm plugin was successfully pushed to Artifact Registry:
gcloud artifacts docker images list $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/my-wasm-plugin --include-tags
Output:
Listing items under project ... IMAGE DIGEST TAGS CREATE_TIME UPDATE_TIME <LOCATION>-docker.pkg.dev/.../my-wasm-plugin sha256:08c12... prod 2021-11-10T23:31:27 2021-11-10T23:31:27
Associate a Proxy-Wasm plugin with your Media CDN deployment
Now we are ready to associate the Proxy-Wasm plugin with your Media CDN deployment.
Proxy-Wasm plugins are attached to a Media CDN EdgeCacheService resource via a CdnEdgeExtension resource.
- First, create a WasmPlugin resource named "my-wasm-plugin-resource" with WasmPluginVersion "v1" referencing the container image uploaded to Artifact Registry:
gcloud service-extensions wasm-plugins create my-wasm-plugin-resource \
--log-config=enable=true,sample-rate=1,min-log-level=INFO \
--image="$LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/my-wasm-plugin:prod" \
--main-version=v1
Verify that the Proxy-Wasm plugin version was created successfully:
gcloud service-extensions wasm-plugin-versions list --wasm-plugin=my-wasm-plugin-resource
Output:
NAME WASM_IMAGE WASM_IMAGE_DIGEST CONFIG_SIZE CONFIG_IMAGE CONFIG_IMAGE_DIGEST UPDATE_TIME v1 <LOCATION>-docker.pkg.dev/.../my-wasm-plugin:prod sha256:6d663... ... ... ... ...
- Next, we define a
CdnEdgeExtensionresource referencing our Wasm plugin resource and matching conditions.
cat >cdn-edge-extension.yaml <<EOF
edgeCacheServices:
- projects/$PROJECT_ID/locations/global/edgeCacheServices/media-cdn
extensionChains:
- name: "edge-plugin-chain"
matchCondition:
celExpression: 'request.path.startsWith("/")'
extensions:
- name: "auth-and-header-plugin"
service: projects/$PROJECT_ID/locations/global/wasmPlugins/my-wasm-plugin-resource
failOpen: false
supportedEvents:
- REQUEST_HEADERS
EOF
The above example invokes WASM_PLUGIN to process request headers when you send a request.
- Next, import the YAML file to create a
CdnEdgeExtensionresource:
gcloud beta service-extensions cdn-edge-extensions import cdn-edge-ext \ --source=cdn-edge-extension.yaml \ --location=global
- Finally, verify that the
CdnEdgeExtensionresource was created and associated with your Media CDN deployment:
You should see a similar output:
gcloud beta service-extensions cdn-edge-extensions describe cdn-edge-ext --location=global
Output:
extensionChains:
- extensions:
- name: edge-plugin-chain
service: projects/.../locations/global/wasmPlugins/log-http-headers-wasm-plugin
supportedEvents:
- REQUEST_HEADERS
matchCondition:
celExpression: request.path.startsWith("/")
name: auth-and-header-plugin
name: projects/.../locations/global/cdnEdgeExtensions/cdn-edge-ext
target:
resources:
- projects/.../locations/global/edgeCacheServices/media-cdn
...
9. Validate Service Extensions Proxy-Wasm Plugin on Media CDN
To test that your service is correctly configured to cache content, use the curl command-line tool to issue requests and check the responses.
curl -svo /dev/null "http://IP_ADDRESS/file.txt"
The command should produce output similar to the following:
< HTTP/2 403 Forbidden ... Access forbidden. ...
Now, issue the request again with the Authorization header set to "secret":
curl -svo /dev/null "http://IP_ADDRESS/file.txt" -H "Authorization: secret"
The command should produce output similar to the following:
< HTTP/2 200 OK ... media-cdn-service-extensions-test ...
10. Optional: Managing Service Extensions Plugins
Updating a Proxy-Wasm plugin
As you update your Proxy-Wasm plugin code, you will need to deploy updated plugin versions to Media CDN. Below are the steps to deploy an updated version of a plugin.
For instance, you might update the plugin code to evaluate the Authorization header against a different secret value.
First, update the src/lib.rs source file with the following code:
use log::info;
use proxy_wasm::traits::*;
use proxy_wasm::types::*;
proxy_wasm::main! { {
proxy_wasm::set_log_level(LogLevel::Trace);
proxy_wasm::set_http_context(|_, _| -> Box<dyn HttpContext> { Box::new(DemoPlugin) });
} }
struct DemoPlugin;
impl HttpContext for DemoPlugin {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
if self.get_http_request_header("Authorization") == Some(String::from("another_secret")) {
info!("Access granted.");
Action::Continue
} else {
warn!("Access forbidden.");
self.send_http_response(403, vec![], Some(b"Access forbidden.\n"));
Action::Pause
}
}
}
impl Context for DemoPlugin {}
Next, build, package, and publish the updated plugin:
cargo build --release --target wasm32-wasip1 docker build --no-cache --platform wasm -t my-wasm-plugin . docker tag my-wasm-plugin $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/my-wasm-plugin:v2 docker push $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/my-wasm-plugin:v2
Once the container image is updated in Artifact Registry, we need to create a new WasmPluginVersion and then update the –main-version of the WasmPlugin to reference the new version.
gcloud service-extensions wasm-plugin-versions create my-version-2 \
--wasm-plugin=my-wasm-plugin-resource \
--image="$LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/my-wasm-plugin:v2"
gcloud service-extensions wasm-plugins update my-wasm-plugin-resource \
--main-version=my-version-2
You have successfully updated the container image version imported from Artifact Registry and deployed it live to Media CDN.
Rolling back to a previous version
To roll back to a previous version of a plugin, update the WasmPlugin resource to reference an earlier WasmPluginVersion.
First, we list the available versions:
gcloud service-extensions wasm-plugin-versions list --wasm-plugin=my-wasm-plugin-resource
You should see the output:
NAME WASM_IMAGE WASM_IMAGE_DIGEST CONFIG_SIZE CONFIG_IMAGE CONFIG_IMAGE_DIGEST UPDATE_TIME c7cfa2 <LOCATION>-docker.pkg.dev/.../my-wasm-plugin@sha256:6d663... ... ... a2a8ce <LOCATION>-docker.pkg.dev/.../my-wasm-plugin@sha256:08c12... ... ...
Next, we update the Wasm plugin resource to reference the previous version, "a2a8ce":
$ gcloud service-extensions wasm-plugins update my-wasm-plugin-resource \
--main-version="a2a8ce"
Once the operation is successful, you should see this output:
✓ WASM Plugin [my-wasm-plugin-resource] is now serving version "a2a8ce"
Since Media CDN saves the image digest of your Docker image each time a new Wasm-plugin resource is created, the rollback will use the version of your code that was running before the last rollout.
gcloud service-extensions wasm-plugins describe my-wasm-plugin-resource
For version "a2a8ce", that is the version with digest sha256:08c12...:
name: "my-wasm-plugin-resource" mainVersion: "a2a8ce" mainVersionDetails: image: "<LOCATION>-docker.pkg.dev/<PROJECT>/<REPOSITORY>/my-wasm-plugin" imageDigest: "<LOCATION>-docker.pkg.dev/<PROJECT>/<REPOSITORY>/my-wasm-plugin@sha256:08c121dd7fd1e4d3a116a28300e9fc1fa41b2e9775620ebf3d96cb7119bd9976"
Deleting a CdnEdgeExtension & WasmPlugin
To delete a CdnEdgeExtension, WasmPlugin, and associated WasmPluginVersion resources, follow these steps in order.
First, remove the CdnEdgeExtension resource associated with your Media CDN EdgeCacheService:
gcloud beta service-extensions cdn-edge-extensions delete cdn-edge-ext --location=global
Next, perform the deletion steps in order:
gcloud service-extensions wasm-plugin-versions delete my-version \ --wasm-plugin=my-wasm-plugin-resource gcloud service-extensions wasm-plugins delete my-wasm-plugin-resource
11. Clean up the Lab environment
After completing the codelab, clean up your lab resources to prevent unintended charges.
The following commands delete the Media CDN EdgeCacheService, EdgeCacheOrigin, and Service Extensions plugin resources in order:
gcloud beta service-extensions cdn-edge-extensions delete cdn-edge-ext --location=global gcloud service-extensions wasm-plugins delete my-wasm-plugin-resource gcloud edge-cache services delete media-cdn gcloud edge-cache origins delete cloud-storage-origin gcloud artifacts repositories delete service-extension-$PROJECT_ID --location=$LOCATION
Each of the commands above should ask you to confirm the deletion of the resource.
12. Congratulations!
Congratulations, you have completed the Service Extensions on Media CDN codelab!
What we've covered
- How to set up Media CDN with a Cloud Storage bucket as an origin
- How to create a Service Extensions plugin with custom HTTP authentication and associate it with Media CDN
- How to validate that the Service Extensions plugin is working as expected
- (Optional) How to manage Service Extensions plugins, including updating, referencing, rolling back, and deleting a specific plugin version