HOWTO: Setup SAML2 For CloudBolt


Python Library Dependencies (Pre-CB v.7.4)

You'll have to first install a library and its dependencies on the CloudBolt appliance with pip. When prompted, type "y" to continuing during the uninstall process.

$ yum install xmlsec1 xmlsec1-openssl

$ pip install djangosaml2==0.16.11

CloudBolt Application Setup


All configuration changes should be made here:


All the changes you see in this section should be made to this file. If the file doesn't exist on your CloudBolt server, you can create it yourself.


The INSTALLED_APPS setting tells CloudBolt which Django applications should be loaded at startup. Since djangosaml2 is a Django app, we need to append it to the list of applications to be loaded:

from settings import INSTALLED_APPS

INSTALLED_APPS += ('djangosaml2',)


This setting configures which authentication plugins are available to CloudBolt. In this case we're adding the SAML2 authentication backend.

from settings import AUTHENTICATION_BACKENDS

AUTHENTICATION_BACKENDS += ('djangosaml2.backends.Saml2Backend',)


We need to instruct CloudBolt not to require login to the urls used for authenticating SAML users.




This step is optional, and forces all user logins to use SAML2.

LOGIN_URL = '/saml2/login/'


The '/var/opt/cloudbolt/proserv/' file is used to provide url mapping to application views. While the djangosaml2 application provides its own routing, we need to include this routing with the parent application routes by adding the following to '/var/opt/cloudbolt/proserv/'.

Again, if this file doesn't already exist, simply create and edit. If you want to set the URL for the SAML path to something other than saml2/ you can do that by changing saml2/ to whatever you'd like; just keep you'll have to update the LOGIN_URL and LOGIN_REQUIRED_URLS_EXCEPTION settings in

Note: If the first two lines are already in the file, you do not need to add them again.

from django.conf.urls import include, url
from urls import urlpatterns

