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
An Azure account with an active subscription. If you don’t have an Azure account, register for free and sign up for a pay-as-you-go subscription.
An Azure Quantum workspace. See Create an Azure Quantum workspace.
The latest version of the Azure Quantum
azure-quantum
package.!pip install --upgrade azure-quantum
If you use Azure CLI, you must have the latest version. For the installation instructions, see:
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 callingfrom_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
Log in to the Azure portal and select your Azure Quantum workspace.
On the left panel, navigate to Operations > Access keys.
Switch the toggle under Access Keys to Enabled or Disabled.
Click on Save to save the changes.
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.
Log in to the Azure portal and select your Azure Quantum workspace.
On the left panel, navigate to Operations > Access keys.
Access Keys have to be enabled to regenerate new keys. If Access Keys are disabled, you need to enable them first.
Click on the circular arrow icon to regenerate the primary or secondary key.