Introduction
This document outlines the methods that can be used for each of the major browsers to capture the response (assertion) that an identity provider (IdP) sends when attempting to log in to Terraform Cloud or Terraform Enterprise using SAML. The values contained within SAML assertions (attributes) are used by Terraform Cloud or Terraform Enterprise to map a login attempt to a particular user and assign attributes such as team, organization, and site admin membership.
Use Case
When troubleshooting SAML sign on for Terraform Cloud and Terraform Enterprise, it is often necessary to capture a SAML assertion in order to determine what attributes the IdP is providing. This data is crucial in helping to troubleshoot common SAML login problems.
Capturing an Assertion
Depending on the browser, there are different methods for capturing a SAML assertion. Below are the necessary steps to capture an assertion on three of the major internet browsers. Decoding the response retrieved will be covered later in this document.
Chrome (as of 89.0.4389.90)
- Navigate to the Terraform Cloud or Terraform Enterprise login page.
- Click “Sign in with SSO”.
- (Terraform Cloud) Enter the name of an organization that has SAML enabled.
- Click the stacked dots menu to the right side of the search bar and choose More Tools > Developer Tools.
- Click on the Network tab and enable Preserve Log.
- Complete the SAML sign in flow.
- Locate and click on the document named “acs” (when using Terraform Cloud) or “auth” (when using Terraform Enterprise).
- Scroll to the bottom and review the Form Data. The base64 encoded SAML assertion will be listed here as the
SAMLResponse
. - Save the response string so that it may be decoded in the later steps of this article.
Firefox (as of 87.0)
- Navigate to the Terraform Cloud or Terraform Enterprise login page.
- Click “Sign in with SSO”.
- (Terraform Cloud) Enter the name of an organization that has SAML enabled.
- Open the “Network” Web Developer pane by navigating clicking Tools > Web Developer > Web Developer Tools and selecting “Network”.
- Click the gear in the upper right corner of the Web Developer tools pane and enable Persist Logs.
- Click “Next” on the sign in page.
- Complete the SAML sign in flow.
- In the Web Develop pane, look for a POST to
[app.terraform.io](http://app.terraform.io)
(Terraform Cloud) for a file namedacs
. On Terraform Enterprise, this POST will be to the Terraform Enterprise hostname and the file will be calledauth
. Click on this request to open it for viewing. - In the “Request” tab of the request inspector, locate the “Form data” section, which contains a
SAMLResponse
parameter. This value is the base64 encoded SAML assertion. - Save the response string so that it may be decoded in the later steps of this article.
Safari (as of 14.0.3)
In order to capture an assertion in Safari, the Develop menu must first be enabled. The following steps will outline enabling this menu.
- Open Safari preferences.
- Navigate to the “Advanced” tab.
- Enable the “Show Develop menu in menu bar” option.
Once the Develop menu has been enabled, a SAML assertion may be captured using the following steps.
- Navigate to the Terraform Cloud or Terraform Enterprise login page.
- (Terraform Cloud) Click “Sign in with SSO”.
- (Terraform Cloud) Enter the name of an organization that has SAML enabled.
- From within Safari’s Develop menu, click to open web inspector, then select the “Network” tab.
- In the upper right corner of the web inspector, click the check box to enable the “Preserve Log” option.
- Log in to Terraform Cloud or Terraform Enterprise using SAML.
- Within the web inspector, locate and click on the document titled with the name of the Terraform Cloud organization that you are logging into. In Terraform Enterprise, the title of the document is “app”.
- Click on the “Headers” section to the right of the file explorer and scroll to the bottom of the field to locate the “Request Data” section and click on the arrow to the right of the “Request Data” field within it.
- Copy all of the text between
SAMLResponse=
and&RelayState=
; this is the base64 and URI encoded SAML assertion. - Save the response string so that it may be decoded in the later steps of this article.
Decoding an Assertion
Once the base64 encoded assertion has been retrieved from the browser, it needs to be decoded to it’s human-readable XML format.
macOS / Linux
To decode an assertion on a machine running macOS or Linux, save the base64 encoded assertion to a file, then open a terminal and run the following command.
$ echo $ENCODED_RESPONSE | base64 --decode
For the assertion retrieved from Safari, an extra step has to be taken as it is URI encoded as well as base64 encoded. To cope with this, edit the string in your text editor of choice to replace all occurrances of %2B
with +
before decoding as described above. Alternatively, an example using sed
is provided below.
$ echo $ENCODED_RESPONSE | sed 's/%2B/\+/g' | base64 --decode
Windows
To decode an assertion on a Windows machine, save the base64 encoded assertion to a file, then open the command prompt and run the following command.
certutil -decode C:\path\to\encoded_saml_response.txt C:\path\to\decoded_saml_response.txt
Additional Information
There are third party tools, such as the SAML Tracer add-on for Firefox or Chrome that make capturing and decoding SAML assertions easier. These tools may be useful if capturing SAML assertions is a task performed on a regular basis, or if any issues are encountered with the steps in this article.