Configure cross-region access to KMS instances for applications

Updated at:

If your application is deployed in virtual private clouds (VPCs) across multiple Alibaba Cloud regions and needs to use Key Management Service (KMS), you can enable cross-region access to KMS instances. To do this, establish cross-region VPC connectivity and configure domain name resolution for the KMS instance using Alibaba Cloud DNS PrivateZone. This topic describes how to complete this configuration.

Background information

Before your application can access resources in a KMS instance, you must ensure that the application environment is connected to the VPC network of the KMS instance and that the domain name resolution for the KMS instance is correctly configured.

If the application's VPC and the KMS instance are in the same region, you can attach the VPC to the KMS instance. Then, the application can access resources in the KMS instance without requiring you to manually configure domain name resolution. For more information, see Access KMS instances from multiple VPCs in the same region. For cross-region scenarios, use one of the following solutions to establish network connectivity.

  • VPC interconnection solutions

    This is the approach described in this topic. You can use Cloud Enterprise Network (CEN), a VPN gateway, a VPC peering connection, or PrivateLink to enable private network communication between VPCs. For more information about the features, descriptions, and configuration methods of these VPC interconnection solutions, see VPC interconnection.

  • Connect a VPC to the public network

    You can use static public IP addresses, Elastic IP Addresses, NAT Gateway, or Server Load Balancer to allow cloud resources in a VPC to access the public network or be accessed from the public network. For more information, see Public network access.

  • Connecting an IDC to a VPC

    You can use a VPN gateway, Express Connect circuit, or Smart Access Gateway to connect your on-premises data center to a VPC on the cloud and build a hybrid cloud. For more information, see Connect a VPC to an on-premises data center or another cloud.

For more information about domain name resolution setup, see Introduction to internal DNS resolution.

Scenarios

  • You need to use KMS in a region where it is not available. In this case, you can purchase a KMS instance in a supported region and configure your application to access that instance from another region. For more information about supported regions, see Regions and zones.

  • Your application is deployed in VPCs across multiple regions that belong to the same or different accounts. To reduce IT procurement costs and key management overhead, you want to purchase KMS instances only in a few regions.

Function Introduction

To configure cross-region access to a KMS instance, you must first connect the VPCs across regions. Then, you can use PrivateZone to configure domain name resolution for the KMS instance and associate the VPCs. This allows applications that are deployed in other regions to integrate with your KMS instance.

PrivateZone is a private DNS service that is based on Alibaba Cloud Virtual Private Cloud (VPC). You can use PrivateZone to map private domain names to IP addresses in one or more custom VPCs. For more information, see What is PrivateZone.

For example, assume that VPC1 hosts the KMS instance and an application in VPC2, which is in a different region, needs to access keys and credentials in the KMS instance. The following figure shows the overall system architecture.

Notes

  • Before you use this solution, evaluate the costs of VPC interconnection and PrivateZone, the Service Level Agreement (SLA), bandwidth capacity, effective time, and other conditions. You must also plan your system architecture, network architecture, operations management strategy, and contingency plan for multi-region application deployment.

    Note

    When KMS service availability is calculated, failed requests that are caused by incorrect PrivateZone or VPC connection configurations are not counted as KMS failures. This applies to requests that never reach the KMS instance.

  • Cross-region access to KMS instances applies only to custom applications that are integrated with KMS. This feature does not apply to cloud services that use server-side encryption integrated with KMS.

  • If the VPC or private IP address of your KMS instance changes, the access channel that is created using this solution becomes unavailable. In this case, you must reconfigure PrivateZone resolution. This change may occur if you use a hardware key management instance and you disconnect and then reconnect the instance.

Prerequisites

You have purchased and enabled a KMS instance. For more information, see Purchase and enable a KMS instance.

Step 1: Query the VPC and private IP address of the KMS instance

Query the VPC and private IP address of the KMS instance. You will use this information to configure domain name resolution for the KMS instance in PrivateZone.

