The purpose of this project is to define Email Domains, Users and Aliases used in Mailu via CRs.
The Mailu-Operator uses the Mailu API to create/update/delete Domains, Users and Aliases, it therefore needs the API
endpoint and token which can be set through command line or the environment variables MAILU_SERVER
and MAILU_TOKEN
.
Important note: A user can still make changes in the Mailu frontend which are not synced back to the CRDs. Also, some changes may be intended to be done "on-the-fly" in the Mailu frontend, for example setting auto reply or changing the password.
This operator adds three custom resources: Domain
, User
and Alias
and each resource represents an object in Mailu API.
For details refer also to your Mailu API documentation: https://mailu.io/master/api.html
Domain fields and defaults (see sample)
- Name (required)
- Comment
- MaxUsers = 0
- MaxAliases = 0
- MaxQuotaBytes = 0
- SignupEnabled = false
- Alternatives
User fields and defaults (see sample)
- Name (required)
- Domain (required)
- AllowSpoofing = false
- ChangePwNextLogin = true
- Comment
- DisplayedName
- Enabled = false
- EnableImap = true
- EnablePop = true
- ForwardDestination
- ForwardEnabled = false
- ForwardKeep = false
- GlobalAdmin = false
- Password (hash, excluded from updates)
- PasswordSecret (takes precedence over
RawPassword
, secret name in the current namespace) - PasswordKey (key within the
PasswordSecret
which contains the password) - QuotaBytes = 0
- QuotaBytesUsed (excluded from updates)
- RawPassword (excluded from updates; optional: if not set, a random password will be generated)
- ReplyBody (TODO: excluded from updates)
- ReplyEnabled = false (TODO: excluded from updates)
- ReplyEnddate (TODO: excluded from updates)
- ReplyStartdate (TODO: excluded from updates)
- ReplySubject (TODO: excluded from updates)
- SpamEnabled = false
- SpamMarkAsRead = false
- SpamThreshold
Alias fields and defaults (see sample)
- Name (required)
- Domain (required)
- Comment
- Destination
- Wildcard = false
Using Domain
as an example resource
flowchart LR
CRD(Domain resource)
Controller
MailuAPI(Mailu API)
User -- 1 create/update/delete Domain resource --> CRD
Controller -- 2 watch Domain resources --> CRD
Controller -- 3 get/create/update/delete Domain --> MailuAPI
Controller -- 4 update resource status --> CRD
Domains defines the domain names known to the mail system.
At the current state, this project does not touch DNS records in any form, nor does it trigger generation of DKIM keys.
It might be interesting to automate DNS records in the future with external-dns
: Mailu/Mailu#547 (comment)
Basically any email address that should be able to receive or send emails on its address must be a user. The domain used must be configured.
Even if you only forward emails to an external address hosted elsewhere, you need to create a user (with forwardDestination
set).
Aliases only work with domains and email addresses know to the system, i.e. you cannot define an alias to forward emails to an external address. For that, you need to create a user.
Aliases are used to route emails for multiple email addresses to a user (email) known to the system.
- go version v1.22.0+
- docker version 17.03+.
- kubectl version v1.30.0+.
- Access to a Kubernetes v1.30.0+ cluster.
- A running installation of Mailu with API enabled.
As this project is brand new and in alpha stage, here are the current steps to try it out:
- get and apply the
install.yaml
which contains the CRDs and the deployment of the operator. - edit the deployment to configure
MAILU_API
andMAILU_TOKEN
environment variables. - create
Domain
,User
andAlias
resources that will be applied to your Mailu instance.
LATEST=https://raw.githubusercontent.com/SickHub/mailu-operator/main/dist/install.yaml
RELEASE=https://raw.githubusercontent.com/SickHub/mailu-operator/v0.0.2/dist/install.yaml
NAMESPACE=mailu
kubectl apply -n $NAMESPACE -f $RELEASE
# edit the deployment and set your Mailu API url and token
kubectl -n $NAMESPACE edit deployment mailu-operator-controller-manager
# now you can add Domain, User and Alias resources
kubectl apply -n $NAMESPACE -f config/samples/operator_v1alpha1_domain.yaml
kubectl apply -n $NAMESPACE -f config/samples/operator_v1alpha1_user.yaml
kubectl apply -n $NAMESPACE -f config/samples/operator_v1alpha1_alias.yaml
# remove the operator again
kubectl delete -n $NAMESPACE -f $RELEASE
Build and install the operator from your fork:
REGISTRY=<your-registry>
NAMESPACE=mailu
# 1. build the image and push it to your own registry
make docker-buildx IMG=$REGISTRY/mailu-operator:dev
# 2. build the `install.yaml` used to deploy the operator (including CRDs, Roles and Deployment)
make build-installer IMG=$REGISTRY/mailu-operator:dev
# 3. apply the `install.yaml` to your k8s cluster
kubectl apply -n $NAMESPACE -f dist/install.yaml
# 4. edit the `MAILU_API` and `MAILU_TOKEN` environment variables
kubectl -n $NAMESPACE edit deployment mailu-operator-controller-manager
Uninstall the operator
kubectl delete -n $NAMESPACE -f dist/install.yaml
To setup the project, operator-sdk
was used to generate the structure and custom resource objects:
operator-sdk init --plugins=go/v4 --domain mailu.io --repo github.com/sickhub/mailu-operator
operator-sdk create api --group operator --version v1alpha1 --kind Domain --resource --controller
operator-sdk create api --group operator --version v1alpha1 --kind User --resource --controller
operator-sdk create api --group operator --version v1alpha1 --kind Alias --resource --controller
Build and push your image to the location specified by IMG
:
make docker-build docker-push IMG=<some-registry>/mailu-operator:tag
NOTE: This image ought to be published in the personal registry you specified. And it is required to have access to pull the image from the working environment. Make sure you have the proper permission to the registry if the above commands don’t work.
Install the CRDs into the cluster:
make install
Deploy the Manager to the cluster with the image specified by IMG
:
make deploy IMG=<some-registry>/mailu-operator:tag
NOTE: If you encounter RBAC errors, you may need to grant yourself cluster-admin privileges or be logged in as admin.
Create instances of your solution You can apply the samples (examples) from the config/sample:
kubectl apply -k config/samples/
NOTE: Ensure that the samples has default values to test it out.
Delete the instances (CRs) from the cluster:
kubectl delete -k config/samples/
Delete the APIs(CRDs) from the cluster:
make uninstall
UnDeploy the controller from the cluster:
make undeploy
Following are the steps to build the installer and distribute this project to users. It is generally advised to create a fork of the repo and create Pull-Requests from your fork.
-
Build the installer for the release tag:
export VERSION=0.1.2 git checkout -b release-$VERSION make build-installer
-
Create a Pull-Request on GitHub with the changes
- at least
dist/install.yaml
andconfig/manager/kustomization.yaml
containing the latest tag
- at least
-
Get the Pull-Request reviewed/approved and merged
- the image will be built and pushed to docker hub
- a release with be created with generated release notes
-
Push the tag
git checkout main git pull git tag v$VERSION git push --tags
// TODO(user): Add detailed information on how you would like others to contribute to this project
# with Rancher Desktop on macOS with Apple Silicon
DOCKER_HOST=unix://$HOME/.rd/docker.sock act --container-architecture linux/amd64 --rm --job analyze
NOTE: Run make help
for more information on all potential make
targets
More information can be found via the Kubebuilder Documentation