How to mask or hide OCP apim subscription key from being displayed in azure portal

Nagender Tipparna 0 Reputation points
2024-04-24T16:34:48.1166667+00:00

Can we hide/mask OCP apim subscription key which is called from KeyVault to display in azure portal apim policies.

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,126 questions
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,769 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. James Hamil 21,851 Reputation points Microsoft Employee
    2024-04-30T19:58:03.8733333+00:00

    Hi @Nagender Tipparna , I haven't tested it but you should be able to hide/mask the OCP APIM subscription key in Azure portal APIM policies by using named values. Named values are a way to store and reference values in your APIM policies without exposing them in plain text.

    Here are the high-level steps to use named values to hide/mask the OCP APIM subscription key:

    1. Create a named value for the OCP APIM subscription key in your APIM instance.
    2. Store the OCP APIM subscription key in Azure Key Vault.
    3. Reference the named value in your APIM policies instead of the OCP APIM subscription key.

    Here's an example policy that shows how to use named values to reference the OCP APIM subscription key:

    <policies>
        <inbound>
            <base />
            <set-header name="Ocp-Apim-Subscription-Key" exists-action="override">
                <value>@{
                    var keyVaultUri = "https://your-key-vault-name.vault.azure.net/";
                    var secretName = "your-secret-name";
                    var secretVersion = "your-secret-version";
                    var secretUri = $"{keyVaultUri}secrets/{secretName}/{secretVersion}";
                    var secretValue = await context.Backend.SendAsync(new HttpRequestMessage(HttpMethod.Get, secretUri));
                    return $"{{{{named-value:{secretValue.Content.ReadAsStringAsync().Result}}}}}";
                }</value>
            </set-header>
    			...
    

    Please let me know if you have any questions and I can help you further.

    If this answer helps you please mark "Accept Answer" so other users can reference it.

    Thank you,

    James

    0 comments No comments