Skip to content

feat: start implementing replication - Add DOVECOT_ITERATE_ATTRS/FILTER ENVs#3426

Closed
williamdes wants to merge 3 commits intodocker-mailserver:masterfrom
williamdes:ldap-2048-iterate-users
Closed

feat: start implementing replication - Add DOVECOT_ITERATE_ATTRS/FILTER ENVs#3426
williamdes wants to merge 3 commits intodocker-mailserver:masterfrom
williamdes:ldap-2048-iterate-users

Conversation

@williamdes
Copy link
Copy Markdown
Contributor

@williamdes williamdes commented Jul 14, 2023

Description

I added two ENVs needed to list users: #2048 (comment)

Ref #2048

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change that does improve existing functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@williamdes williamdes marked this pull request as ready for review July 15, 2023 08:58
@williamdes williamdes changed the title feat: start implementing replication feat: start implementing replication - Add DOVECOT_ITERATE_ATTRS/FILTER ENVs Jul 15, 2023
@williamdes williamdes requested a review from polarathene July 15, 2023 09:09
williamdes added a commit to wdes/mails.wdes.eu that referenced this pull request Jul 15, 2023
@casperklein
Copy link
Copy Markdown
Member

I just did a quick look and wondered, if the two newly added ENVs don't need to be added to _setup_ldap() @ ldap.sh

Does changing those ENVs actually works?

@williamdes
Copy link
Copy Markdown
Contributor Author

I just did a quick look and wondered, if the two newly added ENVs don't need to be added to _setup_ldap() @ ldap.sh

Does changing those ENVs actually works?

Changing the ENVs does work because the tests say so and my production ENV too since some years now ;p
That said, I am wondering if this is only used by doveadm to list users
or to list and manage them
or to also provide a list of users to replicate
I did not check this since I do not want to break my current production replication.

But most probably it's needed to list users to replicate.
Ref: #2048 (comment)

@casperklein
Copy link
Copy Markdown
Member

You're right. I found the snipped that handles the ENV change:

_replace_by_env_in_file 'DOVECOT_' '/etc/dovecot/dovecot-ldap.conf.ext'

Copy link
Copy Markdown
Member

@georglauterbach georglauterbach left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏼

Copy link
Copy Markdown
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

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

This looks fine, except for the test which is not acceptable. Not your fault as I don't expect you to have known why 😅


Most tests have been ported over to our newer conventions which makes it easier to write / maintain tests. LDAP is one of the few that I didn't get around to tackling with my available volunteer time for DMS.

Here you've brought in the same common helper script but from the revised version. You then leverage X_EXTRA_ARGS in a way that it's not meant to be used 😅 (you probably wanted to add the setup helper and call our dedicated method for that instead)

Here's an example of the newer version of tests for setup_file():

load "${REPOSITORY_ROOT}/test/helper/common"
load "${REPOSITORY_ROOT}/test/helper/setup"
BATS_TEST_NAME_PREFIX='[SASLauthd + RIMAP] '
CONTAINER_NAME='dms-test_saslauthd_and_rimap'
function setup_file() {
_init_with_defaults
local CUSTOM_SETUP_ARGUMENTS=(
--env ENABLE_SASLAUTHD=1
--env SASLAUTHD_MECH_OPTIONS=127.0.0.1
--env SASLAUTHD_MECHANISMS=rimap
--env PERMIT_DOCKER=container
)
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
_wait_for_smtp_port_in_container mail_with_imap
}
function teardown_file() { _default_teardown ; }

LDAP has a little bit extra going on with a custom network and LDAP container also being setup.

I can also see that your new test cases are calling setup_file() directly with additional ENV. setup_file() is only meant to be run once for the whole file, test cases aren't meant to call it again.

setup_file() will do any common setup that's relevant for all test cases before they're run, when you need to run containers with different ENV, you can likewise setup the container in test cases instead of in setup_file():

@test "(enabled ENV) should restart clamd when killed" {
export CONTAINER_NAME=${CONTAINER3_NAME}
local CONTAINER_ARGS_ENV_CUSTOM=(
--env ENABLE_CLAMAV=1
)
_init_with_defaults
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
_should_restart_when_killed 'clamd'
_should_stop_cleanly
}

