Skip to content

Commit a0d7ae9

Browse files
Add Instance Principal Authentication section.
1 parent 8229dd2 commit a0d7ae9

File tree

1 file changed

+104
-1
lines changed

1 file changed

+104
-1
lines changed

doc/src/user_guide/connection_handling.rst

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4621,7 +4621,7 @@ the following table.
46214621

46224622
With Simple Authentication, the individual configuration parameters can be provided at runtime.
46234623

4624-
With Instance Principal Authentication, OCI compute instances can be authorized to access services on Oracle Cloud such as Oracle Autonomous Database. Python-oracledb applications running on such a compute instance are automatically authenticated, eliminating the need to provide database user credentials. This authentication method will only work on compute instances where internal network endpoints are reachable. For more information on OCI compute instances, see `OCI Compute Instances <https://docs.oracle.com/en-us/iaas/compute-cloud-at-customer/topics/compute/compute-instances.htm>`__, `Creating a Compute Instance <https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/launchinginstance.htm>`__, and `Calling Services from a Compute Instance <https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/callingservicesfrominstances.htm>`__.
4624+
With Instance Principal Authentication, OCI compute instances can be authorized to access services on Oracle Cloud such as Oracle Autonomous Database. Python-oracledb applications running on such a compute instance are automatically authenticated, eliminating the need to provide database user credentials. This authentication method will only work on compute instances where internal network endpoints are reachable. See :ref:`instanceprincipalauth`.
46254625

46264626
See `OCI SDK Authentication Methods <https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdk_authentication_methods.htm>`__ for more information.
46274627
- Required
@@ -4790,6 +4790,109 @@ to explicitly set the ``extra_auth_params`` and ``externalauth`` parameters of
47904790
dsn=mydb_low,
47914791
extra_auth_params=token_based_auth)
47924792
4793+
.. _instanceprincipalauth:
4794+
4795+
Instance Principal Authentication
4796+
=================================
4797+
4798+
With Instance Principal Authentication, Oracle Cloud Infrastructure (OCI)
4799+
compute instances can be authorized to access services on Oracle Cloud such as
4800+
Oracle Autonomous Database. Python-oracledb applications running on such a
4801+
compute instance do not need to provide database user credentials.
4802+
4803+
Each compute instance behaves as a distinct type of Identity and Access
4804+
Management (IAM) Principal, that is, each compute instance has a unique
4805+
identity in the form of a digital certificate which is managed by OCI. When
4806+
using Instance Principal Authentication, a compute instance authenticates with
4807+
OCI IAM using this identity and obtains a short-lived token. This token is
4808+
then used to access Oracle Cloud services without storing or managing any
4809+
secrets in your application.
4810+
4811+
The example below demonstrates how to connect to Oracle Autonomous
4812+
Database using Instance Principal authentication. To enable this, use
4813+
python-oracledb's :ref:`oci_tokens <ocicloudnativeauthplugin>` plugin which
4814+
is pre-installed with the ``oracledb`` module.
4815+
4816+
**Step 1: Create an OCI Compute Instance**
4817+
4818+
An `OCI compute instance <https://docs.oracle.com/en-us/iaas/compute-cloud-at-
4819+
customer/topics/compute/compute-instances.htm>`__ is a virtual machine running
4820+
within OCI that provides compute resources for your application. This compute
4821+
instance will be used to authenticate access to Oracle Cloud services when
4822+
using Instance Principal Authentication.
4823+
4824+
To create an OCI compute instance, see the steps in `Creating an Instance
4825+
<https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/
4826+
launchinginstance.htm>`__ section of the Oracle Cloud Infrastructure
4827+
documentation.
4828+
4829+
For more information on OCI compute instances, see `Calling Services from a
4830+
Compute Instance <https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/
4831+
callingservicesfrominstances.htm>`__.
4832+
4833+
**Step 2: Install the OCI CLI on your compute instance**
4834+
4835+
The `OCI Command Line Interface (CLI) <https://docs.oracle.com/en-us/iaas/
4836+
Content/API/Concepts/cliconcepts.htm>`__ that can be used on its own or with
4837+
the Oracle Cloud console to complete OCI tasks.
4838+
4839+
To install the OCI CLI on your compute instance, see the installation
4840+
instructions in the `Installing the CLI <https://docs.oracle.com/en-us/iaas/
4841+
Content/API/SDKDocs/cliinstall.htm>`__ section of Oracle Cloud Infrastructure
4842+
documentation.
4843+
4844+
**Step 3: Create a Dynamic Group**
4845+
4846+
A Dynamic Group is used to define rules to group the compute instances that
4847+
require access.
4848+
4849+
To create a dynamic group using the Oracle Cloud console, see the steps in the
4850+
`To create a dynamic group <https://docs.oracle.com/en-us/iaas/Content/
4851+
Identity/Tasks/managingdynamicgroups.htm#>`__ section of the Oracle Cloud
4852+
Infrastructure documentation.
4853+
4854+
**Step 4: Create an IAM Policy**
4855+
4856+
An IAM Policy is used to grant a dynamic group permission to access the
4857+
required OCI services such as Oracle Autonomous Database.
4858+
4859+
To create an IAM policy using Oracle Cloud console, see the steps in the
4860+
`Create an IAM Policy <https://docs.oracle.com/en-us/iaas/application-
4861+
integration/doc/creating-iam-policy.html>`__ section of the Oracle Cloud
4862+
Infrastructure documentation.
4863+
4864+
**Step 5: Map an Instance Principal to an Oracle Database User**
4865+
4866+
You must map the Instance Principal to an Oracle Database user. For more
4867+
information, see `Accessing the Database Using an Instance Principal
4868+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-1B648FB0-BE86-
4869+
4BCE-91D0-239D287C638B>`__.
4870+
4871+
Also, make sure that external authentication is enabled on Oracle ADB and
4872+
Oracle Database parameter ``IDENTITY_PROVIDER_TYPE`` is set to *OCI_IAM*. For
4873+
the steps, see `Enable IAM Authentication on ADB <https://docs.oracle.com/en/
4874+
cloud/paas/autonomous-database/serverless/adbsb/enable-iam-authentication
4875+
.html>`__.
4876+
4877+
**Step 6: Deploy your application on the Compute Instance**
4878+
4879+
To use Instance Principal authentication, set ``extra_auth_params`` when
4880+
creating a standalone connection or a connection pool, for example:
4881+
4882+
.. code-block:: python
4883+
4884+
import oracledb
4885+
import oracledb.plugins.oci_tokens
4886+
4887+
token_based_auth = {
4888+
"auth_type": "InstancePrincipal"
4889+
}
4890+
4891+
connection = oracledb.connect(
4892+
dsn=mydb_low,
4893+
extra_auth_params=token_based_auth
4894+
)
4895+
47934896
Privileged Connections
47944897
======================
47954898

0 commit comments

Comments
 (0)