Skip to content

Latest commit

 

History

History
138 lines (92 loc) · 7.11 KB

security-manage-access-keys.md

File metadata and controls

138 lines (92 loc) · 7.11 KB
author description ms.author ms.date ms.service ms.subservice ms.custom ms.topic no-loc title uid
SoniaLopezBravo
Learn how to manage, regenerate, enable, and disable the access keys and connection strings for your Azure Quantum workspace.
sonialopez
03/04/2024
azure-quantum
qdk
devx-track-azurecli
how-to
Q#
$$v
Authenticate with Access Keys
microsoft.quantum.how-to.manage-access-keys

Using an access key to authenticate

Access keys are used to authenticate and authorize access to your Azure Quantum workspace. You can use access keys to connect and grant access to your workspace using connection strings.

In this article, you learn how to enable or disable the access keys for your Azure Quantum workspace. You can also regenerate new keys to ensure the security of your workspace.

Warning

Storing your account access keys or connection string in clear text presents a security risk and is not recommended. Store your account keys in an encrypted format, or migrate your applications to use Microsoft Entra authorization for access to your Azure Quantum workspace.

Prerequisites

Connect with a connection string

The azure-quantum package provides a Workspace class that represents an Azure Quantum workspace. To connect to your Azure Quantum workspace, you create Workspace object using the connection string as authenticator. For more information, see how to copy a connection string.

When creating a Workspace object, you have two options for identifying your Azure Quantum workspace.

  • You can create a Workspace object by calling from_connection_string.

    # Creating a new Workspace object from a connection string 
    from azure.quantum import Workspace 
    
    connection_string = "[Copy connection string]" 
    workspace = Workspace.from_connection_string(connection_string) 
    
    print(workspace.get_targets()) 
  • If you don't want to copy your connection string in the code, you can also store your connection string in an environment variable and use Workspace().

    # Using environment variable to connect with  connection string
    
    connection_string = "[Copy connection string]" 
    
    import os 
    
    os.environ["AZURE_QUANTUM_CONNECTION_STRING"] = connection_string 
    
    from azure.quantum import Workspace 
    
    workspace = Workspace() 
    print(workspace.get_targets()) 

Manage your keys and connection strings

You can manage access keys and connection strings for your Azure Quantum workspace in the Azure portal.

Enable and disable access keys

  1. Log in to the Azure portal and select your Azure Quantum workspace.

  2. On the left panel, navigate to Operations > Access keys.

  3. Switch the toggle under Access Keys to Enabled or Disabled.

  4. Click on Save to save the changes.

    :::image type="content" source="media/connection-string-enable.png" alt-text="Screenshot of Azure portal showing how to enable Access Keys to use connection strings.":::

Important

When Access Keys are disabled, all request using connection strings or access keys are unauthorized. You can still use the workspace parameters to connect to your workspace.

Regenerate new access keys

If you suspect that your Access Keys have been compromised, or you want to stop sharing your workspace access with others, you can regenerate either the primary or secondary access keys, or both, to ensure the security of your workspace.

  1. Log in to the Azure portal and select your Azure Quantum workspace.

  2. On the left panel, navigate to Operations > Access keys.

  3. Access Keys have to be enabled to regenerate new keys. If Access Keys are disabled, you need to enable them first.

  4. Click on the circular arrow icon to regenerate the primary or secondary key.

    :::image type="content" source="media/connection-string-regenerate.png" alt-text="Screenshot of Azure portal showing how to regenerate primary and secondary Access Keys.":::

    [!TIP] Every Azure Quantum workspace has primary and secondary keys, and their corresponding connection strings. If you want to allow access to your workspace to others, you can share your secondary key and you use your primary for your own services. This way, you can replace the secondary key as needed without having downtime in your own services. For more information about sharing your workspace access, see Share your workspace access.

You can use the Azure Command-Line Interface (Azure CLI) to manage access keys. For more information, see Manage quantum workspaces with the Azure CLI.

  1. Show the access keys for the workspace.

    az quantum workspace keys list 
    
  2. If you suspect that your access keys have been compromised, or you want to stop sharing your workspace access with others, you can regenerate either the primary or secondary access keys, or both, to ensure the security of your workspace.

    az quantum workspace keys regenerate --key-type Primary 
    az quantum workspace keys regenerate --key-type Secondary 
    az quantum workspace keys regenerate --key-type Primary,Secondary 
    

    [!TIP] Every Azure Quantum workspace has primary and secondary keys, and their corresponding connection strings. If you want to allow access to your workspace to others, you can share your secondary key and you use your primary for your own services. This way, you can replace the secondary key as needed without having downtime in your own services. For more information about sharing your workspace access, see Share your workspace access.

  3. You can enable and disable the access keys for the workspace.

    az quantum workspace update --enable-api-key true 
    az quantum workspace update --enable-api-key false 
    

    [!IMPORTANT] When Access Keys is disabled, all request using connection strings or access keys are unauthorized. You can still use the workspace parameters to connect to your workspace.