Skip to content

Commit

Permalink
Create docker-compose for easy development environment bootstrap
Browse files Browse the repository at this point in the history
Create docker-compose configuration, sample postfwd and postfwd antispam
configuration together with initial mysql database creation script.

This allows developers to simply create development environment on local
computer and actively develop and test postfwd plugin.

The postfwd branch is frozen to version `v1.37`.

Signed-off-by: Ondrej Vasko <[email protected]>
  • Loading branch information
Lirt committed Jan 5, 2019
1 parent 3930ad5 commit a945bda
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM postfwd/postfwd:latest
FROM postfwd/postfwd:v1.37

LABEL maintainer="Postfwd GeoIp Spam Plugin Maintainer <[email protected]>"

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ docker run \

This will run `postfwd2` with default arguments, reading postfwd rules file from your mounted volume file `postfwd.cf` and using anti-spam configuration from your file `anti-spam.conf`.

## Development and Prototyping with Docker

Complete development environment with postfwd, anti-spam plugin and mysql database correctly configured together can be run with command `docker-compose -f dev-compose.yml up` from directory `./tests/`.

Note for overriding postfwd arguments:

* Most important arguments to run `postfwd` in Docker are `--stdout` and `--nodaemon`. These arguments configure postfwd to log into standard output and stay in foreground.
* For running postfwd plugin, you also need to set argument `--plugins <path-to-plugin>` to correct location of plugin.

## Installation

To install this plugin follow next steps:
Expand Down
22 changes: 22 additions & 0 deletions tests/dev-anti-spam.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[database]
driver = mysql
database = postfwd-antispam-test
host = mysql-postfwd-db
port = 3306
userid = testuser
password = testpasswordpostfwdantispam

[logging]
# logfile =

[debugging]
# Enable(1) or disable(0) logging
debug = 1
# Make log after exceeding unique country count limit
country_limit = 5
# Make log after exceeding unique ip count limit
ip_limit = 20

[app]
# Flush database records with last login older than 1 day
db_flush_interval = 86400
27 changes: 27 additions & 0 deletions tests/dev-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3.3"
services:
mysql-postfwd-db:
image: mariadb:latest
ports:
- "3306:3306"
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=no
- MYSQL_RANDOM_ROOT_PASSWORD=yes
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testpasswordpostfwdantispam
- MYSQL_DATABASE=postfwd-antispam-test
volumes:
- type: volume
source: ./dev-create-antispam-db.sql
target: /docker-entrypoint-initdb.d/dev-create-antispam-db.sql
postfwd-geoip-antispam:
build: ../
ports:
- "10040:10040"
volumes:
- type: volume
source: ./dev-anti-spam.conf
target: /etc/postfwd/anti-spam.conf
- type: volume
source: ./dev-postfwd.cf
target: /etc/postfwd/postfwd.cf
10 changes: 10 additions & 0 deletions tests/dev-create-antispam-db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
USE postfwd-antispam-test;
CREATE TABLE IF NOT EXISTS postfwd_logins (
sasl_username varchar(100),
ip_address varchar(16),
state_code varchar(4),
login_count int,
last_login timestamp
);
CREATE INDEX postfwd_sasl_client_state_index ON postfwd_logins (sasl_username, ip_address, state_code);
CREATE INDEX postfwd_sasl_username ON postfwd_logins (sasl_username);
27 changes: 27 additions & 0 deletions tests/dev-postfwd.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Anti spam botnet rule:
# This example shows how to limit e-mail address defined by `sasl_username`
# to be able to login from max. 5 different countries, otherwise it will
# be blocked from sending messages.

&&PRIVATE_RANGES { \
client_address=!!(10.0.0.0/8) ; \
client_address=!!(172.16.0.0/12) ; \
client_address=!!(192.168.0.0/16) ; \
};
&&LOOPBACK_RANGE { \
client_address=!!(127.0.0.0/8) ; \
};

id=COUNTRY_LOGIN_COUNT ; \
sasl_username=~^(.+)$ ; \
&&PRIVATE_RANGES ; \
&&LOOPBACK_RANGE ; \
incr_client_country_login_count != 0 ; \
action=jump(BAN_BOTNET)

id=BAN_BOTNET ; \
sasl_username=~^(.+)$ ; \
&&PRIVATE_RANGES ; \
&&LOOPBACK_RANGE ; \
client_uniq_country_login_count > 5 ; \
action=rate(sasl_username/1/3600/554 Your mail account ($$sasl_username) was compromised. Please change your password immediately after next login.);

0 comments on commit a945bda

Please sign in to comment.