Connect to RDS database with STS from ROSA
This content is authored by Red Hat experts, but has not yet been tested on every supported configuration.
The Amazon Web Services Relational Database Service (AWS RDS) can be consumed from Red Hat OpenShift Service on AWS (ROSA) and authenticate to DB with Security Token Service (STS).
This is a guide to quickly connect to RDS Database (Postgres engine) from ROSA.
Amazon Web Services Relational Database Service
Amazon Web Services Relational Database Service (AWS RDS) is a distributed relational database service by Amazon Web Services. It is designed to simplify setup, operation, and scaling of a relational database for use in applications. It supports differents database engines such as Amazon Aurora, MySQL, MariaDB, Oracle, Microsoft SQL Server, and PostgreSQL.
In our example we will use PostgreSQL as engine.
Prerequisites
- A Red Hat OpenShift on AWS (ROSA) 4.12 cluster
- The OC CLI
- The AWS CLI
jqcommand
Set up environment
Export value of your cluster name (
rosa list cluster)Export list of environements variables from your cluster
Create database network
VPC + Subnets
Internet Gateway
DB Subnet group
Create RDS Database
Create DB with aws cli
Authorize ROSA cluster to connect to DB
IAM Permissions
Build the RDS access Policy
Create the RDS Access Policy
This creates a named policy for the cluster, you could use a generic policy for multiple clusters to keep things simpler.
Build Trust Policy
Create Role for accessing database
Attach the Policies to the Role
Test STS
Create new project
Check that STS is working properly
Prepare/Populate Database
Create a Pod for connecting to DB with postgres user
Download dataset IPrange / Country (in the prompt of
oc run)Connect to DB, create user, DB and populate it (in the prompt of
oc run)
Connection with IAM
Create pod to access with a IAM user this time
Test request
Deploy app
Create new-app
Add secrets to deployment
Expose APP
Test app
Expected output
Cleanup
Delete resources
Detach the Policies to the Role
Delete the Role
Delete the Policy