urlpatterns += [
   url(r'^saml2/', include('djangosaml2.urls')),


Service Provider (SP) Configuration (On CloudBolt Server)

Create saml2 directory

If the '/var/opt/cloudbolt/proserv/saml2/' and '/var/opt/cloudbolt/proserv/saml2/attribute-maps/' directories don't exist in '/var/opt/cloudbolt/proserv', please create them as this is the directory where all SAML certs, and IDP metadata will be stored.

Import SAML Attribute Maps

You can download the pysaml2 attribute maps from:

All the .py files in this directory should be downloaded to '/var/opt/cloudbolt/proserv/saml2/attribute-maps/'.

If it’s easier, here’s a small script you can run from the cloudbolt server.

mkdir -p /var/opt/cloudbolt/proserv/saml2/attribute-maps/

cd /var/opt/cloudbolt/proserv/saml2/attribute-maps/







Generate Self-Signed Key-Pair

These attribute maps are used to map standard identifiers for attributes provided by your IdP to local attributes that are mapped to the local system in the SAML_ATTRIBUTE_MAPPING variable. No changes should be required to the attribute map files.

Run the following commands and copy saml.key and saml.crt to /var/opt/cloudbolt/proserv/saml2:

$ openssl genrsa -out saml.key 2048

$ openssl req -new -key saml.key -out certreq.csr

$ openssl x509 -req -in certreq.csr -signkey saml.key -out saml.crt

If names other than saml.key and saml.crt are used, please update their references in the SAML_CONFIG settings in

Fetch IdP Metadata

SAML2 identity providers will often allow you to download their IdP metadata for use on your CloudBolt instance. In the configuration below, our metadata was downloaded from Google's SAML2 configuration control panel and stored at /var/opt/cloudbolt/proserv/saml2/remote_metadata.xml. You'll see this file is referenced in the example configuration file below.


The following configuration is used to connect CloudBolt to Google's SAML2 IDP. You'll want to refer to pysaml2 documentation at for more information on the available directives and configuration options.

import os
import saml2

SAML2_DIR = os.path.join('/var/opt/cloudbolt/proserv/saml2')

   'xmlsec_binary': '/usr/bin/xmlsec1',
   'entityid': '',
   'service': {
       'sp': {
           'want_assertions_signed': False,
           'want_response_signed': False,
           'allow_unsolicited': True,
           'name': 'CloudBolt SP',
           'endpoints': {
               'assertion_consumer_service': [
                       ('', saml2.BINDING_HTTP_POST),
               'single_logout_service': [
                       ('', saml2.BINDING_HTTP_REDIRECT),
           'required_attributes': ['email'],
   'debug': 1,
   'key_file': os.path.join(SAML2_DIR, 'saml.key'),  # private part
   'cert_file': os.path.join(SAML2_DIR, 'saml.crt'),  # public part
   'allow_unknown_attributes': True,
   'attribute_map_dir': os.path.join(SAML2_DIR, 'attribute-maps'),
   'metadata': {
       'local': [os.path.join(SAML2_DIR, '')],
   'contact_person': [{
       'given_name': 'First',
       'sur_name': 'Last',
       'company': 'Company',
       'email_address': '',
       'contact_type': 'technical'
   'organization': {
       'name': 'Company',
       'display_name': 'Company',
       'url': '',
   'valid_for': 24,  # how long is our metadata valid

       'email': ('email', ),
       'givenName': ('first_name', ),
       'sn': ('last_name', ),
       'uid': ('username', ),

In the above example, the key parameters are as follows:

Entity ID:


SLS/Logout URL:

IDP Metadata file:

Integrating LDAP Group Mappings for SAML2 SSO Auto-Created Users

When a user logs in via SSO and they’ve never logged in before, Django will auto create a user in the local user space in CloudBolt without an LDAPUtility assigned.  

Once logged in, the user might expect certain permissions assigned to their user account because they logged in with their LDAP/AD credentials, however, because they logged in via SAML SSO initially, they were not authenticated with an LDAP domain when logging on, so CloudBolt does not know that they should be assigned to any LDAP groups.

The following code modifies the default behavior of the django user create method and passes in the SAML “attributes” sent via SSO to the “External Users Sync” Orchestration Action.  

Save the following code as:


import os
import saml2

SAML2_DIR = os.path.join('/var/opt/cloudbolt/proserv/saml2')

  class CustomSaml2Backend(Saml2Backend):
       def update_user(self, user, attributes, attribute_mapping,
               Custom SAML2 update_user method to handle group
               attributes that will map to CloudBolt groups
 'LDAP attributes = {attributes}')
 'LDAP attribute_mapping: {attribute_mapping}')
           user = super(CustomSaml2Backend, self).update_user(
               user, attributes, attribute_mapping, force_save=False
           profile = user.userprofile
           run_hooks("external_users_sync", job=None,
                     users=[profile], attributes=attributes)
           return user

Also verify the permissions on this file are similar to ./ for ./

Change the /var/opt/cloudbolt/proserv/ file for the following property (replace this entry: “djangosaml2.backends.Saml2Backend”) so that it looks like this:

AUTHENTICATION_BACKENDS += ('djangosaml2.backends2.CustomSaml2Backend',)

Contact your account representative for an updated external users sync script, which calls the external users sync while possibly passing the SAML Attributes that will allow for any LDAP domain configured in CloudBolt to match the user’s login LDAP domain name.

 Here's an excerpt from said plugin:

def run(job, mapping=None, dry_run=False, **kwargs):
   logger.debug("Running hook {}".format(__name__))
   users = kwargs.get('users', None)
   attributes = kwargs.get('attributes', None)
   if attributes and not dry_run:
       setup_ldap_for_saml_logins(users=users, attributes=attributes)

NOTE: It is necessary to configure your SAML2 provider to send an extra attribute in the SAML Assertion data in order to correctly identify the user’s LDAP domain.  The plugin mentioned above assumes a Microsoft ADFS SAML2 provider, and has the configuration set for the appropriate property name in Microsoft’s SAML2 assertion “attributes” data.  You will need to modify this property based on the property name that your SAML2 provider is sending. UPN translates to UserPrincipalName.

UserPrincipalName follows this format: sAMAccountName@LDAPDomainName



Okta, OnePoint and other SAML2 providers should be able to pass an extra attribute with that data, but the name is arbitrary so make sure to modify the “UPN_ATTR” to the name of the attribute being passed from the appropriate SAML2 provider.

After you’ve finished all this, we should now be able to restart the httpd service.

service httpd restart

You should now be able to test SAML2 auto-user creation and have the LDAP Domain configured appropriately on the CloudBolt user sent via SAML2, as well as the appropriate permissions based on your LDAP Group membership (as defined by the LDAPGroupMapping object).

Test the configuration, and look at the /var/log/cloudbolt/application.log if you have issues or if the website doesn’t properly load.

Encrypted SAML Responses

As a part of hardening the SAML integration from a security perspective, we can “encrypt” the SAML response object (all the data that the we use to create users in Django/CloudBolt)

This data includes:

  • LDAP username,
  • Email address,
  • GivenName/FirstName,
  • SurName/LastName,
  • LDAP groups the user is a member of (potentially),

SAML Response encryption requires updates on both the IdP and the on the CloudBolt server in the form of a certificate to encrypt/decrpyt the SAML response data.  For the purposes of testing, you may use the SSL certificate that your dev CloudBolt server’s Apache service is running as.

The IdP will need the public key, and the CloudBolt server will need the public and private keys.

Without the configuration to encrypt saml responses, you will see a log entry in the cloudbolt application.log when a user logs in via a saml assertion:

2019-01-22 13:57:02,079 [DEBUG] saml2.response: ***Unencrypted assertion***

Response Encryption can be attained by adding this information to the /var/opt/cloudbolt/proserv/ in the SAML_CONFIG

    'encryption_keypairs': [{
           'key_file': '/etc/pki/tls/private/',
           'cert_file': '/etc/pki/tls/certs/'

You can use a different key than apache’s SSL certificate.

Note: You will need to restart the httpd service in order for this configuration change to become active.

 Make sure that you configure the IdP to use the public key certificate that is referenced in the SAML_CONFIG[“encryption_keypairs”][“cert_file“] section in, so that the SAML response can be sent encrypted with a certificate that SAML knows how to decrypt.

 Once the configuration is updated in both the IDP and the CloudBolt (and httpd is restarted), on a new SSO login, you should see that the response is encrypted based on this log entry:

 2019-01-22 14:14:12,250 [DEBUG] saml2.response: ***Encrypted assertion/-s***

 ...and SAML2 authentication should process correctly.

 If you get an error in the browser similar to:

'NoneType' object has no attribute 'authn_statement' at least know that the IdP is sending an encrypted response but the SAML_CONFIG in CloudBolt doesn’t know how to process it.

 This typically means one or more of the following conditions have happened:

  • The configuration change was not made to the or it has typographical errors (correct file names?)
  • The httpd service was not restarted after making the configuration changes in the

Example (excerpt):


Common Identity Providers (“IdP”s)

No matter what SAML Identity Provider in use, all that is needed is the same information from any of them to correctly create a user in CloudBolt and attach that user to the correct LDAP Domain (for automatic placement of authenticated users into CloudBolt Groups).

  1. Username
  2. FirstName
  3. LastName
  4. Email
  5. UserPrincipalName
  6. User Group List [Distinguished Names] (OPTIONAL, but suggested for future enhancements to the external users sync script. LDAP-based lookups from CloudBolt work just fine without this)


Okta is a pretty straight-forward IdP and lots of customers have successfully implemented Okta to CloudBolt integration. About the only issue we tend to see is that you can customize the Attribute names and we need to know what the attribute names Okta is sending for each attribute:


From this example we would need the “FirstName”, “LastName”, “Email” and eventually we would need to define “UserName” and or “UserPrincipalName” as well, in order to set the SAML_ATTRIBUTE_MAPPINGS settings correctly for CloudBolt.

This particular string could be used as a template to pass an appropriate value for the “UserPrincipalName” based on what is configured for user.login.  In the example below, the user had something similar to this in user.login (which didn’t match the LDAP domain name required).

Placing this string in the value of the ATTRIBUTE STATEMENTS in Okta for an Attribute named UPN allowed us to send the needed data in the format required to override the emaildomainname that was present in user.login and pass the valid LDAP domain name as part of this Attribute.

String.substringBefore(user.login, "@")+""

ADFS (Microsoft)

Microsoft’s IdP (Active Directory Federation Services) is a little harder to work with, because they customized it a lot and the attribute names are URLs not just names like “username”.

Additionally, differences in ADFS v2 (Windows 2012) and subsequent changes/improvements in ADFS v3 (Windows 2016) make implementations slightly different. Once a Relying Party Trust has been created, verify the following screenshots look similar to this.  Tabs that are not shown here, have nothing configured in them. See examples of the Attributes we can make use of in ADFS (screenshot from ADFS v3):




After configuring the Relying Party Trust, the customer will need to “Edit Claim Issuance Policy” for this Relying Party Trust with the following settings.



NOTE: ADFS can pass the Group list that a user is a member of so that instead of querying LDAP, the SAML Response data can include the group membership list (as Group DistinguishedNames) from Active Directory.  In addition the only LDAP Attribute mapping missing fromthe image above is the “User-Principal-Name” with an “Outgoing Claim Type” of “UPN”.

 In ADFS, we can click on the “View Rule Language” button to see how these Attributes look with their actual attribute names (while noting that some of the URLs are prefixed with “” and others are prefixed with “”:

c:[Type == "", Issuer == "AD AUTHORITY"]

=> issue(store = "Active Directory", types = ("", "", "", "", "", ""), query = ";mail,sn,givenName,sAMAccountName,memberOf,userPrincipalName;{0}", param = c.Value);

NOTE: These URL attribute names are going to be the names we need to map in the for CloudBolt in SAML_ATTRIBUTE_MAPPINGS.



Documentation for SAML2 configuration entries


Time Skew

Time Skew is a major factor when configuring SAML because SAML will refuse to authenticate if the system clocks are off by a particular amount.  Here’s an example from the CloudBolt logs where the CloudBolt server clock and the ADFS server clock are off by too much time. Notice that we are 1.5 minutes ~ outside of the acceptable window in order to use the SAML Response object. (the CloudBolt server is 4 hours off of “Z” aka UTC time.

Please consider configuring the CloudBolt server as an NTP client to correct clock skew.

2019-04-08 12:23:31,528 [DEBUG] saml2.response: conditions: <saml:Conditions xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" NotBefore="2019-04-08T16:24:59.893Z" NotOnOrAfter="2019-04-08T17:24:59.893Z"><saml:AudienceRestriction><saml:Audience></saml:Audience></saml:AudienceRestriction></saml:Conditions> 
2019-04-08 12:23:31,530 [ERROR] saml2.response: Exception on conditions: Can't use response yet: (now=2019-23-08T16:23:31Z + slack=0) <= notbefore=2019-04-08T16:24:59.893Z

Example ADFS configured CloudBolt

If the “Test URL” button from ADFS doesn't work, but you can browse the metadata url from Internet Explorer, Chrome, et al, Check the following Registry Keys on the ADFS server to verify they exist and are set appropriately (in order to enable TLS 1.2 in 64-bit and 32-bit .Net Frameworks for v2 and v4).





NOTE:  A Reboot of your AD FS Server is required after changing the SchUseStrongCrypto Values

Key points:  

  • want_response_signed: Response Signing ensures that the RP (CloudBolt) knows that the IdP sent the data because its signed with a certificate that CloudBolt can verify locally (enabled in this example)
  • encryption_keypairs: Response Encryption encrypts the data to ensure an extra layer of security - in addition to the Response being signed, We can further encrypt the data with another certificate (at IdP) and decode it with the private key in CloudBolt (enabled in this example) - not necessary for basic communication (only provides added security)
  • allow_unknown_attributes: Allows extra attributes to be sent in the SAML Response to the SP beyond what is expecting in the SAML_ATTRIBUTE_MAPPING
  • DEBUG = True (allow debug messages to get sent to the application.log - in conjunction with setting the SAML logging to debug via SAML_CONFIG[‘debug’])
  • AUTHENTICATION_BACKENDS (need to set this to backends2 in order to allow for SAML integrated Django user creation via SAML - in conjunction with external_users_sync modifications) 
import os
import saml2
from settings import INSTALLED_APPS
from settings import AUTHENTICATION_BACKENDS

DEBUG = True

   ("admin", ""),
TIME_ZONE = 'America/New_York'

INSTALLED_APPS += ('djangosaml2',)
AUTHENTICATION_BACKENDS += ('djangosaml2.backends2.CustomSaml2Backend',)
LOGIN_URL = '/saml2/login/'
SAML2_DIR = os.path.join('/var/opt/cloudbolt/proserv/saml2')


   'xmlsec_binary': '/usr/bin/xmlsec1',
   'entityid': '',
   'service': {
       'sp': {
           'allow_unsolicited': True, #must be true
           'name': 'CloudBolt SP',
           'want_assertions_signed': True, #assertion signing (default=True)
           'want_response_signed': True, #is response signing required
           'name_id_format': None,
           'endpoints': {
               'assertion_consumer_service': [
               ], #url to where SSO needs to POST the authentication data
               'single_logout_service': [
               ], #url to where sso needs to redirect on logout
   'debug': 1, #send saml logs to application log in debug mode
   'encryption_keypairs': [{
           'key_file': '/etc/pki/tls/private/',
           'cert_file': '/etc/pki/tls/certs/'
   }], #this controls response encryption (if required by your customer or IdP)
   'key_file': os.path.join(SAML2_DIR, 'saml.key'), # private part
   'cert_file': os.path.join(SAML2_DIR, 'saml.crt'), # public part
   'allow_unknown_attributes': True, #allow extra attributes in response
   'attribute_map_dir': os.path.join(SAML2_DIR, 'attribute-maps'),
   'metadata': {
       'local': [os.path.join(SAML2_DIR,
   }, #this is the metadata file from the IdP
   'contact_person': [{
       'given_name': 'Douglas',
       'sur_name': 'Adams',
       'company': 'HHGTTG',
       'email_address': '',
       'contact_type': 'technical'
   }], #contact data - not integral to authentication
   'organization': {
       'name': '',
       'display_name': 'The HitchHikers Guide To The Galaxy',
       'url': '',
   }, #contact data - not integral to authentication
   'valid_for': 42, #how long is this configuration information valid for (hours)
#what attribute should we create the username with: username is typically used
SAML_CREATE_UNKNOWN_USER = True #create users that don’t exist: True | False

   ORG_WS_CLAIMS + 'emailaddress': ('email', ),
   MS_CLAIMS + 'windowsaccountname': ('username', ),
   ORG_WS_CLAIMS + 'surname': ('last_name', ),
   ORG_WS_CLAIMS + 'givenname': ('first_name', ),
}#upn isn’t in this list and doesn’t need to be



Identity Provider: Server that provides authentication data to CloudBolt


Service Provider (CloudBolt)


Lightweight Directory Access Protocol (Enterprise Directory for User data, commonly implemented as Microsoft Active Directory)


Security Assertion Markup Language version 2 : the open-source backend protocol that makes Single Sign-on possible between an IdP and an SP


User Principal Name: The username for a particular LDAP domain in the following format username@ldapdomain


Have more questions? Submit a request


Please sign in to leave a comment.