Then the teardown will happen automatically if our test file has:

And you've set the container name as shown above.

@williamdes
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @polarathene

Since I mostly did follow the actual testing style (of the file) could we merge this PR and cleanup this in another one?
I would like to avoid having open contributions to look after

@georglauterbach
Copy link
Copy Markdown
Member

Fine we me, just sayin :)

@polarathene
Copy link
Copy Markdown
Member

polarathene commented Jul 24, 2023

Since I mostly did follow the actual testing style (of the file) could we merge this PR and cleanup this in another one?

Are you actually going to follow-up with it? (in a timely manner)

It's not about testing style. I pointed out issues with how you modified the test. You are using the test suite methods itself incorrectly, not just our helpers / conventions.

I don't think we can trust the tests are reliable with the current concerns raised.


You can wait until end of the month, I may have time to address this myself. Otherwise if someone does merge this PR ignoring my concerns:

  • Include a disclaimer comment at the top of the test file referencing my earlier comment about test quality concerns.
  • Potentially revert all other changes to the test beyond the new test cases and comment them out, with comment referencing the same PR comment about the quality of the approach not being acceptable.

@github-actions github-actions Bot added the meta/stale This issue / PR has become stale and will be closed if there is no further activity label Aug 14, 2023
@docker-mailserver docker-mailserver deleted a comment from github-actions Bot Aug 14, 2023
@polarathene polarathene removed the meta/stale This issue / PR has become stale and will be closed if there is no further activity label Aug 14, 2023
@williamdes
Copy link
Copy Markdown
Contributor Author

Oh gosh I forgot about this
I would really appreciate if someone can merge this and patch the test part before me

@georglauterbach
Copy link
Copy Markdown
Member

georglauterbach commented Aug 14, 2023

Oh gosh I forgot about this I would really appreciate if someone can merge this and patch the test part before me

This is probably not going to happen due to a simple lack of time..

@williamdes
Copy link
Copy Markdown
Contributor Author

Oh gosh I forgot about this I would really appreciate if someone can merge this and patch the test part before me

This is probably not going to happen due to a simple lack of time..

Nevermind, still on my todo list

@polarathene
Copy link
Copy Markdown
Member

I've been working on the LDAP test today, it'll be refactored and should be reviewed / merged this week sometime. Your PR here can then adapt to the new test.

@williamdes
Copy link
Copy Markdown
Contributor Author

I've been working on the LDAP test today, it'll be refactored and should be reviewed / merged this week sometime. Your PR here can then adapt to the new test.

Thank you so much

@polarathene
Copy link
Copy Markdown
Member

@williamdes while we wait on #3483 to get merged, are you familiar with any other openldap docker images that you can easily automate setup with?

The one we're using in our tests is quite outdated (version pinned), and upstream is no longer maintained for 2 years.

I have come across a bitnami / vmware image, but it doesn't support .schema files (postfix-book.schema). I figured out how to convert that to a .ldif via slaptest + slapcat I think, but still couldn't quite get the image happy as it was failing with "Invalid DN syntax" when parsing the .ldif files we have for creating the test users.

@williamdes
Copy link
Copy Markdown
Contributor Author

@williamdes while we wait on #3483 to get merged, are you familiar with any other openldap docker images that you can easily automate setup with?

The one we're using in our tests is quite outdated (version pinned), and upstream is no longer maintained for 2 years.

I have come across a bitnami / vmware image, but it doesn't support .schema files (postfix-book.schema). I figured out how to convert that to a .ldif via slaptest + slapcat I think, but still couldn't quite get the image happy as it was failing with "Invalid DN syntax" when parsing the .ldif files we have for creating the test users.

Yeah of course, I built one for the same reasons
https://github.com/sudo-bot/docker-openldap/
With the old one it should be plug and play
See it implemented with DMS: https://github.com/datacenters-network/mails/blob/a28cc971351bad2ee98fe63e04cb2879aeeb8877/docker-compose.yml#L173
Since years now!

Please file issues with anything you want to have for it
Yes I need to add documentation ^^

@polarathene
Copy link
Copy Markdown
Member

polarathene commented Aug 17, 2023

