# AD FS SSO

This guide provides step-by-step instructions on setting up SAML SSO using [Microsoft Active Directory Federation Services](https://docs.microsoft.com/en-us/windows-server/identity/active-directory-federation-services) (AD FS).

:::caution[SAML SSO restrictions]

SAML SSO is only available on select plans. Contact our support to find out if SAML SSO is available on your Workspace's plan.

Since the SAML SSO feature is tied to the above plans, if you decide to downgrade to a free plan, you will lose this feature. All Workspace members will receive an email about the downgrade, and you’ll have two weeks to re-upgrade if you wish to use SAML SSO in your Workspace again.

:::

Before connecting SAML SSO to your Workspace:

- Make sure the AD FS administrator is at hand during the SAML SSO configuration process.
- - Be aware that only the Workspace owner can set up SAML SSO to a Bitrise Workspace.
- Your account on Bitrise has a Workspace with one of our [paid plans](https://bitrise.io/pricing).

In this tutorial we will be jumping back and forth between Bitrise and AD FS so it is recommended that both tools are available during this process.

To configure SAML SSO with AD FS, you'll need to:

1. [Add the **Identity provider sign-on URL** from AD FS on Bitrise](#adding-the-identity-provider-sign-on-url).
1. [Export a certificate generated by AD FS and add it on Bitrise](#exporting-an-ad-fs-certificate).
1. [Add Bitrise as a relying party trust to AD FS](#adding-bitrise-as-a-relying-party-trust-to-ad-fs).
1. [Configure claim rules](#configuring-claim-rules).

## Adding the identity provider sign-on URL

1. 1. Log in to Bitrise and hover over the left navigation bar.
1. Make sure you have the right workspace selected in the **Workspace** menu.
1. Select **Settings**.
1. Go to the **Single Sign-on** tab.
1. Add the **Identity provider sign-on URL** from AD FS in the **SSO URL** field.

   For example, a valid value is `https://<AD FS URL>.com/adfs/ls`.

## Exporting an AD FS certificate

1. You have to add a certificate generated by AD FS to the **SAML SSO provider certificate** field of the **Single Sign-On** page on Bitrise. If you’ve already created a certificate on AD FS, you can export it in PEM format from the AD FS server. If you haven’t created one yet, follow the instructions: [Obtain and Configure TS and TD Certificates for AD FS](https://docs.microsoft.com/en-us/windows-server/identity/ad-fs/operations/configure-ts-td-certs-ad-fs#:\~:text=Open%20the%20AD%20FS%20Management,certificates%2C%20and%20then%20click%20OK.).
1. In **Server Manager**, click **Tools**, and select **AD FS Management**.
1. Select the **Certificates** folder on the left menu pane.
1. Click a certificate under **Token-signing**. This brings up the **Certificates** window.

   ![certtoken-1.jpg](/img/_paligo/uuid-cfe05e2a-2027-50fb-e4a8-56ef4164907f.jpg)
1. Click **Details** tab on the **Certificate** page.

   ![certificate-1.jpg](/img/_paligo/uuid-e960a587-dfa0-3b5d-aad8-6d03208a3ad6.jpg)
1. Hit **Next** on the **Certificate Export Wizard** window.

   ![certwizard.jpg](/img/_paligo/uuid-0ba8034b-4784-e042-02b9-32087bcde8d4.jpg)
1. Select the **Base-64 encoded X.509 (.CER)** the export file format. Click **Next**.

   ![baseencoded.jpg](/img/_paligo/uuid-9a300011-7818-826c-5874-c7ba6ade8176.jpg)
1. Give it a name in the **File name** field and hit **Save**.

   ![filenamesave.jpg](/img/_paligo/uuid-4510e204-8973-1a9a-0c2e-7ffc0c073aad.jpg)
1. Have a final look at your certificate settings. If you need to modify any of those, click the backward arrow next to **Certificate Export Wizard**. Otherwise, click **Finish**. Make sure you leave the AD FS window open as you will need it in a minute.

   ![completewizard.jpg](/img/_paligo/uuid-eaa066c4-99be-c8a5-9990-fe4a08a4154c.jpg)
1. Open the exported certificate by a text editor and copy/paste its content to the **SAML SSO provider certificate** field or upload the file itself from your local computer.
1. Save the settings by clicking **Configure SSO** on Bitrise.

   ![saml_sso_setup.png](/img/_paligo/uuid-26ad84be-65c7-1916-f079-6b553b4c436d.png)

   Let’s continue the SAML SSO configuration on AD FS by adding Bitrise.

## Adding Bitrise as a relying party trust to AD FS

Once you are finished with exporting the certificate, you can continue with adding Bitrise as a [relying party trust to AD FS](https://docs.microsoft.com/en-us/windows-server/identity/ad-fs/operations/create-a-relying-party-trust). The Add Relying Party Trust Wizard guides you through the steps.

1. On AD FS, click **Relying Party Trust** on the left menu bar, then click **Relying Party Trust**.
1. Select **Add Relying Party Trust** under **Actions**.

   ![addreplyingpartytrust.jpg](/img/_paligo/uuid-2e8a2cfc-6fe9-cf2b-9b4a-b4ec2f051568.jpg)
1. On the **Welcome** page, select the **Claims aware** option and hit **Start**.

   ![claimsaware.jpg](/img/_paligo/uuid-d5eac9a8-1c74-efd6-459a-aaa24af4877a.jpg)
1. On the **Select Data Source** page, click the **Enter data about the relying party manually** option on the bottom of the page. Click **Next**.

   ![selectdatasource.jpg](/img/_paligo/uuid-7e451b81-22e3-0f16-af91-380ad8026de1.jpg)
1. On the **Specify Display Name** page, add a **Display name,** for example `MyCorp`. Click **Next**.

   ![specifydisplayname.jpg](/img/_paligo/uuid-a8509ed5-9cc9-8851-c8df-9d298c5ae3bc.jpg)
1. Specify a token encryption certificate on the **Configure Certificate** page is optional. Click **Next**.

   ![optionalconfigure.jpg](/img/_paligo/uuid-1042aa27-f21e-16e5-4065-4088112ae116.jpg)
1. On the **Configure UR**L page, select **Enable support for the SAML 2.0 WebSSO protocol** and copy paste the **Assertion Consumer Service URL (ACS URL)** from Bitrise to the **Relying party SAML 2. 0 SSO service URL** field on AD FS. Click **Next**.

   ![configureurl-1.jpg](/img/_paligo/uuid-a40d7228-e976-458e-0508-99ded152069c.jpg)
1. On the **Configure Identifiers** page, add `Bitrise` in the **Relying party trust identifier** field. Click **Add**, then hit **Next**.

   ![replyingidentifiers2.jpg](/img/_paligo/uuid-c920feb2-3a96-88d7-710a-27d3d4fcba1c.jpg)
1. Do not modify the default access control policy on the **Choose Access Control Policy** page so that everyone can access this SAML SSO connection. Click **Next**.

   ![permiteveryone.jpg](/img/_paligo/uuid-d6600b5b-3ad8-aee2-a28b-62f4ca2b1394.jpg)
1. On the **Ready to Add Trust** page, review the settings and click **Next**.

   ![readytoaddtrust.jpg](/img/_paligo/uuid-4033d0af-df38-8e77-9963-4812d259f9ad.jpg)
1. On the **Finish** page, tick the checkbox to edit claims issuance policy for Bitrise. Click **Close**.

   ![finish.jpg](/img/_paligo/uuid-974f5427-db6a-201d-a112-9bb8fee4ae7f.jpg)

1. On AD FS, click **Relying Party Trust** on the left menu bar, then click **Relying Party Trust**.
1. Select **Add Relying Party Trust** under **Actions**.

   ![addreplyingpartytrust.jpg](/img/_paligo/uuid-2e8a2cfc-6fe9-cf2b-9b4a-b4ec2f051568.jpg)
1. On the **Welcome** page, select the **Claims aware** option and hit **Start**.

   ![claimsaware.jpg](/img/_paligo/uuid-d5eac9a8-1c74-efd6-459a-aaa24af4877a.jpg)
1. On the **Select Data Source** page, click the **Enter data about the relying party manually** option on the bottom of the page. Click **Next**.

   ![selectdatasource.jpg](/img/_paligo/uuid-7e451b81-22e3-0f16-af91-380ad8026de1.jpg)
1. On the **Specify Display Name** page, add a **Display name,** for example `MyCorp`. Click **Next**.

   ![specifydisplayname.jpg](/img/_paligo/uuid-a8509ed5-9cc9-8851-c8df-9d298c5ae3bc.jpg)
1. Specify a token encryption certificate on the **Configure Certificate** page is optional. Click **Next**.

   ![optionalconfigure.jpg](/img/_paligo/uuid-1042aa27-f21e-16e5-4065-4088112ae116.jpg)
1. On the **Configure UR**L page, select **Enable support for the SAML 2.0 WebSSO protocol** and copy paste the **Assertion Consumer Service URL (ACS URL)** from Bitrise to the **Relying party SAML 2. 0 SSO service URL** field on AD FS. Click **Next**.

   ![configureurl-1.jpg](/img/_paligo/uuid-a40d7228-e976-458e-0508-99ded152069c.jpg)
1. On the **Configure Identifiers** page, add `Bitrise` in the **Relying party trust identifier** field. Click **Add**, then hit **Next**.

   ![replyingidentifiers2.jpg](/img/_paligo/uuid-c920feb2-3a96-88d7-710a-27d3d4fcba1c.jpg)
1. Do not modify the default access control policy on the **Choose Access Control Policy** page so that everyone can access this SAML SSO connection. Click **Next**.

   ![permiteveryone.jpg](/img/_paligo/uuid-d6600b5b-3ad8-aee2-a28b-62f4ca2b1394.jpg)
1. On the **Ready to Add Trust** page, review the settings and click **Next**.

   ![readytoaddtrust.jpg](/img/_paligo/uuid-4033d0af-df38-8e77-9963-4812d259f9ad.jpg)
1. On the **Finish** page, tick the checkbox to edit claims issuance policy for Bitrise. Click **Close**.

   ![finish.jpg](/img/_paligo/uuid-974f5427-db6a-201d-a112-9bb8fee4ae7f.jpg)

## Configuring claim rules

1. On the **Edit Claim** **Issuance Policy** page, click the **Add Rule** button and hit **OK**.

   ![editclaims.jpg](/img/_paligo/uuid-0a57f576-6cbd-5055-e09e-078920e410ce.jpg)
1. Create a **Send LDAP Attributes as Claims** claim rule and click **Next**.
1. On the **Configure Claim Rule** page:

   - Add a rule name, for example Send E-mail, in the **Claim rule name** field.
   - Select an **Attribute Store** which is most likely the Active Directory.
   - In the **Mapping of LDAP attributes to outgoing claim types** field select E-mail Addresses.
1. Click **Finish**.

   ![configureclaimrule.jpg](/img/_paligo/uuid-73afe848-4767-6771-43fb-4675ecc1a189.jpg)
1. Add another new rule that turns an E-mail to a formatter NameID. To do so, click **Add rule** in the **Edit Claim** **Issuance Policy** page again.
1. On the **Select Rule Template**, select **Transform an Incoming Claim** option in the **Claim rule template** dropdown. Click **Next**.

   ![chooseruletype.jpg](/img/_paligo/uuid-0ef22e95-4303-25ce-b8e9-69884bbe7cf7.jpg)
1. Give a name to the new rule, for example, `Transform E-mail`.
1. Select **E-Mail Address** as the **Incoming Claim Type**.
1. Select **NameId** as the **Outgoing claim type.**
1. Choose **Email** as the **Outgoing name ID format**.
1. Hit **OK** to finish the process.

   ![newrule.jpg](/img/_paligo/uuid-ce7f8183-941b-0b73-92c2-185e235442ee.jpg)
