In this exercise, you will secure an API by using an API key and an API key-ID pair.
Outcomes
You should be able to configure a Red Hat 3scale API Management product to require authentication by using an API key-ID pair.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command:
Deploys the application you will use in this exercise.
Configures a 3scale API Management product and backend.
[student@workstation ~]$ lab start secure-keys
Procedure 4.2. Instructions
Configure the secure_keys product to require authentication by using the API key.
Verify that the secure_keys_basic application plan in the secure_keys product does not have an associated application.
[student@workstation ~]$ 3scale application list 3scale-tenant \
--plan=secure_keys_basic --service=secure_keys
ID NAME STATE ENABLED ACCOUNT_ID SERVICE_ID PLAN_IDCreate a secure_key_app application that is associated with the secure_keys_basic application plan:
[student@workstation ~]$3scale application create 3scale-tenant \ john secure_keys secure_keys_basic secure_keys_appCreated application id:13
List the API key that is associated with the secure_key_app application.
Use the application ID from the preceding step.
[student@workstation ~]$API_KEY=$(3scale application show 3scale-tenant 13 \ -o json | jq -r '.user_key')[student@workstation ~]$echo $API_KEYbc18aa400edba94148e37a4f632e34b2
Use the key to call the books-api service:
[student@workstation ~]$ curl \
"https://secure-keys-3scale-apicast-staging.apps.ocp4.example.com:443/books?user_key=$API_KEY" | jq
...output omitted...Configure the secure_keys product to require authentication by using the API key-ID pair.
Log in to RHOCP:
[student@workstation ~]$ oc login \
-u=admin -p=redhat --server=https://api.ocp4.example.com:6443
...output omitted...In a web browser, log in to the 3scale API Management Administration Portal as the admin user.
Execute the following command to see the ADMIN_PASSWORD:
[student@workstation ~]$ oc get secret system-seed -n 3scale \
-o json | jq -r .data.ADMIN_PASSWORD | base64 -d; echo
...output omitted...In the section, click the secure_keys product.
Click → .
In the section, select App_ID and App_Key Pair The application is identified via the App_ID and authenticated via the App_Key.
Note that the user_key value becomes the default app_key value.
Click . Then, click and click .
Use the key-ID pair to authenticate your API call.
Verify that using API key is no longer sufficient to authorize to the API:
[student@workstation ~]$ curl \
"https://secure-keys-3scale-apicast-staging.apps.ocp4.example.com:443/books?user_key=$API_KEY"; echo
Authentication parameters missingFind the application ID for the application you created in the preceding steps.
The following step uses ID 13 as the ID for the application:
[student@workstation ~]$API_ID=$(3scale application show 3scale-tenant 13 \ -o json | jq -r '.application_id')[student@workstation ~]$echo $API_IDeb34878e
Authenticate your API call by using the API_KEY and API_ID variables:
[student@workstation ~]$ curl \
"https://secure-keys-3scale-apicast-staging.apps.ocp4.example.com:443/books?app_key=$API_KEY&app_id=$API_ID"| jq
...output omitted...This concludes the guided exercise.