-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add macro to configure TLS for syslog-ng
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{# | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#} | ||
|
||
|
||
{% from 'common/map.jinja' import common %} | ||
{% from 'crypto/map.jinja' import crypto %} | ||
|
||
|
||
{# | ||
# Returns config for a tls network source or destination. | ||
# | ||
# Args: | ||
# is_client: True for use in client config file, false for server config. | ||
# local_cert_dir_name: dir_name from boilerplate_certificate() for the local | ||
# certificate. | ||
# peers: See pillar.log.server.clients for the structure. | ||
#} | ||
{% macro tls_config( | ||
is_client, | ||
local_cert_dir_name, | ||
peers) %} | ||
port(6514) | ||
transport(tls) | ||
tls( | ||
{%- if is_client %} | ||
sni(yes) | ||
{%- endif %} | ||
ssl-options( | ||
{%- for protocol in crypto.openssl.strict_protocols_disabled %} | ||
no-{{ protocol | lower | replace('.', '') }} | ||
{%- endfor %} | ||
) | ||
cipher-suite("{{ | ||
crypto.openssl.ciphers_to_string( | ||
crypto.openssl.strict_ciphers | ||
) | ||
}}") | ||
cert-file({{ common.local_etc }}/x509/{{ local_cert_dir_name }}/cert.pem) | ||
key-file({{ common.local_etc }}/x509/{{ local_cert_dir_name }}/privkey.pem) | ||
peer-verify(required-trusted) | ||
{%- if is_client %} | ||
ca-file(/etc/syslog-ng/conf.d/client-ca-certs.pem) | ||
{%- else %} | ||
{#- | ||
# TODO(syslog-ng >= 4.2.0): Make sure this isn't sent to all (even | ||
# unauthenticated) clients. openssl-conf-cmds() looks promising, possibly by | ||
# setting RequestCAFile to /dev/null or by disabling CANames in Options. | ||
#} | ||
ca-file(/etc/syslog-ng/conf.d/server-ca-certs.pem) | ||
{%- endif %} | ||
# TODO(https://github.com/syslog-ng/syslog-ng/issues/4976): Don't use SHA-1. | ||
trusted-keys( | ||
{%- for peer_name, peer in peers | dictsort %} | ||
{%- set peer_cert = salt['x509.read_certificate'](peer.certificate) %} | ||
{#- | ||
# TODO(https://github.com/syslog-ng/syslog-ng/issues/4978): Switch away | ||
# from using .tls.x509_cn, then remove this validation. | ||
#} | ||
{%- if peer_cert.subject_str != 'CN=' + peer_name %} | ||
{{ raise('Wrong subject for certificate of ' + peer_name) }} | ||
{%- endif %} | ||
"SHA1:{{ peer_cert.fingerprints.sha1 }}" # {{ peer_name }} | ||
{%- endfor %} | ||
) | ||
) | ||
{% endmacro %} |