Skip to content

Commit 3b49a04

Browse files
committed
feat(config): prefer smtpd_tls_chain_files over cert/key files
If smtpd_tls_chain_files is set in pillar, use it and suppress smtpd_tls_cert_file/smtpd_tls_key_file (including from the arbitrary params loop). If neither is set, default to snakeoil certs.
1 parent 8368003 commit 3b49a04

6 files changed

Lines changed: 127 additions & 0 deletions

File tree

kitchen.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,19 @@ suites:
259259
verifier:
260260
inspec_tests:
261261
- path: test/integration/default
262+
- name: chain-files
263+
provisioner:
264+
state_top:
265+
base:
266+
'*':
267+
- postfix._mapdata
268+
- postfix
269+
- postfix.config
270+
pillars:
271+
top.sls:
272+
base:
273+
'*':
274+
- chain_files
275+
verifier:
276+
inspec_tests:
277+
- path: test/integration/chain-files

postfix/files/main.cf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@
7373
{{ set_parameter('smtpd_tls_loglevel', 1) }}
7474
{{ set_parameter('smtpd_tls_security_level', 'may') }}
7575
{{ set_parameter('smtp_tls_CApath', '/etc/ssl/certs') }}
76+
{%- if config.get('smtpd_tls_chain_files') %}
77+
{{ set_parameter('smtpd_tls_chain_files') }}
78+
{%- do processed_parameters.append('smtpd_tls_cert_file') %}
79+
{%- do processed_parameters.append('smtpd_tls_key_file') %}
80+
{%- else %}
7681
{{ set_parameter('smtpd_tls_cert_file', '/etc/ssl/certs/ssl-cert-snakeoil.pem') }}
7782
{{ set_parameter('smtpd_tls_key_file', '/etc/ssl/private/ssl-cert-snakeoil.key') }}
83+
{%- endif %}
7884
{{ set_parameter('smtpd_tls_session_cache_database', 'btree:${data_directory}/smtpd_scache') }}
7985
{{ set_parameter('smtpd_tls_mandatory_ciphers', 'high') }}
8086
{{ set_parameter('smtpd_tls_mandatory_exclude_ciphers', ['aNULL', 'MD5']) }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
control 'Postfix config - smtpd_tls_chain_files' do
4+
title 'smtpd_tls_chain_files suppresses cert/key files'
5+
6+
describe postfix_conf do
7+
# chain_files should be set
8+
its('smtpd_tls_chain_files') do
9+
should match '/etc/ssl/private/ssl-cert-snakeoil.key'
10+
end
11+
# cert_file and key_file must be absent when chain_files is set
12+
its('smtpd_tls_cert_file') { should be_nil }
13+
its('smtpd_tls_key_file') { should be_nil }
14+
end
15+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: chain-files
5+
title: postfix formula - smtpd_tls_chain_files
6+
maintainer: SaltStack Formulas
7+
license: Apache-2.0
8+
summary: Verify that smtpd_tls_chain_files suppresses smtpd_tls_cert_file/key_file
9+
depends:
10+
- name: share
11+
path: test/integration/share
12+
supports:
13+
- platform-name: debian
14+
- platform-name: ubuntu
15+
- platform-name: centos
16+
- platform-name: fedora
17+
- platform-name: opensuse
18+
- platform-name: suse
19+
- platform-name: freebsd
20+
- platform-name: openbsd
21+
- platform-name: amazon
22+
- platform-name: oracle
23+
- platform-name: arch
24+
- platform-name: gentoo
25+
- platform-name: almalinux
26+
- platform-name: rocky
27+
- platform-name: mac_os_x
28+
- platform: windows

test/integration/default/controls/postfix_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
its('smtp_tls_CApath') { should cmp '/etc/ssl/certs' }
2121
its('smtpd_tls_cert_file') { should cmp '/etc/postfix/ssl/server-cert.crt' }
2222
its('smtpd_tls_key_file') { should cmp '/etc/postfix/ssl/server-cert.key' }
23+
its('smtpd_tls_chain_files') { should be_nil }
2324
its('smtpd_tls_session_cache_database') do
2425
should cmp 'btree:${data_directory}/smtpd_scache'
2526
end

test/salt/pillar/chain_files.sls

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
postfix:
5+
manage_master_config: true
6+
enable_service: true
7+
reload_service: true
8+
9+
config:
10+
smtpd_banner: $myhostname ESMTP $mail_name
11+
smtp_tls_CApath: /etc/ssl/certs
12+
biff: 'no'
13+
append_dot_mydomain: 'no'
14+
readme_directory: 'no'
15+
myhostname: localhost
16+
mydestination: localhost, localhost.localdomain
17+
relayhost: ''
18+
mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
19+
mailbox_size_limit: 0
20+
recipient_delimiter: +
21+
inet_interfaces: 127.0.0.1
22+
inet_protocols: all
23+
24+
alias_maps: hash:/etc/aliases
25+
alias_database: hash:/etc/aliases
26+
27+
smtpd_tls_session_cache_database: btree:${data_directory}/smtpd_scache
28+
smtpd_use_tls: 'yes'
29+
smtpd_sasl_auth_enable: 'yes'
30+
smtpd_sasl_type: dovecot
31+
smtpd_sasl_path: /var/run/dovecot/auth-client
32+
smtpd_recipient_restrictions: >-
33+
permit_mynetworks,
34+
permit_sasl_authenticated,
35+
reject_unauth_destination
36+
smtpd_relay_restrictions: >-
37+
permit_mynetworks,
38+
permit_sasl_authenticated,
39+
reject_unauth_destination
40+
smtpd_sasl_security_options: noanonymous
41+
smtpd_sasl_tls_security_options: $smtpd_sasl_security_options
42+
smtpd_tls_auth_only: 'yes'
43+
smtpd_sasl_local_domain: $mydomain
44+
smtpd_tls_loglevel: 1
45+
smtpd_tls_session_cache_timeout: 3600s
46+
47+
relay_domains: '$mydestination'
48+
49+
# Use chain_files instead of cert/key — formula should suppress cert/key
50+
smtpd_tls_chain_files:
51+
- /etc/ssl/private/ssl-cert-snakeoil.key
52+
- /etc/ssl/certs/ssl-cert-snakeoil.pem
53+
54+
smtp_tls_session_cache_database: btree:${data_directory}/smtp_scache
55+
56+
aliases:
57+
use_file: false
58+
present:
59+
root: info@example.com
60+
absent:
61+
- root

0 commit comments

Comments
 (0)