Query the VPC of the KMS instance

  • Method 1: Use the console

    1. Log on to the Key Management Service console. In the top navigation bar, select a region. In the left-side navigation pane, choose Resources > Instances.

    2. Find the target instance and click Actions > Details in the Actions column.

    3. On the Share Resources tab, click the Multi-VPC tab. The VPC that hosts the KMS instance is marked with an image icon. In the Configured VPCs section of the instance details page, view the VPC topology and record the instance ID of the target VPC.

      Note

      All VPCs that are listed on this tab are in the same region as the KMS instance. VPCs that you configure for cross-region access as described in this topic do not appear in this list.

  • Method 2: Use an API operation

    Call the GetKmsInstance operation. The VpcId parameter in the response indicates the VPC that hosts the KMS instance.

Query the private IP address of the KMS instance

  • Method 1: Use the Alibaba Cloud DNS console

    1. Log on to the Alibaba Cloud DNS console.

    2. In the navigation pane on the left, click Private Zone and follow the on-screen instructions to activate PrivateZone. You can skip this step if PrivateZone is already activated.

    3. On the Authoritative Zone page, click the Cloud Service Defined Zones tab.

    4. Set Cloud Service to Key Management Service, or enter cryptoservice.kms.aliyuncs.com in the Zone search box.

    5. Hover over the cloud VPC, find the target zone, and click Actions > View Resource Record in the Actions column. Find the target domain entry and confirm that its associated VPC ID matches the ID of the VPC that hosts the KMS instance.

    6. On the Settings page, view and record the Record Value, which is the private IP address of the KMS instance.

  • Method 2: Use the ping command.

    Run the ping command on an ECS instance that is in the VPC that hosts the KMS instance. Extract the private IP address from the resolution result. The domain name must be in the following format: {KMS instance ID}.cryptoservice.kms.aliyuncs.com.

    For example, you can run the ping kst-szz63292789pf******.cryptoservice.kms.aliyuncs.com command to query the private IP address. The resolution result shows an IP address such as 172.16.XX.XX. The following code provides a sample output:

    Pinging kst-szz63292789pf******.cryptoservice.kms.aliyuncs.com [172.16.XX.XX] with 32 bytes of data

Step 2: Configure network connectivity between VPCs

By default, VPCs are isolated from each other. You must establish a connection between the VPC that hosts the KMS instance and the VPCs in other regions.

Alibaba Cloud VPC provides multiple solutions for VPC interconnection, such as Cloud Enterprise Network (CEN) and VPC peering connections. These solutions support cross-region connectivity between VPCs that belong to the same or different accounts. For more information, see the following topics:

Step 3: Configure domain name resolution in PrivateZone and associate VPCs

Configure PrivateZone to map the private domain name of the KMS instance to its IP address. This allows applications that are deployed in other regions to access the KMS instance.

  1. Log on to the Alibaba Cloud DNS console.

  2. Add a zone.

    1. In the navigation pane on the left, click Private Zone. On the Authoritative Zone tab, go to the User Defined Zones section and click Add Zone.

    2. Enter a name for the zone in the Authoritative Zone field. In the Effective Scope section, select the VPCs that you want to associate. Then, click OK.

  3. Add a PrivateZone resolution record for the zone.

    1. In the domain name list, find the target Zone and click Settings in the Actions column.

    2. On the Settings tab, click Add Record. Enter the configuration items and click <b data-tag="uicontrol" conref="mcms_dita_dnsnext-console-aliyun-com.dita#dnsnext-console-aliyun-com/common.ok"></b>.

      • Record Type: Select A.

      • Hostname: Enter the KMS instance ID.

      • Record Value: Enter the private IP address of the KMS instance.

      • Time-to-live (TTL): The cache duration. A smaller value indicates that record changes propagate faster. The default value is 1 minute. You can adjust the value as needed.

Step 4: Verify the configuration

On an ECS instance that is in a VPC newly associated in Step 3: Configure domain name resolution in PrivateZone and associate VPCs, run the ping command. If the resolved private IP address is the same as the one that you obtained in Step 1: Query the VPC and private IP address of the KMS instance, the configuration is successful.

What to do next