Thursday, April 22, 2021

Configuring OKV automation using REST APIs

 This post will go through the process of creating a few simple scripts to automate OKV installation using the REST API capability of OKV.


NOTE: This information was provided by the product manager Peter Wahl who has a great blog on the features of OKV and some great "Ask Tom" sessions on OKV (and other security pieces),you can watch and learn more.


Step #1 Configure RESTful Services and download client tool

First you need to configure the OKV server for RESTful Services. The instructions can be found here. This is done by navigating to the System tab and clicking on RESTful Services.
It is recommended that you only enable the RESTful services when you are actively onboarding new endpoints.


This bring up the window below.



 There are three things you want to do from this window.
  1. Click on the "Enable" box to enable RESTful services
  2. Download the okvrestcliepackage.zip which are the client utilities.
  3. Save this setting to enable RESTful services.
Now that we have this file, we need to download it our client and start creating the scripts to automate this process.

I downloaded the zip file to my DB host to configure it. I unzipped it in /home/oracle/okv/rest

NOTE: you can also download it directly from the OKV hosts by using any of the commands below.



Step #2 Create a user for the restapi steps

I create a new user in OKV called "restapi" and you can see the permissions below.  Before using the new user, you must login and change the password because the password is expired by default when creating a new user.






Step #3 unzip and configure the client tool 


I unzipped the client tool into my home directory on a DB server so I can put together the automation scripts. In my case I unzipped it into /home/oracle/okv/rest. This creates 3 sub directories. I am going to format the output using this command.




Below is what the output looks like

.
 |-lib
 | |-okvrestcli.jar
 |-bin
 | |-okv.bat
 | |-okv
 |-conf
 | |-okvrestcli.ini
 | |-okvrestcli_logging.properties


Step #4 - Set the environment for the CLI

In order to configure OKV, I am going to need some variables set in my environment. I can do this manually, but in my case I decided to create a "setenv.sh" script that will set the variables and add the OKV script to my path to be executed. I also included the ability to pass a parameter (ORACLE_SID) so that you can use the script in a loop across multiple instances on the same host.
 The 3 main variables I will be using are

OKV_RESTCLI_HOME - Location of the scripts that I am going to be installing. If I source the setenv.sh script, it will set the home to this location.

OKV_RESTCLI_CONFIG - Name of the configuration file that contains the rest CLI configuration.

OKV_HOME - Location to install OKV for the current instance.  This location is $ORACLE_BASE/admin/${DB_UNIQUE_NAME}/okv_home.  This follows the standard for ExaCC.


NOTE: If this is a NEW database

If you want to use these steps to configure OKV on a new database, you need to perform the following steps prior to executing "/ ./setenv.sh".
  1. Add the new $ORACLE_SIDE for the host in the "/etc/oratab" file.
  2. Create the directory "mkdir $ORACLE_BASE/admin/{DB Unique Name}"
  3. Create the directory "mkdir -p $ORACLE_BASE/diag/rdbms/${DB Unique Name}/${ORACLE_SID}
  4. Use ". oraenv" to set the environment to this $ORACLE_SID



Step #5 - Set initialization parameters in okvrestcli.ini file


Next, I am going to configure the initialization parameters. These are found in the okvrestcli.ini file.
You can see that the file contains a "[Default]" profile and a few other example profiles. We will start with the default profile. In this we are going to set a few of the properties.

LOG_PROPERTY - Location of the logging properties. Default location is ./conf directory.

SERVER - IP address (or DNS) of one or more OKV hosts 

 OKV_CLIENT_CONFIG - location of the config file. Default location is ./conf directory

USER - OKV user that has authority to administer endpoints an wallets. In this case it will be the restapi user that I created.

PASSWORD - Password for the user, or location of wallet containing the password. I am NOT going to use this as I am going to use a wallet file.

 CLIENT_WALLET - I am going to use a wallet to store the password, and this is the location of the wallet file. I will be creating the autologin wallet later.

 

Below is what my "[Default]" configuration file looks like after my changes which is located at $OKV_RESTCLI_HOME/conf/okvrestcli.ini . I am going to use the environmental variables I set in the setenv.sh script. 

NOTE: I am choosing to store my password in wallet rather than clear text in the .ini file.

          You need to change the server to either the server name or the IP address.


Step #6 Create the wallet to save the password encrypted

Since I chose to put my password in a wallet, I now need to create that wallet. Using the instructions in the document (linked to at the beginning of this blog), I execute the command from the directory I installed into (/home/oracle/okv/rest)



Step #7 Create and execute the run-me.sh script


The last step is to create the script that will be executed  on the host to create the provision script.  In my script, I took the default and did some checking. This script will
  • Ensure the variable OKV_RESTCLI_HOME is set before it can be executed.
  • Determine the DB_UNIQUE_NAME from the $ORACLE_BASE/diag/rdbms/*/$ORACLE_SID directory. Solving for the  * should give us the DB_UNIQUE_NAME
  • While executing, it tells you what it believes the DB_UNIQUE_NAME is, and gives you a chance to change it if incorrect.
  • It will validate if the endpoint group exists by accessing OKV. If the endpoint group already exists, it does not try to create it again. If it doesn't exist it will create the endpoint group.
  • It will validate if the wallet exists by accessing OKV. If the wallet already exists, it does not try to create it again. If it doesn't exist it will create the wallet .
  • t will add the endpoint, add this endpoint to the endpoint group, and assign the wallet to this endpoint.
  • It will install the client software in $ORACLE_BASE/admin/$DB_UNIQUE_NAME/okv_home/okv
Below is the script I am using.




Step #8 Execute okv-install-${ORACLE_SID}.sh to validate that enrollment works

[oracle@pmdexa1dbadm01vm01 okv]$ ./okv-ep.sh
{
  "result" : "Success"
}
{
  "result" : "Success"
}
{
  "result" : "Success"
}
spawn okv admin endpoint provision --endpoint DEMO31_on_pmdexa1dbadm01vm01 --location /u01/app/oracle/admin/demo31/wallet/okv --auto-login FALSE
Enter Oracle Key Vault endpoint password:
{
  "result" : "Success"
}

Once I ran it I removed the files that were created for the install.

Step #9 Zip it all up and place it in a location to be downloaded

Below is the scripts that will be part of the zip file.

.
 |-wallet
 | |-ewallet.p12.lck
 | |-ewallet.p12
 | |-cwallet.sso.lck
 | |-cwallet.sso
 |-conf
 | |-okvrestcli_logging.properties
 | |-okvrestcli.ini
 |-setenv.sh
 |-runme.sh
 |-lib
 | |-okvrestcli.jar
 |-bin
 | |-okv
 | |-okv.bat

Now I am ready to download this zip file to my Database Host and enroll a database.

NOTE: To change the script to work on another OKV all host I only had to make 3 changes.
  • Update the okvrestcli.ini file with OKV host IP
  • Update the okvrestcli.ini file with the the user
  • recreate the wallet file that contains the password for the OKV user

Step #10 Run root.sh if this is the first on a host

When a new endpoint is added, a script is downloaded into the $OKV_HOME/okv/bin/ directory called root.sh.. This script will copy the PKCS library (liborapkcs.so) in central location on the host as root. This file is needed for the database to access OKV. The location of this file is different on different OS systems.

NOTE: If you are already using a key management software on this host for Oracle databases, running root.sh could overwrite the library used. 



No comments:

Post a Comment