AWS Database Blog
Setting up passwordless login from Amazon EC2 Windows and Linux instances to Amazon RDS Oracle database instances
In today’s world, every organization uses a centralized location to store and manage user credentials. The most commonly used service for this is Microsoft Active Directory (AD). Organizations use LDAP protocol to authenticate users to their peripheral devices, but fewer companies use this centralized credential store to allow users to log in to their databases. If you don’t use a centralized Active Directory for database authentication, the database administrator has to maintain separate key chain for every database a user needs access to. And implementing security measures such as changing passwords periodically becomes a nightmare.
Kerberos is a network authentication protocol that functions by implementing secret key cryptography. This system is used to verify the identity of a user or a host. System administrators can use AWS Directory Service for Microsoft Active Directory to manage the Active Directory. You can use the same AD credentials to log in to an Amazon Elastic Compute Cloud (Amazon EC2) instance and further authenticate into an Amazon Relational Database Service (Amazon RDS) Oracle database instance. This is all done by using tokens. With Kerberos, after the first authentication, the client holds a ticket so that additional authentication attempts don’t overload the AWS Managed Microsoft AD authentication server. In addition, Kerberos facilitates a strong and secure authentication without transmitting passwords. As an additional benefit, you get access to a centralized place to store and manage credentials for multiple database instances.
The purpose of this post is to assist you in setting up Kerberos authentication for Amazon RDS using Oracle database instances from scratch. It delineates specific steps for creating an AWS Managed Microsoft AD, AD users, setting up an Amazon EC2 Linux or Windows instance to connect to an AWS Managed Microsoft AD, and using Kerberos authentication to log in to a database instance from an EC2 instance.
The steps in this walkthrough are structured to complete the setup with minimum configuration changes. For this post, you use Windows Server 2019 AMI for Amazon EC2 Windows, an Amazon Linux 2 AMI for Amazon EC2 Linux, and Oracle Enterprise Edition 12.2.0.1 for Amazon RDS Oracle instance.
Solution overview
After the solution is implemented, users can use the same AD credentials to log in to an EC2 instance and log in to the database with the same credentials. A database administrator still has to create a user account at the database level with the same name as in Active Directory. You also still manage the required grants and privileges of the user at the database level as you would for any other database level user. The only difference is that you don’t manage the user credentials. This provides two-layer security protection. When the user no longer needs database access, you can simply revoke access at the database level. If the user is no longer needed and is removed from Active Directory, the database access is removed automatically.
The following diagram illustrates the solution architecture.
The workflow includes the following steps:
- The user logs in to an EC2 instance using the AD credentials.
- Upon being authenticated by the AWS Managed Microsoft AD, the user gets a ticket granting ticket from the KDC (Key Distribution Center).
- Upon initiating a SQL*Plus or SQL Developer connection, it requests KDC to provide a service ticket.
- The KDC provides a service ticket.
- The SQL client presents this service ticket to the Amazon RDS Oracle database.
- The database instance checks the validity of the ticket against the KCD.
- The user is granted access to the database.
This Oracle feature has been tested with Oracle Client (SQL*Plus) and Oracle SQL Developer with a JDBC thin client. For other clients, refer to vendor support or the documentation for Kerberos support.
Walkthrough overview
The following are the high-level steps to configure an Amazon EC2 Linux or Windows machine that connects to an AWS Managed Microsoft AD and uses Kerberos authentication to log in to an Amazon RDS Oracle database instance:
- Create an AWS Managed Microsoft AD.
- Launch an Amazon EC2 Windows machine (for Active Directory Administration) and install the Active Directory Administration Tools.
- Create AD users with the Active Directory Users and Computers tool.
- Launch an Amazon EC2 Linux or Windows instance (which connects to the database) and make it part of the AD domain.
- Install Oracle Client on Amazon EC2.
- Modify or create an Amazon RDS Oracle DB instance to use Kerberos authentication.
- Configure the EC2 instance to enable Kerberos authentication.
- Connect to the database using Kerberos authentication (SQL*Plus or SQL Developer).
After you complete these steps, you can log in to an Amazon RDS Oracle database instances using passwordless login.
These steps include setting up an AWS Managed Microsoft AD and launching an EC2 instance as part of the AD domain. If your environment already has an EC2 instance set up that is part of the AD domain, you can jump to Step 5: Installing Oracle Client. These steps work using an AWS Managed Microsoft AD.
To set up Kerberos authentication using an on-premises or self-hosted Microsoft AD, create a forest trust or external trust. The trust can be one-way or two-way. For more information about setting up forest trusts using AWS Directory Service, see When to Create a Trust Relationship.
Step 1: Creating an AWS Managed Microsoft AD
To create a new directory, perform the following steps. Before starting this procedure, make sure that you have completed the prerequisites identified in AWS Managed Microsoft AD Prerequisites.
- On the AWS Directory Service console, choose Directories.
- Choose Set up directory.
- On the Select directory type page, choose AWS Managed Microsoft AD.
- Choose Next.
- For Edition, choose Standard Edition.
AWS Managed Microsoft AD (Standard Edition) is optimized to be a primary directory for small and midsize businesses with up to 5,000 employees. It provides you enough storage capacity to support up to 30,000 directory objects, such as users, groups, and computers. Upper limits are approximations. Your directory may support more or less directory objects depending on your objects’ size and your applications’ behavior and performance needs. For more information about editions, see AWS Directory Service for Microsoft Active Directory. - Enter a DNS name.
This is the fully qualified name for the directory. For this post, we entertest.com
. - Enter a directory NetBIOS name (for this post, we enter
TEST
). - Enter a directory description.
- Enter the admin user password.
You use this credential to log in to Amazon EC2 Windows instance to manage other domain users and manage the AD. - Choose a VPC where all the other resources are also available.
- Choose Next.
- Confirm the information and choose Create directory.
After direction creation is complete, the directory details page displays the two assigned DNS IP addresses. Both the directory DNS name and Kerberos DNS name (KDC) istest.com
. The directory NetBIOS isTEST
. It additionally creates a new security group that you can add to the Amazon RDS and EC2 instances. At the minimum, DNS port 53 and Kerberos ports (88 and 464) over TCP/UDP must be kept open.
For more information, see Create Your AWS Managed Microsoft AD directory.
Step 2: Launching an Amazon EC2 Windows instance and installing the Active Directory Administration Tools
To manage the Active Directory from an EC2 Windows instance, complete the following steps.
- Add the Amazon EC2 Windows instance to Active Directory. For instructions, see Seamlessly Join an Amazon EC2 Windows instance.
- Install Active Directory Administration Tools and a telnet client for checking the connectivity to RDS instance. For instructions, see Installing the Active Directory Administration Tools.
Step 3: Creating AD users with the Active Directory Users and Computers tool
Complete the following steps to create additional users as necessary. By default, all users get access to log in to any Amazon EC2 Linux instance. To get RDP access to connect to the Amazon EC2 Windows instance, the users need to be added to the appropriate AWS delegated groups in the AD.
- Log in to the Amazon EC2 Windows instance using the Admin See the following code:
- Create your AD users. For instructions, see Create a User.
For this post, we create the user nametroy@test.com
.
You can leave Make sure the User must change password at next logon unselected. You can also just use the Admin user to complete the setup and test the Kerberos authentication.
Step 4: Launching an Amazon EC2 Windows or Linux instance and configuring it to join AWS Managed Microsoft AD
The following steps add an EC2 instance to be part of the AWS Managed Microsoft AD. This post shows how to use an Amazon Linux 2 AMI and Windows Server 2019. After you add the instance, log in using an AD user and verify the connectivity between Amazon EC2 and Amazon RDS instance with a utility like telnet.
Linux
To use Linux, complete the following steps:
- Configure the Amazon EC2 Linux instance to use the DNS server IP addresses of the AWS Managed Microsoft AD. For instructions, see options 1 and 2 in My private Amazon EC2 instance is running Amazon Linux, Ubuntu, or RHEL. How do I assign a static DNS server to the EC2 instance that persists during reboot?
The DNS configuration may get removed after stopping, starting, and rebooting the instance. You should confirm these settings after the restart of the instance. - Join the Amazon EC2 Linux instance. For instructions, see Manually Join a Linux instance.
To join the instance to the directory, you can use theAdmin@test.com
account.
If you see a timeout error while running therealm
command, recheck the DNS configuration and confirm that they are in place correctly.
Adhere to the following capitalization while running therealm
command: Admin@TEST.COM. - Test the connection using the following code:
Windows
For instructions on joining an Amazon EC2 Windows instance to an AWS Managed Microsoft AD, see Seamlessly Join an Amazon EC2 Windows instance.
Step 5: Installing Oracle Client
In this step, you install the appropriate Oracle client software on the Amazon EC2 Linux or Windows instance, which is a part of AWS Managed Microsoft AD. For this post, we tested the solution on an Oracle 12.2.0.1 client version.
On Windows, it also works with SQL Developer (without the need to install Oracle client with it).
Step 6: Configuring Kerberos on the Amazon RDS Oracle instance
In this step, you modify the Amazon RDS Oracle instance from the console to enable Kerberos authentication.
- In the Database authentication section, choose Password and Kerberos authentication.
- Choose Browse Directory.
- Select the directory (
test.com
).
For more information on enabling Kerberos, see Create or Modify an Oracle DB Instance. - Connect to the Amazon RDS Oracle instance using SQL*Plus.
- Create one DB user for every AD user who wants to log in to the database (use all caps for the username). See the following code:
Alternatively, enter the following code:
Step 7: Configuring Kerberos on the EC2 instance to work with Oracle client
The following steps set up the Kerberos configuration files and configure sqlnet.ora
to enable Kerberos authentication service. This post presents the steps for both Linux and Windows.
Linux
To use Linux, complete the following steps.
- Modify the Kerberos configuration file.
The default contents of the/etc/krb5.conf
file may differ from different OS versions. This post uses Amazon Linux 2 AMI. This file exists; just edit the file and add or modify the following code:For example, see the modified code:
Oracle doesn’t understand the
KEYRING
cache format. Therefore, we changed it toFILE
format. - Reboot the EC2 instance or restart the Kerberos service for the configuration changes to take effect.
- Edit
sqlnet.ora
to add the following parameters (for this post, we used an Oracle 12.2.0.1 client):
Windows
To use Windows, first download and install MIT Kerberos for Windows 4.1. For more information about Kerberos and downloading links for the installer, see Kerberos: The Network Authentication Protocol.
- Download and install the appropriate Kerberos installer.
For instructions, see MIT Kerberos Distribution Page.
Use the latest version available. The current release is MIT Kerberos for Windows 4.1. For a 64-bit machine, use MSI Installer kfw-4.1-amd64.msi. For a 32-bit machine, use MSI Installer kfw-4.1-i386.msi.
The 64-bit installer includes both 32-bit and 64-bit libraries. The 32-bit installer includes 32-bit libraries only. - To run the installer, double-click the .msi file that you downloaded and follow the instructions.
- As an optional step, you can customize the default settings by editing the Kerberos configuration file located under
C:\ProgramData\MIT\Kerberos5\krb5.ini
(normally this is a hidden directory). You can also provide a custom location of configuration file and cache file by setting system environment variables:
– Choose PC Properties
– Choose Advanced System Settings
– On the Advanced tab, choose Environment Variables
UpdateKRB5_CONFIG
andKRB5CCNAME
. For example, see the following code:krb5cache
is a file (not a directory) managed by the Kerberos software, and it should not be created by the user. If you receive a permission error when you first use Kerberos, make sure that thekrb5cache
file doesn’t already exist as a file or a directory.
The following example code is of thekrb5.ini
file contents:It’s preferable to set the cache location via configuration file using the %{uid} file name format. This ensures that the file names are unique for every user. Don’t set the KRB5CCNAME system variable when the default cache name is defined in the configuration file. Additionally, you can’t use %{uid} as a file name format when passed as a system variable.
- Reboot the EC2 instance or restart the Kerberos service for the configuration changes to take effect.
If Oracle Client is installed
If Oracle Client is installed, edit sqlnet.ora
to add the following parameters:
If SQL Developer is installed
If you’re using SQL Developer, no additional configuration changes are required (you can also skip the step to install MIT Kerberos software).
In the connection string properties, for Authentication Type, choose Kerberos and enter the credentials.
Step 8: Connecting to the database
To connect to the database, complete the following steps:
- Log in to EC2 instance using the AD user credentials.
For Linux, enter the following code:For Windows, enter the following code:
- Set the environment variables.
For Linux, enter the following code:For Windows, no additional environment variables are required.
- Employ the existing Kerberos token used while logging into the EC2 instance to log in to the Oracle database.
If no token is listed upon enteringoklist
, generate a new token by enteringokinit
(refer to the following section on troubleshooting for more details). By default, a token is valid for 10 hours, after which you have to regenerate it.
For Linux, enter the following code:For Windows, enter the following code:
Troubleshooting login issues
The following troubleshooting steps are the same for both Linux and Windows (in Windows, Oracle Client must be installed).
- Log in to the EC2 instance using the AD credentials.
You can create a new token or destroy and recreate a Kerberos token and reattempt connecting to the database. - Verify if Oracle can read the existing Kerberos token. See the following code:
- Generate a new Kerberos token and attempt to log in. See the following code:
- If you want to destroy all the existing Kerberos tokens, enter the following code:
Summary
This post described how to set up Kerberos authentication for Amazon RDS Oracle database instances. For more information, see Using Kerberos authentication with Amazon RDS for Oracle and Configuring Kerberos Authentication.
If you have any questions, concerns, or comments, please leave your thoughts in the comments section.
About the Author
Tirthadeep Roy is a Cloud Support Engineer with Amazon Web Services.