Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSMDB-1573 Update documentation to add guidance on LDAP parameters en… #969

Open
wants to merge 6 commits into
base: 8.0
Choose a base branch
from

Conversation

radoslawszulgo
Copy link
Contributor

Add documentation based on @igorsol guidance below:

LDAP documentation refinements

for Set up LDAP authentication and authorization using NativeLDAP - Percona Server for MongoDB 8.0

Creating correct LDAP query may require escaping of special characters. Different parts of such query may have different escaping requirements. There are several RFC documents describing escaping for LDAP:

RFC 4514 | LDAP: Distinguished Names - escaping in Distinguished Names
RFC 4515 | LDAP: String Representation of Search Filters - LDAP search filters utilize its own escaping mechanism
RFC 4516 | LDAP: Uniform Resource Locator - based on general URL escaping. Most obvious example is the need to escape question mark character if it used for something which is not a separator for various parts of LDAP query

There are several parameters in LDAP configuration which require escaping of special characters:

  • security.ldap.authz.queryTemplate and ldapQuery parameter inside security.ldap.userToDNMapping
    both these parameters are LDAP queries which can contain LDAP search filter and distinguished names. So the correct way to escape special characters is to do it step by step:
  1. escape special characters if there are full or partial distinguished names in the query according to RFC 4514
  2. after that escape special characters inside LDAP search filter part of the query according to RFC 4515
  3. after that escape special characters in the whole query according to RFC 4516. Do not escape question marks if that character is used to separate parts of the query
  4. after that if you are going to use result in the YAML config file it might be necessary to do escaping according to YAML specification
  • substitution parameter inside security.ldap.userToDNMapping
    The result of this substitution becomes the value of the {USER} placeholder which is user in the security.ldap.authz.queryTemplate parameter. Generally speaking escaping requirements depends on in which part of the query template it will be substituted. For example the most frequent case result of substitution will be full or part of distinguished name. In that case you will need to escape special characters in the substitution parameters according to RFC 4514.
    It is not necessary to use other escaping mechanisms in this parameter because Percona Server for MongoDB will apply RFC 4515 and RFC 4516 escaping as necessary while making substitutions in the security.ldap.authz.queryTemplate parameter.

One more place where you will need to care about special characters is the user name used while connecting using LDAP authorization. In some cases such user name might be full distinguished name and can be substituted directly into the security.ldap.authz.queryTemplate parameter without using any transformation via security.ldap.userToDNMapping. In other case such user name might represent some user ID such as email or user's real name but after transformation via security.ldap.userToDNMapping some parts of it may become part of distinguished name substituted into the security.ldap.authz.queryTemplate parameter. In any case general rule is: if user name or any part of it will end up substituted as distinguished name it must be escaped according to RFC 4514.

MongoDB documentation has following note in several places:

An explanation of RFC4514, RFC4515, RFC4516, or LDAP queries is out of scope for the MongoDB Documentation. Please review the RFC directly or use your preferred LDAP resource.

Reference:
Self-Managed Configuration File Options - security.ldap.userToDNMapping

@radoslawszulgo
Copy link
Contributor Author

See screenshots from the preview:
image
image

docs/ldap-setup.md Outdated Show resolved Hide resolved
If you don’t know what the substitution or LDAP query string should be, please consult with the LDAP administrators to figure this out.
If you don’t know what the Substitution or LDAP query string should be, please consult with the LDAP administrators to figure this out.

Not, you can use only the `LDAP query` or the `Substitution` stage, the combination of two is not allowed.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Not -> Note

docs/ldap-setup.md Outdated Show resolved Hide resolved
docs/ldap-setup.md Outdated Show resolved Hide resolved
Co-authored-by: Anastasia Alexandrova <anastasia.alexandrova@percona.com>
Co-authored-by: Igor Solodovnikov <igor.solodovnikov@percona.com>

