Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions to securely manage token #2322

Merged
merged 68 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
cab2eea
test twisty
abbycross Nov 14, 2024
f92740f
add info on env variable
abbycross Nov 14, 2024
8cf4f0f
add to functions intro page
abbycross Nov 14, 2024
880a541
squeaky
abbycross Nov 14, 2024
8e7b1bd
add separate section
abbycross Nov 15, 2024
929a1a0
tweak
abbycross Nov 15, 2024
6004777
restore IBM Cloud note
abbycross Nov 15, 2024
ca16e69
Update setup-channel.mdx
abbycross Nov 15, 2024
08377eb
Update docs/guides/setup-channel.mdx
abbycross Nov 18, 2024
5747749
Add tabs w/Runtime option
abbycross Nov 18, 2024
eb1b3a1
Apply suggestions from code review
abbycross Nov 18, 2024
602289c
Update docs/guides/functions.ipynb
abbycross Nov 18, 2024
6f5ed59
Update setup-channel.mdx
abbycross Nov 19, 2024
04285f9
rework page
abbycross Nov 19, 2024
05ec983
rmv ref to removed section
abbycross Nov 20, 2024
2973262
tweaks
abbycross Nov 20, 2024
a150476
rmv extra comments
abbycross Nov 20, 2024
d1f89a0
clarify default
abbycross Nov 20, 2024
215ab29
updates to the Platform section of the page
abbycross Nov 20, 2024
2b88216
redundant
abbycross Nov 21, 2024
ff129c2
bold
abbycross Nov 21, 2024
8b20e08
instructions for untrusted machine
abbycross Nov 21, 2024
d2451be
input from Vignesh
abbycross Nov 22, 2024
4aa4333
tweaks to iqp section
abbycross Nov 22, 2024
185939a
no need to italicize twice in a row
abbycross Nov 22, 2024
8e334db
first pass at REST API section
abbycross Nov 22, 2024
8d26470
test out subsection for REST API
abbycross Nov 22, 2024
c800067
Update docs/guides/setup-channel.mdx
abbycross Nov 26, 2024
b8df8c2
Update docs/guides/setup-channel.mdx
abbycross Nov 26, 2024
1f3d40d
move adm higher, rmv "or random", use original lang
abbycross Nov 26, 2024
0e18cd3
rmv "in plain text"
abbycross Nov 26, 2024
2bb59bf
add save_account() API link
abbycross Nov 26, 2024
f20da5a
copy paste code from account pg
abbycross Nov 26, 2024
b311aa2
fix indent
abbycross Nov 26, 2024
84de35b
rmv overwrite=True
abbycross Nov 26, 2024
e7acc27
separate into 2 blocks
abbycross Nov 26, 2024
8aeac62
tweaks
abbycross Nov 26, 2024
acc2bbd
updating wording on Functions pg
abbycross Nov 26, 2024
54a6c47
tox
abbycross Nov 26, 2024
7925905
Merge branch 'main' into ajc/update-install-instructions
abbycross Nov 26, 2024
c84195d
start fresh w serverless-manage-resources
abbycross Nov 26, 2024
d201682
rmv placeholder API text
abbycross Nov 26, 2024
9f34a79
comment in qunasys code
abbycross Nov 26, 2024
d3d602e
Update serverless-manage-resources.ipynb
abbycross Nov 26, 2024
1e59e09
add comments, remove placeholder text for api code
abbycross Nov 26, 2024
8374f06
add catalog back in
abbycross Nov 26, 2024
97b4f1d
more fix
abbycross Nov 26, 2024
5f31633
underscore
abbycross Nov 26, 2024
beb9434
tox
abbycross Nov 26, 2024
cb6b6fc
Apply suggestions from code review
abbycross Nov 27, 2024
b003b40
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
e0a952d
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
dbf79a9
Merge branch 'main' into ajc/update-install-instructions
abbycross Nov 27, 2024
6f5da2e
format a la iqp section
abbycross Nov 27, 2024
0be84fc
bring warning higher up in section
abbycross Nov 27, 2024
89ad0c0
break up line for readability
abbycross Nov 27, 2024
8c89b3e
Python to `python`
abbycross Nov 27, 2024
ee626fe
update untrusted language
abbycross Nov 27, 2024
57dbf4f
clarify refresh token language
abbycross Nov 27, 2024
a055c25
expire rather than rotate
abbycross Nov 27, 2024
c5a9851
what to do if you accidentally share token
abbycross Nov 27, 2024
dc974c2
tox
abbycross Nov 27, 2024
fe3ad1f
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
9eec6b9
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
cb4f46f
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
58a0205
pythonic
abbycross Nov 27, 2024
065dd39
Merge branch 'ajc/update-install-instructions' of https://github.com/…
abbycross Nov 27, 2024
9a14488
fix up token name
abbycross Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guides/functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"id": "42843fcd-1779-4a74-8d6a-7d00c22e374e",
"metadata": {},
"source": [
"Optionally, you can use the `save_account()` method to save your credentials for easy access later on, before initializing the service. This saves your credentials in the same place as `QiskitRuntimeService.save_account()`, so you can skip this step if you had previously used `QiskitRuntimeService` to save your account. *Note that account credentials are saved in plain text, so only do so if you are using a trusted device.*"
"Optionally, you can use the `save_account()` method to save your credentials for easy access later on, before initializing the service. This saves your credentials in the same place as `QiskitRuntimeService.save_account()`, so you can skip this step if you had previously used `QiskitRuntimeService` to save your account. *Note that account credentials are saved in plain text. To more securely manage your token, it is recommended to use an environment variable; see the [Securely manage your token](/guides/setup-channel#securely-manage) section for more information.*"
abbycross marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand Down
61 changes: 38 additions & 23 deletions docs/guides/setup-channel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Available plans:

* **Premium Plan** - Run quantum circuits on the world's best QPUs using an enterprise quantum time subscription.


### IBM Cloud

IBM Cloud offers pay-as-you-go access plans. See [IBM Quantum access plans](https://www.ibm.com/quantum/access-plans) for details.
Expand Down Expand Up @@ -60,7 +59,7 @@ Available plans:

```

Or, optionally use the `save_account()` method to save your credentials for easy access later on, before initializing the service.
Or, optionally use the `save_account()` method to save your credentials for easy access later on, before initializing the service. *Note that account credentials are saved in plain text. To more securely manage your token, it is recommended to use an environment variable; see the [Securely manage your token](#securely-manage) section for more information.*
abbycross marked this conversation as resolved.
Show resolved Hide resolved

```python
from qiskit_ibm_runtime import QiskitRuntimeService
Expand All @@ -85,20 +84,9 @@ Available plans:
* The `channel` parameter allows you to distinguish between different account types. When initializing the account, IBM Cloud is the default account used if have saved credentials for an IBM Quantum Platform and an IBM Cloud account.

<Admonition type="caution">
Account credentials are saved in plain text, so only do so if you are using a trusted device.
Account credentials are saved in plain text. To more securely manage your token, it is recommended to use an environment variable; see the [Securely manage your token](#securely-manage) section for more information.
abbycross marked this conversation as resolved.
Show resolved Hide resolved
</Admonition>

<Admonition type="note">
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
IBM Cloud is the default account used if you don't specify a different channel or account name.
</Admonition>

<CodeAssistantAdmonition
abbycross marked this conversation as resolved.
Show resolved Hide resolved
tagLine="If you forget the setup code, try asking Qiskit Code Assistant."
prompts={[
"# Set up my IBM Runtime account using TOKEN for my token"
]}
/>

1. Test your setup. Run a simple circuit using Sampler to ensure that your environment is set up properly:

```python
Expand Down Expand Up @@ -205,16 +193,15 @@ Alternatively, you can also access quantum processors with REST APIs, enabling y
1. Find your API key. From the [API keys page](https://cloud.ibm.com/iam/apikeys), view or create your API key, then copy it to a secure location so you can use it for authentication.
2. Find your Cloud Resource Name (CRN). Open the [Instances page](https://cloud.ibm.com/quantum/instances) and click your instance. In the page that opens, click the icon to copy your CRN. Save it in a secure location so you can use it for authentication.

<span id="cloud-save"></span>
1. Authenticate to the service by calling `QiskitRuntimeService` with your saved credentials or with your IBM Cloud API key and CRN:
1. <span id="cloud-save"></span>Authenticate to the service by calling `QiskitRuntimeService` with your saved credentials or with your IBM Cloud API key and CRN:

```python
from qiskit_ibm_runtime import QiskitRuntimeService

service = QiskitRuntimeService(channel="ibm_cloud", token="<IBM Cloud API key>", instance="<IBM Cloud CRN>")
```

You can optionally use the `save_account()` method to save your credentials for easy access later on, before initializing the service.
You can optionally use the `save_account()` method to save your credentials for easy access later on, before initializing the service. *Note that account credentials are saved in plain text. To more securely manage your token, it is recommended to use an environment variable; see the [Securely manage your token](#securely-manage) section for more information.*
abbycross marked this conversation as resolved.
Show resolved Hide resolved

```python
from qiskit_ibm_runtime import QiskitRuntimeService
Expand All @@ -238,17 +225,45 @@ Alternatively, you can also access quantum processors with REST APIs, enabling y
* Credentials are saved to `$HOME/.qiskit/qiskit-ibm.json`. Do not manually edit this file.
* If you don't save your credentials, you must specify them every time you start a new session.


<Admonition type="caution">
Account credentials are saved in plain text, so only do so if you are using a trusted device.
Account credentials are saved in plain text. To more securely manage your token, it is recommended to use an environment variable; see the [Securely manage your token](#securely-manage) section for more information.
abbycross marked this conversation as resolved.
Show resolved Hide resolved
</Admonition>

1. Test your setup. Ensure that you can connect to the service:
6. Test your setup. Ensure that you can connect to the service:

```python
from qiskit_ibm_runtime import QiskitRuntimeService
```python
from qiskit_ibm_runtime import QiskitRuntimeService

service = QiskitRuntimeService()
```
service = QiskitRuntimeService()
```

<span id="securely-manage"></span>
## Securely manage your token

To store sensitive information like account credentials more securely, it’s a good practice to use environment variables instead of saving them in plain text. Here’s how to modify your code to load the API token from an environment variable.
abbycross marked this conversation as resolved.
Show resolved Hide resolved

1. Set the environment variable.

Set the `IQP_API_TOKEN` environment variable in your system. You can do this by adding the following line to your shell profile (for example, `.bashrc`, `.zshrc`) or by setting it directly in your terminal:

```bash
export IQP_API_TOKEN="<YOUR_IQP_API_TOKEN>"
```

2. Modify the code to retrieve the token from the environment variable.

Update your code to retrieve the token from the environment variable instead of saving it directly:

```python
import os
from qiskit_ibm_catalog import QiskitFunctionsCatalog
abbycross marked this conversation as resolved.
Show resolved Hide resolved

# Gather the token from your environment
iqp_api_token = os.getenv("IQP_API_TOKEN")
abbycross marked this conversation as resolved.
Show resolved Hide resolved

QiskitFunctionsCatalog.save_account(token=iqp_api_token)
```

## Next steps

Expand Down
Loading