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 |
10/22/2024 |
azure-quantum |
qdk |
devx-track-azurecli |
how-to |
|
Authenticate with Access Keys |
microsoft.quantum.how-to.manage-access-keys |
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.
-
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:
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())
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.
-
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.
:::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.
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.
:::image type="content" source="media/connection-string-regenerate.png" alt-text="Screenshot of Azure portal showing how to regenerate primary and secondary Access Keys.":::
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.
-
Show the access keys for the workspace.
az quantum workspace keys list
-
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
-
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.