Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Cloud CDN
  • Getting started
    • All guides
    • Connecting to a Cloud CDN provider
      • Creating a resource
      • Editing basic settings of a resource
      • Getting information about a resource
      • Configuring resource caching
      • Configuring log export
      • Pre-loading files to CDN servers
      • Purging resource cache
      • Configuring request and response headers
      • Configuring CORS for responses to clients
      • Configuring HTTP methods
      • Enabling file compression
      • Enabling file segmentation
      • Enabling origin shielding
      • Configuring request redirection
      • Setting up access via a secure token
      • Managing additional resource settings
      • Disabling a resource
      • Managing resource labels
      • Deleting a resource
      • Viewing resource statistics
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • Troubleshooting
  1. Step-by-step guides
  2. Resources
  3. Setting up access via a secure token

Setting up access via a secure token

Written by
Yandex Cloud
Updated at May 13, 2025

Using secure tokens, you can restrict access to CDN resource files. Files will be accessed via signed URLs with the limited validity period.

You can also use secure tokens to specify a trusted IP address to access a CDN resource from.

Enabling access

To enable access via a secure token:

  1. Come up with a secret key that is an arbitrary string of 6 to 32 characters. It will be saved in the CDN resource settings and used to generate signed URLs.

  2. On your website, set up generation of signed URLs with secure tokens.

  3. Enable access to the CDN resource via a secure token:

    Management console
    CLI
    Terraform
    API
    1. In the management console, select the folder where your resource is located.

    2. Select Cloud CDN.

    3. Click the resource name.

    4. In the top-right corner, click Edit.

    5. Enable Access via secure token:

      • Specify a Secret key that is a string of 6 to 32 characters. You will need a secret key to generate pre-signed URLs.

        You can view the secret key you saved in the management console or using the yc cdn resource list CLI command.

      • Use the Limit access by IP address field to restrict access to content by IP address:

        • Only trusted IP addresses: Access to files will be allowed only from a specific IP address of the content recipient. The IP address is specified as a parameter outside a CDN resource when generating an MD5 hash for a pre-signed URL.
        • No restrictions: Access to files will be allowed from any IP address.
    6. Click Save.

    If you do not have the Yandex Cloud (CLI) command line interface yet, install and initialize it.

    The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

    1. View the description of the CLI update resource command:

      yc cdn resource update --help
      
    2. Get a list of all resources in the default folder:

      yc cdn resource list --format yaml
      

      Result:

      id: bc8br5k6iohx********
      folder_id: b1gt6g8ht345********
      cname: testexample.com
      created_at: "2022-01-19T09:23:57.921365Z"
      updated_at: "2022-01-19T10:55:30.305141Z"
      active: true
      options:
        edge_cache_settings:
          enabled: true
          default value: "345600"
        cache_http_headers:
          enabled: true
          value:
          - content-type
          - content-length
          - connection
          - server
          - date
          - test
        stale:
          enabled: true
          value:
          - error
          - updating
        allowed_http_methods:
          value:
          - GET
          - POST
          - HEAD
          - OPTIONS
      origin_group_id: "89783"
      origin_group_name: My origins group
      origin_protocol: HTTP
      ssl_certificate:
        type: DONT_USE
        status: READY
      

      Save the id of the resource you want to set up access for via a secure token.

    3. Enable access via a secure token:

      yc cdn resource update \
        --id <resource_ID> \
        --secure-key <secret_key> \
        --enable-ip-url-signing
      

      Where:

      • --id: ID of the CDN resource you want to enable access for via a secure token.
      • --secure-key: Previously created secret key.
      • --enable-ip-url-signing (optional): Parameter that restricts access to the CDN resource by IP address. The trusted IP address itself is provided outside the CDN resource and specified as a parameter when generating an MD5 hash for a signed URL. If the parameter is not set, file access will be allowed from any IP address.

    If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

    1. Open the Terraform configuration file and add the following parameters to the section with the CDN resource description:

      resource "yandex_cdn_resource" "my_resource" {
        ...
        options {
          ...
          secure_key = "<secret_key>"
          enable_ip_url_signing = true
        }
      }
      

      Where:

      • secure_key: Previously created secret key.
      • enable_ip_url_signing: Optional parameter, true or false. It restricts access to the CDN resource by IP address. The trusted IP address itself is provided outside the CDN resource and specified as a parameter when generating an MD5 hash for a signed URL. If the parameter is not set, file access will be allowed from any IP address.

      For more information about the yandex_cdn_resource parameters in Terraform, see the provider documentation.

    2. Apply the changes:

      1. In the terminal, change to the folder where you edited the configuration file.

      2. Make sure the configuration file is correct using the command:

        terraform validate
        

        If the configuration is correct, the following message is returned:

        Success! The configuration is valid.
        
      3. Run the command:

        terraform plan
        

        The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

      4. Apply the configuration changes:

        terraform apply
        
      5. Confirm the changes: type yes in the terminal and press Enter.

    You can check the updated CDN resource parameters using the management console or this CLI command:

    yc cdn resource get <resource_ID>
    

    Use the update REST API method for the Resource resource or the ResourceService/Update gRPC API call.

    It may take up to 15 minutes for the new settings of the existing resource to apply to CDN servers. After that, we recommend purging the resource cache.

    Enabling access to CDN resource content via a secure token disables access to it via regular links.

Disabling access

To disable access to a CDN resource via a secure token:

Management console
CLI
Terraform
API
  1. In the management console, select the folder where your resource is located.
  2. Select Cloud CDN.
  3. Click the resource name.
  4. In the top-right corner, click Edit.
  5. Enable Access via secure token.
  6. Click Save.

Run this command:

yc cdn resource update \
  --id <resource_ID> \
  --clear-secure-key

Where:

  • --id: ID of the CDN resource you want to disable secure token access for.
  • --clear-secure-key: Parameter for disabling secure token access.
  1. Open the Terraform configuration file and delete the secure_key and enable_ip_url_signing parameters from the section with the CDN resource description:

    resource "yandex_cdn_resource" "my_resource" {
      ...
      options {
        ...
        secure_key = "<secret_key>"
        enable_ip_url_signing = true
      }
    }
    

    For more information about the yandex_cdn_resource parameters in Terraform, see the provider documentation.

  2. Apply the changes:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

You can check the updated CDN resource parameters using the management console or this CLI command:

yc cdn resource get <resource_ID>

Use the update REST API method for the Resource resource or the ResourceService/Update gRPC API call.

It may take up to 15 minutes for the new settings of the existing resource to apply to CDN servers. After that, we recommend purging the resource cache.

Was the article helpful?

Previous
Configuring request redirection
Next
Managing additional resource settings
Yandex project
© 2025 Yandex.Cloud LLC