Using AAD together with Perforce
To use Azure Active Directory as an Identity Provider for Helix Core, Perforce has developed two pieces of software that need to be installed and configured:
- Helix Authentication Service (HAS)
- Helix Authentication Extension
The Service acts as a Token Service in the Authentication flow, the Extension configures Helix Core to make use of that Token Service for Authentication.
Prerequisites
To configure Helix Core to use Azure Active Directory (AAD) as its Identity Provider, a Helix Core commit server needs to be available. For this guide we have installed Helix Core through Perforce’s Enhanced Studio Pack (ESP) in the Azure Marketplace. It contains Helix Core, Swarm, Hansoft and a Windows workstation, with 5 licenses to go with that.
First Log on to the Helix Core Virtual Machine
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Allow the p4 client to create a logged-on context to the database
p4login -v 1
Install Helix Authentication Service
The official documentation for installing Helix Authentication Service (HAS) from Perforce can be found here. In order to group the whole flow in a single document, below are the main commands needed to install HAS.
In this walkthrough we install HAS on the same machine as Helix Core. HAS can also be installed on a dedicated machine, so not to utilize resources from the commit server.
On CentOS we can install HAS through YUM, and the Enhanced Studio Pack installation has already added the Perforce repository to the YUM configuration. So, all we need to do is install HAS:
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Install HAS
sudo yum install helix-auth-svc
After this command HAS is installed and running. In order to be able to access the endpoint the Network Security Group needs to be opened:
- In the Azure portal, go to the Resource Group where the ESP is installed
- Select the Network Security Group
- Click on Inbound security rules on the left
- Click + Add on the top of the blade
- Fill out the input fields:
- Source: IP Addresses
- Source IP addresses/CIDR ranges: the IP address (range) you are connecting from
- Source Port ranges: *
- Destination: Any
- Service: Custom
- Destination port ranges: 3000
- Protocol: Any
- Action: Allow
- Name: HAS
Install Helix Authentication Extension
The extension cannot be installed through YUM at this time. It can be downloaded from the official Perforce Github repository. This walkthrough downloads the latest version from Github, as it contains some new bits around the use of Managed Identities that have not been added to the release yet, at the time of writing. It is also possible to download a QA tested release from Perforce’s Github, but that does not support the Managed Identity flow.
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Download and extract the extension
cd /tmp
wget https://github.com/perforce/helix-authentication-extension/archive/refs/heads/master.zip
unzip master.zip
- Package and install the extension
cd helix-authentication-extension-2021.2/
p4 extension --package loginhook
p4 extension --install loginhook.p4-extension --allow-unsigned -y
Setting up Perforce Users and Groups
When the Enhanced Studio Pack is just installed, there is only one user, and there are no groups. For this walkthrough we’ll create a group of users that need to log on using HAS, and we’ll create a user that is part of that group:
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Create a user named John
p4 user -f john
- Change the following fields:
- Email: should be the email address John has in the AAD tenant
- FullName: John’s full name
- Exit vi and save the configuration
:wq <ENTER>
- Set up Perforce to allow for SSO Authentication to be used:
p4 configure set auth.sso.allow.passwd=1
- Giving the newly created user a random password in Perforce, as they will be using AAD to log in:
yes $(uuidgen) | p4 -u perforce passwd john
- Create a group called SSO
p4 group sso
The Users field is an array, so create a new line after Users:, indent by using a TAB and add John to the list of users in this group
- Exit vi and save the configuration
:wq <ENTER>
Option 1: Configuring HAS and AAD for SAML
Configure AAD for SAML
The easiest way to configure HAS to work with AAD is by using Perforce’s AAD Marketplace solution. A complete walkthrough can be found here. The basic steps are:
- Sign in to the Azure Portal
- Go to your Active Directory
- Choose Enterprise Application from the menu on the left
- Click + New application
- Search for Perforce in the Search application box
- Select Perforce Helix Core - Helix Authentication Service
- Click Create
After the Enterprise Application was successfully deployed, you should see a screen like this:
First, we’ll add some users to make use of the Enterprise Application:
- Click 1. Assign users and groups
- Click + Add user/group from the top of the blade
- Select the users you’d want to add
- Hit the Assign button
Now, we’ll configure the single sign on. For this step, you’ll need the public IP address from the machine you have configured HAS on.
- Go back to the Overview blade
- Click 2. Set up single sign on
- Select SAML
- In Basic SAML Configuration, choose Edit
- In Identifier, add https://<<PUBLIC IP ADDRESS>>:3000/saml
- In Reply URL, add https://<<PUBLIC IP ADDRESS>>:3000/saml/sso
- In Sign on URL, add https://<<PUBLIC IP ADDRESS>>:3000/
- Hit Save on the top of the blade
Configure the Helix Authentication Extension for SAML
To complete this step, you’ll need the public IP address from the machine where HAS has been installed.
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Configure the extension
p4 extension --configure Auth::loginhook
Change the following:
- ExtP4USER: perforce
- Auth-Protocol: saml
- Service-URL: https://<<PUBLIC IP ADDRESS>>:3000
Exit vi and save the configuration
:wq <ENTER>
- Configure the extension instance
p4 extension --configure Auth::loginhook --name loginhook-a1
change the following:
- enable-logging: true
- name-identifier: nameID
- non-sso-users: perforce
- sso-groups: sso
- user-identifier: email
Exit vi and save the configuration
:wq <ENTER>
Configure Helix Authentication Service for SAML
To configure HAS, you’ll need 3 pieces of information:
- The IP address of the Virtual Machine that hosts HAS
- The AAD App Federation Metadata Url:
- Go to the Azure portal
- Go to Azure Active Directory
- Go to Enterprise Applications
- Select the Enterprise Application you created earlier
- Go to Single sign-on on the left
- Scroll down to 3. SAML Signing Certificate
- Copy the App Federation Metadata Url
- The AAD Login URL
- Go to the Azure portal
- Go to Azure Active Directory
- Go to Enterprise Applications
- Select the Enterprise Application you created earlier
- Go to Single sign-on on the left
- Scroll down to 4. Set up Perforce Helix Core - Helix Authentication Service
- Copy the Login URL
Now we can go to the Virtual Machine and configure HAS:
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Create a new configuration file:
cd /opt/perforce/helix-auth-svc/
sudo mv .env .envold
sudo vi .env
- Contents (replace the 3 entries with your own values):
PROTOCOL=saml
SVC_BASE_URI=https://<<PUBLIC IP ADDRESS>>:3000
SAML_IDP_SSO_URL=<<AAD LOGIN URL>>
SAML_SP_ENTITY_ID=https://<<PUBLIC IP ADDRESS>>:3000/saml
LOGGING=/opt/perforce/helix-auth-svc/logging.config.js
SAML_IDP_METADATA_URL=<<APP FEDERATION METADATA URL>>
CLIENT_CERT_CN=LoginExtension
- Exit
:wq <ENTER>
After this step everything is configured, and we should restart both the Extension and HAS:
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- restart HAS and the Extension
sudo systemctl restart helix-auth
p4 admin restart
Option 2: Configuring HAS and AAD for OIDC
Configure AAD for OIDC
Open ID Connect is easiest configured through an AAD Application Registration. To complete this step, you’ll need the public IP address of the Virtual Machine that hosts HAS. Follow these steps:
- Sign in to the Azure Portal
- Go to your Active Directory
- Choose App Registrations from the menu on the left
- Click + New registration
- At Redirect URI:
- Select Web
- For the URI, put in https://<<PUBLIC IP ADDRESS>>:3000/oidc/callback
- Click Register
- After the creation, select Certificates & secrets from the menu on the left
- Hit + New client secret
- Fill out a description and expiration, and click Add
- Make sure to copy the Secret as it will not be retrievable after you leave the page
Configure the Helix Authentication Extension for OIDC
To complete this step, you’ll need the public IP address from the machine where HAS has been installed.
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
Configure the extension
- p4 extension --configure Auth::loginhook
- change the following:
- ExtP4USER: perforce
- Auth-Protocol: oidc
- Service-URL: https://<<PUBLIC IP ADDRESS>>:3000
- change the following:
- Exit vi and save the configuration
:wq <ENTER>
- p4 extension --configure Auth::loginhook
Configure the extension instance
- p4 extension --configure Auth::loginhook --name loginhook-a1
- change the following:
- enable-logging: true
- name-identifier: given_name
- non-sso-users: perforce
- sso-groups: sso
- user-identifier: user
- change the following:
- Exit vi and save the configuration
:wq <ENTER>
- p4 extension --configure Auth::loginhook --name loginhook-a1
Configure Helix Authentication Service for OIDC
To configure HAS, you’ll need 3 pieces of information:
- The IP address of the Virtual Machine that hosts HAS
- The AAD App ID:
- Go to the Azure portal
- Go to Azure Active Directory
- Go to App registrations
- Select the App registration you created earlier
- Copy the Application (client) ID
- The AAD App Client Secret
- You should have saved this when you created the Secret
- The AAD tenant ID
- Go to the Azure portal
- Go to Azure Active Directory
- Copy the Tenant ID
Now we can go to the Virtual Machine and configure HAS:
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Create a new configuration file:
cd /opt/perforce/helix-auth-svc/
sudo mv .env .envold
sudo vi .env
- Contents (replace the 3 entries with your own values):
PROTOCOL=oidc
SVC_BASE_URI=https://<<PUBLIC IP ADDRESS>>:3000
LOGGING=/opt/perforce/helix-auth-svc/logging.config.js
CLIENT_CERT_CN=LoginExtension
OIDC_ISSUER_URI=https://login.microsoftonline.com/<<AAD TENANT ID>>/v2.0
OIDC_CLIENT_ID=<<AAD APP ID>>
OIDC_CLIENT_SECRET_FILE=client-secret.txt
- Exit
:wq <ENTER>
- Now, we need to store the client secret in the designated file:
sudo vi client-secret.txt
Just paste in the Client Secret, nothing else, and close VI
:wq <ENTER>
After this step everything is configured, and we should restart both the Extension and HAS:
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- restart HAS and the Extension
sudo systemctl restart helix-auth
p4 admin restart
Test the setup
Testing the setup can be done through multiple ways. Examples include the Windows Workstation that can be deployed as part of the Enhanced Studio Pack, or the use of the Azure Game Dev VM. In the end we’ll need a machine with the Perforce Client tools installed, either P4V or the CLI tools. It can be an on-premises machine or a cloud-based machine.
In this walkthrough we’ll RDP into an instance of the Azure Game Dev VM, as it has all the tools installed.
To test the setup, you’ll need the IP address of the Helix Core instance. If the machine is in the same Virtual Network, this can be a Private IP address. If it is not in the same Virtual Network, it needs to be the public IP address. Regardless, make sure this machine is listed in the Network Security Group to be able to access Helix Core.
- RDP into the Virtual Machine
- Open up a Windows Terminal
- Set the P4 Environment Variables:
p4 set P4USER=john
p4 set P4PORT=ssl:<<PERFORCE IP ADDRESS>>:1666
- Open P4V, put in the username and the address if it is not set correctly
- Hit Connect, you should see a browser opening, and P4V waiting for that to return
- The browser will complain the connection is not secure, this is because we have not yet correctly configured SSL, by default HAS is using a self-signed certificate for that. If you accept this for now, you will be able to log in using AAD. Once you have successfully done that, you’ll see something like this in the browser:
- When you open P4V back up, you’ll see it has been logged in.
Setting up a custom domain name with SSL
After completing all the steps above, the implementation uses an IP Address for HAS, and gives the end-user warnings about the security of that. HAS can be configured to use custom domains, and use CA-signed certificates. To configure this, we must alter some of the configurations we made earlier. It is outside of the scope of this walkthrough to describe how to set up DNS, and how to obtain a proper SSL certificate. This walkthrough assumes the DNS is set up, and the certificates are obtained.
Make the Certificate available for HAS
The certificate- and the key-file should be made available to HAS in the folder:
- /opt/perforce/helix-auth/certs
The certificate should be named:
- server.crt
The key should be named:
- server.key
Change the AAD configuration (SAML)
- Go to the Azure portal
- Go to Azure Active Directory
- Go to Enterprise Applications
- Select the Enterprise Application you created earlier
- Go to Single sign-on on the left
- On 1. Basic SAML Configuration, hit Edit
- For the 3 entries, change the IP address to the DNS name
Change the AAD configuration (OIDC)
- Go to the Azure portal
- Go to Azure Active Directory
- Go to App registrations
- Select the App registration you created earlier
- Select Authentication from the menu on the left
- On the blade, click on the Redirect URI, and change the IP address to the DNS name
Change the Extension configuration
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Configure the extension
p4 extension --configure Auth::loginhook
- In the Service-URL, change the IP address to the DNS name
- Exit vi and save the configuration
:wq <ENTER>
Change the HAS configuration
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- Edit the .env file
sudo vi /opt/perforce/helix-auth/.env
- Change the IP address to the DNS name. In the SAML configuration this needs to happen for 2 parameters, for the OIDC configuration this only needs to happen for 1 parameter
- Add the following 2 parameters:
SP_CERT_FILE='certs/server.crt'
SP_KEY_FILE='certs/server.key'
- Exit vi and save the configuration
:wq <ENTER>
After this step everything is configured, and we should restart both the Extension and HAS:
- SSH into the Virtual Machine
- Move to the perforce user
sudo su - perforce
- restart HAS and the Extension
sudo systemctl restart helix-auth
p4 admin restart
Now HAS is available using the configured domain name, using SSL.
Troubleshooting
Most issues can be resolved by using the log files from both the Extension and HAS. They can be found at these locations: Extension:
- /p4/1/depots/p4-extensions/117E9283-732B-45A6-9993-AE64C354F1C5/1-data/log.json
HAS:
- /opt/perforce/helix-auth-svc/auth-svc.log
The documentation on the Perforce Github page has an extensive amount of troubleshooting tips.