tail -f /dev/null

If you haven't had any obstacles lately, you're not challenging. be the worst.

wrong answer on RCPT TO "454 4.7.1 <xxx@xxx.com>: Relay access denied"

概要

  • CentOSのコンテナ上でPostfixのインストール〜設定を行っている。
  • 数ヶ月ぶりにビルドした所、postfixが表題のエラーを吐き、メールが送られなくなった。
    • 設定周りは変更せずbuildした為、直接の原因は不明。インストールversionも固定している。
  • 原因としては、設定ファイル mynetworks の不備な模様。
    • Client側IP Addressレンジの追加不足。
    • DockerのデフォルトIPレンジは 172.17.0.0/16

Dockerfile

以下のように記述している(実際にビルドしているものとは多少異なる)。

FROM centos:latest

ENV \
  SOURCE_VER=postfix-3.3.1 \
  BERKELEY_DB_SOURCE_VER=db-5.3.21 \
  LOCAL_DIR=/usr/local/test \
  EPEL_REPO=https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm \
  POSTFIX_SOURCE=ftp://ftp.porcupine.org/mirrors/postfix-release/official/postfix-3.3.1.tar.gz \
  BERKELEY_DB_SOURCE=http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz

USER root

# set locale
RUN \
  unlink /etc/localtime && \
  ln -sf /usr/share/zoneinfo/Japan /etc/localtime && \
  sed -ie 's/en_US/ja_JP/g' /etc/locale.conf && \
  localedef -f UTF-8 -i ja_JP ja_JP.UTF-8

# system update
RUN \
  yum -y update && \
  yum clean all

# create user
RUN \
  groupadd -g 12345 postfix && \
  groupadd -g 54321 postdrop && \
  useradd -c "Postfix Daemon User" -d /var/spool/postfix -g postfix -s /bin/false -u 12345 postfix && \
  chown -v postfix:postfix /var/mail

# install latest postfix and library
RUN \
  yum install -y ${EPEL_REPO} wget db*-devel db4* libdb* mysql mysql-devel pcre-devel cyrus-sasl-plain cyrus-sasl-devel make gcc gcc-c++ m4 expect python-setuptools && \
  easy_install supervisor && \
  mkdir -p ${LOCAL_DIR} && \
  cd ${LOCAL_DIR} && \
  wget ${POSTFIX_SOURCE} && \
  wget ${BERKELEY_DB_SOURCE} && \
  tar -zxf ${SOURCE_VER}.tar.gz && \
  tar -zxf ${BERKELEY_DB_SOURCE_VER}.tar.gz && \
  chown -R root:root ${SOURCE_VER} && \
  chown -R root:root ${BERKELEY_DB_SOURCE_VER}

COPY supervisord.conf /etc/
COPY docker-entrypoint.sh ${LOCAL_DIR}
COPY make_install.expect ${LOCAL_DIR}/${SOURCE_VER}

RUN \
  chmod +x /etc/supervisord.conf && \
  chmod +x ${LOCAL_DIR}/docker-entrypoint.sh && \
  chmod +x ${LOCAL_DIR}/${SOURCE_VER}/make_install.expect

# build Berkeley DB
RUN \
  cd ${LOCAL_DIR}/${BERKELEY_DB_SOURCE_VER}/build_unix && \
  ../dist/configure --prefix=/usr --enable-compat185 --enable-dbm --disable-static --enable-cxx && make && \
  make docdir=/usr/share/doc/${BERKELEY_DB_SOURCE_VER} install && \
  chown -v -R root:root /usr/bin/db_* /usr/include/db{,_185,_cxx}.h /usr/lib/libdb*.{so,la} /usr/share/doc/${BERKELEY_DB_SOURCE_VER}

# build Postfix
RUN \
  cd ${LOCAL_DIR}/${SOURCE_VER}/ && \
  make CCARGS='-DUSE_TLS -I/usr/include/openssl/ -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' AUXLIBS='-lssl -lcrypto -lsasl2' makefiles && make && \
  sh postfix-install -non-interactive daemon_directory=/usr/lib/postfix manpage_directory=/usr/share/man html_directory=/usr/share/doc/postfix-3.3.1/html readme_directory=/usr/share/doc/postfix-3.3.1/readme

sh ${LOCAL_DIR}/${SOURCE_VER}/make_install.expect

EXPOSE 25

ENTRYPOINT ${LOCAL_DIR}/docker-entrypoint.sh

エラーログ

Warning: you still need to edit myorigin/mydestination/mynetworks
parameter settings in /etc/postfix/main.cf.

See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html
for information about dialup sites or about sites inside a firewalled
network.

BTW: Check your /etc/aliases file and be sure to set up aliases
that send mail for root and postmaster to a real person, then run
/usr/bin/newaliases.

対応

  • mynetworks を以下の通り変更する。
postconf -e "mynetworks = 127.0.0.0/8"

postconf -e "mynetworks = 127.0.0.0/8, 172.17.0.0/16"

所感

  • version固定なのにいきなり設定不備でエラーとなった直接の原因は追うの時間掛かりそうなので諦めた。
  • image size半端無くデカイので、centosからalpineに変えたい。

参考