Working with LDAP in CodeScoring.Save
LDAP integration capabilities
CodeScoring.Save supports user authentication over the LDAP protocol (Active Directory, FreeIPA, OpenLDAP and compatible directories) and mapping of the attributes of user entries in LDAP to the attributes of accounts in Save.
- An integration is configured in the web interface, in
Settings -> Identity providers -> LDAP. There can be several integrations. No service restart is required. - On the first successful sign-in Save creates an account with the default
readerrole. Other roles are assigned manually. - A local account with the same email becomes an LDAP account on sign-in with the directory password and keeps its roles (see Existing local accounts).
- Passwords of directory users are not stored in Save.
- Local accounts keep working. The local
admincan sign in even when the directory is unavailable.
The LDAP section is available only to the system administrator (the system-admin role).
The reader role lets a user see and download artifacts from all projects, including those created later. Once a directory is connected, everyone who can pass a password check in it gets this access. If that does not suit you, set a different role or turn the default role off before creating the integration — see Installation parameters.
Authentication page
The Save authentication page does not change: one field for the login or email and a password field. Unlike the CodeScoring platform, Save has no menu for choosing an authentication provider.
Save first looks for a local account. If there is none or the password does not match, the login and password are checked in the active LDAP integrations one by one, in alphabetical order of their names. The user is signed in through the first integration that accepts the password.
The description for users is in Logging In and Your Profile.
Mapping of LDAP user entry attributes to Save account attributes
When a user authenticates through LDAP, the following data from the directory entry is mapped to the account in Save:
- the account name (the directory login);
- the first and last name — together they form the display name;
- the email address.
The name and email are updated on every sign-in.
Identity mapping based on LDAP groups
The current version of Save does not support identity mapping: a user's LDAP groups do not affect roles or project membership.
What to prepare
- The directory address: host name or IP address, port and protocol. The pods of the cs-auth service must have network access to this address.
- A service user with read access to the directory: its DN and password. It is optional, but without it sign-in by email and linking of existing accounts do not work.
- The user search base and the names of the attributes that hold the login, email, first name and last name.
- The certificate authority certificate, if the directory certificate is issued by a corporate CA (see Certificates).
Viewing existing LDAP integrations
Existing integrations are shown in Settings -> Identity providers -> LDAP. The section contains a table with the list of configured integrations, a button for creating a new integration (Configure new) and a search field that matches the name and address.
The three-dot menu in a row contains the Edit LDAP configuration and Delete LDAP configuration actions.
Creating an LDAP integration
- In
Settings -> Identity providers -> LDAP, click Configure new. The New LDAP configuration form opens. - If you have Active Directory, FreeIPA or OpenLDAP, click the corresponding button in the Fill for: row above the form. The fields are filled with typical values. The search bases in them are examples: replace the
DC=...parts with your own. For Active Directory, fill in Domain afterwards. - Fill in the form fields (see below).
- Check the connection and click Create.
After creation, the integration details page opens.
Form fields
- Name — the integration name; it must be unique. The name determines the order in which integrations are tried at sign-in (alphabetical);
- LDAP protocol — a choice between the LDAP and LDAPS (LDAP over SSL) protocols. When the protocol changes, the port changes to the standard one (
389or636) unless you have set your own; - LDAP hostname — the domain name or IP address of the LDAP server, without
ldap://and without the port; - LDAP port — the LDAP server port. The combination of host and port is unique;
- User search base — where to search for user entries, for example
ou=people,dc=example,dc=com; - User search filter — the filter for finding the user entry. It must contain the
%USERNAME%template: during the search it is replaced with the name of the account being authenticated. Example:(&(uid=%USERNAME%)(objectClass=inetOrgPerson)); - Username field — the attribute that holds the account name in the user entry, for example
uid. Its value identifies the user in Save; - Email field — the attribute that holds the user's email, for example
mail; - First name field — the attribute that holds the user's first name, for example
givenName; - Last name field — the attribute that holds the user's last name, for example
sn; - Username format — the format of the authorization string, see Available Username format options;
- Domain — the Active Directory domain (appears when the corresponding Username format is selected);
- Bind DN — the DN of the service user with read access to the directory;
- Bind password — the service user's password. Bind DN and the password are set together or are both left empty;
- Is Active — whether the integration is used to authenticate users. On by default;
- Use TLS (StartTLS) — encrypts the connection with the StartTLS command. The flag is shown only for the LDAP protocol; it is not needed for LDAPS;
- Auto-link by email — automatic linking of local accounts by email, see Existing local accounts. On by default.
All fields except Bind DN, Bind password and the flags are required.
An account is bound to the host:port address through which the user first signed in. Do not add replicas of one directory as separate integrations: sign-in through the "other" replica is rejected, including when the primary one is unavailable. For fault tolerance, specify a shared DNS name or a load balancer address. If the directory has moved, edit the existing integration instead of creating a new one.
The password is stored in the cs-auth database unencrypted. The interface and the API do not show it, and it does not get into the audit log. Grant the service user only read access to the directory, and protect database backups the same way you protect secrets.
Example values for FreeIPA:
Available Username format options
The field determines which name Save sends to the directory together with the password. Each option in the drop-down list has an explanation.
For the ldap format, the user entry must be located directly under User search base: the DN for the password check is built from these two fields.
Testing the LDAP integration configuration
To the right of the create and edit form is the Check connection block. When you click Check, Save connects to the LDAP server and, if Bind DN is set, performs a bind as the service user. On success, the Connection successful notification is shown; on failure, Connection error with the error text from the directory.
Checking the form does not save anything. An integration can be saved even when the directory is unavailable.
The Check button verifies only the connection and the service user. It does not verify the search base, the filter or the username format, so after creating the integration perform a trial sign-in:
- Open Save in a private browser window and sign in with the login and password of any directory user.
- In the administrator window, open
Settings -> Users: the new user's IdP column shows theLDAPtag and the integration name. - Open
Settings -> Audit log: a sign-in through the directory is recorded as a separate event with the integration name.
Viewing the details of an existing LDAP integration
The details page opens when you click the integration name in the list. From it you can edit the integration (Edit LDAP configuration) and delete it (Delete LDAP configuration in the three-dot menu).
In addition to the settings fields, the page shows:
- the creation date (Added at) and the date of the last change (Modified at);
- the availability status (Is available) and the time of the last check (Checked at);
- the unavailability reason (Unavailability reason), if the server is unavailable.
The server is considered unavailable if Save failed to connect, to establish TLS or to perform the service user's bind. A refusal for a single user (for example, a wrong password) does not make the server unavailable.
The availability status is updated:
- by a background check, every 5 minutes by default;
- on every sign-in through the integration;
- manually: open the edit form and, without changing anything in it, click Check.
After a change of the address, protocol, StartTLS flag or service user, and after the integration is turned on again, the status is reset to Not checked until the next check.
After a connection failure, the integration is skipped at sign-in for 30 seconds so that users do not wait for a timeout on every attempt. A manual check lifts this pause immediately.
Editing, disabling and deleting an integration
The edit form is the same as the create form. The Bind password field shows Field is set. Leave empty to keep it; to set a new password, click Edit next to the field. To remove the service user, clear Bind DN and leave the password empty. After changing the settings, click Save.
If you change LDAP hostname, LDAP port, LDAP protocol, Use TLS (StartTLS) or Bind DN for an integration with a service user, enter Bind password again. Otherwise saving fails with an error under the password field: Save does not send the stored password to a different address. For the same reason, the Check button asks for the password if the form has unsaved changes.
Some changes affect users. Before saving, Save shows the Do you really want to save changes? confirmation.
Existing local accounts
Automatic linking by email
If the Auto-link by email flag is on in the integration, a local account with the same email becomes an LDAP account on the first sign-in with the directory password:
- the identifier, roles and project memberships are kept;
- the local password stops working, and open sessions are ended;
- the default role is not added on linking: the account keeps exactly the roles it had.
The following are never linked automatically:
- accounts with an administrator role — otherwise whoever controls the directory entry could take over an administrator's account by specifying the administrator's email;
- robot accounts;
- accounts already linked to another directory entry or to another integration.
In these cases the sign-in is rejected and the reason is written to the audit log. A second account with the same email is not created.
If a user enters their local password, they sign in as usual and no linking takes place.
Manual linking
Manual linking is needed for administrators and for integrations with the Auto-link by email flag turned off. It requires a service user to be set in the integration.
-
Open the integration details page.
-
In the information block at the top of the page, follow the Link existing users link.
-
Wait for the page to load: Save searches the directory for the email of every local account, which can take up to a minute.
-
Check the accounts you need. The Status column shows the search result:
- Can be linked — exactly one entry with this email is found in the directory; the login and DN are shown in the Login in the directory column;
- Ambiguous — the directory has several entries with this email, so linking is not possible;
- Not found in the directory — there is no entry with this email.
Only rows with the Can be linked status can be checked. Administrators are marked with the red Administrator tag.
-
Click Link in the panel above the table and confirm the action.
After linking, the selected users sign in only with the directory password, their local passwords stop working, and open sessions are ended. Roles and project memberships are kept. The notification shows the number of linked accounts (Linked: N) and, if there are any, the list of accounts that were not linked, with the reason.
Only the first 1000 local accounts are checked at a time, as the warning above the table says. If the directory responds slowly, loading may end with the Failed to load link candidates error — click Retry.
LDAP user accounts
Accounts of LDAP users are shown in Settings -> Users together with local ones. Their IdP column shows the LDAP tag and the integration name; local accounts show a dash. The user page additionally shows the Login in the directory field.
- The name and email are taken from the directory. On the Edit user form these fields are disabled and labeled
Taken from the directory. - The password is changed only in the directory.
- Roles are assigned the same way as for local accounts: Edit user, the three-dot menu, Update roles. The
readerrole is granted once, when the account is created: if you remove it, the next sign-in does not bring it back. - Deleting the account in
Settings -> Usersdoes not close the user's access: the record is deleted, but on the next sign-in with the directory password it is created again, as on the first sign-in. - To close access, disable or delete the account in the directory: new sign-ins become impossible. The account in Save remains, and sessions that are already open do not end by themselves. After the account is blocked in the directory, it can be deleted from Save — it does not reappear as long as sign-in through the directory is impossible.
How to grant roles before the first sign-in
- In
Settings -> Users, create a local account with the email from the directory. - Assign it the roles you need.
- On the first sign-in with the directory password it becomes an LDAP account and keeps these roles.
This works if Auto-link by email is on in the integration and the assigned roles are not administrative. Link administrators manually.
Converting to local
- Open the user and click Edit user.
- In the three-dot menu, select Set new password.
- Enter New password and click Save.
The account becomes local: the user signs in with the given password and must change it on the next sign-in. Roles are kept.
If the account in the directory works and Auto-link by email is on in the integration, the next sign-in with the directory password turns the account back into an LDAP account. To prevent this, turn automatic linking off or change the user's email.
Installation parameters
The parameters below belong to the cs-auth service and apply to all LDAP integrations. They are set in values.yaml under configMaps.save-backend-envs.data and take effect after helm upgrade.
To give new users fewer rights than reader provides, create your own role in Settings -> Roles and specify its name in AUTH_LDAP_DEFAULT_ROLE.
Certificates
Save verifies the directory certificate for LDAPS and StartTLS: the name in the certificate must match the LDAP hostname value, and the minimum protocol version is TLS 1.2.
If the certificate is issued by a corporate CA, mount the PEM file with the CA certificate into the auth container and specify its path in AUTH_LDAP_TLS_CA_FILE. When the variable is set, only this file is used. If the file cannot be read or contains no certificates, cs-auth does not start.
With AUTH_LDAP_TLS_INSECURE_SKIP_VERIFY=true, user passwords can be intercepted by anyone able to interfere with the connection between Save and the directory.
Limiting the number of sign-in attempts
If the local password does not match, Save checks the same login and password in the directory. Because of this, password guessing through Save can lock accounts in Active Directory. To avoid that, set the auth.max_login_attempts parameter: after the specified number of failed attempts within 15 minutes, sign-in with that login is closed for 15 minutes.
By default the parameter is 0 — no limit. The current value is shown in Settings -> Configuration; it is changed through the API (an administrator token is required, see Getting an Admin JWT):
What to keep in mind:
- Set the value below the lockout threshold of the domain.
- The counter is kept separately in each cs-auth pod: with several replicas the effective limit is higher by the number of replicas.
- The limit is counted per login and also applies to local accounts, including
admin: someone who knows a login can keep it closed with deliberate failed attempts. - Robot accounts and API keys are not subject to the limit.
Troubleshooting
On any sign-in error the user sees the same Log in failed notification: the reason is deliberately not revealed. Look for the reason in the audit log (Settings -> Audit log) and in the cs-auth logs:
Audit log events related to LDAP:
Typical situations:
Notes
- Using authentication through LDAP does not imply full synchronization with the directory: an account is created and updated only when the user signs in.
- The name and email of an LDAP user cannot be changed in Save, and a password cannot be set for such a user.
- An LDAP user can be assigned any roles, the same as a local user.
- One integration has one address; there is no list of fallback hosts. The CA certificate is set once per installation.
- After linking or conversion to local, a client with the former password may keep passing the Basic Auth check for up to two minutes.
Differences from the LDAP integration in the CodeScoring platform:
- the authentication page has no provider selection menu: integrations are tried automatically;
- a local account and a directory entry with the same email are one account, not two accounts with the same name;
- an account created by a sign-in through the directory immediately gets the default role;
- timeouts are set with environment variables for the whole installation, not in the integration form;
- identity mapping, group fields and the forms for testing user search and group loading are absent.