The LDAP test refactor PR is merged, I'll revise the portion of your test changes in this PR by the weekend 👍


I managed to resolve the issue I was facing today. I gave your image a look but didn't feel it was a better choice for DMS maintainers to rely on. Detailed notes below.

With the old one it should be plug and play

Doesn't seem that way. I looked through the reference links you provided but stopped by this point:

docker run --rm --name ldap-test \
  --env LDAP_ADMIN_PASSWORD=admin --env LDAP_CONFIG_PASSWORD=admin --env LDAP_MONITOR_PASSWORD=admin \
  --env LDAP_BASE_DN='dc=example,dc=test' \
  --env LDAP_AUTH_BASE_DN='ou=people,dc=example,dc=test' \
  --volume '/tmp/ldifs/:/ldifs/:ro' \
  --hostname 'ldap.example.test' \
  botsudo/docker-openldap

It wanted me to configure more ENV and refused to exit with ctrl+c. Also looking over your reference links, it was unclear how the custom data would be populated by the image beyond the seeding example where you have extra scripts to handle it.

The image itself seems to have a lot more going on package / config wise, I would have liked to get the bitnami/openldap image working, but it kept exiting when supplying the .ldif account files:

Alternative (most popular openldap image actively maintained): bitnami/openldap

 docker run --rm --name ldap-test \
  --env LDAP_ROOT='dc=example,dc=test' \
  --env LDAP_PORT_NUMBER=389 \
  --env BITNAMI_DEBUG=true \
  --volume '/tmp//ldifs/:/ldifs/:ro' \
  --volume '/tmp/schema/postfix-schema.ldif:/schema/custom.ldif:ro' \
  --hostname 'ldap.example.test' \
  bitnami/openldap:latest

That image lets you supply a directory with .ldif files to seed with, but the image doesn't support .schema files apparently. The advice I had come across was to convert .schema into .ldif, so I have done that for the postfix-book.schema (and volume mounted above per the image README):

# Read a conf file that imports the schema and any dependencies needed, then export:
mkdir /tmp/ldif-output
slaptest -f /postfix-schema.conf -F /tmp/ldif-output

# Reads converted schema output and filters out unnecessary properties, saving to ldif file:
slapcat -o ldif_wrap=no -n 0 -F /tmp/ldif -H "ldap:///???(cn={4}postfix-book)" \
  | grep -v ^structuralObjectClass: \
  | grep -v ^entryUUID: \
  | grep -v ^creatorsName: \
  | grep -v ^createTimestamp: \
  | grep -v ^entryCSN: \
  | grep -v ^modifiersName: \
  | grep -v ^modifyTimestamp: \
  | sed -e "s/{4}postfix-book/postfix-book/" > /tmp/postfix-schema.ldif

/postfix-schema.conf:

include /opt/bitnami/openldap/etc/schema/core.schema
include /opt/bitnami/openldap/etc/schema/cosine.schema
include /opt/bitnami/openldap/etc/schema/inetorgperson.schema
include /opt/bitnami/openldap/etc/schema/nis.schema
include /postfix-book.schema

/tmp/postfix-schema.ldif:

