When working with DBMS_CLOUD package or cloud REST APIs , I need database instance to be authenticated and authorized. Mainly there are two ways of doing this.
1I can use my own credentials or any IAM users credentials. For this purpose I need to use DBMS_CLOUD.create_credential procedure that comes in three different signatures.
aI can create an Auth token from console or using cli
then using this token and my user I can create a credential. Just to avoid confusion with below script, I use my email address as username in my tenancy.
bAnother way is to introduce my API signing RSA keys to OCI, then use it to create a credential. For generating my own key pair I can use openssl as described here in official documentation . I can also use the console which can generate the keys for me and I can download it. Using console I can upload my existing keys too.
After the API key added to OCI, console will display a configuration that can be used with SDK, CLI or REST calls.
CLI doesn't offer a command for adding API keys but I can always use REST API with http raw request, again response will display required information to use API key with SDK and CLI
Note:Use \n as new line feed for formatting your encoded public/private key
Now I can use a different version of create_credential procedure
Note:Both credentials (Auth Token and API Key) are directly linked to my OCI IAM user.
2I can also use Resource Principals to authorize my ATP instance. Previous method is tied to an IAM user (notice both Auth Token and API Key are created under user), resource principal uses Dynamic Groups to identify the instance and IAM no user is required.
aFirst I need a Dynamic Group to identify my instances. I generally use tagging, but sometimes allowing all autonomous instances is also fine.
bThen with a policy I grant priviliges to the members of that dynamic group
Note:The resource principal token is cached for two hours. Therefore, if you change the policy or the dynamic group, you have to wait for two hours to see the effect of your changes. This note is from documentation .
Here is the complete list of cli commands with some outputs for the same purpose:
cAnd I connect to the database and enable Resource Principal to Access Oracle Cloud Infrastructure Resources .
Testing
1I can see that my credential is visible and enabled in all_credentials. For testing I am just listing objects under an object storage bucket
2I can list objects under a bucket using any of the credentials.
Here is some SQL for testing
No comments:
Post a Comment