Do240 2.11 Student Guide
Do240 2.11 Student Guide
The contents of this course and all its modules and related materials, including handouts to audience members, are
Copyright © 2022 Red Hat, Inc.
No part of this publication may be stored in a retrieval system, transmitted or reproduced in any way, including, but
not limited to, photocopy, photograph, magnetic, electronic or other record, without the prior written permission of
Red Hat, Inc.
This instructional program, including all material provided herein, is supplied without any guarantees from Red Hat,
Inc. Red Hat, Inc. assumes no liability for damages or legal action arising from the use or misuse of contents or details
contained herein.
If you believe Red Hat training materials are being used, copied, or otherwise improperly distributed, please send
email to [email protected] or phone toll-free (USA) +1 (866) 626-2994 or +1 (919) 754-3700.
Red Hat, Red Hat Enterprise Linux, the Red Hat logo, JBoss, OpenShift, Fedora, Hibernate, Ansible, CloudForms,
RHCA, RHCE, RHCSA, Ceph, and Gluster are trademarks or registered trademarks of Red Hat, Inc. or its subsidiaries
in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS® is a registered trademark of Hewlett Packard Enterprise Development LP or its subsidiaries in the United
States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is a trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open
source or commercial project.
The OpenStack word mark and the Square O Design, together or apart, are trademarks or registered trademarks
of OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's
permission. Red Hat, Inc. is not affiliated with, endorsed by, or sponsored by the OpenStack Foundation or the
OpenStack community.
Introduction xi
Cloud-native API Administration with Red Hat 3scale API Management ............................ xi
Orientation to the Classroom Environment .................................................................. xii
DO240-RH3APIM2.11-en-2-20220405 vii
Configuring API Analytics ........................................................................................ 176
Guided Exercise: Configuring API Analytics ............................................................... 180
Monitoring 3Scale Infrastructure .............................................................................. 183
Guided Exercise: Monitoring 3Scale Infrastructure ...................................................... 186
Quiz: Monitoring APIs with Red Hat 3scale API Management ........................................ 191
Summary .............................................................................................................. 195
7. Monetizing APIs with Red Hat 3Scale API Management 197
Configuring Billing for APIs ..................................................................................... 198
Guided Exercise: Configuring Billing for APIs ............................................................ 202
Configuring Pricing Rules for API Consumption ......................................................... 205
Guided Exercise: Configuring Pricing Rules for API Consumption ................................. 208
Quiz: Monetizing APIs with Red Hat 3Scale API Management ....................................... 210
Summary .............................................................................................................. 212
viii DO240-RH3APIM2.11-en-2-20220405
Document Conventions
This section describes various conventions and practices used throughout all
Red Hat Training courses.
Admonitions
Red Hat Training courses use the following admonitions:
References
These describe where to find external documentation relevant to a
subject.
Note
These are tips, shortcuts, or alternative approaches to the task at hand.
Ignoring a note should have no negative consequences, but you might
miss out on something that makes your life easier.
Important
These provide details of information that is easily missed: configuration
changes that only apply to the current session, or services that need
restarting before an update will apply. Ignoring these admonitions will
not cause data loss, but may cause irritation and frustration.
Warning
These should not be ignored. Ignoring these admonitions will most likely
cause data loss.
Inclusive Language
Red Hat Training is currently reviewing its use of language in various areas
to help remove any potentially offensive terms. This is an ongoing process
and requires alignment with the products and services covered in Red Hat
Training courses. Red Hat appreciates your patience during this process.
DO240-RH3APIM2.11-en-2-20220405 ix
x DO240-RH3APIM2.11-en-2-20220405
Introduction
DO240-RH3APIM2.11-en-2-20220405 xi
Introduction
In this course, the main computer system used for hands-on learning activities is workstation.
The system called bastion must always be running. These two systems are in the
lab.example.com DNS domain.
All student computer systems have a standard user account, student, which has the password
student. The root password on all student systems is redhat.
Classroom Machines
xii DO240-RH3APIM2.11-en-2-20220405
Introduction
The bastion system acts as a router between the network that connects the student machines
and the classroom network. If bastion is down, other student machines may not function
properly or may even hang during boot.
The utility system acts as a router between the network that connects the OpenShift cluster
machines and the student network. If utility is down, the OpenShift cluster will not function
properly or may even hang during boot.
Students use the workstation machine to access a dedicated OpenShift cluster, for which they
have cluster administrator privileges.
Machine States
active The virtual machine is running and available (or, when booting, soon
will be).
DO240-RH3APIM2.11-en-2-20220405 xiii
Introduction
Classroom/Machine Actions
CREATE Create the ROL classroom. Creates all of the virtual machines needed
for the classroom and starts them. Can take several minutes to
complete.
DELETE Delete the ROL classroom. Destroys all virtual machines in the
classroom. Caution: Any work generated on the disks is lost.
OPEN CONSOLE Open a new tab in the browser and connect to the console of the
virtual machine. Students can log in directly to the virtual machine and
run commands. In most cases, you should log in to the workstation
virtual machine and use ssh to connect to the other virtual machines.
ACTION > Shutdown Gracefully shut down the virtual machine, preserving the contents of
its disk.
ACTION > Power Off Forcefully shut down the virtual machine, preserving the contents of its
disk. This is equivalent to removing the power from a physical machine.
ACTION > Reset Forcefully shut down the virtual machine and reset the disk to its initial
state. Caution: Any work generated on the disk is lost.
At the start of an exercise, if instructed to reset a single virtual machine node, click ACTION >
Reset for only the specific virtual machine.
At the start of an exercise, if instructed to reset all virtual machines, click ACTION > Reset
If you want to return the classroom environment to its original state at the start of the course, you
can click DELETE to remove the entire classroom environment. After the lab has been deleted,
you can click CREATE to provision a new set of classroom systems.
Warning
The DELETE operation cannot be undone. Any work you have completed in the
classroom environment up to that point will be lost.
To adjust the timer, click + to add one hour to the timer. Note that there is a maximum time of
twelve hours.
xiv DO240-RH3APIM2.11-en-2-20220405
Introduction
Machine States
STARTED The virtual machine is running and available (or, when booting, soon
will be).
STOPPED The virtual machine is completely shut down. Upon starting, the virtual
machine boots into the same state as when it was shut down (the disk
will have been preserved).
WAITING_TO_START The virtual machine is waiting for other virtual machines to start.
Classroom/Machine Actions
PROVISION LAB Create the ROL classroom. Creates all of the virtual machines needed
for the classroom and starts them. Can take several minutes to
complete.
DELETE LAB Delete the ROL classroom. Destroys all virtual machines in the
classroom. Caution: Any work generated on the disks is lost.
OPEN CONSOLE Open a new tab in the browser and connect to the console of the
virtual machine. You can log in directly to the virtual machine and run
commands. In most cases, you should log in to the workstation
virtual machine and use ssh to connect to the other virtual machines.
DO240-RH3APIM2.11-en-2-20220405 xv
Introduction
ACTION > Shutdown Gracefully shut down the virtual machine, preserving the contents of
its disk.
ACTION > Power Off Forcefully shut down the virtual machine, preserving the contents of its
disk. This is equivalent to removing the power from a physical machine.
ACTION > Reset Forcefully shut down the virtual machine and reset the disk to its initial
state. Caution: Any work generated on the disk is lost.
At the start of an exercise, if instructed to reset a single virtual machine node, click ACTION >
Reset for only the specific virtual machine.
At the start of an exercise, if instructed to reset all virtual machines, click ACTION > Reset
If you want to return the classroom environment to its original state at the start of the course,
you can click DELETE LAB to remove the entire classroom environment. After the lab has been
deleted, you can click PROVISION LAB to provision a new set of classroom systems.
Warning
The DELETE LAB operation cannot be undone. Any work you have completed in the
classroom environment up to that point will be lost.
To adjust the timer, click MODIFY to display the New Autostop Time dialog box. Set the number
of hours until the classroom should automatically stop. Note that there is a maximum time of ten
hours. Click ADJUST TIME to apply this change to the timer settings.
xvi DO240-RH3APIM2.11-en-2-20220405
Chapter 1
DO240-RH3APIM2.11-en-2-20220405 1
Chapter 1 | Introducing Red Hat 3scale API Management
Objectives
After completing this section, you should be able to describe the architecture of Red Hat 3scale
API Management and the benefits of API Management.
You can deploy 3scale on-premises, in the cloud, as a managed service, or as a combination.
Features
• There are two different logical components: the API Manager and the API Gateway. If the API
Manager is down, then the API Gateway still works.
• Administrators can manage their APIs through a rich user interface, the Admin Portal.
• Administrator can manage their APIs through a rich command-line utility, the 3scale Toolbox
CLI.
API 1
Incoming request
API Gateway API 2
2 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
The API Gateway fetches the API Manager information (routing policies, users, rate limits…)
periodically and saves it. This means that the API Gateway does not have to get the information
from the API Manager on every incoming request, therefore, reducing latency. At the same time, if
the API Manager is down for some minutes, the API Gateway can work independently because it
holds the cached information.
Routing policies
You can use a routing policy to define an external route where the consumers of your APIs will
make requests. Then, after these requests reach 3scale, you define where they are delivered.
For example, consider that you have a book API available at http://books.mystore.com/. You
want your clients to consume your API through 3scale to be able to manage different aspects of
the API. Consider also that you define a 3scale route /books, which is the public external route
that your clients will use. With the routing capabilities of 3scale, you can map the /books route
to your external service http://books.mystore.com/. The following diagram illustrates this
process.
Your APIs
API Manager
/books -->http://books.mystore.com/
3scale installation
To create routing policies, 3scale provides two abstractions: products and backends. A product is
used to define the external routes accessible by your clients. A backend is used to define your API
services. Then, a product is mapped to one or several backends to achieve the routing policy. The
following diagram illustrates the books example with a new route, /authors. The /books route
is mapped to http://books.mystore.com/ and the /authors route is mapped to http://
authors.mystore.com/.
DO240-RH3APIM2.11-en-2-20220405 3
Chapter 1 | Introducing Red Hat 3scale API Management
http://authors.mystore.com/
API Manager
Product Backend
Your APIs
/books http://books.mystore.com/
Backend
/authors http://authors.mystore.com/
3scale installation
Figure 1.3: API Manager routing example based on products and backends
Rate limits
You can use rate limits to control the number of requests that each of your clients can make to
your APIs.
3scale provides the abstraction of an application. You can consider that each of your clients is a
3scale application. On every request, 3scale must identify which of your clients (i.e. applications) is
making the request to be able to apply the rate limits. Every application is assigned a random user
key. Then, your client must include this user key on every request.
At the same time, an application holds an application plan, which is used to define the rate limits
for every application.
For example, consider the books example previously mentioned. If you have two clients, client1
and client2, then you can create two applications. For every application, a random user key is
generated, which must be provided when making external requests. For every application, you
can create an application plan, which contains the rate limits of the application (i.e. how many
requests the application can make in a specific period of time). The following diagram illustrates
this behavior.
4 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
Your APIs
API Manager
Product Backend
/books http://books.mystore.com/
3scale installation
Developer Portal
The Developer Portal is a public web page that you can use to provide information about your
APIs. The Developer Portal is entirely customizable and it provides features such as Swagger
definitions importing, authentication for developers, or email templates.
DO240-RH3APIM2.11-en-2-20220405 5
Chapter 1 | Introducing Red Hat 3scale API Management
Tenants
In the context of 3scale API Management, a tenant acts as an instance of 3scale. Within the same
3scale installation, you can create several instances of the product.
By using several tenants, you can create a logical separation of your APIs. For example, consider
that you have two tenants: orders and finance. In the order tenants you create APIs related to
orders, and in the finance tenant you create APIs related to payments. At the same time, you can
restrict who has access to every tenant independently.
The default tenant is called 3scale, and you can create as many tenants as you want depending
on your needs.
The implementation of the API Gateway is APIcast, an open-source NGINX-based API Gateway.
The default 3scale installation comes with two APIcast instances: one for a staging environment
and another one for a production environment.
6 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
Request
Request
Your APIs
Request
API Manager
3scale installation
References
Red Hat Developer - Red Hat 3scale API Management
https://developers.redhat.com/products/3scale/overview
DO240-RH3APIM2.11-en-2-20220405 7
Chapter 1 | Introducing Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to:
• Log in to OpenShift.
Instructions
1. Log in to RHOCP.
1.1. In a command-line terminal, run the oc login command with the following
credentials:
• Username: admin
• Passsword: redhat
...output omitted...
2. Clone the DO240-apps GitHub repository. This repository contains scripts and applications
that you will use throughout the course.
8 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
2.2. To execute the scripts later in the course, grant execution permissions to the files in
the scripts directory.
Finish
On the workstation machine, use the lab command to complete this exercise.
DO240-RH3APIM2.11-en-2-20220405 9
Chapter 1 | Introducing Red Hat 3scale API Management
Objectives
After completing this section, you should be able to install Red Hat 3scale API Management on
OpenShift and install the 3scale Toolbox CLI.
System Requirements
Depending on your OpenShift installation and your application's workload, your system
requirements might vary. Review the recommended parameters in 3scale official documentation
[https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.11/html-
single/installing_3scale/index#system-requirements-for-installing-threescale-on-openshift].
You can authenticate your OpenShift cluster by creating an OpenShift docker-registry secret.
This secret contains the username and token that is used when pulling images from the Red Hat
Registry. Use the Red Hat Registry Service Account credentials.
Then, link the secret to your OpenShift service account for pulling container images. You can link it
to the default OpenShift service account.
10 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
Link the secret to the builder OpenShift service account for pushing and pulling build images.
The 3scale operator provides several custom resources used to deploy some of the product
features. After installing the operator, you must deploy a new APIManager custom resource. The
APIManager custom resource is used to deploy the 3scale API Management product itself. The
following snippet is an APIManager example:
apiVersion: apps.3scale.net/v1alpha1
kind: APIManager
metadata:
name: apimanager-sample
namespace: 3scale
spec:
wildcardDomain: example.com
Note
Red Hat recommends to both install the operator and deploy the APIManager
custom resource in a custom project. For example, in the previous snippet, the
3scale project is used.
The wildcardDomain field must be a resolvable domain. Usually, it is the domain where
your OpenShift cluster is running. For example, if your OpenShift cluster is running in
yourdomain.com, then the deployment of the APIManager custom resource generates routes
such as 3scale-admin.yourdomain.com.
The most frequent issues that you might face when installing 3scale are:
DO240-RH3APIM2.11-en-2-20220405 11
Chapter 1 | Introducing Red Hat 3scale API Management
Not enough Some pods cannot get to Increase the memory and/or CPU of your
memory the Running or Completed OpenShift nodes.
and/or CPU status after several minutes
to deploy
3scale
You can use the Toolbox by running the official container image provided by 3scale,
registry.redhat.io/3scale-amp2/toolbox-rhel8:3scale2.11. Because the container
image is stored in the Red Hat Registry, you must log in with your Red Hat Registry credentials.
You can use podman run to execute the Toolbox by using the following format:
USAGE
3scale <sub-command> [options]
...output omitted...
Because executing podman run is too long, you can create a bash alias.
12 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
To use the Toolbox, you must configure one or more remotes. A Toolbox remote holds the
credentials to interact with a 3scale tenant. The following is an example of a Toolbox remote.
https://ACCESS_TOKEN@TENANT_ADMIN_PORTAL_URL
The TENANT_ADMIN_PORTAL_URL variable is your tenant's Admin Portal URL. The default tenant
created when you install 3scale is 3scale, therefore, the URL of the default tenant's Admin Portal
is 3scale-admin.YOUR_DOMAIN. The ACCESS_TOKEN variable is used to authenticate the
remote against the tenant. You can create a new access token by using the Admin Portal of the
tenant.
Then, you can use the remote add command to add the remote to the Toolbox.
Note
The -k option, provided in the previous command, allows connections to 3scale
without an SSL certificate. Because the container created by podman run does not
hold a proper certificate, you must add the -k option.
Because the podman run command creates a new container on every execution, the remote
data is not kept between executions. You can solve this issue by creating a new container image
that contains the remote information. This way, podman run creates a new container on every
execution with an image that holds the remote.
For example, you can use podman run to create a named container that contains the remote
information.
Then, you can use podman commit to create a new image, toolbox, from the named container.
Because the previous created container holds the remote information, the new image contains it
too.
Now, you can update the 3scale bash alias to use the toolbox image.
DO240-RH3APIM2.11-en-2-20220405 13
Chapter 1 | Introducing Red Hat 3scale API Management
Note
To persist this alias across sessions, add it to your user's ~/.bashrc file.
References
Red Hat 3scale official documentation - Installing 3scale on OpenShift
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/installing_3scale/index#install-
threescale-on-openshift-guide
14 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to:
• Install Red Hat 3scale API Management on OpenShift by using the 3scale OpenShift
operator.
Run the following command to ensure that your OpenShift cluster is running properly.
Instructions
1. Log in to the Red Hat OpenShift web console with an account that has cluster administrator
privileges.
• Username: admin
• Password: redhat
2. Create a new OpenShift project, where you will install the 3scale Operator.
2.2. Click Create Project and type 3scale in the Name field. Then, click Create.
DO240-RH3APIM2.11-en-2-20220405 15
Chapter 1 | Introducing Red Hat 3scale API Management
3.3. Select the Red Hat Integration - 3scale operator, and then click Install.
3.4. Complete the form according to the following parameters, and then click Install.
16 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
4.1. In the Provided APIs section, find APIManager. Click Create instance.
The Create APIManager form displays.
4.2. Click YAML view in the Configure via section to see the APIManager custom
resource as a YAML file.
apiVersion: apps.3scale.net/v1alpha1
kind: APIManager
metadata:
name: apimanager-sample
namespace: 3scale
spec:
wildcardDomain: apps.ocp4.example.com
resourceRequirementsEnabled: false
Note
The wildcardDomain field is used to create the accessible routes of 3scale. For
example, the Admin Portal might be 3scale-admin.wildcardDomain.
4.4. Click Create. The APIManager deployment creates several OpenShift resources,
therefore, it takes several minutes for all the pods to be available.
In the meantime, you can proceed with the exercise by installing the 3scale Toolbox
CLI.
5. Install the 3scale Toolbox CLI. The official way of installing the Toolbox is by using the
3scale Toolbox CLI container image, registry.redhat.io/3scale-amp2/toolbox-
rhel8:3scale2.11.
5.2. Click New Service Account to create a new Service Account. In the Name field type
do240, and then click Create.
Note
Your username also includes the random string of numbers provided before the
Name field. For example, if you provide the do240 name, then a possible username
string is 89238478|do240.
5.3. The Token Information page displays your username and token. Keep this page
open, as the contents are necessary later in this exercise.
DO240-RH3APIM2.11-en-2-20220405 17
Chapter 1 | Introducing Red Hat 3scale API Management
5.4. In your command-line terminal, log in to the Red Hat Registry by using Podman. Use
the username and token from the previous step.
5.5. Pull the 3scale Toolbox CLI image from the Red Hat Registry by using Podman.
5.6. Verify the installation. You can use podman run to execute the 3scale Toolbox CLI
by using the following format:
For example, if you want to execute the help command in the 3scale Toolbox CLI.
USAGE
3scale <sub-command> [options]
...output omitted...
5.7. Because using podman run is too long, you can create a bash alias.
Now you can run 3scale COMMAND. For example, you can run the 3scale help
command.
USAGE
3scale <sub-command> [options]
...output omitted...
6. In the 3scale Toolbox CLI, add a remote for the default 3scale tenant.
18 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
...output omitted...
6.2. In your command-line terminal, use the oc get secret command to retrieve the
password for the 3scale tenant Admin Portal.
The default passwords of 3scale are stored in the system-seed secret. By executing
the previous command, you retrieve the ADMIN_PASSWORD entry of the system-
seed secret. Then, because the secret is encoded in Base64, you decode it.
• Username: admin
Warning
As noted before, the deployment of the APIManager custom resource takes several
minutes. If the Admin Portal is not accessible, try again in a few minutes.
If the How does 3scale work page displays, click X to close it.
6.4. In the top pane, click Dashboard to display the drop down menu. Then, click Account
Settings.
DO240-RH3APIM2.11-en-2-20220405 19
Chapter 1 | Introducing Red Hat 3scale API Management
6.6. In the Access Tokens section, click Add Access Token. Complete the form
according to the following values:
• Name: toolbox
Then, click Create Access token. Save the access token displayed.
6.7. Using the official 3scale Toolbox CLI image, create a container with a name of
toolbox-original. This image must contain the remote information.
Note
Because podman run creates a new container on every execution, the information
added is not kept between executions. A solution to this issue is creating a new
image from the original 3scale Toolbox CLI image that contains the remote
information. This way, you use podman run to execute an image with the remote
information on every execution.
6.9. Update the 3scale bash alias to use the new image.
Note
The classroom workstation includes a .bashrc file with the preceding alias
configured. Future workstation sessions do not require setting the alias again.
Note that the -k option allows connections without an SSL certificate. Now you can
list the remotes by using the 3scale alias.
20 DO240-RH3APIM2.11-en-2-20220405
Chapter 1 | Introducing Red Hat 3scale API Management
Finish
Run the following command
DO240-RH3APIM2.11-en-2-20220405 21
Chapter 1 | Introducing Red Hat 3scale API Management
Summary
In this chapter, you learned:
• How to configure your classroom workstation to administer RHOCP and Red Hat 3scale API
Management.
22 DO240-RH3APIM2.11-en-2-20220405
Chapter 2
DO240-RH3APIM2.11-en-2-20220405 23
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to create Backends and Products in the Admin
Portal. Describe the process to promote APIs from Development to Production.
Conceptually, you can imagine requests traversing through the various parts of your configuration.
In the preceding diagram, note that the underlying APIs are not publicly exposed.
Backends
A backend represents a deployed application by pointing to its root URL.
24 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
However, the URL of the 3scale backend would solely contain http://myapp.example.com.
This allows the requester to reach multiple endpoints with a single backend for an application.
Backends are associated with one or more products. By associating a backend to a product, the
product's users can access the underlying API.
From here, you can create new backends and manage existing ones.
To create a new backend, click Create Backend, fill out the form, and submit it.
Products
Products, previously called services, represent a collection of 3scale objects that pertain to a
specific client or group of users.
• Application plans
• Applications
Note that backends do not belong to a product. This is because the same backend can be
associated with several different products. Different products do not need separate backends for
the same underlying API.
DO240-RH3APIM2.11-en-2-20220405 25
Chapter 2 | Managing APIs with Red Hat 3scale API Management
• Create
• Copy
• Delete
• Show
• List
• Apply
From here, you can create new products and manage existing ones.
After selecting a product to work within, the left-hand pane is used to navigate between the
management pages for components within that product.
26 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
For example, in the previous screenshot, the library-product is selected. Click Applications >
Application Plans to manage application plans within that product.
This page shows the list of backends currently accessible by the product, their URLs, and the
product path to access them. To add an existing backend to the product, click Add Backend,
select the backend, and provide a path. This path is a prefix that maps to the backend.
Note that backend paths must be unique within a product, as they are what the router uses to
direct requests to the correct backend.
Changes you make to a product are not live until you promote the configuration. If you have any
changes not yet in the staging environment then the Configuration item shows a warning icon.
DO240-RH3APIM2.11-en-2-20220405 27
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Figure 2.4: A warning icon shows that there are changes to be promoted.
The two environments are staging and production. Each environment can have separate
configurations, but changes must go to the staging environment first.
After promoting changes to staging, you can then promote them to production by clicking
Promote v. X to Production APIcast.
References
For more information, refer to the Adding backends to a product chapter in the
Red Hat 3scale API Management Getting Started Guide at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.8/html/getting_started/first-steps#adding-
backends-product
28 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Guided Exercise
• Backends
• Products
• Applications
• Application plans
Outcomes
You should be able to:
• Deploy microservices on Red Hat OpenShift Container Platform (RHOCP) in a way that is
consumable by 3scale API Management.
Instructions
1. Create a product called library_product. Within that product, create an application and
application plan.
Note
In 3scale API Management, a product and a service are the same.
DO240-RH3APIM2.11-en-2-20220405 29
Chapter 2 | Managing APIs with Red Hat 3scale API Management
2.1. Using a web browser, log in to the Admin Portal as the admin user. The portal is
located at https://3scale-admin.apps.ocp4.example.com.
Note
If this is your first time accessing the admin portal, a setup wizard opens. Use the X
button to exit this wizard.
2.2. From the top pane drop-down menu, select Backends to view the list of backends.
2.3. Create a backend for the book API by clicking Create Backend, providing the
following values, and submitting the form. Leave all other fields as their default
values.
Field Value
Name book-backend
2.4. Create another backend for the patron API with the following values:
Field Value
Name patron-backend
30 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
3.1. From the top pane drop-down menu, select Products to view the list of products.
Click the name of the library_product product in the list.
3.2. Navigate to the list of backends associated with the product by selecting Integration
> Backends. Associate a backend with the product by clicking Add Backend. Select
book-backend as the backend, provide the unique path /b-api, and submit the
form.
3.3. Repeat the previous step for the patron backend, but select the patron-backend
and enter /p-api as the path.
4.2. Promote the product's configuration to the staging environment by clicking Promote
v.1 to Staging APIcast.
4.4. From the Production APIcast section, copy the hostname from the URL value. In
the command line, store this value in an environment variable called API, to use in a
later step.
4.5. From the Staging APIcast section, copy the user_key value from the example
curl command. In the command line, store this value in a USER_KEY environment
variable.
Note
Your user_key will differ from the one listed here.
DO240-RH3APIM2.11-en-2-20220405 31
Chapter 2 | Managing APIs with Red Hat 3scale API Management
"copies": 5
},
{
"title": "Pride and Prejudice",
"authorName": "Jane Austen",
"year": 1813,
"copies": 3
}
]
4.8. Run the previous command several times to generate request metrics.
5.2. Use the selection menu to adjust the scale of the graph by selecting Hits (hits). Make
sure 24 hours is selected so that the time scale is correct.
Note that your graph could look slightly different based on how many times you ran
the curl command.
32 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
DO240-RH3APIM2.11-en-2-20220405 33
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to create application plans and set rate limits for
APIs.
• Click the Create Application Plan button to go to the Create Application Plan section.
• Set a name and a system name for the new plan. System names must be unique because they
are used by Red Hat 3scale API Management as unique identifiers.
• Select the Applications require approval? check box if applications need to be evaluated by the
administrator before they become available.
• Use the drop-down list below Default Plan, select the plan you want to set as default.
34 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Pricing Models
Pricing models are strategies that enable customers to pay for the return value they can get.
Pricing models can be configured for volume, functionality and resources.
• Volume usage, you can assign global request count for calls on products or at the method level.
• Functionality, depending on the tier some features of the product can be enabled or disabled.
• Resources, you can create tiers for resource levels such as: bandwidth, number of users or
transaction values.
• Navigate to Metrics, Methods, Limits & Pricing Rules where you can define pricing rules for total
requests or in a more granular way at the method level.
You can define pricing rules for products in the Product Level section. In this section you can
configure a range of requests and assign costs per unit.
DO240-RH3APIM2.11-en-2-20220405 35
Chapter 2 | Managing APIs with Red Hat 3scale API Management
To create an application plan using the toolbox CLI use the application-plan create option
and set the --approval-required, --cost-per-month, --setup-fee, --trial-period-
days for the tenant application plan. In this example the tenant name is: 3scale-tenant and the
application plan is: new_plan.
36 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
• Click on Limits.
References
For more information, refer to the Application Plans chapter in the Red Hat 3Scale
Api Management Admin Portal Guide at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/admin_portal_guide/
index#application-plans
DO240-RH3APIM2.11-en-2-20220405 37
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to:
• Verify that application plans and rate limits work properly for backends and applications
This command ensures that the 3scale API is online and deploys the books application.
Instructions
1. Create an application plan by using the toolbox CLI.
1.1. Use the 3scale remote command to get the list of 3scale tenants. Select the
desired tenant to add an application plan in this case the remote name is: 3scale-
tenant.
Note
The 3scale client configuration should be performed as indicated in the Chapter 1
section: "Installing Red Hat 3scale API Management".
1.2. List the services on the 3scale-tenant and identify the API ID.
38 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
1.3. Add a new application plan to the API service with the following settings:
1.4. Verify that the new application plan was created successfully for the 3scale-
tenant service ID 2.
2.1. Verify that the books API application is available at the http://books-
api.apps.ocp4.example.com URL.
2.3. On the New Backend section create a backend with the following values:
• Name: Books
DO240-RH3APIM2.11-en-2-20220405 39
Chapter 2 | Managing APIs with Red Hat 3scale API Management
3.2. Navigate to the API > Integration > Backends section and click the Add Backend
button.
3.3. Select the Books backend from the Backend drop-down, set the Path field to /
library, and click the Add to Product button.
40 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
4.2. Click the Promote v. 1 to Staging APIcast button to promote the API backends to
Staging APIcast.
Your version number could differ if you previously promoted the API product.
4.3. Copy the Example curl for testing command. This curl command has a
user_key parameter containing the authentication token for the staging API.
4.4. Verify the backend. On the terminal paste the curl command copied on the previous
step and add the library/books path to the URL and execute it.
5.1. Navigate to API > Overview > Applications > Application plans.
5.4. On the Backend Level section, click on the Books backend to expand the pricing and
limits section.
5.5. Click the Limits link to expand the limits section and click on the New usage limit link.
DO240-RH3APIM2.11-en-2-20220405 41
Chapter 2 | Managing APIs with Red Hat 3scale API Management
5.6. Set the following values to the fields of the New Usage limit modal.
• Period: minute
• Max. Value: 5
5.7. Click the Create usage limit button to create the new usage limit.
6.1. Navigate to the products management of the top pane drop-down menu and click on
API > Applications > Listing.
6.3. On the Change plan section select: Example Plan and click the Change plan button.
42 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
7.2. Navigate to Books > Mapping Rules and click on the Create Mapping Rule.
7.3. Set the following values for the new mapping rule and submit the form.
• Verb: GET
• Pattern: /books
• Metric: Hits
• Increment by: 1
7.4. Navigate to Products > API > Integration > Configuration and click Promote v. 2 to
Staging APIcast.
Your version number could differ if you previously promoted the API product.
7.5. Use the following curl command to generate a new hit to the mapping rule.
7.6. Verify the mapping rule: navigate to Books > Analytics, the graphic information
should show an increment by 1.
DO240-RH3APIM2.11-en-2-20220405 43
Chapter 2 | Managing APIs with Red Hat 3scale API Management
8.2. Verify that the usage limit was reached by using the following curl command.
The books API call should respond with the: Usage limit exceeded message.
8.3. Verify the rate limit rule: navigate to Books > Analytics, the graphic information
should show an increment only by 5.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
44 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
DO240-RH3APIM2.11-en-2-20220405 45
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to create and configure multiple versions of APIs.
You use API versioning when there is a need to change the client code before using a new
incompatible version.
There are several ways to implement API versioning depending on where you place the version
number, such as:
• URL versioning specifies the version number as part of the URL path or in a URL query
parameter.
• Request header versioning specifies the version number in an HTTP header. This can be the
accept header or a custom header such as x-api-version.
To implement URL API versioning in Red Hat 3scale API Management, create a backend per
version of your application. Then, add them all to a single product, but prefix each with a unique
path based on the version string.
3scale API Management also offers the Routing policy, which provides request header
versioning.
URL Versioning
With URL versioning, requests are routed based on the version value taken from the request URL.
46 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
URL versioning makes the version clear because the version is apparent from the URL. However,
using URL versioning can break the one-to-one relationship between a resource and its REST
URL. Namely, a resource that has no changes gets another URL for the new version.
For example, clients for the first API version use a URL such as https://example.com/v1/
resource-name, where the v1 indicates the version of the API the client wants to consume.
To release a breaking change, you must change the URL to use a new version.
Following the previous example, incrementing from v1 to v2 changes the URL to https://
example.com/v2/resource-name, representing the new version.
DO240-RH3APIM2.11-en-2-20220405 47
Chapter 2 | Managing APIs with Red Hat 3scale API Management
The different versions in the request path route the request to the correct endpoint in the target
API.
Having each backend point to a different path creates a logical separation for each version.
backend_v1 http://microservice-internal-url/
api/v1
backend_v2 http://microservice-internal-url/
api/v2
For the preceding example, you assign both backends to the product by using a public path that
represents the version.
When handling the request, 3scale API Management rewrites the path and eliminates the public
path specified in the mapping between the product and the backend.
https://example.com/v1/resource- http://microservice-internal-url/
name api/v1/resource-name
https://example.com/v2/resource- http://microservice-internal-url/
name api/v2/resource-name
This policy routes requests based on the URL, request headers, or JWT claims.
The Routing policy must be placed before the APIcast policy in the policy chain.
48 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
You can configure the Routing policy to route requests by using a custom header, such as x-
api-version.
For this, you can configure the Routing policy in the Admin Portal with the following values.
Field Value
url http://microservice-internal-url/api/v2
combine_op and
match header
value v2
op ==
header_name x-api-version
With this configuration, the Routing policy routes requests containing the header x-api-
version: v2 to http://microservice-interal-url/api/v2.
After updating the policy configuration, you must click Update Policy Chain in the Policies section.
Then, promote the configuration to staging to verify that it routes to the correct version.
You can use the curl utility to test the request header versioning by adding the version header to
the request.
DO240-RH3APIM2.11-en-2-20220405 49
Chapter 2 | Managing APIs with Red Hat 3scale API Management
You can also use the 3scale Toolbox CLI to create the policy chain by executing the policies
command with the import subcommand and an argument with a file containing the policy list.
Where policy-chain.yaml contains a policy list with the Routing policy followed by the
default 3scale APIcast policy.
- name: routing
version: builtin
configuration:
rules:
- condition:
combine_op: and
operations:
- value_type: plain
match: header
value: v2
op: matches
header_name: x-api-version
url: http://example.com/api/v2
enabled: true
- name: apicast
version: builtin
configuration: {}
enabled: true
This command creates a new configuration for the product and promotes that configuration to the
staging environment.
References
For more information, refer to the URL versioning section in the Red Hat 3scale API
Management Administering the API Gateway at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html/administering_the_api_gateway/
versioning-3scale#url_versioning
50 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to:
Note
For faster feedback, this exercise is executed on the staging environment to
avoid having to propagate changes to both staging and production.
• The applications-versions project is created and has the last books-api API
version deployed.
• The books-api version v1 is already in production and accessible through 3scale, but v2
is only privately accessible.
• The RHOCP cluster has a pod named curl-pod to allow curl command execution within
the cluster.
Instructions
1. Use the 3scale Toolbox CLI to extract the USER_KEY and STAGING_DOMAIN environment
variables to use during this exercise.
DO240-RH3APIM2.11-en-2-20220405 51
Chapter 2 | Managing APIs with Red Hat 3scale API Management
1.3. Verify that the previous steps correctly assigned the STAGING_DOMAIN and
USER_KEY environment variables.
Note
Your USER_KEY will differ from the one listed here.
2. Compare versions v1 and v2 to verify that there is a breaking change in the books-api
API. Only version v1 is publicly accessible. To test v2 you must log in to RHOCP as the
developer user and execute a curl command within the cluster.
2.1. Test public access to the books resource in the applications_versions product
to verify that only version v1 is accessible.
52 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
The response No Mapping Rule matched indicates that the resource is not
publicly accessible for v2.
2.2. To verify that v2 is actually deployed within the cluster, log in to RHOCP as the
developer user. Then use the cluster pod curl-pod to query the v2 of the books
resource by using the FQDN for the books-api service.
Issue the login command to log into RHOCP.
Execute a curl command from within the cluster to verify that v2 is deployed and that
the books resource contains a breaking change.
[
{
"title": "Frankenstein",
"author": {
"name": "Mary Shelley",
"birthYear": 1797
},
"year": 1818,
"copies": 10
},
...output omitted...
]
The version v2 replaced authorName with the author object. This is a backward
incompatible change and must be published under a new version to avoid breaking
existing client code.
3. Navigate to the 3scale Admin Portal and create a backend called books_backend_v2.
Set the backend URL to point to the service version v2 by using the http://books-
api.applications-versions.svc.cluster.local:80/api/v2/books URL.
3.1. Using a web browser, log in to the 3Scale Admin Portal as the admin user. The portal
is located at https://3scale-admin.apps.ocp4.example.com.
3.2. From the top pane drop-down menu, select Backends to view the list of backends.
3.3. Create a backend for the v2 by clicking Create Backend, providing the following
values, and submitting the form. Leave all other fields as their default values.
DO240-RH3APIM2.11-en-2-20220405 53
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Field Value
Name books_backend_v2
4.1. From the top pane drop-down menu, click Products, and then click the
applications_versions product.
4.2. Navigate to the list of backends associated with the product by selecting Integration
> Backends. Associate a backend with the product by clicking Add Backend.
Select books_backend_v2 as the backend, provide the unique path /v2, and
submit the form.
This causes a path rewrite in the handling of the request. It eliminates /v2 from the
request path and proceeds to use the backend base URL, which is http://books-
api.applications-versions.svc.cluster.local/api/v2.
https://applications- http://books-api.applications-
versions-3scale-apicast- versions.svc.cluster.local/api/v2/
staging.apps.ocp4.example.com/v2/ books
books
5. Use the 3scale Toolbox CLI to create a new metric hits_v2 to count the number of
requests to v2.
6. To allow public access to v2 create a mapping rule for the pattern /v2 and assign it the
metric hits_v2.
6.1. Navigate to the list of mapping rules associated with the product by selecting
Integration > Mapping Rules.
6.2. Create a mapping rule for the applications_versions product by clicking Create
Mapping Rule, providing the following values, and submitting the form. Leave all
other fields as their default values.
54 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Field Value
Verb GET
Pattern /v2
To promote to production you can use the proxy-config command with the
promote subcommand instead.
7.2. Verify that v2 is publicly accessible by sending a request to the books resource.
DO240-RH3APIM2.11-en-2-20220405 55
Chapter 2 | Managing APIs with Red Hat 3scale API Management
9. Review the endpoint metrics within the 3scale Admin Portal and verify that v2 has 5 more
requests than v1.
9.2. Select metric Hits used by v1 by clicking Hits (hits). Note the number to compare it
with v2
9.3. Select metric hits_v2 used by v2 by clicking hits_v2 (hits_v2). Note the resulting
total in the graph. This number should be 5 units higher than the number for v1.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
56 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to discover applications deployed on OpenShift
automatically.
• Add metadata to the services to enable service discovery and configure the service information.
• Make sure that 3scale has access to the services that you want to import.
If you installed 3scale by using the operator method then service discovery is enabled by default.
DO240-RH3APIM2.11-en-2-20220405 57
Chapter 2 | Managing APIs with Red Hat 3scale API Management
For example, to configure a service using http and listening on port 8080 with only the required
configuration:
You can also achieve the same result by editing the service resource definition:
apiVersion: v1
kind: Service
metadata:
annotations:
discovery.3scale.net/port: "8080"
discovery.3scale.net/scheme: http
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: "2022-01-07T17:15:42Z"
labels:
app: books-api
app.kubernetes.io/component: books-api
app.kubernetes.io/instance: books-api
discovery.3scale.net: "true"
name: books-api
...output omitted...
58 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
You can also give 3scale access to all the projects in the cluster by assigning it the view role as a
cluster role.
To import a discovered service, click Products on the top pane drop-down menu to navigate to
the Products page. Then click Create Product to navigate to the New Product form.
In the New Product form, select Import from OpenShift. This populates the Namespace and
Name drop-down menus with the discovered services. Select the desired service, then click
Create Product.
By clicking Create Product, 3scale creates the product and backend based on the 3scale
metadata from the service.
DO240-RH3APIM2.11-en-2-20220405 59
Chapter 2 | Managing APIs with Red Hat 3scale API Management
To access the imported product and the backend associated with it, the product needs a 3scale
application plan and an application.
To create an application plan named APPLICATION_PLAN you must reference the TENANT and
the PRODUCT_SYSTEM_NAME resources.
To create the application you need a user account to link it to, the PRODUCT_SYSTEM_NAME, the
previously created plan, and the name you want for the application.
This application provides us with a user_key to make requests in the Staging APIcast
environment.
To verify the product import, navigate to the product detail page in the Admin Portal. Then click
Integration > Configuration and scroll down to the Staging APICast section. There you can
copy an example curl request to validate that your service is working properly in the staging
environment.
60 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
References
For more information, refer to the Service Discovery chapter in the Red Hat
3scale Api Management 2.11 Admin Portal Guide at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html/admin_portal_guide/service-
discovery_service-discovery
DO240-RH3APIM2.11-en-2-20220405 61
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to:
Instructions
1. Create an OpenShift project called library and deploy the sample application books-
api from the Git repository.
62 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
2. Make the service discoverable from 3scale. Add the required metadata to books-api,
ensure service discovery is enabled, and give the amp service account view permissions to
the library project.
2.3. Verify that the books-api service has been modified accordingly.
apiVersion: v1
kind: Service
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
discovery.3scale.net/scheme: http
discovery.3scale.net/port: "8080"
labels:
app: books-api
app.kubernetes.io/component: books-api
app.kubernetes.io/instance: books-api
discovery.3scale.net: "true"
name: books-api
namespace: library
spec:
...output omitted...
DO240-RH3APIM2.11-en-2-20220405 63
Chapter 2 | Managing APIs with Red Hat 3scale API Management
2.4. Validate that 3scale service discovery is enabled. Describe the system configmap in
the 3scale project and, under service_discovery.yml, verify that the following
values show for the keys production.enabled, production.bearer_token,
and production.authentication_method.
production:
enabled: <%= cluster_token_file_exists = File.exists?(cluster_token_file_path
='/var/run/secrets/kubernetes.io/serviceaccount/token') %>
bearer_token: "<%= File.read(cluster_token_file_path) if
cluster_token_file_exists %>"
authentication_method: service_account
...output omitted...
2.5. Grant the 3scale amp service account with view permissions on the library project
so that 3scale can access the books-api service metadata.
If ls-discoverable.sh does not print anything, verify that you added the required
metadata correctly.
Run the following command to validate that 3scale can access your service definition.
64 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
From the previous command note that the amp service account has the
ClusterRole/view in the library namespace. Therefore, our service is visible
from 3scale.
3. Import the 3scale product and backend by using the 3scale Admin Portal.
3.2. Click Products on the top pane's drop-down menu to go to the products page.
DO240-RH3APIM2.11-en-2-20220405 65
Chapter 2 | Managing APIs with Red Hat 3scale API Management
3.4. In the New Product form, select Import from OpenShift. This populates the
Namespace and Name drop-down menus with the discovered services. Select
books-api in the Name selector field and click Create Product.
Note
If services do not show in the Namespace drop-down menu, verify that the label
and the annotations are correct. Also, validate that the 3scale amp service account
has view permissions on your service namespace.
3.5. Go to the products page and verify that 3scale imported the discovered service.
4. To access the books-api through 3scale, create an application plan and an application
by using 3scale Toolbox CLI. Use the 3scale-tenant remote configured in previous
sections.
66 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Note
The Toolbox CLI has the -h help option, which provides reference information for
3scale commands and subcommands.
To find out which arguments you need to create an application, you can execute the
following command.
Note
The 3scale alias created in previous sections uses the -k option because the
3scale Toolbox CLI container image does not have the proper certificate installed. If
you get SSL certificate errors then you can either use the -k to avoid verifying the
certificate's validity or install a valid certificate.
4.1. Create an application plan called library_basic_plan by using the 3scale Toolbox
CLI in the command line.
4.2. Create an application on the default john account, with the name library-app,
and assign it the library_basic_plan.
5. Make a curl request to the /books endpoint in the staging APIcast service to determine
whether we can reach the API through 3scale.
5.1. Go to the books-api product page in the 3scale Admin Portal. Then, go to
Integration > Configuration and scroll down to the Staging APIcast section to
copy the example curl command.
DO240-RH3APIM2.11-en-2-20220405 67
Chapter 2 | Managing APIs with Red Hat 3scale API Management
5.2. Edit the copied curl command to send a request to the /books endpoint.
6. Update the books-api OpenShift service port to 8181. Repeat the curl request to see it
fail.
6.1. Edit the books-api OpenShift service to make it listen on port 8181.
6.2. Execute the curl command to verify that we can no longer reach books-api.
68 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
6.4. Inspect the logs in the APIcast staging service to see why it fails.
From the previous log, notice that 3scale is trying to reach our service on port 8080
and APIcast can not find anything on that port.
We can search for our books-api service to verify that it is running on port 8181.
6.5. Revert the service port to its original value and send another request to see it
succeed.
DO240-RH3APIM2.11-en-2-20220405 69
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
70 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to create multiple tenants in Red Hat 3scale API
Management.
Introducing Tenants
You can configure multiple 3scale API Management instances within the same installation. An
instance of 3scale API Management is called a tenant. Every tenant can be managed through its
own Admin Portal.
By default, the 3scale API Management installation creates the 3scale tenant. In previous
sections of this course, you have used the Admin Portal of the default 3scale tenant to manage
your APIs (https://3scale-admin.apps.ocp4.example.com).
While the default tenant, 3scale, might be enough for most organizations, larger companies
might prefer to have several, independent instances to manage their APIs. For example, a social
network might choose to have a tenant for internal APIs, and another tenant for APIs that can be
consumed by external developers.
Features of a Tenant
Every tenant provides several interesting features that you might consider when deciding the
number of tenants that you want to have:
Custom Every tenant gets a staging The URL for staging follows the pattern
APIcast URL and production APIcast URL api-TENANT_NAME-apicast-
containing the tenant name. staging.WILDCARD_DOMAIN. The
URL for production follows the pattern
api-TENANT_NAME-apicast-
production.WILDCARD_DOMAIN.
DO240-RH3APIM2.11-en-2-20220405 71
Chapter 2 | Managing APIs with Red Hat 3scale API Management
To access the Users page, click Account Settings in the drop-down menu, located in the top
pane of the Master Portal. Then, click Users > Listing.
The default master user is displayed. Click Invite a New User to create a new user by providing a
valid email address. 3scale sends an email with a link to join the Master Portal. Click Invitations to
list the invitations sent.
To access the Accounts page, click Audience in the drop-down menu located in the top pane.
This page lists the available accounts.
72 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Click Create to create a new account. You must complete the form by taking into consideration
what every field means.
Field Explanation
Username The username of the user that you use to access the Admin
Portal of the tenant.
Password The password of the user that you use to access the Admin
Portal of the tenant.
Email The email of the user that you use to access the Admin Portal
of the tenant.
Organization/Group Name The tenant name. This is used as a subdomain to generate the
URLs of the Admin Portal, Developer Portal and APIcast.
Field Value
Username do240-user
Password do240-password
Email [email protected]
Then the following URLs are created, considering that the wildcard domain is example.com:
Name URL
DO240-RH3APIM2.11-en-2-20220405 73
Chapter 2 | Managing APIs with Red Hat 3scale API Management
You can access the Admin Portal of your tenant by opening the URL TENANT_NAME-
admin.WILDCARD_DOMAIN in a web browser. Log in by using the credentials (username and
password) that you provided when creating the tenant.
To access the Users page, click Account Settings in the drop-down menu of the Admin Portal.
Then, click Users > Listing in the left pane. The list of users with access to the Admin Portal is
displayed.
Click Invite a New User to create a new user by providing a valid email address. An email is sent to
the email provided with a link to join the tenant. Click Invitations to list the invitations sent.
74 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
The Master Portal contains one account, 3scale, which corresponds to the default 3scale
tenant. At the same time, the Master Portal has one user, master, which is the default user. You
can log in to the Master Portal by opening the https://master.apps.ocp4.example.com
URL in a web browser. Then, you can use the master user credentials to authenticate.
The 3scale Admin Portal contains the default admin user, and the default API
product. You can log in to the 3scale Admin Portal by opening the https://3scale-
admin.apps.ocp4.example.com in a web browser. Then, you can use the admin user
credentials to authenticate.
DO240-RH3APIM2.11-en-2-20220405 75
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Consider also that your organization needs a separate tenant to manage the finance APIs
independently. If you add a new finance Master account (i.e. tenant) with the following data:
• Username: finance-user
• Password: finance-password
• Email: [email protected]
The Master Portal contains two accounts, 3scale and finance. The finance Admin Portal
holds one user, finance-user, which is the username that you provided when creating the
tenant. At the same time, the finance Admin Portal contains the API Product, which is created
by default.
Note
The APIcast URLs displayed in the graphics assume that you are using the API
default product. 3scale API Management provides a different URL prefix for
every product by using the following pattern: PRODUCT-TENANT-apicast-
staging.apps.ocp4.example.com.
76 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Configuring SMTP
Because 3scale sends invitations through email, a SMTP server must be configured. 3scale does
not provide an SMTP server by default, so if you want to create a Master Portal or Admin Portal
user, then you must provide your own SMTP server. You can configure an SMTP server for the
entire 3scale API Manager installation. Therefore, the Master Portal and all the tenants use the
same email server.
When you have your SMTP server ready, you must configure 3scale to use the SMTP server. The
system-smtp OpenShift secret contains the following parameters to connect to the server.
Parameter Explanation
You can modify the system-smtp secret by using the OpenShift Console, or by executing the
proper oc patch command. In the following command, you must replace both PARAMETER and
VALUE by the parameter and value that you want to update, respectively.
After you update the secret with the correct parameters for your SMTP server, you must restart
the pods involved in the email sending.
DO240-RH3APIM2.11-en-2-20220405 77
Chapter 2 | Managing APIs with Red Hat 3scale API Management
References
3cale Multitenancy
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html/installing_3scale/install-threescale-on-
openshift-guide
78 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to create a new 3scale tenant, create a new user for the tenant, and
modify the user's permissions.
This command ensures that the workstation machine is ready and the OpenShift cluster is
available. At the same time, it deploys an email interceptor that you will use in the exercise.
Instructions
1. Log in to the 3scale Master Portal by using the default installation password.
Important
Because the start function restarts some OpenShift pods to deploy the email
server, the Master Portal might be temporary unavailable. If the Master Portal is not
available, then try again in a few minutes.
1.2. In a command-line terminal, retrieve the master password from the system-seed
OpenShift secret.
DO240-RH3APIM2.11-en-2-20220405 79
Chapter 2 | Managing APIs with Red Hat 3scale API Management
• Username: master
2. Create a new tenant called do240 by using the Master Portal. Remember that in 3scale a
tenant is a master account.
2.1. Click Dashboard to display the drop-down menu. Then, click Audience.
2.2. The Accounts page is displayed by default. This page lists all the available master
accounts.
• Username: do240-user
• Password: do240
Then, click Create. Remember that the organization name provided is used to create
the Admin Portal subdomain.
2.5. The do240 account page gives some information, such as the public domain of the
tenant or the Admin Portal URL. By default, 3scale creates two users: do240-user,
with the credentials that you provided previously, and another one called 3scale
Admin, which is used by the system. Both users have admin privileges.
3. Activate the do240-user so that you can use it to access the do240 tenant Admin Portal.
3.1. Click 2 Users in the top pane. The page displays the two created users for the tenant.
80 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
3.2. Click Activate in the do240-user row to activate the user. Now you can use this user
to access the do240 tenant Admin Portal.
4. Verify that you can log in to the do240 tenant Admin Portal.
• Username: do240-user
• Password: do240
4.2. If the How does 3scale work page displays, click X to close it. The dashboard
shows the default API product.
5. Invite a new user to the do240 tenant by using the Admin Portal. Then, use the link
provided in the email to join the do240 tenant.
5.1. In the do240 tenant Admin Portal, click Dashboard to display the dropdown menu.
Then, click Account Settings.
5.2. Click Users, and then click Listing. This section shows all the users that can log in to
the Admin Portal. It is synchronized with the Users section of the do240 tenant in
the Master Portal.
5.3. In the left pane, click Invitations, and then click Invite a New Team Member.
5.4. In a real-world scenario, you should complete the form with the email of the person
that you want to have access to the tenant. For the purpose of this exercise, use the
[email protected] email address. Then, click Send.
Important
In this exercise, the email is not sent. The lab start function that you executed at
the beginning of the exercise deploys an email interceptor. You can fetch the email
that would be sent in a production environment by using the email interceptor.
5.5. Log out of the do240 tenant Admin Portal. Click on the Session icon in the top
pane, and then click Sign Out.
If you have any problems signing up or believe you received this email
erroneously, please open a Support Case at https://access.redhat.com/support.
DO240-RH3APIM2.11-en-2-20220405 81
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Thank you,
The email contains a link to join the tenant. Copy the link.
5.7. In a web browser, open the link from the previous step. Complete the sign-up form
according to the following data:
Important
If you are still logged-in with the do240-user, then you cannot see the sign-up
form. Log out first and try again.
• Username: gls-user
• Password: gls-password
Then, click Sign up. You are redirected to the log-in page.
5.8. Log in to the do240 tenant Admin Portal with the credentials from the previous step.
• Username: gls-user
• Password: gls-password
By default, invited users get the member role assigned. Therefore, you do not have
permissions to see any products.
Figure 2.31: The gls-user does not have permissions to see any products.
5.9. Log out of the do240 tenant Admin Portal. Click on the Session icon in the top
pane, and then click Sign Out.
6. Change the gls-user user permissions, so that the user can view the API product.
82 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
• Username: do240-user
• Password: do240
6.2. Click Dashboard to display the dropdown menu. Then, click Account Settings.
6.3. Click Users, and then click Listing. The GLS Red Hat user (gls-user) is now
displayed in this page. Click over its name to edit it.
6.4. The Administrative section allows you to change the role of user. The Admin role
provides full access to the tenant. The Member role allows you to choose the sections
that the user can access.
6.5. Click the Create, read, update and delete developer accounts and
applications of selected API products checkbox.
6.6. When you click this checkbox, the All current and future API products
check is displayed. With this option, you grant access to all the products.
DO240-RH3APIM2.11-en-2-20220405 83
Chapter 2 | Managing APIs with Red Hat 3scale API Management
6.8. Log out of the do240 tenant Admin Portal. Click on the Session icon in the top
pane, and then click Sign Out.
7. Verify that the gls-user user can view the API Product.
• Username: gls-user
• Password: gls-password
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
84 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Quiz
Based on the preceding scenario, choose the correct answers to the following questions:
1. Which feature provides the necessary separation between the different companies?
a. Policies
b. Applications
c. Multi-tenancy
d. Client Separators
2. If you have four different client companies that each need access to all of your APIs,
how many total 3scale backends do you need to create?
a. One
b. Three
c. Four
d. Twelve
3. One of your clients, Shadowman Software Inc, operates under a tenant named
shadowman. Which of the following is the correct command to create a product
named trucking-product?
a. 3scale service create shadowman trucking-product
b. 3scale service new trucking-product
c. 3scale product create shadowman trucking-product
d. 3scale product create trucking_product
4. Which set of objects are the minimum you must create to make an external request to
an internal API via 3scale?
a. A product, backend, application, and application plan
b. Only a product and backend
c. Only an application and application plan
d. None, only the default objects are needed
DO240-RH3APIM2.11-en-2-20220405 85
Chapter 2 | Managing APIs with Red Hat 3scale API Management
5. For the Shadowman Software tenant, which of the following statements best
describes how to create a backend for the Fleet Management service?
a. 3scale backend create shadowman fleet-management
b. 3scale use-tenant shadowman and 3scale create-backend fleet-
management
c. Use the Admin Portal web UI to create a backend specifying the URL https://
fleet.example.com:8080.
d. Backends are created automatically, so you do not need to create one.
6. When creating an application plan via the 3scale Toolbox CLI, which of the following is
the correct command option to specify a cost per month of $10?
a. --cost-per-month=10.00
b. --cost 10
c. --cpm 10
d. There is no way to specify the cost per month via the 3scale Toolbox CLI.
86 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Solution
Based on the preceding scenario, choose the correct answers to the following questions:
1. Which feature provides the necessary separation between the different companies?
a. Policies
b. Applications
c. Multi-tenancy
d. Client Separators
2. If you have four different client companies that each need access to all of your APIs,
how many total 3scale backends do you need to create?
a. One
b. Three
c. Four
d. Twelve
3. One of your clients, Shadowman Software Inc, operates under a tenant named
shadowman. Which of the following is the correct command to create a product
named trucking-product?
a. 3scale service create shadowman trucking-product
b. 3scale service new trucking-product
c. 3scale product create shadowman trucking-product
d. 3scale product create trucking_product
4. Which set of objects are the minimum you must create to make an external request to
an internal API via 3scale?
a. A product, backend, application, and application plan
b. Only a product and backend
c. Only an application and application plan
d. None, only the default objects are needed
DO240-RH3APIM2.11-en-2-20220405 87
Chapter 2 | Managing APIs with Red Hat 3scale API Management
5. For the Shadowman Software tenant, which of the following statements best
describes how to create a backend for the Fleet Management service?
a. 3scale backend create shadowman fleet-management
b. 3scale use-tenant shadowman and 3scale create-backend fleet-
management
c. Use the Admin Portal web UI to create a backend specifying the URL https://
fleet.example.com:8080.
d. Backends are created automatically, so you do not need to create one.
6. When creating an application plan via the 3scale Toolbox CLI, which of the following is
the correct command option to specify a cost per month of $10?
a. --cost-per-month=10.00
b. --cost 10
c. --cpm 10
d. There is no way to specify the cost per month via the 3scale Toolbox CLI.
88 DO240-RH3APIM2.11-en-2-20220405
Chapter 2 | Managing APIs with Red Hat 3scale API Management
Summary
In this chapter, you learned:
• How to create and manage 3scale products, backends, applications, and application plans.
• How to manage API versions and the 3scale approach to API management.
DO240-RH3APIM2.11-en-2-20220405 89
90 DO240-RH3APIM2.11-en-2-20220405
Chapter 3
DO240-RH3APIM2.11-en-2-20220405 91
Chapter 3 | Managing and Customizing API Gateways
Objectives
After completing this section, you should be able to allow external access to your API by
configuring APIcast gateways.
3scale API Management provides two environments: staging and production. By default,
3scale API Management provides an APIcast gateway for each of these environments. Promoting
the configuration of a product means propagating the changes to the specific APIcast gateway.
To have full control over the APIcast gateway, you can avoid using the default gateways. You
might choose to deploy a self-managed gateway if you want to manage the full lifecycle of the
application.
You can replace any of the default gateways (staging and production) with your self-managed
gateway.
92 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
For example, consider that you have a 3scale API Management installation, with two default
gateways. Consider also that you want to deploy a self-managed gateway for the production
environment in a separate network. The self-managed gateway receives the incoming requests for
the production environment and must fetch the information, such as the routing policies and rate
limits, from the APIManager. The following diagram illustrates this behavior.
You can install the operator by using the RHOCP OperatorHub catalog.
DO240-RH3APIM2.11-en-2-20220405 93
Chapter 3 | Managing and Customizing API Gateways
apiVersion: apps.3scale.net/v1alpha1
kind: APIcast
metadata:
name: custom-apicast
spec:
adminPortalCredentialsRef:
name: apicast-secret
deploymentEnvironment: production
exposedHost:
host: custom-apicast.apps.ocp4.example.com
tls:
- {}
Name of the RHOCP secret that contains the authentication against the APIManager. This
authentication is covered in detail later in this lecture.
The APIcast operator creates an RHOCP route with the host provided in the manifest, so that your
gateway is accessible externally.
94 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
To create a new access token, navigate to the Account Settings page of your tenant's Admin
Portal, and click Personal > Tokens. Then, click Add Access Token. The token must include the
Account Management API scope.
For example, if you want to authenticate the gateway against the default tenant, 3scale, and you
have an access token 1234, then the secret displays as follows:
To change the settings of a product, click Integration > Settings in the product's page left pane.
In the DEPLOYMENT section, select APIcast self-managed to enable a self-managed gateway
for the product. Then, you use the Staging Public Base URL and Production Public
Base URL fields to provide the external URL of your gateway for the staging and production
environments (respectively).
To deploy APIcast Gateway in your own server, you must install OpenResty and other
dependencies. You can find a detailed installation guide in this link [https://access.redhat.com/
documentation/en-us/red_hat_3scale_api_management/2.0/html/deployment_options/apicast-
self-managed].
To deploy APIcast Gateway in a Docker containerized environment, you must download a ready
to use container image. This image contains all the dependencies needed to run APIcast. You can
find a detailed installation guide in this link [https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.0/html/deployment_options/apicast-docker].
DO240-RH3APIM2.11-en-2-20220405 95
Chapter 3 | Managing and Customizing API Gateways
References
Red Hat 3cale Documentation - Administering the API Gateway
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/administering_the_api_gateway/
index
96 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
Guided Exercise
Outcomes
You should be able to:
The start function creates a 3scale product called apicast, which points to a backend
that uses the 3scale Echo API. You will use this product in this exercise to test the self-
managed APIcast.
Instructions
1. Create a new OpenShift project called apicast, where you will deploy the APIcast custom
resource. By deploying it in a different namespace, you simulate the logical isolation that
you might require in a real-world scenario.
DO240-RH3APIM2.11-en-2-20220405 97
Chapter 3 | Managing and Customizing API Gateways
• Username: admin
• Password: redhat
2.3. Type APIcast in the search text box input, and select the Red Hat Integration
- 3scale APIcast gateway option. Then, click Install.
2.4. Complete the Install Operator form with the following options.
Leave other fields with the default selected options. Then, click Install. The operator
takes some time to install.
3. Create a personal access token in the default 3scale tenant, so that the APIcast operator
can fetch the information from the APIManager.
3.1. In your command-line terminal, use the oc get secret command to retrieve the
password for the 3scale tenant Admin Portal, where you will create the access
token.
The default passwords of 3scale are stored in the system-seed secret. By executing
the previous command, you retrieve the ADMIN_PASSWORD entry of the system-
seed secret. Then, because the secret is encoded in Base64, you decode it.
• Username: admin
3.3. In the top pane, click Dashboard to display the drop-down menu. Then, click Account
Settings.
3.5. In the Access Tokens section, click Add Access Token. Complete the form
according to the following values:
• Name: apicast
Then, click Create Access token. Save the access token displayed.
3.6. Create an OpenShift secret that contains the access token. You will use this secret
later to authenticate the APIcast operator.
98 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
4. Deploy the APIcast custom resource. Use the the OpenShift secret created in the previous
step.
4.1. By using a text editor of your preference, create a new file called apicast.yaml that
contains the following snippet.
You can use the /home/student/DO240/labs/gateways-apicast/
apicast.yaml file.
apiVersion: apps.3scale.net/v1alpha1
kind: APIcast
metadata:
name: custom-apicast
spec:
adminPortalCredentialsRef:
name: apicast-secret
deploymentEnvironment: staging
exposedHost:
host: custom-apicast.apps.ocp4.example.com
tls:
- {}
resources:
limits:
cpu: '0'
memory: 128Mi
5.1. In the 3scale tenant Admin Portal, click Products in the drop-down menu. Then click
gateways_apicast.
5.2. In the left pane menu, click Integration > Settings. The settings page for the
gateways_apicast product is displayed.
DO240-RH3APIM2.11-en-2-20220405 99
Chapter 3 | Managing and Customizing API Gateways
5.4. In the Staging Public Base URL field, type the OpenShift route that you
created previously, https://custom-apicast.apps.ocp4.example.com.
Then, click Update Product.
6.2. Click Promote v. 1 to Staging APIcast to replace the default Staging APIcast by your
self-managed APIcast.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
100 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
Objectives
After completing this section, you should be able to customize request processing using APIcast
policies.
Policies enable higher flexibility and control in how APIcast handles traffic by providing more-
granular abstractions for the NGINX proxy configuration.
Configured policies exist within a product as part of a policy chain, which is an ordered list of
policies that every request to the product is filtered through.
In the preceding example diagram, blue boxes represent the policies, and dashed outlines show
which policies are optional. Note that the default 3scale APIcast policy is required, as it
represents 3scale API Management's routing configuration.
Each policy within a chain can alter or add information to the request before it is sent to the next
policy.
Alternatively, a policy might conditionally alter how the request is handled. For example, an
authorization policy might short-circuit a request and reject it before it reaches later polices or
an API. In this way, policies can potentially improve the performance or resource usage of your
system.
DO240-RH3APIM2.11-en-2-20220405 101
Chapter 3 | Managing and Customizing API Gateways
• Routing
• Utility
Policies that customize how APIcast routes incoming requests include the following:
• Routing: a general-purpose policy that gives you fine-grained control over how requests are
routed.
The collection of standard policies also includes policies to handle authentication and
authorization tasks, such as the following:
• RH-SSO/Keycloak Role Check: integrates with RH-SSO to verify realm roles as a request
allowlist or blocklist.
• JWT Claim Check: validates JWTs from requests and either allows or blocks the request
based on claims within the token.
• OAuth 2.0 Token Introspection: communicates with an OIDC token issuer to authorize
requests by using tokens.
• Anonymous Access: removes the user_key parameter requirement from all requests to the
product by supplementing the request with a pre-configured user token.
• Custom Metrics: adds hooks into the response to update custom metrics created in the
Admin Portal.
• Maintenance Mode: responds to all requests with a preconfigured status code and message,
which is useful for temporarily disabling the product for maintenance.
Using the toolbox CLI, you can export and import policy chains by using the 3scale policies
super-command. For example, the following commands export an example policy chain as YAML
and then re-imports it:
102 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
version: builtin
configuration: {}
enabled: true
- name: apicast
version: builtin
configuration: {}
enabled: true
- name: maintenance_mode
version: builtin
configuration: {}
enabled: true
[student@workstation ~]$ 3scale policies import 3scale-tenant \
policy_sandbox -f policy_chain.yml
The name of the product is policy_sandbox and the -f option specifies the name of the file to
import.
In most cases, you use the Admin Portal to manage policies. To add a policy via the Admin Portal,
use the Integration > Policies section within the product. This graphical editor enables you to
update the product's policy chain.
Figure 3.5: The Policies section within a product in the Admin Portal.
Once added, individual policies can be updated, removed, and reordered within the policy chain.
In the accompanying guided exercise, you practice adding, updating, reordering, and removing
policies from a product by using the Admin Portal.
References
For a complete list of available policies, as well as more extensive documentation for
the standard policies, please visit the APIcast policies chapter of the 3scale
API Management documentation at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html/administering_the_api_gateway/
apicast_policies
DO240-RH3APIM2.11-en-2-20220405 103
Chapter 3 | Managing and Customizing API Gateways
Guided Exercise
Outcomes
You should be able to add, update, reorder, and delete policies within a product.
This command creates a new product called gateways_policies to house the policies.
This product uses a basic echo backend that responds with information about the request.
Instructions
1. Explore the product and backend before applying changes via policies.
1.2. Using the top pane navigation drop-down, click Products, and then click
gateways_policies.
1.3. Navigate to Integration > Configuration and click Promote v.1 to Staging APIcast to
promote the configuration to the staging environment.
1.4. In a command-line terminal, run the example curl command. Be sure to use the
correct user_key value.
1.5. Copy just the generated user_key value from the example curl command. You will
use this in one of the following steps to configure a policy.
For example, if your curl command is similar to the one in the preceding step, then
the user_key to copy would be some-user-key.
104 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
1.6. Attempt to make a request to the endpoint without providing a user_key. This
request fails due to missing authentication parameters.
2.2. Add a policy to this chain by clicking Add policy. Select Anonymous Access from
the list of available policies.
2.3. Update the policy by clicking Anonymous Access within the policy chain. Ensure the
policy is enabled and user_key is selected for the auth_type field.
Paste your user key value into the user_key field and click Update Policy.
2.4. Within the policy chain, use the arrow icon to drag the Anonymous Access policy so
that it comes before the 3scale APIcast policy.
Figure 3.6: Reorder the policies so that Anonymous Access comes first.
2.5. Click Update Policy Chain to apply the new policy to the policy chain.
2.6. Deploy the changes to the staging environment by navigating to Integration >
Configuration and clicking Promote v.2 to Staging APIcast.
2.7. From a command-line terminal, run the example curl command, but without
providing the user_key.
DO240-RH3APIM2.11-en-2-20220405 105
Chapter 3 | Managing and Customizing API Gateways
Notice that the request is processed by the echo API without providing a user key.
Instead, the policy provides the configured user key.
Note
Use caution when applying the Anonymous Access policy, as anybody with a valid
URL can make requests to any API available to the product. In particular, these
requests have the same permissions as the user whose key is configured within the
policy.
3. Create a policy that puts the product in maintenance mode and returns an appropriate
response.
3.2. Add a policy to this chain, selecting the Maintenance Mode policy.
3.4. Deploy the changes to the staging environment by navigating to Integration >
Configuration and clicking Promote v.3 to Staging APIcast.
3.5. From a command-line terminal, run the example curl command. With the
Anonymous Access policy still active, do not provide the user_key.
Notice that the service responds with a maintenance message and a 503 status code.
4.2. Click the Maintenance Mode policy to update it. At the bottom of the form, click
Remove.
4.4. Deploy the changes to the staging environment by navigating to Integration >
Configuration and clicking Promote v.4 to Staging APIcast.
4.5. From a command-line terminal, run the example curl command. With the
Anonymous Access policy still active, do not provide the user_key.
106 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
Notice that the service no longer responds with the maintenance message.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
DO240-RH3APIM2.11-en-2-20220405 107
Chapter 3 | Managing and Customizing API Gateways
Quiz
2. Which two of the following statements about the APIcast gateway are correct?
(Choose two.)
a. You can only deploy an APIcast gateway by using the official operator.
b. When you deploy a self-managed gateway, it is automatically applied to all products.
c. By default, two APIcast gateways are provided: staging and production.
d. You can deploy an APIcast gateway in your own machine. Then, you can replace any of
the default gateways by your self-managed gateway.
3. Consider the following manifest. Which two of the following statements are correct?
(Choose two.)
apiVersion: apps.3scale.net/v1alpha1
kind: APIcast
metadata:
name: custom-apicast
spec:
adminPortalCredentialsRef:
name: apicast-auth
deploymentEnvironment: staging
exposedHost:
host: custom-apicast.example.com
tls:
- {}
108 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
4. Which two of the following statements about policies are correct? (Choose two.)
a. A policy might conditionally alter how the request is handled.
b. You can not manage policies by using the 3scale Toolbox CLI.
c. The 3scale APIcast policy is not required.
d. Each policy within a chain can alter or add information to the request before it is sent to
the next policy.
5. Which two of the following statements about policies are correct? (Choose two.)
a. The IP Check policy configures allowlists and blocklists by using a list of IP addresses
or blocks of addresses.
b. The OAuth 2.0 Token Introspection policy integrates with RH-SSO to verify
realm roles as a request allowlist or blocklist.
c. The Maintenance Mode policy responds to all requests with a preconfigured status
code and message.
d. The JWT Claim Check removes the user_key parameter requirement from all
requests to the product.
DO240-RH3APIM2.11-en-2-20220405 109
Chapter 3 | Managing and Customizing API Gateways
6. Consider that you have exported the policies of a product by using the 3scale
policies export command. Consider also that the following YAML is the result
of the export command. Which one of the following statements about the YAML is
correct? (Choose one.)
---
- name: custom_metrics
version: builtin
configuration:
rules:
- metric: status-203
increment: '1'
condition:
combine_op: and
operations:
- left_type: liquid
right_type: plain
left: "{{status}}"
right: '203'
op: matches
enabled: true
- name: apicast
version: builtin
configuration: {}
enabled: true
110 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
Solution
2. Which two of the following statements about the APIcast gateway are correct?
(Choose two.)
a. You can only deploy an APIcast gateway by using the official operator.
b. When you deploy a self-managed gateway, it is automatically applied to all products.
c. By default, two APIcast gateways are provided: staging and production.
d. You can deploy an APIcast gateway in your own machine. Then, you can replace any of
the default gateways by your self-managed gateway.
3. Consider the following manifest. Which two of the following statements are correct?
(Choose two.)
apiVersion: apps.3scale.net/v1alpha1
kind: APIcast
metadata:
name: custom-apicast
spec:
adminPortalCredentialsRef:
name: apicast-auth
deploymentEnvironment: staging
exposedHost:
host: custom-apicast.example.com
tls:
- {}
DO240-RH3APIM2.11-en-2-20220405 111
Chapter 3 | Managing and Customizing API Gateways
4. Which two of the following statements about policies are correct? (Choose two.)
a. A policy might conditionally alter how the request is handled.
b. You can not manage policies by using the 3scale Toolbox CLI.
c. The 3scale APIcast policy is not required.
d. Each policy within a chain can alter or add information to the request before it is sent to
the next policy.
5. Which two of the following statements about policies are correct? (Choose two.)
a. The IP Check policy configures allowlists and blocklists by using a list of IP addresses
or blocks of addresses.
b. The OAuth 2.0 Token Introspection policy integrates with RH-SSO to verify
realm roles as a request allowlist or blocklist.
c. The Maintenance Mode policy responds to all requests with a preconfigured status
code and message.
d. The JWT Claim Check removes the user_key parameter requirement from all
requests to the product.
112 DO240-RH3APIM2.11-en-2-20220405
Chapter 3 | Managing and Customizing API Gateways
6. Consider that you have exported the policies of a product by using the 3scale
policies export command. Consider also that the following YAML is the result
of the export command. Which one of the following statements about the YAML is
correct? (Choose one.)
---
- name: custom_metrics
version: builtin
configuration:
rules:
- metric: status-203
increment: '1'
condition:
combine_op: and
operations:
- left_type: liquid
right_type: plain
left: "{{status}}"
right: '203'
op: matches
enabled: true
- name: apicast
version: builtin
configuration: {}
enabled: true
DO240-RH3APIM2.11-en-2-20220405 113
Chapter 3 | Managing and Customizing API Gateways
Summary
In this chapter, you learned:
• APIcast is an nginx-based gateway in Red Hat 3scale API Management that is responsible for
receiving and managing the incoming traffic of your APIs.
• 3scale API Management provides two environments: staging and production. By default,
3scale API Management provides an APIcast gateway for each of these environments.
• You can replace any of the default gateways (staging and production) with your self-managed
gateway.
• Policies enable higher flexibility and control in how APIcast handles traffic by providing more-
granular abstractions for the NGINX proxy configuration.
• Configured policies exist within a product as part of a policy chain, which is an ordered list of
policies that every request to the product is filtered through.
114 DO240-RH3APIM2.11-en-2-20220405
Chapter 4
DO240-RH3APIM2.11-en-2-20220405 115
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to create and configure Admin Portal users.
Role admin
Users with this role have unrestricted access to the Admin Portal and can invite other
members.
Role member
Users with this role have limited access to the Admin Portal.
You can create member users with limited permissions to share the administration tasks for your
APIs.
For example, an organization might have one or more administrators with the admin role. An
administrator can create users for the sales department with the member role, and limited
permissions to access only the billing section in the Admin Portal. Also, an administrator can
create users with access permission to a specific product. This means that for example the API
development team might access only the products related to the API versioning strategy.
If your organization has departments that are independently developing their APIs, then you can
provide a stronger administrative separation by creating a tenant per department. This way, you
can isolate administration tasks at the department level.
You can find the tools to manage Admin Portal users in the Account Settings page in the Users
menu.
116 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
• Use Single Sign On (SSO) integration. 3scale API Management supports Red Hat Single Sign
On (RHSSO) and Auth0 integrations.
In both cases, new users have the member role by default, and need additional permissions to do
any work in the Admin Portal.
To update user permissions you must navigate to Users>Listing in the Accounts Settings page
and select the user you want to configure. There you can update the user role to be admin or
configure the member permissions.
There are two sets of access permissions that you can configure:
• With the second set of permissions, which have finer granularity, you can grant a user access to
specific products in the following Admin Portal sections:
The product level access permissions can either be granted to all current and future products, or
only to a subset of the available products.
Notifications
As an Admin Portal user, you can subscribe to events related to the following 3scale API
Management interactions.
Accounts
Notify developer account events.
Billing
Notify payment and billing events.
Applications
Notify application and application plan events.
DO240-RH3APIM2.11-en-2-20220405 117
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Users with the admin role have access to all the available types of notifications.
Users with the member role can only receive notifications that relate to the access permission they
have.
Users receive notifications by mail. Notifications also show in the notifications section in the
Dashboard page.
• Billing API
• Analytics API
Depending on the API you want to use you need a different type of token.
• Access Tokens provide read-only or read-write access to the following 3scale management APIs.
– Billing API
– Analytics API
• Service Tokens provide per product access to the Service Management API.
Access tokens belong to the Admin Portal user, whereas service tokens are associated to the
product. Therefore, different users will have their own access tokens, but they will share the service
token for a product if they have access permission to that product.
As an Admin Portal user, you can create and edit the permissions for your own access tokens from
the Personal>Tokens section in the Account Settings page. If your user has a member role then
you can only create tokens for the APIs you have access to.
You can use access tokens and service tokens to explore the different 3scale API Management
administration APIs in the 3scale API Docs page.
118 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
References
For more information, refer to the Inviting users and managing rights chapter in the
Red Hat 3scale API Management Admin Portal Guide at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/admin_portal_guide/
index#inviting-users-managing-rights
DO240-RH3APIM2.11-en-2-20220405 119
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to:
Instructions
1. Send an invitation to create a member user by using the Admin Portal.
Important
Because the start function restarts some 3scale API Management pods to deploy
the email server, the Admin Portal might be temporary unavailable. If the Admin
Portal is not available, then try again in a few minutes.
120 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
• Username: admin
1.4. Click Account Settings on the top pane drop-down menu. Then navigate to Users >
Invitations and invite a new user by clicking Invite a New Team Member.
Fill the Invite a New Team Member form with the email for the invitation. Then submit
the form.
1.5. Execute the /scripts/get-emails.sh script to receive the emails sent by 3scale
API Management.
If you have any problems signing up or believe you received this email
erroneously, please open a Support Case at https://access.redhat.com/support.
Thank you,
1.6. Log out of the Admin Portal by clicking the user icon and then clicking Sign Out.
1.7. Navigate to the sign up form by using the link copied from the invitation email.
Complete the sign up form according to the following data:
• Username: member_user
• Password: gls-password
After submitting the form, the Admin Portal redirects the browser to the login form.
DO240-RH3APIM2.11-en-2-20220405 121
Chapter 4 | Securing APIs with Red Hat 3scale API Management
1.8. Log in to the Admin Portal as member_user by using the credentials from the
previous step. If you are presented with the welcome screen then close it by pressing
X.
The new user neither has permissions to navigate to the Products or Backends pages.
3. Log in to the Admin Portal as the admin user and give member_user permissions to query
the analytics of all API products.
3.1. Log out of the Admin Portal by clicking the user icon and then clicking Sign Out.
3.3. To edit member_user click Account Settings on the top pane drop-down menu.
Then, click Users > Listing and select member_user.
3.4. Give member_user access to the analytics section by clicking Access & query
analytics of in the ADMINISTRATIVE section. Select All current and future existing
API products to access analytics in all the products and submit the form.
122 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
4. Log in to the Admin Portal as member_user and verify that the user can access analytics
for the API product.
4.2. Verify that member_user has access to product analytics by clicking API in the
Products section, from the welcome page.
In the API product detail page, you can verify that only the Analytics menu is
available in the sidebar.
5. Create a new user, admin_user, and grant the user the admin role.
5.1. Log in to the Admin Portal as the admin user and send the user an invitation to the
[email protected] address.
DO240-RH3APIM2.11-en-2-20220405 123
Chapter 4 | Securing APIs with Red Hat 3scale API Management
5.2. Run the /scripts/get-emails.sh script in the DO240-apps like you did in the
previous step to copy the invitation link from the email.
5.3. Log out of the Admin Portal and use the previous invitation link to access the sign up
form. Submit the form with the following values:
• Username: admin_user
• Password: gls-password
5.4. Log in to the Admin Portal as admin and edit the admin_user by clicking
Users > Listing and clicking admin_user in the Accounts Settings page. In the
ADMINISTRATIVE section, select Admin (full access) and submit the form.
5.5. Log in to the Admin Portal as the admin_user, and verify that you have unrestricted
access to the Admin Portal.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
124 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to secure APIs by using API keys and API key-
pair authentication.
• Providing a security layer for your APIs without the need to change or redeploy your application.
• API key
For more information about OIDC, see Securing APIs with Red Hat Single Sign-on and OAuth.
API_KEY = a6548169babc4d7847268ba63db15b65
An API key is a string that uniquely identifies each application that communicates with APIs
managed by the 3scale Application Manager. The API key serves both as the ID and a secret token
that is necessary to authenticate an API call. This is the simplest form of authentication, suitable
for testing and environments with low security requirements.
The application key-ID pair decouples the API key from the application ID. Each call to the API that
uses the key-ID authentication pattern requires the following information:
APP_ID = 76b49d63
APP_KEY = d2fe3c9494f34a306b91c8e78f11a5f6
Consequently, each API call is identified by a unique ID and a unique secret token. Because the
ID and secret token are decoupled from each other, you can create multiple application keys for a
single application ID.
DO240-RH3APIM2.11-en-2-20220405 125
Chapter 4 | Securing APIs with Red Hat 3scale API Management
This is useful when regenerating your token. You can provision a new secret token, update your
application, and then decommission the original secret token. Consequently, this means you can
avoid disrupting your service due to regenerating a secret token.
In the Admin Portal, select the product you want to configure. Then, click Integration > Settings
and see the Authentication section.
Products use the API key authentication pattern by default. Select the App_ID and App_Key Pair
option to require authentication by using a key-ID pair.
By default, each API call expects the user_key query parameter with the value of your API key,
for example:
If you enforce authentication by using the key-ID authentication pattern in the headers named
app_key and app_id respectively, then the API call will look as follows:
126 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
To create a new application object that is associated with your product, select your product in the
Admin Portal. Then, click Applications > Listing and click Create Application.
After you create the application object, see the API Credentials section to view the API key or the
key-ID pair generated for your application.
If your product uses the key-ID authentication pattern, then you can click the Add Custom key or
Add Random key to associate multiple keys with your application ID. You can associate at most
five keys with each application object.
DO240-RH3APIM2.11-en-2-20220405 127
Chapter 4 | Securing APIs with Red Hat 3scale API Management
References
For more information, refer to the API authentication chapter in the Administering
the API Gateway guide at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/administering_the_api_gateway/
index#authentication-patterns
128 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to configure a Red Hat 3scale API Management product to require
authentication by using an API key-ID pair.
This command:
Instructions
1. Configure the secure_keys product to require authentication by using the API key.
1.1. Verify that the secure_keys_basic application plan in the secure_keys product
does not have an associated application.
1.3. List the API key that is associated with the secure_key_app application. Use the
application ID from the preceding step.
DO240-RH3APIM2.11-en-2-20220405 129
Chapter 4 | Securing APIs with Red Hat 3scale API Management
2. Configure the secure_keys product to require authentication by using the API key-ID
pair.
2.2. In a web browser, log in to the the 3scale API Management Administration Portal as
the admin user.
Execute the following command to see the ADMIN_PASSWORD:
2.5. In the Authentication section, select App_ID and App_Key Pair The
application is identified via the App_ID and authenticated via
the App_Key.
2.6. Click Update Product. Then, click Configuration and click Promote v. 2 to Staging
APIcast.
3.1. Verify that using API key is no longer sufficient to authorize to the API:
3.2. Find the application ID for the application you created in the preceding steps. The
following step uses ID 13 as the ID for the application:
130 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
3.3. Authenticate your API call by using the API_KEY and API_ID variables:
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
DO240-RH3APIM2.11-en-2-20220405 131
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to secure APIs by using Red Hat Single Sign-On.
• The JWT token contains the necessary claims, such as the authorized party (azp) or audience
(aud).
When you configure OIDC integration, APIcast reads the configuration of the OIDC provider
by using the https://OIDC_PROVIDER_HOST/.well-known/openid-configuration
discovery endpoint. APIcast caches information required for validating JWT tokens, such as public
keys and signing algorithms.
Requests to the protected API then require a valid JWT token. The following diagram provides an
example of an authentication request flow:
132 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
• Connect to RHSSO.
For example, on Red Hat OpenShift Container Platform, if the zync-queue pods do not trust the
RHSSO TLS certificates then the communication fails.
Additionally, Zync must authenticate with RHSSO by using a confidential Service Account
client with the manage-clients role. Otherwise, Zync cannot create clients in RHSSO.
See the references section for more information about implementing the prerequisite steps.
Configuring OIDC
You can configure OIDC integration for each product in your 3scale API Management installation.
When you configure OIDC integration for a particular product:
• 3scale API Management synchronizes new applications to RHSSO, provided that you configured
the prerequisites.
• Clients must authenticate by using OIDC to reach the protected APIs. Authenticating with
application credentials without JWT tokens is denied.
To configure OIDC for a product, navigate to the Admin Portal, select your product, and click
Integration > Settings. Then, select the OpenID Connect Use OpenID Connect for any OAuth 2.0
flow. authentication option.
You must provide the OIDC issuer URL with the following parameters:
DO240-RH3APIM2.11-en-2-20220405 133
Chapter 4 | Securing APIs with Red Hat 3scale API Management
• REALM_NAME: 3scale API Management creates RHSSO clients in this realm. Additionally, you
can use users from this realm to authenticate your requests.
https://zync-client:[email protected]/auth/
realms/example-realm
{
"name": "apicast.policy.jwt_claim_check",
"configuration": {
"error_message": "Invalid JWT check",
"rules": [
{
"operations": [
{"op": "==", "jwt_claim": "role", "jwt_claim_type": "plain", "value":
"admin"}
],
"combine_op":"and",
"methods": ["GET"],
"resource": "/resource",
134 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
"resource_type": "plain"
}
]
}
}
For the GET /resource request, the policy enforces that the provided JWT token contains the
role claim with the value admin. Other resources and methods do not require the role claim
check. All resources and methods still require a valid JWT token.
The preceding example requires RHSSO to provide the role claim for some JWT tokens.
You can configure the policy check for a particular product. Click Integration > Policies, then click
Add policy and select JWT Claim Check.
DO240-RH3APIM2.11-en-2-20220405 135
Chapter 4 | Securing APIs with Red Hat 3scale API Management
• The RHSSO client that you configured has sufficient permissions to create other clients.
You can check the zync-queue logs for more details. The following example shows a RHSSO
client that does not have enough permissions to create other clients:
The following example shows a JWT token that does not contain the audience (aud) claim on
the stage APIcast:
You can implement APIcast CORS checks by adding the CORS Request Handling policy to
your policy chain.
References
For more information about integrating 3scale API Management and RHSSO, refer
to the Integration of 3scale with Red Hat Single Sign-On chapter in the Administering
the API Gateway guide at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/administering_the_api_gateway/
index#integration-threescale-rhsso_api-gateway-apicast
136 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to:
• Configure 3scale API Management to require a valid JSON Web Token (JWT) to
authenticate an API call.
This command:
• Deploys the application you will use in this exercise, which consists of:
Instructions
1. Verify that the books_api_v2 backend does not require Open ID Connect for
authentication.
1.2. Get the user key for the application, for example for an application with the ID 7:
DO240-RH3APIM2.11-en-2-20220405 137
Chapter 4 | Securing APIs with Red Hat 3scale API Management
2. Add the RHSSO certificate chain to the 3scale API Management certificate chain.
Note
This step is necessary because the 3scale API Management Zync pod does not trust
the self-signed certificates of RHSSO.
[student@workstation ~]$ sh \
/home/student/DO240/labs/secure-oauth/inject_rhsso_ca.sh
...output omitted...
configmap/zync-new-ca-bundle created
deploymentconfig.apps.openshift.io/zync-que volume updated
deploymentconfig.apps.openshift.io/zync-que updated
2.3. Verify that the zync pod in the 3scale project is in the Running state:
138 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
3.5. Click the Service Account Roles tab. In the Client Roles section, select Realm
Management.
Click manage clients, then click Add selected.
3.6. Click the Credentials tab. You will require the Secret value later.
Keep the browser tab open.
4.1. In a new browser tab, log in to the the 3scale API Management Administration Portal
as the admin user.
Execute the following command to see the ADMIN_PASSWORD:
4.4. In the Authentication section, select OpenID Connect Use OpenID Connect
for any OAuth 2.0 flow.
4.5. In the OpenID Connect (OIDC) Basics section, construct the OpenID Connect Issuer
URL in the following format:
https://CLIENT-ID:CLIENT-SECRET@RHSSO-URL
Use the following parameters:
• Client-id: zync-client
• Client-secret: Copy the Secret value from the RHSSO web console.
For example:
https://zync-client:f6f0..7dd4@keycloak-
rhsso.apps.ocp4.example.com/auth/realms/do240
4.6. Click Update Product. Then, click Configuration and click Promote v. 2 to Staging
APIcast.
DO240-RH3APIM2.11-en-2-20220405 139
Chapter 4 | Securing APIs with Red Hat 3scale API Management
• Name: sso_app
• Description: sso_app
6.2. Click the newly created client, for example 7308b6b9. Verify that the name of the
client is sso_app.
• Web Origins: *
7.1. Edit the book-config configuration map in the secure-oauth project, and change
the REACT_APP_CLIENT_ID property to the client ID of the sso_app
8.1. In the 3scale API Management Administration Portal, open the secure_oauth
product.
140 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
8.2. Click Integration > Policies. Then, click Add policy and select the CORS Request
Handling policy.
8.3. Move the CORS Request Handling policy to the start of the policy chain.
Warning
Failure to put the CORS policy as the first policy in the policy chain might result in
the front end application not working.
8.4. Click the CORS Request Handling policy. Enter the following configuration:
• allow_origin: *
http://books-frontend-secure-oauth.apps.ocp4.example.com
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
DO240-RH3APIM2.11-en-2-20220405 141
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Quiz
1. Which one of the following statements about authentication in Red Hat 3scale API
Management is correct?
a. APIs that are managed by 3scale API Management must use an adapter library to
integrate with the authentication workflow.
b. 3scale API Management does not support any cryptographically verified authentication
method.
c. You can require authentication for APIs that are managed by 3scale API Management
without the need to redeploy or modify your API.
d. 3scale API Management only supports authentication concerns when you integrate it
with Red Hat Single Sign On.
2. When you try to access a web application that communicates with an API managed by
3scale API Manager, you are presented with the following CORS error. Which one of
the provided statements is the most likely cause and solution for the error?
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote
resource at https://example-product-3scale-apicast-staging.apps.ocp4.example.com/
a. You must modify your API to include a proper CORS header value in the API response.
b. You can use the CORS Request Handling policy. This means APIcast will include a
proper CORS header value in the API response.
c. You must adapt your front end application to include a proper header in the request.
d. 3scale API Management does not support interactions by using a browser.
142 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
4. Which one of the following statements about regenerating API keys in 3scale
Application Management is correct?
a. You can generate up to five API keys when you use the key-ID authentication pattern.
b. The only way to regenerate an API key is to create a new application object.
c. You can generate up to five API keys when you use the API key authentication pattern.
d. You must regenerate your API keys periodically.
DO240-RH3APIM2.11-en-2-20220405 143
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Solution
1. Which one of the following statements about authentication in Red Hat 3scale API
Management is correct?
a. APIs that are managed by 3scale API Management must use an adapter library to
integrate with the authentication workflow.
b. 3scale API Management does not support any cryptographically verified authentication
method.
c. You can require authentication for APIs that are managed by 3scale API Management
without the need to redeploy or modify your API.
d. 3scale API Management only supports authentication concerns when you integrate it
with Red Hat Single Sign On.
2. When you try to access a web application that communicates with an API managed by
3scale API Manager, you are presented with the following CORS error. Which one of
the provided statements is the most likely cause and solution for the error?
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote
resource at https://example-product-3scale-apicast-staging.apps.ocp4.example.com/
a. You must modify your API to include a proper CORS header value in the API response.
b. You can use the CORS Request Handling policy. This means APIcast will include a
proper CORS header value in the API response.
c. You must adapt your front end application to include a proper header in the request.
d. 3scale API Management does not support interactions by using a browser.
144 DO240-RH3APIM2.11-en-2-20220405
Chapter 4 | Securing APIs with Red Hat 3scale API Management
4. Which one of the following statements about regenerating API keys in 3scale
Application Management is correct?
a. You can generate up to five API keys when you use the key-ID authentication pattern.
b. The only way to regenerate an API key is to create a new application object.
c. You can generate up to five API keys when you use the API key authentication pattern.
d. You must regenerate your API keys periodically.
DO240-RH3APIM2.11-en-2-20220405 145
Chapter 4 | Securing APIs with Red Hat 3scale API Management
Summary
In this chapter, you learned:
• Red Hat 3scale Application Management Admin Portal users can have the admin or member
role with configurable permission settings.
• You can require authentication for APIs managed by 3scale Application Management without
the need to modify or redeploy the APIs.
– API key
– Integration with 3rd party identity provider, such as Red Hat Single Sign On
• 3scale Application Management can synchronize application objects to Red Hat Single Sign On.
146 DO240-RH3APIM2.11-en-2-20220405
Chapter 5
DO240-RH3APIM2.11-en-2-20220405 147
Chapter 5 | Creating a Developer Portal
Objectives
After completing this section, you should be able to create and configure a developer portal for
API consumption.
To access the Developer Portal customization options, select Audience from the drop-down
menu, and then click Developer Portal. The following list describes sections in the Developer
Portal menu:
Content
Contains Developer Portal content that you can create and manage, such as HTML, CSS, and
JavaScript files.
Drafts
Lists the content with the Draft status.
Redirects
Create and manage redirects from one portal URL to another, for example when you
deprecate a page on your Developer Portal.
148 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Groups
Create and manage user groups. You can use groups to limit access to content sections.
Logo
Upload a Developer Portal logo.
Feature Visibility
Toggle advanced features of your Developer Portal, such as webhooks, or identity and access
management (IAM) tools.
ActiveDocs
Contains the OpenAPI documentation for your APIs.
In the Content section, you can create and edit the following elements:
Page
A page typically contains liquid-templated HTML content to be shown when the users access
a given URL. You can also create pages in Markdown or Textile.
Section
A section is a logical grouping of pages that you can use to create hierarchical page
structures. For example, you can group all pages accessible by users that belong to a
particular group under a common URL subpath.
Layout
Layouts define a common structure that is often used by multiple pages. For example, you
might reference common CSS and JavaScript files in one layout and use the layout for all your
pages.
Partial
Partials are reusable elements that you can embed in pages. Layouts and partials are distinct
elements. Typically, layouts define the structure of pages whereas partials are contained in
Pages.
For example, a layout defines a common header and footer for your pages, while a partial
defines a disclaimer which you add to a subset of your pages.
File
Files are content uploaded to the Developer Portal that you want to reference or display, such
as an image later referenced in a page.
Portlets
Portlets gather and show information from external sources. You can use the following
portlets:
Table of Contents
Generates a list of links for the pages in a given section.
DO240-RH3APIM2.11-en-2-20220405 149
Chapter 5 | Creating a Developer Portal
To add content to the portal, click New Page. To create another kind of content, use the drop-
down menu of that button to select the desired content type.
For example in the New Page editor, provide the following data:
Title
Name of the page.
Section
Section to file the page under.
Path
URL path relative to the Developer Portal that shows the page.
Note
The page called Homepage has a special path (/) that does not include the file
name. This is because homepage is implemented as an index.html file, which is
automatically served if no file name is provided.
Layout
Layout to define the general structure of the page.
After you provide the details, use the content box below to write the content of the page. 3scale
API Management supports content written in HTML, Markdown and Textile.
Use the Preview button to validate the results and view how this new content is presented to
the client. You can view the content in a preview page with a preview toolbar. This toolbar shows
information about the page and the templates used to render the page. You can also switch
between publishing modes.
For example, consider that there is a group of developers called partners. You can create a new
section with the following details:
Section data
Field Value
Public Unselected
Parent .Root
Then, you create a page in the private section, for example with the following parameters:
150 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Page data
Field Value
Path /howitworks
Layout Main
After you create a restricted section, create a group and give it access to that section. Navigate
to Developer Portal > Groups and click Create Group. Set the name of the group to Partner's
Group, mark the Partner pages section as allowed, and click Create Group.
Finally, add users to this group to grant access to pages that belong to the Partner pages section.
Navigate to Dashboard > Audience, then click Accounts > Listing, and select a user. In the
account page, click Group membership and select the Partner's Group.
This means that the user has access to the PORTAL-URL/howitworks path.
References
For more information, refer to the Creating the Developer Portal guide at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/creating_the_developer_portal/
index
DO240-RH3APIM2.11-en-2-20220405 151
Chapter 5 | Creating a Developer Portal
Guided Exercise
Outcomes
You should be able to:
Instructions
1. Navigate to the Developer Portal.
1.2. In a new browser tab, log in to the 3scale tenant Admin Portal as the admin user.
Execute the following command to see the ADMIN_PASSWORD:
1.3. Click Dashboard > Audience, select Developer Portal, and click Content.
1.4. Click Open your Portal to the world and select Ok. Then, in the left side menu, click
Visit Portal.
152 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
• Username: portal-user
• Email: [email protected]
• Password: redhat
2.3. In the Admin Portal, click Accounts > Listing. Then, click Activate to enable the
portal-user account.
3.1. Click the GLS link. Note that the registration created an application for the user.
3.2. Click the GLS's App link. Note that the user uses the Basic application plan, and
has access to the API product.
4.1. Click Developer Portal > Content. Then, click the arrow next to New Page and select
New Section.
Enter the following details:
• Public: unchecked
4.2. Then, click the arrow next to New Section and select New Page.
Enter the following details:
• Path: /restricted
5.1. Open a new browser window in an incognito mode, for example by pressing
ctrl+shift+n in Firefox.
Note
If you visit the restricted section when logged in to the Admin Portal then you will
see the content. You must either log out of the Admin Portal, open a different
browser, or open a new browser window in the incognito mode.
DO240-RH3APIM2.11-en-2-20220405 153
Chapter 5 | Creating a Developer Portal
• Name: privileged
6.3. Click Privileged. Then, select the Restricted section and click Save.
Note
There is currently a bug that prevents selected sections from being properly
assigned to a group. You must open the group, select the section, and then update
the group.
6.5. Click 0 Group Memberships. Then, select the privileged group and click Save.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
154 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Objectives
After completing this section, you should be able to configure a developer portal with custom look
and feel.
On top of minor additions and tweaks, you can modify or replace many parts of the default
Developer Portal.
This view is divided into two main panes. The left pane shows the structure of the various
components and templates, and the right pane is used to edit a selected component.
Figure 5.2: The left and right panes of the Developer Portal editing page.
The left pane is filterable by ownership and component type. Click My to only show components
you own and 3scale to show components owned by the system. Components owned by 3scale can
be modified, but they cannot be deleted.
DO240-RH3APIM2.11-en-2-20220405 155
Chapter 5 | Creating a Developer Portal
To filter the list by component type, select the icons representing the types you wish to see. For
example, click the icon of a jigsaw puzzle piece to only show partials.
Figure 5.3: Use the filters to limit the list of components by type.
To edit the components, select one and edit it in the right pane. Test your changes by clicking
Preview. Once you are happy with your changes, click Publish to deploy the changes to the
Developer Portal.
Customizing Templates
The Developer Portal uses a templating engine called Liquid. By using a templating engine, each
page can reuse elements and features without the need for duplicate code.
When a user visits a page, the server stitches together the parts before sending the response. This
makes the portal feel like a cohesive web application rather than a set of disparate pages.
The default Liquid templates in the Developer Portal use standard HTML, JavaScript, and CSS.
Liquid syntax enables you to define and reference variables within the pages, as well as create
conditional and repeating structures.
Assuming the variable name is set to Bob, the resulting HTML would be the following:
<strong>Bob</strong>
The curly brace and percent symbol syntax ({% and %}) indicates parts to be parsed as Liquid
syntax, but does not get replaced with anything. These parts are used to define parts of the
template that control the structure, such as loops.
<ul>
{% for user in users %}
<li>{{ user.name }}</li>
{% endfor %}
</ul>
156 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Assuming users is a list of objects with a name property, the resulting HTML would be an
unordered list of the names of users.
For example, the provider.logo_url and provider.name are set to the custom logo URL
and company name, respectively.
The following HTML and Liquid snippet produces an anchor tag that has the company name and
logo.
<a href="/">
<img src="{{ provider.logo_url }}" />
{{ provider.name }}
</a>
References
For more information, refer to the Red Hat 3scale API Management Creating the
Developer Portal at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/creating_the_developer_portal
For more information on using Liquid, refer to the Red Hat 3scale API Management
Liquid Reference at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html/liquid_reference/liquid-reference
DO240-RH3APIM2.11-en-2-20220405 157
Chapter 5 | Creating a Developer Portal
Guided Exercise
Outcomes
You should be able to:
Instructions
1. Update the company name for use within the developer portal.
1.1. Within a web browser, navigate to the 3scale API Management Admin Portal. The
URL to the Admin Portal is https://3scale-admin.apps.ocp4.example.com.
1.2. Using the top pane navigation drop-down, click Account Settings.
1.4. Change the organization name to Bob's Boxes and click Update Account.
2.2. Preview the current version of the developer portal by clicking Developer Portal >
Visit Portal.
158 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Close the CMS toolbar by clicking the X (close) button in the top right corner.
2.3. Review the default style and theme of the portal. Notice the blue theme and that the
company name is Bob's Boxes.
Leave this tab open because you will visit the portal several times to view your
changes.
3.1. Within the Admin Portal, navigate to Developer Portal > Logo and upload the file ~/
DO240/labs/portal-customizing/icon.png.
3.3. Within the file hierarchy, under the Layouts heading, select the file called Main
layout. This file provides the structure for many of the pages within the default
developer portal.
3.4. Modify the contents of the file by adding an img tag referencing the
provider.logo_url variable. After your updates, the file should match the
following contents:
...output omitted...
<nav class="navbar navbar-fixed-top navbar-inverse" role="navigation">
<div class="container tabbed">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-
toggle="collapse" data-target="#navbar-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<img src="{{ provider.logo_url }}" height="32px" />
{{ provider.name }}
</a>
</div>
{% include 'submenu'%}
</div>
</nav>
...output omitted...
3.5. Deploy your changes to the developer portal by clicking Publish at the bottom of the
file editing panel.
3.6. Select the developer portal tab and refresh the page to view the logo in the
navigation bar.
4. Customize the style of the developer portal by modifying the included CSS file.
4.1. Within the Admin Portal tab, select the default.css file from the file hierarchy.
DO240-RH3APIM2.11-en-2-20220405 159
Chapter 5 | Creating a Developer Portal
4.2. Modify the background color of the body selector to orange. The file should match
the following excerpt:
...output omitted...
body {
background-color: darkorange; /* fallback */
background-color: rgb(255, 140, 0);
...output omitted...
}
...output omitted...
4.3. Deploy your changes to the developer portal by clicking Publish at the bottom of the
file editing panel.
Select the developer portal tab and refresh the page to view the color theme change
to orange.
5. Add a new page to the developer portal that shows company information.
5.1. Within the Admin Portal, open the file called Documentation. Click New Page at the
top right.
Field Value
Title About
Path /about
Within the Advanced Options section, make sure Liquid enabled is checked.
Leave all other fields as their default values and click Create Page.
5.3. Update the contents for the about page by pasting the following HTML snippet into
the editor:
<h1>About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam accumsan est id
neque interdum posuere. Ut eleifend et sapien nec pharetra. Vivamus condimentum
magna vitae justo rutrum, non vestibulum odio ultricies. Morbi eget sem sit amet
erat dapibus molestie. Nullam nec felis et massa tincidunt interdum. Integer
imperdiet nisi ac lacus feugiat pretium. Suspendisse accumsan consequat augue, a
feugiat metus commodo sed.</p>
5.4. Deploy your changes to the developer portal by clicking Publish at the bottom of the
file editing panel.
Select the developer portal tab and navigate to
https://3scale.apps.ocp4.example.com/about to view the new about page.
6.1. Within the Admin Portal tab, open the file called submenu under the Partials
heading.
160 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
6.2. Update the contents of the partial to include an anchor tag for the about page. The
file should match the following excerpt:
...output omitted...
{% if current_user %}
...output omitted...
<li><a class="{% if urls.docs.active? %}active{% endif %}" href="/
docs">Documentation</a></li>
</ul>
...output omitted...
{% else %}
<ul class="nav navbar-nav">
<li><a href="/docs">Documentation</a></li>
<li><a href="/#plans">Plans</a></li>
<li class="{% if request.path == "/about" %}active{% endif %}">
<a href="/about">About</a>
</li>
</ul>
...output omitted...
{% endif %}
</div>
6.3. Deploy your changes to the developer portal by clicking Publish at the bottom of the
file editing panel.
Select the developer portal tab and refresh the page. Use the navigation at the top of
the page to navigate between the different pages, including the new about page.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
DO240-RH3APIM2.11-en-2-20220405 161
Chapter 5 | Creating a Developer Portal
Objectives
After completing this section, you should be able to import OpenAPI standard API definitions into
Red Hat 3scale API Management.
• It allows API consumers to interact with your API from the documentation, for example for
testing purposes.
• It offers a way to generate clients and servers that comply with the OAS you define.
This specification is used by Red Hat 3scale API Management to provide interactive
documentation for the Developer Portal. In 3scale API Management the OAS integration is called
ActiveDocs.
Also, by using the 3scale Toolbox CLI and the import command you can generate all the 3scale
API Management objects needed to create an application based on the OAS definition.
To select any product for the OAS definition, create the ActiveDocs from the Audience page. For
this you must navigate to Developer Portal>ActiveDocs, click Create a new spec, and complete
the ActiveDocs form.
162 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
USAGE
3scale activedocs <sub-command> [options]
DESCRIPTION
Manage your ActiveDocs
SUBCOMMANDS
apply Update activedocs
create Create an ActiveDocs
delete Delete an ActiveDocs
list List ActiveDocs
All these subcommands affect ActiveDocs objects exclusively. For example, you can use the
delete subcommand as a way to delete ActiveDocs objects.
This operation does more than creating the ActiveDocs object. It generates many 3scale API
Management objects based on the OAS definition file. It creates:
DO240-RH3APIM2.11-en-2-20220405 163
Chapter 5 | Creating a Developer Portal
• A product with a name taken from the title attribute in the OAS file.
• A backend with a name taken from the title attribute and a backend URL taken from the
servers section in the OAS file.
• Mapping rules and methods based on the paths section from the OAS file.
This is the system name that is used as the system name for the product, the backend and
the ActiveDocs objects.
This option adds an Anonymous Access policy. The value provided here is used for
unauthenticated endpoints.
The OAS file in JSON or YAML. This option also accepts a URL that returns the OAS
definition.
After executing this command you must create an application plan and an application to make your
API public.
To use the ActiveDocs interactive documentation you must add a CORS Request Handling
policy and set the allow_origin to the Developer Portal domain. The reason for this is that the
ActiveDocs request is sent from the Developer Portal domain, which is different from your API
domain. When the domain from where the request is originated differs from the domain serving
the request, the browser blocks the call unless you configure APIcast to allow it.
References
For more information, refer to the How to write an OpenAPI document for use as a
3scale OpenAPI spec chapter in the Red Hat 3scale API Management Providing APIs
in the Developer Portal at
https://access.redhat.com/documentation/en-
us/red_hat_3scale_api_management/2.11/html/
providing_apis_in_the_developer_portal/how-to-write-an-openapi-document-for-
use-as-a-threescale-openapi-spec_creating-a-new-service-based-on-oas
OpenAPI Specification
https://github.com/OAI/OpenAPI-Specification
164 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Guided Exercise
Outcomes
You should be able to:
• Update the Documentation template in Admin Portal to show all the ActiveDocs in the
Developer Portal.
This command deploys a pet shelter API to the Red Hat OpenShift Container Platform
(RHOCP) cluster.
Instructions
1. Add the backend URL to the OpenApi definition. This is the pet shelter API internal URL
accessible from within the RHOCP cluster.
1.2. Replace the CHANGE_ME URL value with the cluster API URL, http://
petshelter-api.portal-openapi.svc.cluster.local
2.1. Execute the 3scale_wrapper.sh script to import the OpenApi definition. Name
the product resulting from the import with portal_openapi by providing the --
target_system_name=portal_openapi argument.
The 3scale_wrapper.sh script mounts the last parameter as a Podman volume file
to run 3scale Toolbox CLI with Podman.
DO240-RH3APIM2.11-en-2-20220405 165
Chapter 5 | Creating a Developer Portal
[student@workstation ~]$ \
~/DO240/labs/portal-openapi/3scale_wrapper.sh import openapi \
--target_system_name=portal_openapi \
--destination=3scale-tenant \
DO240/labs/portal-openapi/openapi-definition.yaml
{
"code": "E_3SCALE",
"message": "User key must be provided by --default-credentials-userkey optional
param",
"class": "ThreeScaleToolbox::Error"
}
Created service id: 3, name: Pet Shelter
Service proxy updated
destroying all mapping rules
Created PUT /pet$ endpoint
Created POST /pet$ endpoint
Created GET /pet/findByStatus$ endpoint
Created GET /pet/{petId}$ endpoint
Created DELETE /pet/{petId}$ endpoint
Note
You can add the --default-credentials-userkey=anonymous_api_key
option to allow for unauthenticated endpoints. This creates an Anonymous Access
policy with the anonymous_api_key value.
2.2. Use the 3scale Toolbox CLI proxy-config command to get the portal_openapi
product's proxy configuration, and verify that the previous step creates a backend
with the correct URL.
3.1. Create an application plan called basic_plan by using the 3scale Toolbox CLI from
the command line.
3.2. Create an application on the default john account called shelter-app, and assign
it the basic_plan application plan.
166 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
4. Configure the portal_openapi product to allow access from the Admin Portal and the
Developer Portal.
4.1. Navigate to Integration > Policies from the portal_openapi product page. Then
update the policy chain by adding the CORS Request Handling policy and placing
it before the 3scale APIcast policy in the policy chain.
Configure the CORS policy by setting:
• allow_origin: (3scale-admin|3scale).apps.ocp4.example.com
4.2. Promote the portal_openapi configuration first to staging and then to production.
5. Verify that you can reach the petshelter-api RHOCP service by using the ActiveDocs in
the Admin Portal.
5.1. Click ActiveDocs from the side menu in the portal_openapi product. Then click
portal_openapi to go to the interactive documentation.
• Click the Fisrt userkey from latest 5 applications drop-down menu and select the
shelter-app to automatically fill the user_key parameter.
The response shows in the 200 code under the Server response section.
{
"0": {
"photoUrls": [
"photo_1_url",
"photo_2_url"
],
"name": "spotty",
"id": 0,
"category": {
"name": "dogs",
DO240-RH3APIM2.11-en-2-20220405 167
Chapter 5 | Creating a Developer Portal
"id": 6
},
...output omitted...
6. Update the Developer Portal Documentation page to show all the ActiveDocs in the tenant.
6.2. Navigate to the Audience page. Then click Developer Portal > Content and click
Documentation to edit the documentation page.
6.3. Scroll to the Draft section and replace the default template by pasting the contents
from the dev-portal-docs.liquid file. Then click Save and Publish.
7. Use the 3scale Toolbox CLI to retrieve the user_key for the shelter-app application.
• Paste the user_key from the previous step to fill the user_key parameter.
The response shows in the 200 code under the Server response section.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
168 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Quiz
1. Consider that you want to create a new page in your Developer Portal, which is only
visible to a restricted number of developers. Which of the following is the most
appropriate? (Choose one.)
a. You create a new public page with a difficult and long path. Then, you share the URL with
the corresponding developers.
b. You create a new private page and a new group called restricted-developers.
c. You create a new public page and a new group called restricted-developers. Then,
you assign the corresponding users to the group.
d. You create a new private page and a new group called restricted-developers.
Then, you assign the corresponding users to the group.
2. Which of the following are correct about the Developer Portal? (Choose two.)
a. Layouts are reusable elements that you can embed in pages.
b. When you sign up in the Developer Portal, an account with a developer user and an
application are created specifically for you.
c. You can create pages by using Markdown instead of HTML.
d. RSS is not supported.
3. Consider the following code snippet from a layout of the Developer Portal. Which of
the following statements are correct? (Choose two.)
a. If the name of the Developer Portal is Red Hat, then the logo of the Developer Portal is
rendered.
b. If the name of the Developer Portal is NOT Red Hat, then a black square with the logo
of the Developer Portal is rendered.
c. If the name of the Developer Portal is Red Hat, then a black square is rendered.
d. If the name of the Developer Portal is NOT Red Hat, then a black square with the
current path is rendered.
DO240-RH3APIM2.11-en-2-20220405 169
Chapter 5 | Creating a Developer Portal
4. Consider the following 3scale Toolbox CLI command. Which of the following
statements are correct about the command? (Choose two.)
170 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Solution
1. Consider that you want to create a new page in your Developer Portal, which is only
visible to a restricted number of developers. Which of the following is the most
appropriate? (Choose one.)
a. You create a new public page with a difficult and long path. Then, you share the URL with
the corresponding developers.
b. You create a new private page and a new group called restricted-developers.
c. You create a new public page and a new group called restricted-developers. Then,
you assign the corresponding users to the group.
d. You create a new private page and a new group called restricted-developers.
Then, you assign the corresponding users to the group.
2. Which of the following are correct about the Developer Portal? (Choose two.)
a. Layouts are reusable elements that you can embed in pages.
b. When you sign up in the Developer Portal, an account with a developer user and an
application are created specifically for you.
c. You can create pages by using Markdown instead of HTML.
d. RSS is not supported.
3. Consider the following code snippet from a layout of the Developer Portal. Which of
the following statements are correct? (Choose two.)
a. If the name of the Developer Portal is Red Hat, then the logo of the Developer Portal is
rendered.
b. If the name of the Developer Portal is NOT Red Hat, then a black square with the logo
of the Developer Portal is rendered.
c. If the name of the Developer Portal is Red Hat, then a black square is rendered.
d. If the name of the Developer Portal is NOT Red Hat, then a black square with the
current path is rendered.
DO240-RH3APIM2.11-en-2-20220405 171
Chapter 5 | Creating a Developer Portal
4. Consider the following 3scale Toolbox CLI command. Which of the following
statements are correct about the command? (Choose two.)
172 DO240-RH3APIM2.11-en-2-20220405
Chapter 5 | Creating a Developer Portal
Summary
In this chapter, you learned:
DO240-RH3APIM2.11-en-2-20220405 173
174 DO240-RH3APIM2.11-en-2-20220405
Chapter 6
DO240-RH3APIM2.11-en-2-20220405 175
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to configure API analytics to gather runtime
metrics for APIs.
You can define a new metric at the 3cale API Management product level, therefore, a product is
composed of one or many metrics. By default, 3scale creates the Hits metric, which counts the
number of requests that reach the product at any path. For example, if you create a product called
product1, then 3cale API Management creates the Hits metric for the / path, which means that
a request to any path increments the metric.
A metric is composed of several fields. The following table gives an explanation of every field.
Field Explanation
System name A unique name that identifies the metric within the 3scale API
Management system.
Managing Metrics
To manage the metrics you can use the Admin Portal or the CLI Toolbox.
To create a new metric, click New metric and complete the form.
176 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
You can create a new metric by using the 3scale metric create command. For example,
if you want to create a metric metric1 for the product1 product in the 3scale tenant, then a
possible command is as follows:
You can update an existing metric by using the 3scale metric apply command. The following
command updates the name for the metric1 metric.
You can list the existing metrics by using the 3scale metric list.
The previous commands include several options to modify the metric, such as name or
description. For a complete understanding of the options associated to every command,
visit the official Red Hat documentation [https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/operating_3scale/index#creating-metrics].
Incrementing Metrics
The main purpose of a metric is to measure, therefore, it must be incremented based on your
specific use cases.
To add the policy, navigate to Integration: > Policies and click Add policy. Then, select Custom
Metrics from the policies list. For the policy to work, you must give it priority over the default
APIcast policy policy.
You can consider that every operation is an equality expression with two operands: left and
right. The operation holds an op field, which is applied to the left and right operands.
DO240-RH3APIM2.11-en-2-20220405 177
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
The left and right fields can be plain text, or Liquid (the programming language) expressions.
In the Liquid programming language, variables are enclosed with two brackets (for example,
{{variable}}). The policy provides the built-in variable {{status}}, which is used to get the
status code of the response. For example, if you only want the metric to be incremented when the
status code is 404, then the expression is similar to the following:
3scale API Management evaluates the previous expression on every request, and only increments
the metric if the evaluation is true. You can include complex expressions by creating several
operations combined by a logical expression (and or or).
The previous expression increments the metric if the status code is equal to 404 or 500.
To configure the policy, you must complete the form, which includes several fields.
The following table explains the fields involved in the configuration of the policy.
Field Explanation
left_type The type of the left operand (either plain text or liquid
expression).
178 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Field Explanation
right_type The type of the right operand (either plain text or liquid
expression).
Metric to increment The system name of the metric to increment if the expression
evaluates to true.
References
Red Hat 3scale API Management documentation - Creating Metrics
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/operating_3scale/
index#creating-metrics
DO240-RH3APIM2.11-en-2-20220405 179
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to configure the Custom Metrics APIcast policy to increment a metric
based on the HTTP status code of the response.
The start function deploys the status-api application. The application exposes an
endpoint, /status/{code}, which returns the HTTP status code (200, 201 or 203)
provided in the path parameter. You will use this API to track the number of responses that
return the 203 status code. At the same time, a product and a backend, called status, are
created to perform the exercise.
Instructions
1. Explore the status product and review the default metrics.
1.1. In the 3scale Admin Portal, navigate to the monitoring_analytics product page.
1.2. In the left pane, click Analytics > Traffic. The default metric, Hits, is incremented
every time that a request for the product arrives.
2. Create a new metric to track the number of requests to the /status endpoint of the
Status API.
2.1. In the left pane, click Integration: > Methods & Metrics. Then, click New metric.
Complete the form according to the following values:
Field Value
Unit 1
180 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
2.2. In the status metric row, click Add a mapping rule to attach the metric to the /
status path. Complete the form according to the following values:
Field Value
Verb GET
Pattern /status
3. Create a new metric to track the 203 HTTP status codes returned by the status product.
3.1. In the left pane, click Integration: > Methods & Metrics. Then, click New metric.
Complete the form according to the following values:
Field Value
Unit 1
4. Add the Custom Metrics policy, so that APIcast can increment the status-203 metric
on every request that returns a 203 HTTP status code.
4.1. In the left pane, click Integration: > Policies. Then, click Add policy.
4.2. Within the policies list, select Custom Metrics. Then, use the arrow icon to move
the Custom Metrics policy to the first position.
4.3. Click Custom Metrics to update the policy. Complete the form according to the
following values:
Field Value
left {{status}}
right 203
op matches
left_type
DO240-RH3APIM2.11-en-2-20220405 Evaluate 'left' as liquid 181
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
This policy increments the status-203 metrics whenever the status code of the
response is 203.
5.3. From the curl example, copy the user_key parameter. You use this later in this
exercise.
6. Verify that the status-203 metric is only incremented when a 203 HTTP status code is
returned.
6.2. In the Admin Portal, navigate to Analytics: > Traffic. In the drop-down menu, select
the status-203 metric.
6.3. The number that the status-203 metric displays should be equal to the number of
responses with the 203 status code provided by the test-status-api.sh script.
Although the Status API has returned other status codes, only the 203 status code
has incremented the metric.
6.4. In the drop-down menu, select the status metric. The number displayed should be
equal to 20, which is the number of total requests sent to the product.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
182 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Objectives
After completing this section, you should be able to configure monitoring and metrics collection
for the 3scale API Management infrastructure.
Prometheus is responsible for collecting and managing the monitoring and metrics data. Grafana
provides an interface and widgets for creating dashboards with the metrics.
Both the Prometheus and Grafana operators provide Custom Resource Definitions (CRDs). With
monitoring enabled, the 3scale API Management operator creates resources based on these
CRDs to automatically configure Prometheus and Grafana.
Enabling Monitoring
To enable the monitoring functionality within 3scale API Management, you must do so within the
APImanager definition.
For example, in the following APImanager definition, the highlighted monitoring attribute
instructs the 3scale API Management operator to create applicable Prometheus and Grafana
resources.
apiVersion: apps.3scale.net/v1alpha1
kind: APIManager
metadata:
name: apimanager-sample
namespace: 3scale
spec:
wildcardDomain: apps.ocp4.example.com
monitoring:
enabled: true
There are multiple ways to run Prometheus within Red Hat OpenShift Container Platform
(RHOCP). However, this course only focuses on using the Prometheus operator.
The 3scale API Management operator is designed to integrate with the Prometheus operator.
Specifically, the 3scale API Management operator configures a standard set of Prometheus
alerting rules and pod monitors.
DO240-RH3APIM2.11-en-2-20220405 183
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Alerting rules define certain conditions that, when met, should trigger actions. For example, you
might use an alert rule to send an email notification whenever CPU usage exceeds a certain
threshold. Pod monitors gather metrics data from pods within the cluster.
In addition to installing the operator, you must also create a Prometheus instance by creating a
resource of type Prometheus. The following is an excerpt of an example Prometheus definition:
kind: Prometheus
...output omitted...
spec:
serviceAccountName: prometheus-k8s
podMonitorSelector:
matchExpressions:
- key: app
operator: In
values:
- my-app
The name of the Red Hat OpenShift service account that the Prometheus instance will use.
This service account should have permissions to access all selected resources.
This expression configures Prometheus to look for pod monitors with the app=my-app label.
Alert rules and service monitors are selected similarly by using the ruleSelector and
podMonitorSelector attributes, respectively.
Similar to Prometheus, this course focuses on installing Grafana by using an operator. You must
also create a Grafana instance by creating a resource of type Grafana. The following is an excerpt
of an example Grafana definition:
kind: Grafana
...output omitted...
spec:
config:
...output omitted...
dashboardLabelSelector:
- matchExpressions:
- key: app
operator: In
values:
- my-app
You must provide a configuration object which is passed to the Grafana instance.
This expression configures Grafana to look for dashboard resources with the app=my-app
label.
184 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
For the Grafana instance to retrieve data from the Prometheus instance, you also need a resource
of type GrafanaDataSource, which provides connection information. The following is an excerpt
of an example Grafana data source definition:
kind: GrafanaDataSource
...output omitted...
spec:
name: middleware
datasources:
- name: Prometheus
url: http://prometheus-operated:9090
...output omitted...
You must provide a connection string that resolves to the Prometheus instance.
Available Dashboards
Once you have monitoring set up, you can view the default metrics and dashboards.
The 3scale API Management operator creates seven Grafana dashboards. Each of these uses the
data that Prometheus gathers from the various components within 3scale API Management.
The following are some of the default dashboards and the metrics that they display:
• Apicast: Shows APIcast instance metrics, such as the number of error requests in the last
hour. Use the environment selection menu to choose between the staging and production
APIcast instances.
• System: Shows metrics about 3scale API Management itself, such as tenants requests per
second.
• Zync: Shows metrics from the Zync component and its RHOCP pods, such as the number of
Zync requests per second and CPU usage.
References
For more information, refer to the Monitoring 3scale chapter in the Red Hat 3scale
API Management 2.11 Operating 3scale guide at
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html/operating_3scale/monitoring-
threescale
DO240-RH3APIM2.11-en-2-20220405 185
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Guided Exercise
Outcomes
You should be able to:
Instructions
1. Review the available metrics by using the APIcast staging pod.
1.1. Within a command line terminal, log in as the admin user and select the 3scale
project with the oc command. When prompted, use the password redhat.
1.3. Make a request to localhost, which is the APIcast pod itself, to retrieve the list of
available metrics.
186 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
2.1. In a web browser, log in to the Red Hat OpenShift Container Platform (RHOCP) web
console by using the htpasswd provider, username admin, and password redhat.
The URL for the RHOCP web console is https://console-openshift-
console.apps.ocp4.example.com.
2.3. Make sure the 3scale project is selected by using the Project selection menu at the
top of the page.
2.5. Make sure the Installed Namespace is set to 3scale and click Install.
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: 3scale-monitor
namespace: 3scale
spec:
serviceAccountName: prometheus-k8s
podMonitorSelector:
matchExpressions:
- key: app
operator: In
values:
- 3scale-api-management
ruleSelector:
matchExpressions:
- key: app
operator: In
values:
- 3scale-api-management
Applying the preceding resource creates a new Prometheus instance within the
3scale project. This instance watches for pod monitors and Prometheus rules that
have the RHOCP label app=3scale-api-management.
DO240-RH3APIM2.11-en-2-20220405 187
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
3.1. Within a web browser, navigate back to Operators > OperatorHub and search for
grafana.
3.3. Make sure the Installed Namespace is set to 3scale and click Install.
apiVersion: integreatly.org/v1alpha1
kind: Grafana
metadata:
name: grafana
namespace: 3scale
spec:
ingress:
enabled: True
config:
log:
mode: "console"
level: "warn"
auth:
disable_login_form: False
disable_signout_menu: True
auth.anonymous:
enabled: True
dashboardLabelSelector:
- matchExpressions:
- key: app
operator: In
values:
- 3scale-api-management
Applying the preceding resource creates a Grafana instance within the 3scale
project. This instance also watches for the app=3scale-api-management RHOCP
label.
3.5. Within a command line terminal, apply the grafana-3scale.yml file. The Grafana
operator creates the relevant resources, including a Grafana pod.
188 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
apiVersion: integreatly.org/v1alpha1
kind: GrafanaDataSource
metadata:
name: prometheus
namespace: 3scale
spec:
name: middleware
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus-operated:9090
isDefault: true
version: 1
editable: true
jsonData:
timeInterval: "5s"
4.1. Observe that no pod monitors or rules exist in the 3scale project.
4.2. Edit the APImanager you created as part of the 3scale API Management set up:
...output omitted...
spec:
...output omitted...
monitoring:
enabled: true
...output omitted...
DO240-RH3APIM2.11-en-2-20220405 189
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
4.4. Observe that the 3scale API Management operator creates relevant Prometheus
resources.
5. View the 3scale API Management metrics within the Grafana web interface.
5.2. Click 3scale to expand the list of available dashboards. Then, click Apicast to view a
dashboard showing APIcast metrics.
5.3. In the top right of the page, select Last 5 minutes from the selection menu. This
makes it easier to see the data because Prometheus does not receive any data until
monitoring is enabled.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
190 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Quiz
1. Which two of the following components are a part of the 3scale API Management
monitoring stack?
a. Prometheus
b. Logstash
c. Grafana
d. Kibana
3. Which one of the following metrics is the default metric within a 3scale API
Management product and what does it collect?
a. Hits, which counts the number of requests that 3scale API Management processes
across all products.
b. Hits, which counts the number of requests that reach the product at any path.
c. Requests, which counts the number of requests that reach the product at any path.
d. Requests, which counts the number of requests that reach a specified backend.
4. Other than creating a mapping rule, which one of the following responses best
describes a 3scale API Management feature that enables you to increment a custom
metric?
a. The Increment Metric policy
b. The Custom Metrics policy
c. Prometheus and Grafana
d. You must create a mapping rule.
5. Which one of the following definitions best describes a Prometheus alert rule?
a. Alert rules establish the connection between Prometheus and Grafana.
b. Alert rules define how a graph appears within the Prometheus user interface.
c. Alert rules are used to trigger configured actions, such as sending an email notification
once a certain condition is met.
d. Alert rules are not a feature of Prometheus.
DO240-RH3APIM2.11-en-2-20220405 191
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
6. Your team has a product called my-app in which you would like to track the number of
request errors with HTTP status code 500. Which of the following best describes the
process you should follow?
a. Create a new metric in the product, add the Custom Metrics policy to the product's
policy chain, and promote the configuration.
b. Create a new metric in the product, add a mapping rule, and promote the configuration.
c. Create a new metric in the product and then create an alerting rule in Prometheus.
d. The 3scale API Management creates a default Grafana dashboard with this metric
already included.
7. For the same scenario as outlined in question 6, when setting up the operands for the
Custom Metrics policy, what would be the left and right values, respectively?
Consider that left_type = liquid and right_type = plain text.
a. left and 500
b. 500 and {{status}}
c. {{status}} and 500
d. status and {{500}}
192 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Solution
1. Which two of the following components are a part of the 3scale API Management
monitoring stack?
a. Prometheus
b. Logstash
c. Grafana
d. Kibana
3. Which one of the following metrics is the default metric within a 3scale API
Management product and what does it collect?
a. Hits, which counts the number of requests that 3scale API Management processes
across all products.
b. Hits, which counts the number of requests that reach the product at any path.
c. Requests, which counts the number of requests that reach the product at any path.
d. Requests, which counts the number of requests that reach a specified backend.
4. Other than creating a mapping rule, which one of the following responses best
describes a 3scale API Management feature that enables you to increment a custom
metric?
a. The Increment Metric policy
b. The Custom Metrics policy
c. Prometheus and Grafana
d. You must create a mapping rule.
5. Which one of the following definitions best describes a Prometheus alert rule?
a. Alert rules establish the connection between Prometheus and Grafana.
b. Alert rules define how a graph appears within the Prometheus user interface.
c. Alert rules are used to trigger configured actions, such as sending an email notification
once a certain condition is met.
d. Alert rules are not a feature of Prometheus.
DO240-RH3APIM2.11-en-2-20220405 193
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
6. Your team has a product called my-app in which you would like to track the number of
request errors with HTTP status code 500. Which of the following best describes the
process you should follow?
a. Create a new metric in the product, add the Custom Metrics policy to the product's
policy chain, and promote the configuration.
b. Create a new metric in the product, add a mapping rule, and promote the configuration.
c. Create a new metric in the product and then create an alerting rule in Prometheus.
d. The 3scale API Management creates a default Grafana dashboard with this metric
already included.
7. For the same scenario as outlined in question 6, when setting up the operands for the
Custom Metrics policy, what would be the left and right values, respectively?
Consider that left_type = liquid and right_type = plain text.
a. left and 500
b. 500 and {{status}}
c. {{status}} and 500
d. status and {{500}}
194 DO240-RH3APIM2.11-en-2-20220405
Chapter 6 | Monitoring APIs with Red Hat 3scale API Management
Summary
In this chapter, you learned:
• How to use the Prometheus and Grafana operators to monitor 3scale API Management.
DO240-RH3APIM2.11-en-2-20220405 195
196 DO240-RH3APIM2.11-en-2-20220405
Chapter 7
DO240-RH3APIM2.11-en-2-20220405 197
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Objectives
After completing this section, you should be able to configure billing for API consumers.
3scale API Management billing generates a monthly invoice for the customer based on the
application plans the customer signed up for. Customers in 3scale API Management are the
developer accounts that signed up to use your APIs.
To configure billing in the Admin Portal navigate to the Audience page. There you can access the
Billing menu.
Automatic billing is enabled by default for all the accounts. You can disable automatic billing for
individual accounts by navigating to the account and clicking Disable in the billing section from the
account details page.
You can enable automatic payments globally. For this, you must navigate to Billing > Settings >
Charging & Gateway and click Charging enabled. This affects every developer account in the
tenant, but you can disable it for individual accounts in the billing section from the account details
page.
To use automatic payments you must configure a payment gateway. 3scale API Management
offers integration's with credit card gateways like Stripe or Braintree.
Billing Configuration
To configure billing, navigate to Billing > Settings > Charging & Gateway.
198 DO240-RH3APIM2.11-en-2-20220405
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
There you have the following options to customize the invoices that 3scale API Management
sends to customers.
Mode
You can select Prepaid or Postpaid depending on which month you want clients to pay in
the current month invoice.
Charging enabled
You must enable this if you want to have automated payments by using a payment gateway.
Currency
You can pick the currency for the invoice. If you set up automatic payments, pick a currency
supported by your payment gateway.
Invoice footnote
The text you provide shows at the bottom of every PDF invoice.
Managing Invoices
You can list and search the existing invoices by navigating to Billing > Invoices.
From the invoice list you can see some invoice details like identifier, the developer account, and
the invoice state.
Open
The invoice is created and the invoice contents can be updated.
Finalized
The invoice has all the current billing period charges added to it.
Pending
3scale API Management issued the invoice to the customer and the invoice is awaiting
payment.
Unpaid
The invoice payment failed, but the system will retry.
DO240-RH3APIM2.11-en-2-20220405 199
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Paid
The invoice payment terminated with success.
Failed
The invoice payment failed after several attempts and 3scale API Management stops retrying.
Canceled
The administrator canceled the invoice.
Prepaid
3scale API Management bills fixed and set-up fees at the beginning of the month. Variable
costs for the current month are billed at the beginning of the following month.
Postpaid
3scale API Management bills all the fees at the beginning of next month.
The billing process executes every day. The tasks to execute differ depending on whether it is the
the first day of the month, and whether the billing mode is set to prepaid or postpaid.
• Prepaid
• Postpaid
– Create an open invoice for this month and bill fixed costs.
The following tasks execute every day of the month, including the first day:
• Create an open invoice for today's new contracts and expired trials.
• Issue invoices to customers and change the state from finalized to pending.
• Charge invoices. Invoices in an unpaid and pending state are charged if the Due On invoice
property is set for today or earlier. A failed payment changes the state to unpaid. After three
failed payment attempts the invoice is set to failed.
You can manually trigger these tasks from the Admin Portal. For this, navigate to the selected
invoice by clicking the invoice identifier in the invoice list. If the selected invoice is not paid you
can perform different actions. For example, if the invoice is open then you can issue the invoice by
clicking Issue invoice and leave it in a pending state.
200 DO240-RH3APIM2.11-en-2-20220405
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
References
Credit card gateways for payments
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/admin_portal_guide/
index#credit-card-gateways-for-payments
Adding currencies
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/admin_portal_guide/
index#yaml_configuration_for_currencies
DO240-RH3APIM2.11-en-2-20220405 201
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Guided Exercise
Outcomes
You should be able to:
This command:
Instructions
1. Set billing to prepaid mode in the Admin Portal.
1.1. In a web browser, log in to the the 3scale API Management Admin Portal as the
admin user.
1.2. From the Audience page, navigate to Billing > Settings > Charging & Gateway and
click Switch to PREPAID.
When a prompt shows asking for confirmation, click OK.
2. Create a monthly plan with a set-up fee of $30 and a monthly fee of $10.
3. Create an application for the john user account and subscribe to the monthly_plan.
202 DO240-RH3APIM2.11-en-2-20220405
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
4. Update the 3scale API Management billing process to run every minute.
Warning
The sidekiq_shcedule.yml file for this exercise is intentionally incomplete and
contains only the cron definition for billing jobs. If you leave this configuration other
types of jobs will not execute.
4.2. Log in to Red Hat OpenShift Container Platform (RHOCP) as the admin user.
4.3. Patch the system configmap to include the new schedule for the billing job.
[student@workstation ~]$ sh \
/home/student/DO240/labs/monetizing-billing/update_trial_dates.sh
mysql: [Warning] Using a password on the command line interface can be insecure.
6. Verify that the billing process generates an invoice for the Developer account.
6.1. Navigate to the Audience page in the Admin Portal. Then click Billing > Invoices.
6.2. Verify that the billing process generated an invoice for the Developer account and
that the invoice state is set to Finalized.
The billing process job could take a minute until it runs again. Refresh the page if the
invoice list is empty.
6.3. Navigate to the invoice details by clicking the invoice number. Then verify that two
line items show in the Line Items section:
DO240-RH3APIM2.11-en-2-20220405 203
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
• Fixed fee ('monthly_plan') with a max value of $10 depending on how close today is
to the beginning of the month.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
204 DO240-RH3APIM2.11-en-2-20220405
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Objectives
After completing this section, you should be able to configure pricing rules for APIs.
Describing Pricing
Along with exposing your APIs to the public, you might want to charge your consumers for using
your APIs. By using Red Hat 3scale API Management you can set price rates for the requests at
the product level.
For example, if you have a product called example with two paths, /test and /test1, you might
want to charge your consumers for using one or both paths.
In 3scale API Management, pricing rates are linked with application plans. When you create an
application plan, you can choose fixed and variable charges for your APIs. Then, you link an
application plan with an application, and your consumers use the application's user key to make
requests.
You can set a setup fee, which is a one-time charge applied upon subscription to the service. It is
only charged the first month and it is not applied when an application moves to another application
plan.
You can also set a cost per month fee, which is a fixed charge applied monthly, regardless of
the number of requests. If the subscription happens in the middle of the month, then the fee is
prorated.
To access the fixed costs, navigate to the product page of the product that you want to use. Then,
click Applications > Application Plans and choose the application plan that you want to modify.
In the form you can see two fields: Setup fee and Cost per month.
DO240-RH3APIM2.11-en-2-20220405 205
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
You create pricing rules for a metric or a method, and you specify the cost of every request linked
with the metric or method.
For example, consider that you have a method mapped to the /test path. You create a pricing
rule for the method with a cost of 1 USD per request. Therefore, every request to the /test path
costs 1 USD.
To create a pricing rule, select an application plan first. Then, in the Metrics, Methods,
Limits & Pricing Rules section, click Pricing (X).
206 DO240-RH3APIM2.11-en-2-20220405
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
You set the pricing for a range of requests. The From field sets the lower side of the range, and the
To field sets the higher side of the range. The Cost per request field sets the price of every
request in the range.
From = 1
To = 124
Cost per request = 0.5 USD
From = 125
To = 1000
Cost per request = 0.2 USD
In the previous example, from the first to the 124th request, every request is charged at 0.5 USD.
Then, from the 125th to the 1000th request, every request is charged at 0.2 USD.
Note
Keep in mind that, because the default Hits metric captures all paths (/), the
pricing rules linked to the Hits metrics are applied to all paths.
References
Red Hat 3scale API Management Official Documentation - Pricing
https://access.redhat.com/documentation/en-us/
red_hat_3scale_api_management/2.11/html-single/admin_portal_guide/
index#pricing
DO240-RH3APIM2.11-en-2-20220405 207
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Guided Exercise
Outcomes
You should be able to:
Instructions
1. View the echo product, which points to the 3scale Echo API.
1.1. In the 3scale Admin Portal, navigate to the Products page. Click echo.
1.2. In the left pane, click Applications > Application Plans. The custom application plan
is displayed.
2. Update the custom application plan to include a setup fee of 5 USD, and a cost per month
of 3 USD.
3. Update the custom application plan to charge 0.5 USD per request for the first 120
requests.
3.2. In the Metrics, Methods, Limits & Pricing Rules section, click Pricing
(0) for the Hits metric row. The pricing rules are applied to the Hits metrics, which
captures all paths.
208 DO240-RH3APIM2.11-en-2-20220405
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Field Value
From 1
To 120
4. Update the custom application plan to charge 0.3 USD per request for the following 1000
requests.
Field Value
From 121
To 1121
5. Update the custom application to charge 0.1 USD per request from the 1122th request.
Field Value
From 1122
To (blank)
Important
To verify that the pricing rules work as expected, you can use the invoice reports
generated by 3scale API Management. Because the reports are generated monthly,
you can not verify the pricing rules of this guided exercise immediately.
Finish
On the workstation machine, use the lab command to complete this exercise. This is important
to ensure that resources from previous exercises do not impact upcoming exercises.
DO240-RH3APIM2.11-en-2-20220405 209
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Quiz
1. Which two of the following statements about billing are correct? (Choose two.)
a. Automatic billing is disabled for all accounts by default.
b. In the prepaid billing mode, fixed and set-up costs are billed at the beginning of the
month.
c. You can not use Red Hat 3scale API Management to set up a billing payment gateway.
d. You can see your invoices by using the Admin Portal.
3. Which two of the following statements about pricing rules are correct? (Choose two.)
a. Fixed costs are applied regardless of the number of requests that the product receives.
b. The set-up fee is applied when an application moves to another application plan.
c. If the subscription happens in the middle of the month, then the monthly fee is prorated.
d. You can update the fixed costs in the settings page of a product.
4. Which two of the following statements about pricing rules are correct? (Choose two.)
a. You apply pricing rules to a range of requests. When creating a pricing rule, you select a
from and a to to specify the lower and upper limits of the range.
b. All ranges must have the same cost per request.
c. You can create pricing rules by using the Master Portal.
d. Pricing rules are applied to a metric or a method.
210 DO240-RH3APIM2.11-en-2-20220405
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Solution
1. Which two of the following statements about billing are correct? (Choose two.)
a. Automatic billing is disabled for all accounts by default.
b. In the prepaid billing mode, fixed and set-up costs are billed at the beginning of the
month.
c. You can not use Red Hat 3scale API Management to set up a billing payment gateway.
d. You can see your invoices by using the Admin Portal.
3. Which two of the following statements about pricing rules are correct? (Choose two.)
a. Fixed costs are applied regardless of the number of requests that the product receives.
b. The set-up fee is applied when an application moves to another application plan.
c. If the subscription happens in the middle of the month, then the monthly fee is prorated.
d. You can update the fixed costs in the settings page of a product.
4. Which two of the following statements about pricing rules are correct? (Choose two.)
a. You apply pricing rules to a range of requests. When creating a pricing rule, you select a
from and a to to specify the lower and upper limits of the range.
b. All ranges must have the same cost per request.
c. You can create pricing rules by using the Master Portal.
d. Pricing rules are applied to a metric or a method.
DO240-RH3APIM2.11-en-2-20220405 211
Chapter 7 | Monetizing APIs with Red Hat 3Scale API Management
Summary
In this chapter, you learned:
• Invoices are generated monthly, and 3scale API Management offers two billing modes: prepaid
and postpaid.
• You can use an application plan to configure fixed and variables costs.
• When creating a pricing rule, you select a range of requests. A cost per request is selected for
every range of requests.
212 DO240-RH3APIM2.11-en-2-20220405