Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

feat: First version #3

Merged
merged 1 commit into from
Nov 8, 2021
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/opensmtpd"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- master

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/opensmtpd"

jobs:
build:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ gradle-app.setting
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache
.gradletasknamecache

.env
**/secrets
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
FROM homecentr/base:3.1.1-alpine
FROM homecentr/base:3.4.0-alpine

RUN apk add --no-cache \
opensmtpd=6.8.0p2-r0

COPY ./fs /

# smtpd must be run as root therefore disable the privilege drop functionality
RUN rm /etc/cont-init.d/10-init.sh
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
[![Project status](https://badgen.net/badge/project%20status/stable%20%26%20actively%20maintaned?color=green)](https://github.com/homecentr/docker-$$IMAGE_NAME$$/graphs/commit-activity) [![](https://badgen.net/github/label-issues/homecentr/docker-$$IMAGE_NAME$$/bug?label=open%20bugs&color=green)](https://github.com/homecentr/docker-$$IMAGE_NAME$$/labels/bug) [![](https://badgen.net/github/release/homecentr/docker-$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![](https://badgen.net/docker/pulls/homecentr/$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![](https://badgen.net/docker/size/homecentr/$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![Project status](https://badgen.net/badge/project%20status/stable%20%26%20actively%20maintaned?color=green)](https://github.com/homecentr/docker-opensmtpd/graphs/commit-activity) [![](https://badgen.net/github/label-issues/homecentr/docker-opensmtpd/bug?label=open%20bugs&color=green)](https://github.com/homecentr/docker-opensmtpd/labels/bug) [![](https://badgen.net/github/release/homecentr/docker-opensmtpd)](https://hub.docker.com/repository/docker/homecentr/opensmtpd)
[![](https://badgen.net/docker/pulls/homecentr/opensmtpd)](https://hub.docker.com/repository/docker/homecentr/opensmtpd)
[![](https://badgen.net/docker/size/homecentr/opensmtpd)](https://hub.docker.com/repository/docker/homecentr/opensmtpd)

![CI/CD on master](https://github.com/homecentr/docker-$$IMAGE_NAME$$/workflows/CI/CD%20on%20master/badge.svg)
![CI/CD on master](https://github.com/homecentr/docker-opensmtpd/workflows/CI/CD%20on%20master/badge.svg)


# Homecentr - $$IMAGE_NAME$$
# Homecentr - opensmtpd

## Usage

```yml
version: "3.7"
services:
$$IMAGE_NAME$$:
opensmtpd:
build: .
image: homecentr/$$IMAGE_NAME$$
image: homecentr/opensmtpd
```

## Environment variables

| Name | Default value | Description |
|------|---------------|-------------|
| PUID | 7077 | UID of the user $$IMAGE_NAME$$ should be running as. |
| PGID | 7077 | GID of the user $$IMAGE_NAME$$ should be running as. |
| SMTP_ARGS | | Command line arguments passed to the `smtpd` executable. |

## Exposed ports

| Port | Protocol | Description |
|------|------|-------------|
| 80 | TCP | Some useful details |
| 25 | TCP | SMTP |

> Other ports may be exposed by configuring the `smtpd.conf` config file.

## Volumes

| Container path | Description |
|------------|---------------|
| /config | Some useful details |
| /config/smtpd.conf | Opensmtpd main [configuration file](https://man.openbsd.org/smtpd.conf). |

## Security
The container is regularly scanned for vulnerabilities and updated. Further info can be found in the [Security tab](https://github.com/homecentr/docker-$$IMAGE_NAME$$/security).
The container is regularly scanned for vulnerabilities and updated. Further info can be found in the [Security tab](https://github.com/homecentr/docker-opensmtpd/security).

### Container user
The container supports privilege drop. Even though the container starts as root, it will use the permissions only to perform the initial set up. The $$IMAGE_NAME$$ process runs as UID/GID provided in the PUID and PGID environment variables.
The container supports privilege drop. Even though the container starts as root, it will use the permissions only to perform the initial set up. The opensmtpd process runs as UID/GID provided in the PUID and PGID environment variables.

:warning: Do not change the container user directly using the `user` Docker compose property or using the `--user` argument. This would break the privilege drop logic.
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
version: "3.7"
services:
$$IMAGE_NAME$$:
opensmtpd:
build: .
image: homecentr/$$IMAGE_NAME$$
restart: unless-stopped
image: homecentr/opensmtpd-relay
ports:
- "2525:25/tcp"
volumes:
- "./example:/config"
14 changes: 14 additions & 0 deletions example/smtpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Listen on all interfaces (limited by the scope of Docker container so there is no point in filtering the interfaces)
listen on 0.0.0.0

# Define secrets table
table secrets file:/config/secrets

# Define table of IPs which are allowed to connect to smtpd
table sources file:/config/sources

# Define relay rule for all incoming e-mails
action "relay" relay host smtp+tls://secret-sendgrid@smtp.sendgrid.net:587 auth <secrets> mail-from "test@homecentr.io" helo smtp.homecentr.io

# Relay only e-mails from trusted IP addresses
match from src <sources> for any action "relay"
4 changes: 4 additions & 0 deletions example/sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Comment 1
192.168.0.0/24
# Comment 2
172.18.0.1/16
3 changes: 3 additions & 0 deletions fs/etc/services.d/opensmtpd/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/execlineb -S1

s6-svscanctl -t /var/run/s6/services
3 changes: 3 additions & 0 deletions fs/etc/services.d/opensmtpd/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv ash

exec /usr/sbin/smtpd -d -f /config/smtpd.conf $SMTPD_ARGS
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "homecentr-$$IMAGE_NAME$$",
"name": "homecentr-opensmtpd",
"version": "1.0.0",
"description": "",
"repository": {
"type": "git",
"url": "git+https://github.com/homecentr/docker-$$IMAGE_NAME$$.git"
"url": "git+https://github.com/homecentr/docker-opensmtpd.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/homecentr/docker-$$IMAGE_NAME$$/issues"
"url": "https://github.com/homecentr/docker-opensmtpd/issues"
},
"homepage": "https://github.com/homecentr/docker-$$IMAGE_NAME$$#readme"
"homepage": "https://github.com/homecentr/docker-opensmtpd#readme"
}
2 changes: 1 addition & 1 deletion tests/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions tests/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions tests/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>docker-$$IMAGE_NAME$$-tests</name>
<name>docker-opensmtpd-tests</name>
<comment>Project tests created by Buildship.</comment>
<projects>
</projects>
Expand Down
3 changes: 2 additions & 1 deletion tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ repositories {

dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.16.0'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.16.2'
testImplementation group: 'io.homecentr', name: 'testcontainers-extensions', version: '1.6.0'
testImplementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32'
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.32'
testImplementation group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'
}

test {
Expand Down
6 changes: 6 additions & 0 deletions tests/out/test/tests/smtpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Listen on all interfaces (limited by the scope of Docker container so there is no point in filtering the interfaces)
listen on 0.0.0.0

action "local_mail" mbox

match for any action "local_mail"
2 changes: 1 addition & 1 deletion tests/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'docker-$$IMAGE_NAME$$-tests'
rootProject.name = 'docker-opensmtpd-tests'

67 changes: 67 additions & 0 deletions tests/src/test/java/OpenSmtpdContainerShould.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.utility.LogUtils;

import helpers.DockerImageTagResolver;

import io.homecentr.testcontainers.containers.GenericContainerEx;
import io.homecentr.testcontainers.containers.wait.strategy.WaitEx;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.nio.file.Paths;
import java.util.Properties;

public class OpenSmtpdContainerShould {
private static final Logger logger = LoggerFactory.getLogger(OpenSmtpdContainerShould.class);

private static GenericContainerEx _container;

@BeforeClass
public static void setUp() {
_container = new GenericContainerEx<>(new DockerImageTagResolver())
.withRelativeFileSystemBind(Paths.get( "src", "test", "resources", "smtpd.conf"), "/config/smtpd.conf")
.withRelativeFileSystemBind(Paths.get( "src", "test", "resources", "users"), "/config/users")
.withExposedPorts(25)
.waitingFor(WaitEx.forS6OverlayStart());

_container.start();

LogUtils.followOutput(DockerClientFactory.instance().client(), _container.getContainerId(), new Slf4jLogConsumer(logger));
}

@AfterClass
public static void cleanUp() {
_container.close();
}

@Test
public void sendMail() throws Exception {
Properties prop = new Properties();
prop.put("mail.smtp.host", "localhost");
prop.put("mail.smtp.port", _container.getMappedPort(25));
prop.put("mail.smtp.auth", "false");
prop.put("mail.smtp.starttls.enable", "false");

Session session = Session.getInstance(prop);

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("sender@domain.com"));
message.setRecipients(
Message.RecipientType.TO,
InternetAddress.parse("nobody@domain.com")
);
message.setSubject("Testing OpenSMTPd");
message.setText("Hello, world!");

Transport.send(message);
}
}
2 changes: 1 addition & 1 deletion tests/src/test/java/helpers/DockerImageTagResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public class DockerImageTagResolver extends EnvironmentImageTagResolver {
public DockerImageTagResolver() {
super("homecentr/$$IMAGE_NAME$$:local");
super("homecentr/opensmtpd:local");
}
}
8 changes: 8 additions & 0 deletions tests/src/test/resources/smtpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Listen on all interfaces (limited by the scope of Docker container so there is no point in filtering the interfaces)
listen on 0.0.0.0

# table users file:/config/users

action "dir" mda "echo -"

match from any for any action "dir"
1 change: 1 addition & 0 deletions tests/src/test/resources/users
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@ recipient@domain.com