* In this setup, we use the following OpenLDAP groups:
* The setup of an LDAP server is out of scope of this document. We assume that you are familiar with the LDAP server schema.
* An explanation of [RFC4514](https://www.ietf.org/rfc/rfc4514.txt), [RFC4515](https://tools.ietf.org/html/rfc4515), [RFC4516](https://tools.ietf.org/html/rfc4516), or LDAP queries is out of scope of this setup. Please review the RFC directly or use your preferred LDAP resource.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would trade places by mentioning LDAP queries first and then RCFs that describe special character escaping in those queries

@@ -31,6 +22,12 @@ cn: otherusers
member: cn=bob,dc=percona,dc=com
```

## Prerequisites
- To configure LDAP, you must have the `sudo` privilege to the server with the {{ product.psmdb_full_name }} installed.
- If your LDAP server disallows anonymous binds, create the user that Percona Server for MongoDB will use to connect to and query the LDAP server. Afterwards, set that username and password using`security.ldap.bind.queryUser` and `security.ldap.bind.queryPassword` parameters in the `mongod.conf` configuration file. If username or any part of it will end up substituted as distinguished name it must be escaped according to [RFC 4514](https://tools.ietf.org/html/rfc4514). It may happen when:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand the requirement to escape special characters applies to all usernames, not just for the one PSMDB uses to connect to LDAP. Maybe it's worth mentioning this?

- To configure LDAP, you must have the `sudo` privilege to the server with the {{ product.psmdb_full_name }} installed.
- If your LDAP server disallows anonymous binds, create the user that Percona Server for MongoDB will use to connect to and query the LDAP server. Afterwards, set that username and password using`security.ldap.bind.queryUser` and `security.ldap.bind.queryPassword` parameters in the `mongod.conf` configuration file. If username or any part of it will end up substituted as distinguished name it must be escaped according to [RFC 4514](https://tools.ietf.org/html/rfc4514). It may happen when:
- A username is a fully distinguished name and can be substituted directly into the `security.ldap.authz.queryTemplate` parameter without using any transformation via `security.ldap.userToDNMapping`.
- A username represents an email address or fullname and after transformation via `security.ldap.userToDNMapping` some parts of it may become part of distinguished name substituted into the `security.ldap.authz.queryTemplate` parameter.
Copy link
Contributor

@nastena1606 nastena1606 Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- A username represents an email address or fullname and after transformation via `security.ldap.userToDNMapping` some parts of it may become part of distinguished name substituted into the `security.ldap.authz.queryTemplate` parameter.
- A username represents an email address or full name and after transformation via `security.ldap.userToDNMapping`, some parts of it may become part of a distinguished name substituted into the `security.ldap.authz.queryTemplate` parameter.

Moved the tip to a separate subsection since it also applies to AD setup
docs/authorization.md Show resolved Hide resolved
@@ -59,6 +59,34 @@ Both `substitution` and `ldapQuery` should contain placeholders to insert parts

So having an array of documents, Percona Server for MongoDB tries to match each document against the provided name and if it matches, the name is replaced either with the substitution string or with the result of the LDAP query.

### Escaping special characters in usernames

A username can contain special characters in any of its parts. An example of a special character is the `@` sign in an email.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @ character in the mail is probably not the best example because not always it should be escaped. For example on userToDNMapping stage regular expression might match everything before the @ character - in this case there is no reason to esscape it.

Probably it would be better to say that any character which is not alphanumeric or is not an ASCII character may require escaping but which exact characters require escaping depends on all parts of configuration and especially on our LDAP query templates and on our regular expressions inside userToDNMapping.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved

docs/authorization.md Outdated Show resolved Hide resolved
@@ -4,32 +4,32 @@ This document describes an example configuration of LDAP authentication and auth

## Assumptions

1. The setup of an LDAP server is out of scope of this document. We assume that you are familiar with the LDAP server schema.
* The setup of an LDAP server is out of scope of this document. We assume that you are familiar with the LDAP server schema.
* If usernames contain special characters, they must be escaped as described in [RFC4514](https://www.ietf.org/rfc/rfc4514.txt), [RFC4515](https://tools.ietf.org/html/rfc4515), [RFC4516](https://tools.ietf.org/html/rfc4516). An explanation of escaping rules or LDAP queries is out of scope of this setup. Please review the RFC directly or use your preferred LDAP resource.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If usernames contain special characters, they must be escaped as described in [RFC4514](https://www.ietf.org/rfc/rfc4514.txt), [RFC4515](https://tools.ietf.org/html/rfc4515), [RFC4516](https://tools.ietf.org/html/rfc4516). An explanation of escaping rules or LDAP queries is out of scope of this setup. Please review the RFC directly or use your preferred LDAP resource.
* If usernames contain special characters, they must be escaped as described in [RFC4514](https://www.ietf.org/rfc/rfc4514.txt), [RFC4515](https://tools.ietf.org/html/rfc4515), [RFC4516](https://tools.ietf.org/html/rfc4516). Usage of particular escaping methods depends on the part of the LDAP query which will contain substituted value. An explanation of escaping rules or LDAP queries is out of scope of this setup. Please review the RFC directly or use your preferred LDAP resource.

version: 8.0.4-1
---

# {{ product.psmdb_full_name }} {{ page.meta.version }} ({{date.8_0_4}})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this change is part of this PR or the "8.0.4 release notes" PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a fix "by chance" :)

@radoslawszulgo
Copy link
Contributor Author

Thanks for changes Nastya. That also works for me.

@nastena1606
Copy link
Contributor

Thanks for changes Nastya. That also works for me.

Can I consider this answer as approval?:)

@radoslawszulgo
Copy link
Contributor Author

radoslawszulgo commented Jan 28, 2025 via email

@nastena1606 nastena1606 requested a review from igorsol January 28, 2025 16:44
docs/ldap-setup.md Outdated Show resolved Hide resolved
docs/authorization.md Outdated Show resolved Hide resolved
Co-authored-by: Igor Solodovnikov <igor.solodovnikov@percona.com>
Copy link

@igorsol igorsol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants