Skip to content

Commit 23c5859

Browse files
committed
Added opctl and docs
1 parent b2020e7 commit 23c5859

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

ads/opctl/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def init_vscode(**kwargs):
230230
"--auth",
231231
"-a",
232232
help="authentication method",
233-
type=click.Choice(["api_key", "resource_principal"]),
233+
type=click.Choice(["api_key", "resource_principal", "security_token"]),
234234
default=None,
235235
),
236236
click.option(

ads/opctl/config/merger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _fill_config_with_defaults(self, ads_config_path: str) -> None:
115115
else:
116116
self.config["execution"]["auth"] = AuthType.API_KEY
117117
# determine profile
118-
if self.config["execution"]["auth"] != AuthType.API_KEY:
118+
if self.config["execution"]["auth"] == AuthType.RESOURCE_PRINCIPAL:
119119
profile = self.config["execution"]["auth"].upper()
120120
exec_config.pop("oci_profile", None)
121121
self.config["execution"]["oci_profile"] = None

docs/source/user_guide/cli/authentication.rst

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,28 @@ You can choose to use the instance principal to authenticate while using the Acc
6262
mc = ModelCatalog(compartment_id="<compartment_id>")
6363
mc.list_models()
6464
65+
4. Authenticating Using Security Token
66+
--------------------------------------
6567

66-
4. Overriding Defaults
68+
**Prerequisite**
69+
70+
* You have setup security token as per the instruction `here <https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/clitoken.htm>`_
71+
72+
You can choose to use the security token to authenticate while using the Accelerated Data Science (ADS) SDK by running ``ads.set_auth(auth='security_token')``. For example:
73+
74+
.. code-block:: python
75+
76+
import ads
77+
ads.set_auth(auth='security_token')
78+
mc = ModelCatalog(compartment_id="<compartment_id>")
79+
mc.list_models()
80+
81+
5. Overriding Defaults
6782
----------------------
6883

6984
The default authentication that is used by ADS is set with the ``set_auth()`` method. However, each relevant ADS method has an optional parameter to specify the authentication method to use. The most common use case for this is when you have different permissions in different API keys or there are differences between the permissions granted in the resource principals and your API keys.
7085

71-
By default, ADS uses API keys to sign requests to OCI resources. The ``set_auth()`` method is used to explicitly set a default signing method. This method accepts one of three strings ``"api_key"``, ``"resource_principal"``, or ``instance_principal``.
86+
By default, ADS uses API keys to sign requests to OCI resources. The ``set_auth()`` method is used to explicitly set a default signing method. This method accepts one of four strings ``"api_key"``, ``"resource_principal"``, ``instance_principal`` or ``security_token``.
7287

7388
The ``~/.oci/config`` configuration allow for multiple configurations to be stored in the same file. The ``set_auth()`` method takes is ``oci_config_location`` parameter that specifies the location of the configuration, and the default is ``"~/.oci/config"``. Each configuration is called a profile, and the default profile is ``DEFAULT``. The ``set_auth()`` method takes in a parameter ``profile``. It specifies which profile in the ``~/.oci/config`` configuration file to use. In this context, the ``profile`` parameter is only used when API keys are being used. If no value for ``profile`` is specified, then the ``DEFAULT`` profile section is used.
7489

@@ -97,6 +112,7 @@ The ``~/.oci/config`` configuration allow for multiple configurations to be stor
97112
98113
ads.set_auth("resource_principal") # default signer is set to resource principal authentication
99114
ads.set_auth("instance_principal") # default signer is set to instance principal authentication
115+
ads.set_auth("security_token") # default signer is set to security token authentication
100116
101117
singer = oci.auth.signers.ResourcePrincipalsFederationSigner()
102118
ads.set_auth(config={}, singer=signer) # default signer is set to ResourcePrincipalsFederationSigner
@@ -122,9 +138,12 @@ Additional signers may be provided by running ``set_auth()`` with ``signer`` or
122138
oc.OCIClientFactory(**auth).object_storage
123139
124140
# Example 3: Create Object Storage client with timeout set to 6000 using API Key authentication.
125-
auth = authutil.api_keys(oci_config="/home/datascience/.oci/config", profile="TEST", kwargs={"timeout": 6000})
141+
auth = authutil.api_keys(oci_config="/home/datascience/.oci/config", profile="TEST", client_kwargs={"timeout": 6000})
126142
oc.OCIClientFactory(**auth).object_storage
127143
144+
# Example 4: Create Object Storage client with timeout set to 6000 using security token authentication.
145+
auth = authutil.security_token(oci_config="/home/datascience/.oci/config", profile="test_session", client_kwargs={"timeout": 6000})
146+
oc.OCIClientFactory(**auth).object_storage
128147
129148
In the this example, the default authentication uses API keys specified with the ``set_auth`` method. However, since the ``os_auth`` is specified to use resource principals, the notebook session uses the resource principal to access OCI Object Store.
130149

@@ -144,11 +163,14 @@ More signers can be created using the ``create_signer()`` method. With the ``aut
144163
# Example 1. Create signer that uses instance principals
145164
auth = ads.auth.create_signer("instance_principal")
146165
147-
# Example 2. Provide a ResourcePrincipalsFederationSigner object
166+
# Example 2. Create signer that uses security token
167+
auth = ads.auth.create_signer("security_token", profile="test_session")
168+
169+
# Example 3. Provide a ResourcePrincipalsFederationSigner object
148170
singer = oci.auth.signers.ResourcePrincipalsFederationSigner()
149171
auth = ads.auth.create_signer(config={}, singer=signer)
150172
151-
# Example 3. Create signer that uses instance principals with log requests enabled
173+
# Example 4. Create signer that uses instance principals with log requests enabled
152174
signer_callable = oci.auth.signers.InstancePrincipalsSecurityTokenSigner
153175
signer_kwargs = dict(log_requests=True) # will log the request url and response data when retrieving
154176
auth = ads.auth.create_signer(signer_callable=signer_callable, signer_kwargs=signer_kwargs)

0 commit comments

Comments
 (0)