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

[bitnami/openldap] Add support for setting the password crypt format #70398

Closed
wants to merge 2,498 commits into from

Conversation

mistial-dev
Copy link

@mistial-dev mistial-dev commented Jul 29, 2024

Description of the change

This patch adds the configuration option "LDAP_PASSWORD_CRYPT_SALT_FORMAT", allowing the crypt salt format to be set in the container environment variables.

Additionally, this patch changes the default for password encoding from SHA (which is now retired by NIST) to salted SHA-256 using crypt() (which defaults to 5,000 rounds). This change is also applied to administrative passwords (admin, config admin, accesslog admin).

Benefits

NIST recommends moving away from SHA-1 due to insecurity.

The SHA-1 algorithm, one of the first widely used methods of protecting electronic information, has reached the end of its useful life, according to security experts at the National Institute of Standards and Technology (NIST). The agency is now recommending that IT professionals replace SHA-1, in the limited situations where it is still used, with newer algorithms that are more secure.

While it is possible to use a third party module for SHA-256 and SHA-512 from an atlassian employee, it is simpler and more compatible to use {CRYPT} support. This allows the number of rounds to be user-configured for increased attack resistance, allows the algorithm to be specified, and provides the hash in a way that other applications using compatible crypt() implementations can interoperate with.

This improves the default security posture while supporting existing configurations.

Possible drawbacks

Applications designed to work directly with hash values (for example, the SHA or MD5 hash) will not work unless they also have support for crypt passwords. The previous behaviour can be restored by setting LDAP_PASSWORD_HASH to "SSHA".

Note that applications that bind as a user with a simple password should be unaffected by this change. Only applications using the password hash directly may be affected.

Additional information

To take advantage of the new security defaults, LDAP_CONFIGURE_PPOLICY and LDAP_PPOLICY_HASH_CLEARTEXT should be set to yes. This will result in user passwords automatically being hashed, even if they are set in plaintext. This applies to users created through the LDAP_USERS and LDAP_PASSWORDS environment variables.

20351936-3250-4940-912B-B61BF8E994D3

@github-actions github-actions bot added openldap triage Triage is needed labels Jul 29, 2024
@github-actions github-actions bot requested a review from carrodher July 29, 2024 10:52
@mistial-dev mistial-dev changed the title [bitnami/openssl] Add support for setting the password crypt format [bitnami/openldap] Add support for setting the password crypt format Jul 29, 2024
@mistial-dev
Copy link
Author

I kept the automatic plaintext conversion disabled in the interest of compatibility. I could change that as well to make this more secure out of the box, or add a LDAP_HARDENED environment variable that sets some sensible security defaults, including adding ACLs.

Unless you need something like MSCHAPv2 support (VPN for windows, mainly), it's a very good idea to have ACLs set which prohibit reading the contents of the userPassword attribute. If I were doing a hardened config, I'd also be tempted to limit anonymous binding and disable enumeration by users (permitting search by email or username), and adding an ou for service accounts that had full access.

@carrodher carrodher added verify Execute verification workflow for these changes in-progress labels Jul 29, 2024
@github-actions github-actions bot removed the triage Triage is needed label Jul 29, 2024
@github-actions github-actions bot removed the request for review from carrodher July 29, 2024 11:41
@github-actions github-actions bot requested a review from andresbono July 29, 2024 11:41
@andresbono
Copy link
Contributor

Hi, thank you very much for this PR, it looks like a very nice addition! I will run some manual tests on my side and I'll get back to you.

Thanks again!

Copy link
Contributor

@andresbono andresbono left a comment

Choose a reason for hiding this comment

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

Could you please check my comments? Thanks!

Comment on lines 116 to 118
export LDAP_ENCRYPTED_ADMIN_PASSWORD="$(echo -n $LDAP_ADMIN_PASSWORD | slappasswd -c '$5$%.16s' -n -T /dev/stdin)"
export LDAP_ENCRYPTED_CONFIG_ADMIN_PASSWORD="$(echo -n $LDAP_CONFIG_ADMIN_PASSWORD | slappasswd -c '$5$%.16s' -n -T /dev/stdin)"
export LDAP_ENCRYPTED_ACCESSLOG_ADMIN_PASSWORD="$(echo -n $LDAP_ACCESSLOG_ADMIN_PASSWORD | slappasswd -c '$5$%.16s' -n -T /dev/stdin)"
Copy link
Contributor

Choose a reason for hiding this comment

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

If LDAP_PASSWORD_CRYPT_SALT_FORMAT is configurable, should it be used here instead of hardcoding the value?

Copy link
Author

Choose a reason for hiding this comment

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

This approach forced the use of the higher security default for the admin password. I could make it configurable, but it wouldn't force the higher security option for the admin password.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I think it should be configurable. If users may need different formats for admin and the rest, maybe we can define a new env-var: LDAP_ADMIN_PASSWORD_CRYPT_SALT_FORMAT. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

That makes sense.

Copy link
Author

