Configure a Media CDN edge extension

This page describes how to configure Media CDN edge extensions (CdnEdgeExtension) to attach WebAssembly (Wasm) plugins to Media CDN Edge Cache Services (EdgeCacheService).

A CdnEdgeExtension resource attaches directly to an EdgeCacheService deployment and runs one or more ordered extension chains (extensionChains). Each extension chain is matched by using Common Expression Language (CEL) expressions and can contain a maximum of two chained WasmPlugin resources.

For more information, see Media CDN extensions overview.

Before you begin

  1. Create a Media CDN origin
  2. Create a Media CDN service
  3. Create a plugin by using Service Extensions

  4. When configuring a CdnEdgeExtension resource, consider that Media CDN edge extensions run before most Media CDN features, including route matching and cache lookup. This lets a plugin rewrite headers or URLs to influence HTTP routing. However, plugin code can't inspect custom headers that Media CDN route rules add or built-in features. To access client and connection properties, such as client region, IP address, or TLS parameters, configure forward attributes.

Set up the Media CDN edge extension

To configure a CdnEdgeExtension resource and attach plugins to an EdgeCacheService deployment, do the following:

  1. Define the CdnEdgeExtension resource in a YAML file.

    The following example invokes WASM_PLUGIN to process both request and response headers when you send a request to media.example.com.

    Note: The failOpen: false setting returns an HTTP 500 error code if the plugin fails or times out.

    cat >cdn-edge-extension.yaml <<EOF
    edgeCacheServices:
    - projects/PROJECT_ID/locations/global/edgeCacheServices/SERVICE_NAME
    extensionChains:
    - name: "edge-plugin-chain"
      matchCondition:
        celExpression: 'request.host == "media.example.com"'
      extensions:
      - name: "auth-and-header-plugin"
        service: projects/PROJECT_ID/locations/global/wasmPlugins/WASM_PLUGIN
        failOpen: false
        supportedEvents:
        - REQUEST_HEADERS
        - RESPONSE_HEADERS
        forwardAttributes:
        - request.method
        - request.host
        - request.path
        - source.client_region
    EOF
    

    Replace the following:

    • PROJECT_ID: ID of your Google Cloud project
    • SERVICE_NAME: name of the target Media CDN service (EdgeCacheService)
    • WASM_PLUGIN: name of your plugin, such as my-wasm-plugin-resource

    For more information about the fields in the YAML file, see ExtensionChain in the API documentation.

  2. Use the gcloud beta service-extensions cdn-edge-extensions import command to import the CdnEdgeExtension resource:

    gcloud beta service-extensions cdn-edge-extensions import cdn-edge-ext \
       --source=cdn-edge-extension.yaml \
       --location=global
    

    Note: It might take some time for the new plugin configuration to be distributed across all locations.

Limitations

  • You can attach only one edge extension to an EdgeCacheService deployment.
  • An edge extension chain can contain a maximum of two plugins.
  • Media CDN edge extensions support REQUEST_HEADERS and RESPONSE_HEADERS events. These extensions don't support HTTP body or trailer processing.
  • Media CDN edge extensions let you use only one regular expression for each CEL expression.
  • Names of extension chains and extensions must conform to RFC-1034. Under this specification, names can contain up to 63 lowercase alphanumeric characters or hyphens, must start with a letter, and must end with a letter or number.

For more information about resource limits, see Quotas and limits.

What's next