scripts: rework environment variables setup#2716
Conversation
This commit contains major parts of the work of refactoring the setup and usage of environment variables. It outsources the setup into its own script and provides dedicated functions to be executed at a later point in time. A **new** env variable was added: `USER_PROVISIONG` which provides a better way of defining which method / protocol to use when it comes to setting up users. This way, the `ENABLE_LDAP` variable is deprecated, but all of this is backwards compatible due to a "compatibility layer", a function provided by the new variables script. This is not a breaking change. It mostly refators internal scripts. The only change facing the user-side is the deprecation of `ENABLE_LDAP`. We can prolong the period of deprecation for this variable as long as we want, because the new function that ensures backwards compatibility provides a clean interface for the future.
polarathene
left a comment
There was a problem hiding this comment.
This is a welcome change 😀
I'm especially fond of the ENV grouping to separate scopes for SASLAUTHD, LDAP, and SPAM!
You did seem to drop one ENV as noted in the review, but everything else seems untouched from diffing 👍
Please note that while I would have preferred that you had two PRs to contribute the ENV refactor and the ENABLE_LDAP rename separately, I do not want you to split the PR now. I would like to complete the review (no force pushing until approved please).
After approval, if another reviewer would like the PR split, or you want to rewrite history, that's fine, but it's easier for me to complete the review as-is with commit diffs to follow changes.
My main concerns are:
- Add back the missing ENV, or justify it's removal.
- Change the
PAMvalue to a more appropriate one, or justify the choice. - Consider changing
USER_PROVISIONINGto a different name. - Resolve the concern with
_setup_supervisor()and_obtain_hostname_and_domainname()(specifically the reason for wrapping in conditionals, and relevance to belonging invariables.shinstead ofstart-mailserver.sh). - Better distinguish the only non-LDAP
SASLAUTHD_*ENV from others in that scope.
This is done in order to allow users to better graps the transition to the new environment variable that handles acccount provisioning.
This variable was only ever declared but never used.
With this commit, the early setup is cleaner. Thanks to @polarathene for making me aware of this. The Supervisor setup and host-/domainname resolution is now done in the beginning, the env setup is done afterwards.
@polarathene made me aware of the fact that `SASLATUHD_` only ever has one variable really that is not used within an LDAP context. Therefore, the new setup went straight into the LDAP setup routine.
The removal of this variable was an error on my side.
polarathene
left a comment
There was a problem hiding this comment.
LGTM 👍
Some optional suggestions, mostly opinionated so feel free to dismiss them if you disagree.
|
When review comments have been resolved, on the Web UI it seems notifications don't properly take you to the discussion in my experience, so I'm instead linking to those and quoting them instead since wading through the history to find the actual updated sub-thread can be annoying 😅 I could probably have marked them unresolved instead, but the actual feedback was addressed. Review feedback comment: #2716 (comment)
By "LDAP docs", I meant our own doc pages for LDAP. Earlier in the comment I was pointing out that we don't have any test, documentation, or scripts usage beyond the ENV fallback (which was originally in the Dockerfile) for So we already use Review feedback comment: #2716 (comment)
If it wasn't clear my appreciation was for the referenced/highlighted change: if [[ ${ENABLE_SASLAUTHD} -eq 1 ]]
then
_environment_variables_saslauthd
_register_setup_function '_setup_saslauthd'
fias previously the ENV portion was not guarded with
I wasn't sure if you were asking a question about doing this in another PR, or just acknowledging that it should be. A follow-up PR would be good if you have the time for it 👍 |
1. I have splitted the general ENV setup further to provide an even better overview. I hope this distinction is not too fine grained. 2. I added `DMS_FQDN` (and from this derived, `DMS_HOSTNAME` & `DMS_DOMAINNAME`) for a future PR which resolves the current DNS "issues" with using `HOSTNAME` and `DOMAINNAME`. The `OVERRIDE_HOSTNAME` variable will then be deprecated.
|
I have not resolved the comments this time in case there is more to them. I added the I also added a stub (not enabled by now) for a future DNS-related-code refactoring. The |
polarathene
left a comment
There was a problem hiding this comment.
Great work thanks @georglauterbach ! 😀
The more granular scoping is good too, the DMS_* stub is also nice 👍
|
LGTM 👍 The only thing I am personally not completely confident with is the var handling in While I understand your intention, I think it's too fine grained and adds more complexity than benefit. It seems also not completely consistent: You grouped the var assignment by topic. A much simpler approach would be going back to one big list, but change some ENV namings to have them easily in order: Old: New: You see at the first look, all related fetchmail vars, instead of checking different functions. The "big list" could also be grouped by adding empty lines and/or by adding comments. |
|
The concern may be valid, but don't go changing ENV for now as this is for I'm mostly interested in the other methods separating out the anti-spam, network, ldap and sasl. I don't see any issue with function wrapping for the grouping. If you're concerned about sorting order you can looking with |
Yeah that was just a general proposal / mind game and if chosen, something for the next major release.
I do. More information on less space. Creating functions to call them only once makes no sense in that case. Especially in comparison to any multi purpose script file, we have a dedicated file here just for variable assignments. So using functions just for grouping is not necessary. Just go with something like this (KISS --> Keep it simple, stupid): # LDAP stuff
VARS[LDAP_foo]
VARS[LDAP_bar]
VARS[LDAP_baz]
# Antispam stuff
VARS[Antispam_foo]
VARS[Antispam_bar]
VARS[Antispam_baz]If I am overruled here, at least improve the thing in regards of consistency (see example with fetchmail). Also Antivirus/Antispam/Security is currently completely mixed in
|
We could definitely look into a breaking change (probably with v13 where we might tackle the I'd also like to find time for addressing the SSL ENV support, but I may be too busy to invest time into that until early next year.
I can understand that, but the added verbosity is a little helpful IMO. I see that we've never really had decent separation here in the past 6 years it's just been a sorted list of ENV that accumulated. When you migrated the Splitting these off into their own function scope instead of a comment allows for this: if [[ ${ENABLE_SASLAUTHD} -eq 1 ]]
then
_environment_variables_saslauthd
_register_setup_function '_setup_saslauthd'
fiYou don't have to scan through the list of ENV among the rest to know they're not default ENV but feature gated, and it's much more clearer where these are going to be used next. It's now very clear that the bulk of These nested scopes come with additional inline documentation related to that scope, a debug log message and can be only added to I know you were in favor of the flat list (as the current logic does) and having all ENV state be stored into If we moved the If an issue reporter shares
I'm all for consistency 👍
We could definitely improve this further, although I'm fine with that being tackled in a follow-up PR, but as we've both reviewed now, additional commits that address that in this PR is ok too. This just seemed to be moving in a direction that was more desirable for me as a maintainer. If we want new contributors, they should be able to ideally figure out what ENV relates to a feature / topic vs the alphabetic sorting we have presently. Personally as part of tackling the multi-stage Dockerfile build, I'd like it more if we can better isolate features further beyond just ENV. That'd serve as improved documentation in itself (for new contributors that could hopefully become maintainers, it's important that friction is reduced to grok how everything fits and flows together). I'd like to look into ClamAV being it's own stage in the Dockerfile, that pulls from the official image and gets the DB from that. And if possible, scope that stage that it's very clear what belongs to supporting that feature, that the stage itself could be dropped to remove the feature entirely if desired. I want that mostly for Amavis and SpamAssassin, which may one day get swapped for rspamd instead for example. And to simplify what packages are installed for what (currently that's another mess with alphabetical sorting + fail2ban install), which will make it easier to be more flexible on base image choice and using tools like |
|
Related to the discussion of future breaking changes with ENV rework, I want to reference this comment from another issue I made. Summary: Personally all the configomat ENV and the If I find time to polish up the Rust port, it could be further adapted to accommodate our related shell scripts as a single CLI binary, or bundled with those shell scripts. We can provide/maintain it as a separate project with docs pointing users to that, or include it in the DMS image with a |
|
Will take care of this when I'm back from vacation. In the meantime, I'd go with a middle-way, and remove the function-in-function calls while staying true to the sorting (mostly). Definite want to keep the functions for |
Do you have an ETA on that? I have a PR that introduces ENV but if you're going to be away for more than a week, perhaps I should submit the PR and have this one resolve the conflict if it's merged prior? |
I will be able to work on this maybe on Sunday. Feel free to submit your PR, I don't mind resolving conflicts:) |
This is a middle-way, and keeps KISS while properly seperating environment variables.
Co-authored-by: Casper <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
|
Documentation preview for this PR is ready! 🎉 Built with commit: d459597 |
Description
This PR refactors (mostly internal) setup of environment variables. I believe this setup to be cleaner because it is properly separated from other scripts. Please also have a look at the commit messages for more detailed information.
This PR also serves as a foundation for #2713. Therefore,
ENABLE_LDAPwas deprecated (absolutely backwards compatible, no breaking change), andACCOUNT_PROVISIONERwas added to serve as the new switch for which method / protocol users should be added and used.Type of change
Checklist:
docs/)