Choose a reason for hiding this comment

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

I see. I think it should be configurable. If users may need different formats for admin and the rest, maybe we can define a new env-var: LDAP_ADMIN_PASSWORD_CRYPT_SALT_FORMAT. What do you think?

Added. Additionally, I changed the defaults to enable ppolicy and hash plaintext passwords by default.

It can be turned off easily enough, either through environment variables or ldapmodify after the fact. Sane defaults are better, and with Microsoft Active Directory using hashed passwords, there's precedent for not doing plaintext passwords. It also works fine for shadow support, and the use of CRYPT instead of something weird increases compatibility when used elsewhere.

@mistial-dev
Copy link
Author

bitnami/openldap/2.5/debian-12/rootfs/opt/bitnami/scripts/libopenldap.sh

Looking at them now.

Copy link
Contributor

@andresbono andresbono left a comment

Choose a reason for hiding this comment

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

Thank you, could you please check my comment?

Comment on lines 116 to 118
export LDAP_ENCRYPTED_ADMIN_PASSWORD="$(echo -n $LDAP_ADMIN_PASSWORD | slappasswd -c '$5$%.16s' -n -T /dev/stdin)"
export LDAP_ENCRYPTED_CONFIG_ADMIN_PASSWORD="$(echo -n $LDAP_CONFIG_ADMIN_PASSWORD | slappasswd -c '$5$%.16s' -n -T /dev/stdin)"
export LDAP_ENCRYPTED_ACCESSLOG_ADMIN_PASSWORD="$(echo -n $LDAP_ACCESSLOG_ADMIN_PASSWORD | slappasswd -c '$5$%.16s' -n -T /dev/stdin)"
Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I think it should be configurable. If users may need different formats for admin and the rest, maybe we can define a new env-var: LDAP_ADMIN_PASSWORD_CRYPT_SALT_FORMAT. What do you think?

Copy link

This Pull Request has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thank you for your contribution.

@github-actions github-actions bot added stale 15 days without activity and removed stale 15 days without activity labels Sep 13, 2024
export LDAP_PPOLICY_USE_LOCKOUT="${LDAP_PPOLICY_USE_LOCKOUT:-no}"
export LDAP_PPOLICY_HASH_CLEARTEXT="${LDAP_PPOLICY_HASH_CLEARTEXT:-no}"
export LDAP_PPOLICY_HASH_CLEARTEXT="${LDAP_PPOLICY_HASH_CLEARTEXT:-yes}"
Copy link
Author

Choose a reason for hiding this comment

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

Applying this through the policy means that it's applied when necessary. It doesn't force a particular hashed format if non-plaintext passwords are applied.

export LDAP_PASSWORD_HASH="${LDAP_PASSWORD_HASH:-{CRYPT\}}"
export LDAP_PASSWORD_CRYPT_SALT_FORMAT="${LDAP_PASSWORD_CRYPT_SALT_FORMAT:-\$5\$%.16s}"
export LDAP_ADMIN_PASSWORD_CRYPT_SALT_FORMAT="${LDAP_ADMIN_PASSWORD_CRYPT_SALT_FORMAT:-\$5\$%.16s}"
export LDAP_CONFIGURE_PPOLICY="${LDAP_CONFIGURE_PPOLICY:-yes}"
Copy link
Author

Choose a reason for hiding this comment

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

Setting this as the default ensures that password hashing is used even when the environment variables are used to pass credentials and no policy is set. Leaving plaintext passwords around is risky.

@mistial-dev mistial-dev force-pushed the openldap-add-crypt-format branch 2 times, most recently from 46f84e6 to ca84e4c Compare September 20, 2024 05:53
@andresbono
Copy link
Contributor

@mistial-dev, just one minor thing, The DCO check failed. Please read https://github.com/bitnami/containers/pull/70398/checks?check_run_id=30415074724 to see how you can fix that. Thanks!

@carrodher carrodher assigned gongomgra and unassigned andresbono Oct 1, 2024
bitnami-bot and others added 20 commits October 3, 2024 17:07
…itnami#72646)

[bitnami][clickhouse] Correct ClickHouse behavior when user adds custom init/start script

Signed-off-by: Tin Trung Ngo <[email protected]>
Signed-off-by: Mistial Developer <[email protected]>
…bian-12-r0 (bitnami#73015)

Signed-off-by: Bitnami Bot <[email protected]>
Signed-off-by: Mistial Developer <[email protected]>
@gongomgra
Copy link
Contributor

Hi @mistial-dev,

Thanks for fixing the DCO issue. Can you rebase the main branch on your fork and fix the conflicts?

Copy link

This Pull Request has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thank you for your contribution.

@github-actions github-actions bot added the stale 15 days without activity label Oct 23, 2024
Copy link

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Pull Request. Do not hesitate to reopen it later if necessary.

@bitnami-bot bitnami-bot added stale 15 days without activity and removed stale 15 days without activity labels Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openldap solved stale 15 days without activity verify Execute verification workflow for these changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants