Michele Baldessari 2f038b30e8 Make sure we bind the rabbit inter-cluster to a specific interface
Currently the inter-cluster communication port listens to all ip
addresses:
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 25631/beam.smp

In order to limit it to listen only to the network assigned to rabbitmq
we need to add the following:
{kernel, [
    ...
    {inet_dist_use_interface, {172,17,0,16}},
    ...
  ]}

In order to do the conversion from an ip address to the Erlang
representation we add a function that takes a string and returns a
converted output. The (~400 randomly generated) IPv6/4 addresses at [1]
have been parsed both via erl's built-in inet:parse_address() function
and our ruby implementation. All converted ip addresses resulted in the
same output [2], [3]. The only difference is that Erlang's parse_address()
considers network ip addresses (e.g. 10.0.0.0) invalid whereas the ruby
function does not. This should not be a problem as the use case here is
to bind a service to a specific ip address on an interface and if
anything we likely prefer the less strict behaviour, given that at least
in theory it is perfectly valid for an interface to have a network
address assigned to it.

[1] http://acksyn.org/files/tripleo/ip-addresses.txt
[2] http://acksyn.org/files/tripleo/ip-addresses-ruby.txt
[3] http://acksyn.org/files/tripleo/ip-addresses-erl.txt
Change-Id: I211c75b9bab25c545bcc7f90f34edebc92bba788
Partial-Bug: #1645898
2017-01-20 08:41:22 +01:00

109 lines
3.5 KiB
Puppet

# Copyright 2016 Red Hat, Inc.
#
# 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
#
# http://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.
#
# == Class: tripleo::profile::base::rabbitmq
#
# RabbitMQ profile for tripleo
#
# === Parameters
#
# [*config_variables*]
# (Optional) RabbitMQ environment.
# Defaults to hiera('rabbitmq_config_variables').
#
# [*environment*]
# (Optional) RabbitMQ environment.
# Defaults to hiera('rabbitmq_environment').
#
# [*ipv6*]
# (Optional) Whether to deploy RabbitMQ on IPv6 network.
# Defaults to str2bool(hiera('rabbit_ipv6', false)).
#
# [*kernel_variables*]
# (Optional) RabbitMQ environment.
# Defaults to hiera('rabbitmq_environment').
#
# [*inet_dist_interface*]
# (Optional) Address to bind the inter-cluster interface
# to. It is the inet_dist_use_interface option in the kernel variables
# Defaults to hiera('rabbitmq::interface', undef).
#
# [*nodes*]
# (Optional) Array of host(s) for RabbitMQ nodes.
# Defaults to hiera('rabbitmq_node_names', []).
#
# [*step*]
# (Optional) The current step in deployment. See tripleo-heat-templates
# for more details.
# Defaults to hiera('step')
#
class tripleo::profile::base::rabbitmq (
$config_variables = hiera('rabbitmq_config_variables'),
$environment = hiera('rabbitmq_environment'),
$ipv6 = str2bool(hiera('rabbit_ipv6', false)),
$kernel_variables = hiera('rabbitmq_kernel_variables'),
$inet_dist_interface = hiera('rabbitmq::interface', undef),
$nodes = hiera('rabbitmq_node_names', []),
$step = hiera('step'),
) {
# IPv6 environment, necessary for RabbitMQ.
if $ipv6 {
$rabbit_env = merge($environment, {
'RABBITMQ_SERVER_START_ARGS' => '"-proto_dist inet6_tcp"',
'RABBITMQ_CTL_ERL_ARGS' => '"-proto_dist inet6_tcp"'
})
} else {
$rabbit_env = $environment
}
if $inet_dist_interface {
$real_kernel_variables = merge(
$kernel_variables,
{ 'inet_dist_use_interface' => ip_to_erl_format($inet_dist_interface) },
)
} else {
$real_kernel_variables = $kernel_variables
}
$manage_service = hiera('rabbitmq::service_manage', true)
if $step >= 1 {
# Specific configuration for multi-nodes or when running with Pacemaker.
if count($nodes) > 1 or ! $manage_service {
class { '::rabbitmq':
config_cluster => $manage_service,
cluster_nodes => $nodes,
config_kernel_variables => $real_kernel_variables,
config_variables => $config_variables,
environment_variables => $rabbit_env,
}
# when running multi-nodes without Pacemaker
if $manage_service {
rabbitmq_policy { 'ha-all@/':
pattern => '^(?!amq\.).*',
definition => {
'ha-mode' => 'all',
},
}
}
} else {
# Standard configuration
class { '::rabbitmq':
config_kernel_variables => $kernel_variables,
config_variables => $config_variables,
environment_variables => $rabbit_env,
}
}
}
}