AWS Database Blog
Using external Kerberos authentication with Amazon RDS for PostgreSQL
In the first post in this series, Preparing on-premises and AWS environments for external Kerberos authentication for Amazon RDS, we built the infrastructure for a one-way forest trust between an on-premises Microsoft Active Directory (AD) domain (trust: incoming) and an AWS Managed Microsoft AD domain (trust: outgoing) provided by AWS Directory Service. In this post, we walk through how to join an Amazon Relational Database Service (Amazon RDS) for PostgreSQL instance to an AWS Managed Microsoft AD and demonstrate user authentication for Amazon RDS for PostgreSQL using external Kerberos and Microsoft AD.
Prerequisites
Before we start, make sure that you have prepared your on-premises and AWS environments, as shown in the following architectural diagram, including one on-premises AD user joedoe@onprem
and one Windows and one Linux client, which are joined to the on-premises AD domain onprem.local
.
Creating RDS for PostgreSQL instances and joining them to an AWS Managed Microsoft AD domain
We first create RDS for PostgreSQL instances in aws-acc-1
and aws-acc-2
and join the instance to AWS Managed Microsoft AD.
- Log in to the Amazon RDS console from
aws-acc-1
. - Create the DB subnet group
aws-acc-1-db-subnet-group
, which covers the three subnets inaws-acc-1-rds-vpc
.
- Create the security group
aws-acc-1-rds-vpc-allow-connection
to allow connection from on-premises clients (inon-prem-client-vpc
) to access Amazon RDS for PostgreSQL via TCP on port 5432.
- On the Amazon RDS console, create the RDS for PostgreSQL instance
rpg-acc-1-kerberos-12-2
in the DB subnet groupaws-acc-1-db-subnet-group
. - For VPC security group, select Choose existing.
- Choose the security group you created.
- For Database authentication options, select Password and Kerberos authentication.
- Choose Browse Directory.
- In the Choose directory section, select myaws.com.
- Choose Choose.
You can now see ad.myaws.com
in the Directory field.
After successfully creating the RDS for PostgreSQL instance, we see that the instance has joined the AWS Managed Microsoft AD, and the directory status shows as kerberos-enabled
.
We can also verify the directory status via the AWS Command Line Interface (AWS CLI). See the following code:
You can also create the RDS for PostgreSQL instances via the AWS CLI:
For Amazon RDS for PostgreSQL to call AWS Directory Service for you, you need an AWS Identity and Access Management (IAM) role that uses the managed IAM policy AmazonRDSDirectoryServiceAccess
. When you create a DB instance on the AWS Management Console and the console user has the iam:CreateRole
permission, the console creates this role automatically.
For this use case, the role name is rds-directoryservice-kerberos-access-role
.
For instructions on creating the role manually, see Create an IAM Role for Amazon Aurora to Access the AWS Directory Service. When you create this role, choose Directory Service, and attach the AWS managed policy AmazonRDSDirectoryServiceAccess
to it.
For existing RDS for PostgreSQL instances, we can modify the instance to join the AWS Managed Microsoft AD from the Amazon RDS console, or the AWS CLI:
- Repeat these steps in
aws-acc-2
to create an RDS for PostgreSQL instance and join the instance to the shared AWS Managed Microsoft AD, with following details:
-
- Instance name –
rpg-acc-2-kerberos-12-2
- DB subnet groups –
aws-acc-2-db-subnet-group
- Security group –
aws-acc-2-rds-vpc-allow-connection
- Database authentication options – Password and Kerberos authentication
- Directory –
myaws.com
(d-97671c1f8c
), shared byaws-acc-1
- Instance name –
- On the Amazon RDS console, make sure the RDS for PostgreSQL instance in
aws-acc-2
has joined the shared AWS Managed Microsoft AD successfully.
We can also verify the status via the AWS CLI:
- In
on-prem-account
, log in to the Windows client and install the pgAdmin and psql - Log in to the newly created RDS for PostgreSQL instance in
aws-acc-1
with the primary user account. - Create the DB user
joedoe@ONPREM.LOCAL
and grant therds_ad
role to this user.
The username in PostgreSQL is case-sensitive. Kerberos authentication requires that the domain suffix of the username be in uppercase; the case of user account name joedoe
needs to match the case of User logon name (pre-Windows 2000) in the AD, as shown in the following screenshot.
- Log in to the newly created RDS for PostgreSQL instance in
aws-acc-2
with the primary user account. - Create the DB user
joedoe@ONPREM.LOCAL
and grant therds_ad
role to this user.
Logging in to RDS for PostgreSQL instances on a Windows platform
To use external Kerberos and Microsoft AD to log in to the RDS for PostgreSQL instances on a Windows platform, we need to use a special endpoint. Instead of using the Amazon domain rds.amazonaws.com
in the endpoint, use the domain name of the AWS Managed Microsoft AD.
For example, to connect to the RDS for PostgreSQL instance rpg-acc-1-kerberos-12-2
created in aws-acc-1
, instead of using rpg-acc-1-kerberos-12-2.cz54v71h2eg5.ap-southeast-2.rds.amazonaws.com
as the endpoint, we use the special endpoint rpg-acc-1-kerberos-12-2.cz54v71h2eg5.ap-southeast-2.ad.myaws.com
, where ad.myaws.com
is the domain name of the AWS Managed Microsoft AD.
For more information, see Connecting to PostgreSQL with Kerberos Authentication.
- Log in as AD user
joedoe@onprem
to the Windows client that is joined to the on-premises domainonprem.local
. - Log in to the RDS for PostgreSQL instance created in
aws-acc-1
with the special instance endpoint as DB userjoedoe@ONPREM.LOCAL
(no password is required for psql).
- Log in to the RDS for PostgreSQL instance created in
aws-acc-2
.
This instance joined the AWS Managed Microsoft AD that is shared by aws-acc-1
. The connections to the special endpoints can be established successfully without a password.
We can also connect to the RDS for PostgreSQL instance with the special endpoint without a password from the pgAdmin application. See the following screenshots.
The following screenshot shows that external Kerberos authentication works for the special instance endpoint in pgAdmin for Amazon RDS for PostgreSQL created in aws-acc-1
and aws-acc-2
.
Logging in to RDS for PostgreSQL instances on a Linux platform
To use external Kerberos and Microsoft AD to log in to the RDS for PostgreSQL instances on a Linux platform, you don’t need to use the special endpoint. Both the original endpoint (ending with rds.amazonrds.com
) and special endpoint (ending with ad.myaws.com) work.
- Install the psql client on Linux, which you created and configured in the post Preparing on-premises and AWS environments for external Kerberos authentication for Amazon RDS.
- Log in to the Linux client as AD user
joedoe@onprem
. - Use the
kinit
command to get a Kerberos ticket fromonprem.local
. - Log in to the RDS for PostgreSQL instance in
aws-acc-1
; with both the original and special endpoint, no password is required.
- Log in to the RDS for PostgreSQL instance in
aws-acc-2
; with both the original and special endpoint, no password is required.
Summary
In this post, we demonstrated DB user authentication for Amazon RDS for PostgreSQL using external Kerberos and Microsoft AD, based on a one-way forest trust between an on-premises AD domain and an AWS Managed Microsoft AD domain. For instructions on creating this trust environment, see Preparing on-premises and AWS environments for external Kerberos authentication for Amazon RDS.
About the Author
Zhen Wang is an RDS Cloud Support Engineer at Amazon Web Services.’.