Authenticate in your workspace using an access key

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 to your Azure Quantum workspace 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 access keys and connection strings

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 manage the 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.

    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.

    Screenshot of Azure portal showing how to regenerate primary and secondary Access Keys.