Skip to content

This repository builds the docker image for the SMTP Relay server and pushes it to the Shared Services Elastic Container Repository

License

Notifications You must be signed in to change notification settings

ministryofjustice/staff-infrastructure-smtp-relay-server

Repository files navigation

repo standards badge

Staff Infrastructure SMTP Relay Server

Introduction

This repository builds the docker image for the SMTP Relay Server and pushes it to the Shared Services Elastic Container Repository, so that the pre-configured ECS task can pull down this image and launch a new container.

This repository depends on the network services infrastructure repository, which builds the underlying base infrastructure with required ECR repository and ECS service definitions to work with this docker image.

Documentation:

SMTP Relay Server

The Postfix SMTP Relay Server is a server-side application for routing and delivering mail. You can use Postfix to set up a local mail server, create a null-client mail relay, use a Postfix server as a destination for multiple domains, or choose an LDAP directory instead of files for lookups.

The key features of using Postfix SMTP Relay Server:

  • Security features to protect against common email related threats
  • Customization options, including support for virtual domains and aliases

The Postfix SMTP Relay Server enables devices which are unable to use authentication to use unauthenticated SMTP to send email. Currently, printers and a few legacy applications from various MoJ HQ sites are using this SMTP relay service via the Transit Gateway to send emails to both justice and digital domains.

High Level Architecture

The SMTP Relay Service runs within the Staff Infrastructure Network Services VPC.This service consists of an AWS ECS cluster running two instances of SMTP Relay Server containers with postfix image in two availibilty zones in London region. Two load balancers from those two availibility zones are there to accept incoming requests from clients via the Transit gateway and then to distribute the requests to those SMTP Relay Server containers. This provides high availibility and resiliency to the service.

Here is a diagram:

staff-infrastructure-network-services-architecture
Diagram source

Related Repositories

This repository builds the docker image for SMTP Relay server only. Here are some of the other related repositories:

Technical Guide

Once you have deployed the infrastructure, you may use this guide to build and push the SMTP Relay server image.

Prerequisites

To be able to follow this guide, you need to have the following already:

🎉 TIP
You may configure your AWS Vault to use AWS SSO. A step-by-step guide can be found in our team documentation site.

Authenticating with DockerHub

Local development shouldn't go over the download limits of Dockerhub. https://docs.docker.com/docker-hub/download-rate-limit/

If these limits are encountered, authenticating with Docker is required:

export DOCKER_USERNAME=your-docker-hub-username
export DOCKER_PASSWORD=your-docker-hub-password

make authenticate-docker

Clone SMTP Relay Server Repo

  1. Clone the staff-infrastructure-smtp-relay-server repository to a local directory on your machine.

Prepare the Environment Variables

The configuration/environment variables for running and building the SMTP Relay Server container for the required environment are automatically populated through utilisation of the generate-env-file.sh script which is executed when using the 'make gen-env' command. With this approach an engineer can see what the values are and where they are stored. This helps to speed up the process in getting the SMTP Relay container deployed locally.

  1. Generate .env file with the required values for the environment automatically, run:
make gen-env

Build the image

  1. To build the image on your local docker, run:
make build-dev

Run the server locally

  1. To run the SMTP Relay server on your local docker, run:
make run

Test locally

  1. To test the build locally, run:
make test

Push your docker image

  1. To push the built image on to your isolated ECR repository, run:
make publish  

Deploy a force remote ECS restart

make deploy  

Stopping Local Environment

Once you have finished using the docker image, to shut down the environment, run:

make stop  

SMTP Relay Disaster Recovery

In the event of disaster recovery for the SMTP Relay Server it is recommended to roll forward with a fix than to roll back. If a rollback is still required, follow the steps in this guide

The SMTP service has no persistent data to restore in the event of disaster recovery as it is relaying emails from one destination to another. The configuration for the SMTP Relay Server is stored as parameters in Systems Manager (SSM) Parameter store and set in the various places it is required as defined in the code. As a result the code which is stored in the repositories is all that is needed to bring the service back online.

Disaster Recovery Prerequisites

  • Access to the existing AWS account with AWS BYOIP addresses in order to be able to send on mail to ExchangeOnline/GoogleWorkspace. If this is not possible the new Elastic Public IPs will need to be replaced on mail-relay.staff.service.justice.gov.uk PTR records within Route53 else mail delivery will fail.
  • If account has lost attachment to transit gateway then push access to the transit gateway repo.

Recovering from a disaster

In the event that Grafana has alerted on a disaster scenario, follow the steps below to restore the STMP Relay service:

1. Restore the ECS infrastructure

Deploy the underlying AWS infrastructure required for the SMTP Relay Server by following the How to deploy the Infrastructure guide. This documentation covers steps for prerequisites, creating a terraform workspace and standing up the infrastructure.

2. Restore the SMTP Relay Server

Once Step 1 is complete and the underlying AWS infrastructure is deployed/restored proceed to restoring the SMTP Relay Server container into ECS Fargate by following the steps of this README's Technical Guide. This guide includes the necessary prerequisite steps and instructions for Building, Running, Testing, Publishing (to ECR) and Deploying/Restoring the SMTP Relay container into ECS.

About

This repository builds the docker image for the SMTP Relay server and pushes it to the Shared Services Elastic Container Repository

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published