Amazon Web Services Feed
Federate access to your Amazon Redshift cluster with Active Directory Federation Services (AD FS): Part 1
Many customers request detailed steps to set up federated single sign-on (SSO) using Microsoft Active Directory Federation Services (AD FS) for Amazon Redshift. In this two-part series, you will find detailed steps to achieve federated SSO using AD FS.
Part 1 contains steps to set up a Windows 2016 domain controller and AD FS and test SSO to the AWS Management Console using a web browser.
Part 2 provides detailed steps to use the AD FS server you set up in Part1 to authenticate from SQL Workbench/J using a JDBC connection.
Amazon Redshift supports user sign-on using federated SSO through identity providers compliant with SAML 2.0 (Security Assertion Markup Language) like AD FS, Ping Federate, and Okta. You can manage users and roles centrally for all your applications using an enterprise identity provider (IdP) and set up Amazon Redshift to use IdP authentication and assume roles at the time of login.
For more information about designing and enabling federation with Amazon Redshift at a high level, see Federate Database User Authentication Easily with IAM and Amazon Redshift. This series takes that approach further and dives deep into the details of setup and testing.
Overview of solution
This post contains detailed steps to set up a Windows 2016 domain controller using an Amazon Elastic Compute Cloud (Amazon EC2) instance, Active Directory Federation Service (AD FS) as IdP, and federated database user authentication with AWS Identity and Access Management (IAM) and Amazon Redshift. You create users and groups within your organization’s Active Directory and establish federated authentication using AD FS to the console using a web browser.
The following diagram illustrates the solution’s architecture.
The workflow includes the following steps:
- A user browses to the IdP.
- The IdP authenticates the user and returns a SAML assertion.
- The client browser posts the SAML assertion to an AWS SAML endpoint.
- The endpoint validates the assertion and sends back a redirect.
- The client browser is sent to the console to sign in.
Walkthrough
In this post, you go through the following steps:
- Set up an Active Directory (AD) domain controller using an AWS CloudFormation template on a Windows 2016 EC2 instance.
- Configure federation in AD FS.
- Configure AWS as the relying party with AD FS using an IAM SAML provider and SAML roles with an attached policy to allow access to the Amazon Redshift cluster.
- Configure claim rules.
- Test the SAML authentication using a web browser.
Prerequisites
For this walkthrough, you should have the following prerequisites:
- An AWS account.
- AWS permissions to provision Amazon EC2 instances and default VPC, deploy AWS CloudFormation templates, and create an IAM role and policy.
- For the purposes of this post, this could be a dev or test environment. Check with your administrator to ensure that you have access to these prerequisites.
- The ability to access remotely using Remote Desktop Protocol (RDP) for the Windows 2016 EC2 instance.
- Some familiarity with working on an Microsoft Windows environment, such as running MS PowerShell to follow along with this post.
Setting up the domain controller and AD FS
To set up your domain controller and AD FS, complete the following steps:
- Launch the following CloudFormation template:This template provisions the EC2 instance and sets up a domain controller.
- Enter a name for the stack, such as ADFS2016Redshift.
- Provide the following parameters:
- Amild – Keep as default
- DomainDNSName – adfsredshift.com
- DomainNetBIOSName – adfsredshift
- InstanceType – Keep as default (m5.large)
- KeyName: The .pem key pair in the Region for your IAM user.For instructions on creating a key pair, see Creating or importing a key pair.
- RestoreModePassword – Enter a strong and memorable password of your choice
- SourceCidrForRDP – Open (you restrict it through your security group later)
For production systems, it’s highly advised to change SourceCidrForRDP and restrict to only the IP range you want to allow access from. The format for the IP entry is similar to xxx.xxx.xxx.xxx/32 for a single IPv4 address.
- Choose Next.
- Select the check-box acknowledging that the template might cause AWS CloudFormation to create IAM resources on your behalf.
- Choose Next.
- Choose Create stack.
On the dashboard, you should see the status IN PROGRESS. You can see the template’s progress on the Events tab. When the deployment is successful, the status changes to CREATE_COMPLETE.
- On the Amazon EC2 console, choose the Windows 2016 EC2 instance created by Cloudformation template.
- In the description below, click on the security group, which will open it up.
- From the Actions drop-down menu, choose Edit inbound rules.
- Edit the inbound rules to restrict the IP range for RDP access and add a rule for HTTPS using your own IP range.
To find your IP in the rule, for Source, choose MyIP from the drop-down menu.
- Choose Save.
- After updating security group, go back to the Windows 2016 EC2 instance, from the Actions drop-down menu, choose Get Windows Password using the key pair you used when you launched the instance.
For more information, see Connect to your Windows Instance. You use the generated password for the RDP session to the domain controller instance later.
- Use an RDP client from your desktop to connect the EC2 instance using the administrator user and password from previous step.
- Create test users and groups in AD using the Windows command prompt by entering the following code (this walkthrough creates the user Bob, which you use again in Part 2):
You can also use the Active Directory Users and Computers graphical user interface to create these users and groups.
After you run the preceding commands successfully, you can see the users and groups as in the following screenshot.
- On the same Windows 2016 EC2 instance, install the AD FS 2016 role using PowerShell:
PS C:UsersAdministrator> Install-windowsfeature adfs-federation –IncludeManagementTools
For more information, see Install the AD FS Role Service.
Federation servers use a server authentication certificate, such as the Secure Sockets Layer (SSL) certificate in Internet Information Services (IIS). For more information, see Certificate Requirements for Federation Servers.
For testing purposes, you use a self-signed certificate, but as a recommended best practice, self-signed SSL certificates aren’t recommended for production environments.
- To create the self-signed certificate, use PowerShell to install and configure the IIS:
PS C:UsersAdministrator> Install-WindowsFeature -name Web-Server -IncludeManagementTools
After IIS installation is successful, you use it to create a self-signed certificate.
- In the Amazon EC2 Windows server, under Administrative Tools, open IIS.
- Choose the IIS server.
- Choose Server Certificates.
- Under Actions, choose Create Self-Signed Certificate.
- Enter a name, such as AD FSCertificate.
- Choose Ok.
You’ve now created a certificate that’s ready to use.
Configuring federation in AD FS
To configure federation, complete the following steps:
- On the Windows 2016 EC2 instance, open Server Manager.
- Choose the flag icon.
- Choose Configure the federation server on this server.
You can ignore the warning message to promote this server to domain controller. This doesn’t interfere with the setup because as the AD FS is working at this point and the server is already a domain controller.
- Select Create the first federation server in a federation server farm.
- Choose Next
- On the SSL Certificate drop-down menu, choose the self-signed certificate you created during IIS setup.
The Federation Service Name gets auto-populated.
- For Federation Service Display Name, enter ADFSRedshiftDemo.
- Choose Next.
- Confirm the names to ensure that it’s valid.
- Choose Ok.
- Enter the password for the service account – ADFSSVC that you created earlier, in previous section’s step 15.
- Choose Next.
- Choose Next two more times.
- Review and run the prerequisite checks and choose Configure.
You can see the installation progress and AD FS installation starts.
You may receive a warning message, but you can ignore it for this walkthrough. You also need to restart the Windows 2016 EC2 instance.
- After you RDP back into the Windows 2016 EC2 instance, download the federation metadata from AD FS.
- To capture the hostname, under Windows, Administrative Tools, choose AD FS Manager.
- Choose Edit Federation Service Properties.
- Copy the federation service name, for example <<YourInstanceHostname.adfsredshift.com>>.
- Install Google Chrome on the EC2 instance via RDP by entering the following code in the Windows PowerShell command prompt:
Internet Explorer on the EC2 instance generated by the CloudFormation template is, by default, in Enhanced Security configuration, so may not be available to use.
You may choose to install any other browser or disable Enhanced Security for Internet Explorer.
-
- From Google Chrome, enter the following URL with the hostname from the previous step:
https://<<YourInstanceHostname.adfsredshift.com>>/FederationMetadata/2007-06/FederationMetadata.xml
If you receive an error message, choose the advance icon and then choose Proceed to… to download the file.
-
- Copy the FederationMetadata.xml file from the RDP download location and save it to your local desktop to use later.
Configuring AWS as the relying party with AD FS
To configure AWS as the relying party, you first need to create the SAML provider and federation role, and create and attach IAM policies.
Creating the SAML provider
To create the SAML provider, complete the following steps:
- On the IAM console, choose Identity Provider.
- Choose Create provider.
- For Provider type, choose SAML.
- For Provider name, enter
ADFZ
. - For Choose File, choose the FederationMetadata.xml you downloaded earlier.
- Choose Create.
You should see the provider as in the following screenshot.
You should continue to use the name ADFZ
for the SAML IdP because this name carries over in other parts of the post and is referred to in the claim rules.
Creating a SAML federation role
You can now create a SAML federation role.
- On the IAM console, choose Roles
- Choose Create role.
- Choose SAML 2.0 Federation.
- For SAML provider, enter
ADFZ
. - For Attribute, choose SAML:aud.
- For Value, enter
https://signin.aws.amazon.com/saml
.
- Choose Next.
- Choose any permissions you need for the role (for this walkthrough, choose AmazonRedshiftFullAccess).
In a production environment, it’s advised to use a role with restricted access as required.
- Choose Next twice.
- For Role name, choose ADFZ-Dev.
- Repeat the previous steps to create another role called
ADFZ-Production
.
Creating an IAM policy
For the ADFZ-Production role, you now create an IAM policy.
- On the IAM console, choose Policies.
- Choose Create policy.
- On the JSON tab, enter the following policy:
- The
GetClusterCredentials
Redshift API with AWS credentials to get the temporary database credentials. This API creates the user and adds it to a specified DB group, so you also need to provideredshift:CreateClusterUser
andredshift:JoinGroup
permissions to the IAM role. See the following code:
- The
- Choose Review policy.
Ideally, development and production IAM roles are in two different accounts. The Resource section here is set to be open with *, but in a production environment, you should specify the exact resource you want to control with the policy.
- Enter a policy name, for example
redshift-marketing
. - Choose Create policy.
- Return to the
ADFZ-Production
role. - Choose Attach policies.
- Choose the policy you created.
Configuring AWS as the relying party
To complete configuring AWS as the relying party, go back to RDP on Windows 2016 EC2 instance.
- In the AD FS management application, choose Add Relying Party Trust.
- Choose Claims aware.
- Choose Start.
- On the next page, for Data Source, enter the standard URL as
https://signin.aws.amazon.com/static/saml-metadata.xml
for importing data about the relying party published online or on a local network option. - Choose Next.
- Enter a display name, for example,
Amazon Web Services
. - Choose Next.
- For Access Control Policy, choose Permit everyone.
- Choose Next with default choices until you see the Finish page.
- Choose Close.
Configuring claim rules
AD FS uses a claims-based identity model and issues a token that contains a set of claims as part of its function as federation services. Claim rules govern the decision with regards to claims that AD FS issues. Claim rules and all server configuration data are stored in the AD FS configuration database. AD FS makes issuance decisions that are based on claims and other contextual information by taking one set of claims as input, performing transformations, and returning a different set of claims as output.
For this walkthrough, you set up two standard claim rules and three custom claim rules.
Configuring standard claim rules
After you choose Close in the previous step, you are redirected to a window to define the claim rules. If this doesn’t happen, you can return to the AD FS management console on the Windows 2016 EC2 instance, choose Relying Party Trusts, and choose Edit Claim Issuance Policy. To add a rule for NameID
, complete the following steps:
- Choose Choose Rule Type.
- For the claim rule template, choose Transform an Incoming Claim.
- Choose Next.
- For Claim rule name, enter
NameId
. - For Incoming claim type, choose Windows account name.
- For Outgoing claim type, enter
Name ID
. - For Outgoing Name ID format, choose Persistent identifier.
- Select Pass through all claim values.
- Choose Finish.
You now add another rule for RoleSessionName
.
- Choose Choose Rule Type.
- For Claim rule template, choose Send LDAP Attributes as Claims.
- For Claim rule name, enter
RoleSessionName
. - For Attribute store, choose Active Directory.
- For LDAP Attribute, choose E-Mail Addresses.
- For Outgoing Claim Type, enter
https://aws.amazon.com/SAML/Attributes/RoleSessionName
. - Choose Finish.
Configuring custom claim rules
By using a custom claim rule, you can create rules with more complex logic than a standard rule template. You use custom rules to send claims based on values that are extracted from a custom attribute store for AD groups, DB groups, and roles.
To add a custom rule for your AD group, complete the following steps:
- Choose Choose Rule Type.
- For Claim rule template, choose Send Claims Using a Custom Rule.
- Choose Next.
- For Claims rule name, enter
Get AD Groups
. - Add the following custom rule:
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"] => add(store = "Active Directory", types = ("http://temp/variable"), query = ";tokenGroups;{0}", param = c.Value);
- Choose Finish.
To add a custom rule for roles, you replace the string with your account ID using the temporary variable you created earlier. This step takes all the groups from the temporary variable from previous step and replaces AWS-
with an Amazon Resource Name (ARN) with your account ID and the prefix for the roles created in AWS. The list is then sent as the path in the following code.
- Follow the previous steps to create the rule
Roles
. - Enter the following custom rule, replacing your own account ID and role prefix:
c:[Type == "http://temp/variable", Value =~ "(?i)^AWS-"] => issue(Type = "https://aws.amazon.com/SAML/Attributes/Role", Value = RegExReplace(c.Value, "AWS-", "arn:aws:iam::<AWSAccountID>:saml-provider/ADFZ,arn:aws:iam::<AWSAccountID>:role/ADFZ-"));
You now add a third custom rule for the database group DBGroups
mapping of an AD group RSDB-marketing
to a database group marketing
, which you create later in Amazon Redshift in Part2.
- Follow the previous steps to create the rule
DBGroups
. - Enter the following custom rule:
c:[Type == "http://temp/variable", Value =~ "(?i)^RSDB-"]=> issue(Type = "https://redshift.amazon.com/SAML/Attributes/DbGroups", Value = RegExReplace(c.Value, "RSDB-", ""));
- Choose Finish.
In this claim rule, you take an AD group starting with the name RSDB-
and remove the prefix. The remaining string (marketing
), matches the database group name. This allows the user after SAML authentication to join the database group with same name, which is only valid during the session window. This allows the user to access the resources allowed by the database group marketing
, which is defined at the database level.
- Confirm the five rules are correct and choose Ok.
Testing SAML federation using a web browser
Before starting your test, run the following code using PowerShell:
Set-AdfsProperties -EnableIdpInitiatedSignonPage $true
EnableIdpInitiatedSignonPage= False is set by default, and it has to be turned on for the test. You can validate EnableIdpInitiatedSignonPage is set to True by entering the following code:
Get-AdfsProperties
For more information, see AD FS Troubleshooting – Idp-Initiated Sign On.
To test your federation, complete the following steps:
- Open Google Chrome on Windows Server 2016 through RDP.
- Enter the following link:
https://<<YourInstanceHostname.adfsredshift.com>>/adfs/ls/IdpInitiatedSignOn.aspx
. - Sign in as
bob@adfsredshift.com
and use the password set for the AD userBob
. - For Select a role, select ADFZ-Dev.
- Choose Sign in.
The Dev role has administrator access, so you can verify the authenticated user on the console.
Cleaning up
If you want to stop here (without continuing to Part 2) and avoid incurring future charges, delete the CloudFormation stack on the console. If you want to set up Amazon Redshift federation, wait to complete the cleanup steps in Part 2.
Conclusion
In this post, you learned to spin up a Windows 2016 Amazon EC2 instance to simulate an on-premises domain controller and AD FS setup process. The groups and users you created in Active Directory running on Windows 2016 were federated with SAML using AWS as the relying party. When you initiated the sign-in URL from your browser using the user ID you created in Active directory, the browser communicated with AD FS as IdP to authenticate the user ID. Then the web browser communicated to AWS Security Token Service (AWS STS), which returned temporary user credentials for console access. In the web browser, after you selected a federated role, the policy attached to the role allowed the user to assume the role and granted permissions on the console.
Special acknowledgment goes to AWS colleague Jose Eduardo Montilla Lugo for his valuable comments and suggestions.
About the Authors
Rajesh Francis is a Data Warehouse Specialist Solutions Architect at AWS. He specializes in Amazon Redshift and works with customers to build scalable Analytic solutions.
Vaibhav Agrawal is an Analytics Specialist Solutions Architect at AWS. Throughout his career, he has focused on helping customers design and build well-architected analytics and decision support platforms.