Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/javascript-node
{
"name": "ns8-kickstart",
"name": "ns8-carbonio-proxy",
"build": {
"dockerfile": "../ui/Containerfile"
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clean-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
steps:
- uses: NethServer/ns8-github-actions/.github/actions/delete-image@v1
with:
images: "kickstart"
images: "carbonio-proxy carbonio-proxy-server"
delete_image_token: ${{ secrets.IMAGES_CLEANUP_TOKEN }}
3 changes: 1 addition & 2 deletions .github/workflows/publish-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
trivy:
needs: module

# module-info derives the image from the repo name, but the template still
# publishes as kickstart: no image found until reponame is renamed.
# Trivy scan of the published images (stable releases, or on demand)
if: ${{ needs.module.outputs.images != '' && (needs.module.outputs.release == 'stable' || needs.module.outputs.release == 'latest' || github.event_name == 'workflow_dispatch') }}
uses: NethServer/ns8-github-actions/.github/workflows/scan-with-trivy.yml@v1
with:
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/test-module-qemu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ jobs:
statuses: write
uses: NethServer/ns8-github-actions/.github/workflows/test-module-qemu.yml@v1
with:
# optional: build-images.sh's reponame is a template placeholder
# (kickstart), shared with ns8-kickstart-mariadb. Sed it together with
# this value if this repo is cloned into a differently named module.
image_name: kickstart
image_name: carbonio-proxy
# update tested separately later, independent of this drop-in
# scenarios: '["install","update"]'
ui_tests_strategy: ${{ github.event.inputs.ui_tests == 'true' && 'always' || 'on_renovate_ui_change' }}
debug_shell: ${{ github.event.inputs.debug_shell == 'true' }}
# vm_mem: 12288 # guest memory, MiB
# The suite installs a ns8-carbonio main server for the proxy to join
vm_mem: 12288
timeout_minutes: 120
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port
/build/
server/.localca.crt
256 changes: 130 additions & 126 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,172 +1,176 @@
# ns8-kickstart
# ns8-carbonio-proxy

This is a template module for [NethServer 8](https://github.com/NethServer/ns8-core).
To start a new module from it:
An edge proxy for a multi-server [Carbonio CE](https://www.zextras.com/carbonio-community-edition/)
installation built with [ns8-carbonio](https://github.com/geniusdynamics/ns8-carbonio)
on [NethServer 8](https://github.com/NethServer/ns8-core).

1. Click on [Use this template](https://github.com/NethServer/ns8-kickstart/generate).
Name your repo with `ns8-` prefix (e.g. `ns8-mymodule`).
Do not end your module name with a number, like ~~`ns8-baaad2`~~!
The proxy is an extra entry point to the installation, on a node of its own. It
serves webmail, the Admin Panel, IMAP and POP3, and sends every user to the
mailbox server that holds their mailbox.

1. Clone the repository, enter the cloned directory and
[configure your GIT identity](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup#_your_identity)
> **Unofficial.** Genius Dynamics builds this module from the public Carbonio CE
> packages. Zextras does not endorse it. "Carbonio" and "Zextras" are trademarks
> of Zextras.

1. Rename some references inside the repo:
```
modulename=$(basename $(pwd) | sed 's/^ns8-//') &&
git mv imageroot/systemd/user/kickstart.service imageroot/systemd/user/${modulename}.service &&
git mv imageroot/systemd/user/kickstart-app.service imageroot/systemd/user/${modulename}-app.service &&
git mv tests/kickstart.robot tests/${modulename}.robot &&
sed -i "s/kickstart/${modulename}/g" $(find .github/ * -type f) &&
git commit -a -m "Repository initialization"
```

1. Edit this `README.md` file, by replacing this section with your module
description

1. Adjust `.github/workflows` to your needs. `clean-registry.yml` might
need the proper list of image names to work correctly. Unused workflows
can be disabled from the GitHub Actions interface.

1. Commit and push your local changes

## Install
**A single business does not need this module.** A single ns8-carbonio server
already includes the Carbonio proxy, and owns the mail ports of its node.

Instantiate the module with:
**Experimental.** Multi-server behaviour was tested with containers on one host.
The CI checks only installation, validation and removal, because one test node
cannot run both a main server and a proxy.

add-module ghcr.io/nethserver/kickstart:latest 1
## Contents

The output of the command will return the instance name.
Output example:
- [How it works](#how-it-works)
- [Setup](#setup)
- [Ports](#ports)
- [Redis key contract](#redis-key-contract)
- [Secrets](#secrets)
- [Backup](#backup)
- [Updates](#updates)
- [Known limits](#known-limits)
- [Licences](#licences)
- [Debug](#debug)

{"module_id": "kickstart1", "image_name": "kickstart", "image_url": "ghcr.io/nethserver/kickstart:latest"}
## How it works

## Configure
This module runs the Carbonio **proxy role** (nginx and memcached), in the same
container image as ns8-carbonio, built from the public Carbonio CE packages.
See [server/](server). That directory is kept identical to the one in
ns8-carbonio.

Let's assume that the mattermost instance is named `kickstart1`.
At its first start the proxy joins the directory (LDAP) of an ns8-carbonio
**main server**. From then on, Carbonio's own route lookup finds the right
mailbox server for each login, so the module writes no upstream list. A mailbox
server added later is routed as soon as it exists in the directory.

Launch `configure-module`, by setting the following parameters:
- `host`: a fully qualified domain name for the application
- `http2https`: enable or disable HTTP to HTTPS redirection (true/false)
- `lets_encrypt`: enable or disable Let's Encrypt certificate (true/false)
The proxy also needs to resolve the host names of the main server and of every
additional mailbox server to their WireGuard addresses. It reads them from the
Redis service records and refreshes them live:

- on the `carbonio-server-changed` event,
- on the `module-removed` event.

Example:
The container is not restarted for this.

```
api-cli run configure-module --agent module/kickstart1 --data - <<EOF
{
"host": "kickstart.domain.com",
"http2https": true,
"lets_encrypt": false
}
EOF
```
What stays elsewhere:

The above command will:
- start and configure the kickstart instance
- configure a virtual host for trafik to access the instance
- **Traefik** keeps ports 80 and 443 of the node, and forwards the web client
to the proxy.
- **SMTP** (inbound mail, submission on 587 and 465) stays on the main server.
The Carbonio proxy does not proxy SMTP.

## Get the configuration
You can retrieve the configuration with
## Setup

```
api-cli run get-configuration --agent module/kickstart1
```
1. Set up the main server. On one node, configure ns8-carbonio as *Main server
of a multi-server installation*, with *Accept new servers* on. Optionally,
add mailbox servers on other nodes.
2. Install the proxy on another node. That node must not run another mail
application:

## Uninstall
add-module ghcr.io/geniusdynamics/carbonio-proxy:latest 1

To uninstall the instance:
3. Configure the proxy in *Settings*. Choose the main server from the list (it
shows the main servers of the same Carbonio release), then set the host name
of the proxy. Or from the command line:

remove-module --no-preserve kickstart1
```bash
api-cli run module/carbonio-proxy1/configure-module --data '{"host":"webmail.example.org","join":"carbonio1","lets_encrypt":true}'
```

## Update
4. Point users at the proxy. In DNS, point the webmail and IMAP/POP3 names at
the proxy node. MX records keep pointing at the main server.

To Update the instance:
The *Status* page, and the `get-health` action, show the state of the proxy
services and the servers of the installation.

api-cli run update-module --data '{"module_url":"ghcr.io/nethserver/kickstart:latest","instances":["kickstart1"],"force":true}'
## Ports

## Smarthost setting discovery
| Port | Bound on |
|---|---|
| 110, 143, 993, 995 | every node address, opened in the firewall |
| web client (443 in the container) | 127.0.0.1, `TCP_PORTS[0]`, behind Traefik |
| Admin Panel (6071 in the container) | 127.0.0.1, `TCP_PORTS[1]`, behind Traefik when an Admin Panel host name is set |

Some configuration settings, like the smarthost setup, are not part of the
`configure-module` action input: they are discovered by looking at some
Redis keys. To ensure the module is always up-to-date with the
centralized [smarthost
setup](https://nethserver.github.io/ns8-core/core/smarthost/) every time
kickstart starts, the command `bin/discover-smarthost` runs and refreshes
the `state/smarthost.env` file with fresh values from Redis.
Configuration is refused when another mail module (ns8-carbonio, ns8-mail,
mailcow and others) is on the node, or when one of these ports is in use.
Connections in TIME_WAIT do not count as in use.

Furthermore if smarthost setup is changed when kickstart is already
running, the event handler `events/smarthost-changed/10reload_services`
restarts the main module service.
## Redis key contract

See also the `systemd/user/kickstart.service` file.
Each proxy publishes a non-secret record:

This setting discovery is just an example to understand how the module is
expected to work: it can be rewritten or discarded completely.
```
module/<module_id>/srv/tcp/carbonio-proxy (hash)
host WireGuard address of the node
fqdn Carbonio server name of the proxy
role proxy
master module id of the main server
node node id
release Carbonio release
public_host web host name
```

## Debug
It reads the `module/*/srv/tcp/carbonio` records of the ns8-carbonio servers.
That contract is documented in the ns8-carbonio README.

some CLI are needed to debug
## Secrets

- The module runs under an agent that initiate a lot of environment variables (in /home/kickstart1/.config/state), it could be nice to verify them
on the root terminal
The proxy receives the passwords of the directory service accounts from the
main server as a sealed bundle:

`runagent -m kickstart1 env`
1. The proxy creates an ephemeral X25519 key pair and sends the public key with
its `seal-join-bundle` request.
2. The main server encrypts the bundle for that key, with ECDH, then
HKDF-SHA256, then AES-256-GCM.
3. The proxy decrypts it and writes the passwords to `state/secrets.env`, with
mode 0600.

- you can become runagent for testing scripts and initiate all environment variables
`runagent -m kickstart1`
The passwords never reach Redis in clear. Only modules holding the
`carbonio-peer` role on the main server can call that action. The proxy has
that role through its image label `carbonio@any:carbonio-peer`.

the path become :
```
echo $PATH
/home/kickstart1/.config/bin:/usr/local/agent/pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/
```
`get-configuration` returns only a `ldap_secrets_set` boolean.

- if you want to debug a container or see environment inside
`runagent -m kickstart1`
```
podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d292c6ff28e9 localhost/podman-pause:4.6.1-1702418000 9 minutes ago Up 9 minutes 127.0.0.1:20015->80/tcp 80b8de25945f-infra
d8df02bf6f4a docker.io/library/postgres:15.5-alpine3.19 --character-set-s... 9 minutes ago Up 9 minutes 127.0.0.1:20015->80/tcp postgresql-app
9e58e5bd676f docker.io/library/nginx:stable-alpine3.17 nginx -g daemon o... 9 minutes ago Up 9 minutes 127.0.0.1:20015->80/tcp kickstart-app
```
## Backup

you can see what environment variable is inside the container
```
podman exec kickstart-app env
TERM=xterm
container=podman
NGINX_VERSION=1.24.0
PKG_RELEASE=1
NJS_VERSION=0.7.12
NGINX_IMAGE=docker.io/nginx:stable-alpine3.17
CONFIG_DATABASE_URI="postgresql://postgres:Nethesis,1234@127.0.0.1:5432/toto"
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/root
```
The backup includes:

you can run a shell inside the container
- `state/secrets.env`,
- the configuration, data and certificate volumes.

```
podman exec -ti kickstart-app sh
/ #
```
## Testing
The proxy holds no mail. On restore, the proxy joins the same main server again.

Test the module using the `test-module.sh` script:
## Updates

- The same release check as ns8-carbonio runs: a downgrade of the Carbonio
packages is refused, and the running release is kept.
- Update the main server first, then the mailbox servers, then the proxies.
- A proxy joins only a main server of the same release.

./test-module.sh <NODE_ADDR> ghcr.io/nethserver/kickstart:latest
## Known limits

The tests are made using [Robot Framework](https://robotframework.org/)
- **Stale routes after a mailbox move.** From Carbonio 26.3, memcached listens
only on the loopback, and the purge of the route cache by the mailbox servers
moved to the Carbonio Mesh, which this release does not run. After a mailbox
moves to another server, a cached route can last until it expires
(`zimbraReverseProxyCacheEntryTTL`). To clear the cache earlier, restart the
proxy.
- **No SMTP.** Only webmail, Admin Panel, IMAP and POP3 go through the proxy.

## UI translation
## Licences

Translated with [Weblate](https://hosted.weblate.org/projects/ns8/).
- **The module** is under GPL-3.0-or-later.
- **The runtime image** contains the unmodified Carbonio CE packages, under
GPL-2.0-only and AGPL-3.0-only, with their licence texts in `/usr/share/doc`.
Their source code is at https://github.com/zextras.
- **No proprietary package is included.** The proprietary `pending-setups` is
replaced by a no-op stand-in.

To setup the translation process:
## Debug

- add [GitHub Weblate app](https://docs.weblate.org/en/latest/admin/continuous.html#github-setup) to your repository
- add your repository to [hosted.weblate.org]((https://hosted.weblate.org) or ask a NethServer developer to add it to ns8 Weblate project
```bash
runagent -m carbonio-proxy1 systemctl --user status carbonio
runagent -m carbonio-proxy1 podman exec carbonio carbonio-status
journalctl _UID=$(id -u carbonio-proxy1) -t carbonio -f
```
Loading
Loading