dn: cn=postfix-book,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: postfix-book
olcAttributeTypes: {0}( 1.3.6.1.4.1.29426.1.10.1 NAME 'mailHomeDirectory' DESC 'The absolute path to the mail user home directory' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE )
olcAttributeTypes: {1}( 1.3.6.1.4.1.29426.1.10.2 NAME 'mailAlias' DESC 'RFC822 Mailbox - mail alias' EQUALITY caseIgnoreIA5Match SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} )
olcAttributeTypes: {2}( 1.3.6.1.4.1.29426.1.10.3 NAME 'mailUidNumber' DESC 'UID required to access the mailbox' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
olcAttributeTypes: {3}( 1.3.6.1.4.1.29426.1.10.4 NAME 'mailGidNumber' DESC 'GID required to access the mailbox' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
olcAttributeTypes: {4}( 1.3.6.1.4.1.29426.1.10.5 NAME 'mailEnabled' DESC 'TRUE to enable, FALSE to disable account' EQUALITY booleanMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 SINGLE-VALUE )
olcAttributeTypes: {5}( 1.3.6.1.4.1.29426.1.10.6 NAME 'mailGroupMember' DESC 'Name of a mail distribution list' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
olcAttributeTypes: {6}( 1.3.6.1.4.1.29426.1.10.7 NAME 'mailQuota' DESC 'Mail quota limit in kilobytes' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
olcAttributeTypes: {7}( 1.3.6.1.4.1.29426.1.10.8 NAME 'mailStorageDirectory' DESC 'The absolute path to the mail users mailbox' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE )
olcObjectClasses: {0}( 1.3.6.1.4.1.29426.1.2.2.1 NAME 'PostfixBookMailAccount' DESC 'Mail account used in Postfix Book' SUP top AUXILIARY MUST mail MAY ( mailHomeDirectory $ mailAlias $ mailGroupMember $ mailUidNumber $ mailGidNumber $ mailEnabled $ mailQuota $ mailStorageDirectory ) )
olcObjectClasses: {1}( 1.3.6.1.4.1.29426.1.2.2.2 NAME 'PostfixBookMailForward' DESC 'Mail forward used in Postfix Book' SUP top AUXILIARY MUST ( mail $ mailAlias ) )

Even if that's one of the first items to be parsed lumped in with the /ldifs mount dir, it still has problems 🤷‍♂️ Yet if I shell in to the container instead with those files mounted at a different location and manually add them with ldapadd no problem. I'd have to troubleshoot further, but supposedly just mounting the /ldifs dir alters the initial config setup.

One issue on their repo suggested using their supported /docker-entrypoint-initdb.d/ to add in a custom shell script that would do the necessary ldapadd.

My previous comment suggests I may have got it working at some point, but not quite with the "Invalid DN syntax" issue.

Alternative: bitnami/openldap image variant

Based off bitnami/openldap: https://github.com/clayrisser/docker-openldap

This image carries the postfix-book.schema among other improvements, and provides the best experience so far, although it's a bit to new but for using in tests should be fine 👍

 docker run --rm --name ldap-test \
  --env LDAP_ROOT='dc=example,dc=test' \
  --env LDAP_PORT_NUMBER=389 \
  --env BITNAMI_DEBUG=true \
  --volume '/tmp//ldifs/:/ldifs/:ro' \
  --volume '/tmp/migrations:/migrations:ro' \
  --hostname 'ldap.example.test' \
  registry.gitlab.com/bitspur/rock8s/docker-openldap

The only issue I ran into was getting testsaslauthd to be successful. Got familiar with LDAP a bit more and some commands, and eventually figured out the issue was the default ACL config was causing a misleading "Invalid credentials (49)" error.

The separate migrations/ volume provides an .ldif that corrects that based on our current osixia/openldap image used and related openldap docs I came across.

@williamdes
Copy link
Copy Markdown
Contributor Author

Can you open an issue on my image?

If I understand you are missing loading ldiff files at startup?

You "should not need" to load more of them since they are pre loaded by myself, the postfix schema and all.
No more need for a custom image
That said I did some tweaks to have saslauthd inside it, maybe I should remove this part in a variant of the image

Comment on lines +12 to +13
iterate_filter = (objectClass=PostfixBookMailAccount)
iterate_attrs = mail=user
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On production I had removed the user patches lines to insert the following lines

I am starting to think that only adding ENVs like DOVECOT_ITERATE_ATTRS may not be enougth to have the magic work. Maybe default values in this file are an essential part too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is not working for you?

You just want the test-cases you added to pass with the expected output correct? I'll ensure that happens 👍

mail=user means that the identifier in the LDAP object is "mail" attr.
This is also according to other uses: LDAP_QUERY_FILTER_USER
And with the reality of a production ENV
@williamdes
Copy link
Copy Markdown
Contributor Author

The LDAP test refactor PR is merged, I'll revise the portion of your test changes in this PR by the weekend 👍

On it

@github-actions
Copy link
Copy Markdown
Contributor

Documentation preview for this PR is ready! 🎉

Built with commit: 80818b3

Comment on lines +172 to +174
local CUSTOM_SETUP_ARGUMENTS=(
--env DOVECOT_ITERATE_ATTRS='uniqueIdentifier=user'
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for reasons that I ignore, this does not seem to give the options to the container creation process

Any help would be very welcome 🙏🏻

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You will need to provide the array CUSTOM_SETUP_ARGUMENTS on container startup to the function that creates the container. Functions like _run_in_container do not take it into account.

If you want to have it added to the ENV of the container, you'll need to do so at the top of the file where the container is created I guess (or wherever it is created). Probably

https://github.com/docker-mailserver/docker-mailserver/pull/3426/files#diff-664e916443d73f328b2c0c61c3a1aca1de5b968cfb03316012765971cbb5980bR79

and

https://github.com/docker-mailserver/docker-mailserver/pull/3426/files#diff-664e916443d73f328b2c0c61c3a1aca1de5b968cfb03316012765971cbb5980bR93

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, we need to create a new container instance when we want to use different ENV like your test-cases do.

I've converted the test file into the new format we use, but it is the kind that sets all containers up in the main setup() method, whereas you'll see some other tests elsewhere like hostname.bats needs to run different variations for different test cases so each test-case is making it's own container instance, and calling many functions as "test-cases" (a workaround I opted for).

We could technically have multiple .bats files instead, but for such small test-cases like yours that seems unnecessary. I will adapt this LDAP test to support both approaches, but the main annoyance I had was with the ENV setup / sharing.

Technically you could right now define a common base ENV and combine like done here:

local ENABLED_PROCESS_LIST=(
"${CORE_PROCESS_LIST[@]}"
"${ENV_PROCESS_LIST[@]}"
)

Then you can create a container with different ENV like this small test-case:

# Split into separate test case for the benefit of minimizing CPU + RAM overhead of clamd.
# NOTE: Does not reduce test time of previous test case. Adds 10 seconds to test time.
@test "(enabled ENV) should restart clamd when killed" {
export CONTAINER_NAME=${CONTAINER3_NAME}
local CONTAINER_ARGS_ENV_CUSTOM=(
--env ENABLE_CLAMAV=1
)
_init_with_defaults
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
_should_restart_when_killed 'clamd'
_should_stop_cleanly
}

You'd just expand an array like in the prior snippet I showed for sharing the base ENV each container is needing. Do note that you don't have to call it CUSTOM_SETUP_ARGUMENTS (although you should when you can), we just have to match the string value of the variable name that is passed to _common_container_setup().

Plan is that after converting all tests to the new format, to do another pass that moves to compose.yaml, which may instead rely on ENV files or a different way to modularize these config variants.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also note that a PR is about to get merged which changes the test uniqueIdentifier to userID (uid).

Although my goal is iterating towards mail attribute, at least as the login name but presently the test and DMS are not properly configured for this, hence why your PR is delayed. I'd like to get that transition for our LDAP tests and docs addressed first, but am happy to go ahead with this Dovecot support for v13 after I can be more confident in our LDAP support and test coverage :)

@polarathene
Copy link
Copy Markdown
Member

On it

Yeah sorry, I've had some other events need my attention and within DMS I've been trying to queue some additional LDAP related changes before adjusting the test a bit more before meeting your requirements needed here. Almost there 😅

Copy link
Copy Markdown
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

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

You can probably use this review feedback to get the tests working/passing, but like I've said I'm combing through LDAP support and history within DMS and may introduce some breaking changes before returning to this PR.

I don't feel there is a rush to merge this, unless you have a follow-up you want to push through for v13 as well? (if so, take my feedback and update the LDAP tests for me and we'll look into merging it sooner)

Comment on lines +12 to +13
iterate_filter = (objectClass=PostfixBookMailAccount)
iterate_attrs = mail=user
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is not working for you?

You just want the test-cases you added to pass with the expected output correct? I'll ensure that happens 👍

Comment on lines +172 to +174
local CUSTOM_SETUP_ARGUMENTS=(
--env DOVECOT_ITERATE_ATTRS='uniqueIdentifier=user'
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, we need to create a new container instance when we want to use different ENV like your test-cases do.

I've converted the test file into the new format we use, but it is the kind that sets all containers up in the main setup() method, whereas you'll see some other tests elsewhere like hostname.bats needs to run different variations for different test cases so each test-case is making it's own container instance, and calling many functions as "test-cases" (a workaround I opted for).

We could technically have multiple .bats files instead, but for such small test-cases like yours that seems unnecessary. I will adapt this LDAP test to support both approaches, but the main annoyance I had was with the ENV setup / sharing.

Technically you could right now define a common base ENV and combine like done here:

local ENABLED_PROCESS_LIST=(
"${CORE_PROCESS_LIST[@]}"
"${ENV_PROCESS_LIST[@]}"
)

Then you can create a container with different ENV like this small test-case:

# Split into separate test case for the benefit of minimizing CPU + RAM overhead of clamd.
# NOTE: Does not reduce test time of previous test case. Adds 10 seconds to test time.
@test "(enabled ENV) should restart clamd when killed" {
export CONTAINER_NAME=${CONTAINER3_NAME}
local CONTAINER_ARGS_ENV_CUSTOM=(
--env ENABLE_CLAMAV=1
)
_init_with_defaults
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
_should_restart_when_killed 'clamd'
_should_stop_cleanly
}

You'd just expand an array like in the prior snippet I showed for sharing the base ENV each container is needing. Do note that you don't have to call it CUSTOM_SETUP_ARGUMENTS (although you should when you can), we just have to match the string value of the variable name that is passed to _common_container_setup().

Plan is that after converting all tests to the new format, to do another pass that moves to compose.yaml, which may instead rely on ENV files or a different way to modularize these config variants.

Comment on lines +172 to +174
local CUSTOM_SETUP_ARGUMENTS=(
--env DOVECOT_ITERATE_ATTRS='uniqueIdentifier=user'
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also note that a PR is about to get merged which changes the test uniqueIdentifier to userID (uid).

Although my goal is iterating towards mail attribute, at least as the login name but presently the test and DMS are not properly configured for this, hence why your PR is delayed. I'd like to get that transition for our LDAP tests and docs addressed first, but am happy to go ahead with this Dovecot support for v13 after I can be more confident in our LDAP support and test coverage :)

Comment on lines +184 to +195
@test "dovecot: (ENV DOVECOT_ITERATE_FILTER=(objectClass=PostfixBookMailAccount)) ldap email listing works" {
local CUSTOM_SETUP_ARGUMENTS=(
--env DOVECOT_ITERATE_FILTER='(objectClass=PostfixBookMailAccount)'
)

_run_in_container doveadm user '*'
assert_success
assert_line --index 0 '[email protected]'
assert_line --index 1 '[email protected]'
assert_line --index 2 '[email protected]'
_should_output_number_of_lines 3
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here's an example of what this would look like from the advice given in my review feedback:

@test "dovecot: (ENV DOVECOT_ITERATE_FILTER=(objectClass=PostfixBookMailAccount)) ldap email listing works" {
  # Container setup:
  export CONTAINER_NAME='dms-test_ldap_dovecot-iter3'
  local CONTAINER_ARGS_ENV_CUSTOM=(
    "${CONFIG_CONTAINER_BASE[@]}"
    --env DOVECOT_ITERATE_FILTER='(objectClass=PostfixBookMailAccount)'
  )
  _init_with_defaults
  _common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'

  # Actual test-case:
  _run_in_container doveadm user '*'
  assert_success
  assert_line --index 0 '[email protected]'
  assert_line --index 1 '[email protected]'
  assert_line --index 2 '[email protected]'
  _should_output_number_of_lines 3

  # Cleanup, removes test-case container:
  _default_teardown
}

The cleanup is just force removing the container:

# Can be used in BATS' `teardown_file` function as a default value.
#
# @param ${1} = container name [OPTIONAL]
function _default_teardown() {
local TARGET_CONTAINER_NAME=${1:-${CONTAINER_NAME}}
docker rm -f "${TARGET_CONTAINER_NAME}"
}

Setup is like we do in setup(), except we need to export the custom args as a common base var to expand / import here. It's important to give each container a unique name to identify it, I chose to use the name variant dovecot-iter3 as it's the 3rd test-case container for testing against that ENV (or 2nd if we don't create a separate container for the default test).

Setting the name will ensure the helper methods used will know which container to use implicitly.

@polarathene
Copy link
Copy Markdown
Member

polarathene commented Aug 29, 2023

Once this PR is merged, adding your LDAP test cases should be pretty straight-forward 😁

  • Add CONTAINER0_NAME= (where 0 is incremented appropriately) with a value matching the convention shown at the top of the test file. See the referenced PR for usage with the extra container added for a test-case.
  • Add container config/setup at end of setup(), just before the final export (used to set CONTAINER_NAME to the main DMS container).
  • Add your test-cases with a small change like the modified one shows (should only require adding the extra export CONTAINER_NAME= line).
  • You do not need to worry about adding your new ENVs with heavy comments like the others have. Just define them as you have is good enough 👍

Alternatively I'll take care of it once that PR is merged.

@polarathene
Copy link
Copy Markdown
Member

polarathene commented Sep 1, 2023

I am considering a different approach that should meet your needs for these two settings, and any other users future needs for missing settings that these configs are meant to support. Our current approach is a bit awkward and could be improved both for the user and maintainers.


@williamdes how important is the ENV support to set these two settings vs including a file with them? I understand your request for this was to avoid the user-patches.sh workaround you currently use.

Only Postfix LDAP config files are supported in /tmp/docker-mailserver right now, but since they replace the internal base config instead of compliment it, that requires providing all the other settings needed (I plan to fix that). I understand the convenience of ENV, my concern is just if we really should have override support for each individual setting of these files via ENV vs defer to supplying configs like any other feature.

UPDATE:: For ENV replacement at least with the new template approach I'm going to open a PR for, it'd be handled by this little dance:

ENV_PREFIX='DOVECOT_'
ENV_TEMPLATE=/dms/ldap/dovecot.tmpl

# Ensures that envsubst is only run with ENV from the target prefix.
# Those ENV were provided as a generated `.env` file (with prefix dropped by sed)
# to zenv which runs the envsubst command within that constrained environment.

env --ignore-environment \
  ./zenv --file <(env | grep "^${ENV_PREFIX}" | sed "s/^${ENV_PREFIX}//") \
  envsubst < "${ENV_TEMPLATE}"

# stdout now provides the transformed template to be layered with any potential user supplied file config.

That's viable I guess 😅

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has become stale because it has been open for 20 days without activity.
This pull request will be closed in 10 days automatically unless:

  • a maintainer removes the meta/stale label or adds the stale-bot/ignore label
  • new activity occurs, such as a new comment

@github-actions github-actions Bot added the meta/stale This issue / PR has become stale and will be closed if there is no further activity label Sep 23, 2023
@williamdes williamdes added stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI and removed meta/stale This issue / PR has become stale and will be closed if there is no further activity labels Sep 23, 2023
@georglauterbach georglauterbach added the meta/feature freeze On hold due to upcoming release process label Nov 8, 2023
@georglauterbach georglauterbach removed the meta/feature freeze On hold due to upcoming release process label Nov 26, 2023
@williamdes
Copy link
Copy Markdown
Contributor Author

Closing this one. My brain forgot what was left todo.

Feel free to pick stuff out if needed

@williamdes williamdes closed this Dec 8, 2023
@williamdes williamdes deleted the ldap-2048-iterate-users branch December 8, 2023 21:55
@williamdes
Copy link
Copy Markdown
Contributor Author

Thank you for your work on LDAP support @polarathene !

Please do mention me directly on PRs so I can review them if you want.

Having an easier way to define ENVs to create the dovecot config keys

@williamdes how important is the ENV support to set these two settings vs including a file with them? I understand your request for this was to #2048 (comment).

The only goal was to remove more lines from my patch file :)

@georglauterbach
Copy link
Copy Markdown
Member

Thank you for closing this as it has become stale! This saves me the maintenance of stale PRs :)

@polarathene
Copy link
Copy Markdown
Member

Please do mention me directly on PRs so I can review them if you want.

#3524 is the improved approach to what this PR was tackling. It enables support more broadly. Feel free to review it or suggest feedback for some concerns I've noted.

It's only really blocked by my rewrite of the docs for the feature which I've kept on-hold due to very low time right now. Hoping to have a week or so for dedicating to DMS later this month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants