Skip to content

Commit 522d36e

Browse files
jaymzhfacebook-github-bot
authored andcommitted
New cookbook: fb_ejabberd (facebook#264)
Summary: A cookbook to manage ejabberd Signed-off-by: Phil Dibowitz <phil@ipom.com> Pull Request resolved: facebook#264 Differential Revision: D69798310 fbshipit-source-id: a4c2bd462a4a2eee9d8bdff8f4cbf7d7ed620dda
1 parent a5dc358 commit 522d36e

File tree

8 files changed

+384
-0
lines changed

8 files changed

+384
-0
lines changed

cookbooks/fb_ejabberd/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
fb_ejabberd Cookbook
2+
====================
3+
4+
Requirements
5+
------------
6+
Currently this only works on Debian/Ubuntu since ejabberd has not been packaged
7+
for Fedora since F37.
8+
9+
Attributes
10+
----------
11+
* node['fb_ejabberd']['config']
12+
* node['fb_ejabberd']['extra_packages']
13+
* node['fb_ejabberd']['manage_packages']
14+
* node['fb_ejabberd']['sysconfig']
15+
16+
Usage
17+
-----
18+
### Packages
19+
20+
This cookbook will install the ejabberd package for your platform along with
21+
any extra packages specified in `extra_packages`. For example:
22+
23+
```ruby
24+
node.default['fb_ejabberd']['extra_packages'] << 'ejabberd-mod-s2s-log'
25+
```
26+
27+
If you prefer to manage packages yourself, set
28+
`node['fb_ejabberd']['manage_packages']` to `false`.
29+
30+
### Configuration
31+
32+
The `ejabberd.yml` config is generated from `node['fb_ejabberd']['config']`. A
33+
basic config is included in attributes, you can change it as you see fit. For
34+
simple setups only `hosts` and `certfiles` should be needed.
35+
36+
### Service environment variables
37+
38+
The environment variables for the service are in
39+
`node['fb_ejabberd']['sysconfig']`, use lowercase, the variables names will be
40+
upcased when the file is generated. Note that `ejabberd_config_path` and
41+
`contrib_modules_conf_dir` are hard-coded, per the FB standard of controlling
42+
the config path, and thus will be ignored if set in this hash.
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
#
2+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
3+
#
4+
# Copyright (c) 2025-present, Meta Platforms, Inc.
5+
# Copyright (c) 2025-present, Phil Dibowitz
6+
# All rights reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
default['fb_ejabberd'] = {
22+
'manage_packages' => true,
23+
'extra_packages' => [],
24+
'sysconfig' => {
25+
'erl_options' => '-env ERL_CRASH_DUMP_BYTES 0',
26+
'erlang_node' => "ejabberd@#{node['hostname']}",
27+
'ejabberd_pid_path' => '/run/ejabberd/ejabberd.pid',
28+
},
29+
'config' => {
30+
'loglevel' => 5,
31+
'log_rotate_size' => 'infinity',
32+
'hosts' => [],
33+
'certfiles' => [],
34+
'acme' => {
35+
'auto' => false,
36+
},
37+
'define_macro' => {
38+
'TLS_CIPHERS' => 'HIGH:!aNULL:!eNULL:!3DES:@STRENGTH',
39+
'TLS_OPTIONS' => [
40+
'no_sslv3',
41+
'no_tlsv1',
42+
'no_tlsv1_1',
43+
'cipher_server_preference',
44+
'no_compression',
45+
],
46+
},
47+
'c2s_ciphers' => 'TLS_CIPHERS',
48+
's2s_ciphers' => 'TLS_CIPHERS',
49+
'c2s_protocol_options' => 'TLS_OPTIONS',
50+
's2s_protocol_options' => 'TLS_OPTIONS',
51+
'listen' => [
52+
{
53+
'port' => 5222,
54+
'ip' => '::',
55+
'module' => 'ejabberd_c2s',
56+
'max_stanza_size' => 262144,
57+
'shaper' => 'c2s_shaper',
58+
'access' => 'c2s',
59+
'starttls' => true,
60+
'starttls_required' => true,
61+
'protocol_options' => 'TLS_OPTIONS',
62+
},
63+
{
64+
'port' => 5269,
65+
'ip' => '::',
66+
'module' => 'ejabberd_s2s_in',
67+
},
68+
],
69+
'disable_sasl_mechanisms' => [
70+
'digest-md5',
71+
'X-OAUTH2',
72+
],
73+
's2s_use_starttls' => 'required',
74+
'auth_method' => 'internal',
75+
'resource_conflict' => 'closeold',
76+
'auth_password_format' => 'scram',
77+
'shaper' => {
78+
'normal' => {
79+
'rate' => 3000,
80+
'burst_size' => 20000,
81+
},
82+
'fast' => 200000,
83+
},
84+
'shaper_rules' => {
85+
'max_user_sessions' => 10,
86+
'max_user_offline_messages' => {
87+
5000 => 'admin',
88+
100 => 'all',
89+
},
90+
'c2s_shaper' => {
91+
'none' => 'admin',
92+
'normal' => 'all',
93+
},
94+
's2s_shaper' => 'fast',
95+
},
96+
'max_fsm_queue' => 1000,
97+
'acl' => {
98+
'local' => {
99+
'user_regexp' => '',
100+
},
101+
'loopback' => {
102+
'ip' => [
103+
'127.0.0.0/8',
104+
],
105+
},
106+
},
107+
'access_rules' => {
108+
'local' => {
109+
'allow' => 'local',
110+
},
111+
'c2s' => {
112+
'deny' => 'blocked',
113+
'allow' => 'all',
114+
},
115+
'announce' => {
116+
'allow' => 'admin',
117+
},
118+
'configure' => {
119+
'allow' => 'admin',
120+
},
121+
'muc_create' => {
122+
'allow' => 'local',
123+
},
124+
'pubsub_createnode' => {
125+
'allow' => 'local',
126+
},
127+
'trusted_network' => {
128+
'allow' => 'loopback',
129+
},
130+
},
131+
'api_permissions' => {
132+
'console commands' => {
133+
'from' => [
134+
'ejabberd_ctl',
135+
],
136+
'who' => 'all',
137+
'what' => '*',
138+
},
139+
'admin access' => {
140+
'who' => {
141+
'access' => {
142+
'allow' => [
143+
{ 'acl' => 'loopback' },
144+
{ 'acl' => 'admin' },
145+
],
146+
},
147+
'oauth' => {
148+
'scope' => 'ejabberd:admin',
149+
'access' => {
150+
'allow' => [
151+
{ 'acl' => 'loopback' },
152+
{ 'acl' => 'admin' },
153+
],
154+
},
155+
},
156+
},
157+
'what' => [
158+
'*',
159+
'!stop',
160+
'!start',
161+
],
162+
},
163+
'public commands' => {
164+
'who' => {
165+
'ip' => '127.0.0.1/8',
166+
},
167+
'what' => [
168+
'status',
169+
'connected_users_number',
170+
],
171+
},
172+
},
173+
'language' => 'en',
174+
'modules' => {
175+
'mod_adhoc' => {},
176+
'mod_admin_extra' => {},
177+
'mod_announce' => {
178+
'access' => 'announce',
179+
},
180+
'mod_blocking' => {},
181+
'mod_bosh' => {},
182+
'mod_caps' => {},
183+
'mod_carboncopy' => {},
184+
'mod_configure' => {},
185+
'mod_disco' => {},
186+
'mod_fail2ban' => {},
187+
'mod_http_api' => {},
188+
'mod_last' => {},
189+
'mod_mqtt' => {},
190+
'mod_muc' => {
191+
'access' => [
192+
'allow',
193+
],
194+
'access_admin' => [
195+
{
196+
'allow' => 'admin',
197+
},
198+
],
199+
'access_create' => 'muc_create',
200+
'access_persistent' => 'muc_create',
201+
'access_mam' => [
202+
'allow',
203+
],
204+
'default_room_options' => {
205+
'mam' => true,
206+
},
207+
},
208+
'mod_muc_admin' => {},
209+
'mod_offline' => {
210+
'access_max_user_messages' => 'max_user_offline_messages',
211+
},
212+
'mod_ping' => {},
213+
'mod_privacy' => {},
214+
'mod_private' => {},
215+
'mod_pubsub' => {
216+
'access_createnode' => 'pubsub_createnode',
217+
'ignore_pep_from_offline' => true,
218+
'last_item_cache' => false,
219+
'plugins' => [
220+
'flat',
221+
'pep',
222+
],
223+
'force_node_config' => {
224+
'eu.siacs.conversations.axolotl.*' => {
225+
'access_model' => 'open',
226+
},
227+
'storage:bookmarks:' => {
228+
'access_model' => 'whitelist',
229+
},
230+
},
231+
},
232+
'mod_push' => {},
233+
'mod_push_keepalive' => {},
234+
'mod_register' => {
235+
'welcome_message' => {
236+
'subject' => 'Welcome!',
237+
'body' => "Hi.\nWelcome to this XMPP server.\n",
238+
},
239+
'ip_access' => 'trusted_network',
240+
'access' => 'register',
241+
},
242+
'mod_roster' => {
243+
'versioning' => true,
244+
},
245+
'mod_s2s_dialback' => {},
246+
'mod_shared_roster' => {},
247+
'mod_sic' => {},
248+
'mod_stream_mgmt' => {
249+
'resend_on_timeout' => 'if_offline',
250+
},
251+
'mod_stun_disco' => {},
252+
'mod_stats' => {},
253+
'mod_time' => {},
254+
'mod_vcard' => {
255+
'search' => false,
256+
},
257+
'mod_vcard_xupdate' => {},
258+
'mod_version' => {},
259+
},
260+
},
261+
}

cookbooks/fb_ejabberd/metadata.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name 'fb_ejabberd'
2+
maintainer 'Meta Platforms, Inc.'
3+
maintainer_email 'noreply@meta.com'
4+
license 'Apache-2.0'
5+
description 'Installs/Configures ejabberd'
6+
version '0.1.0'
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Cookbook:: fb_ejabberd
3+
# Recipe:: default
4+
#
5+
# Copyright (c) 2025-present, Meta Platforms, Inc.
6+
# Copyright (c) 2025-present, Phil Dibowitz
7+
# All rights reserved.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
#
21+
22+
package 'ejabberd packages' do
23+
only_if { node['fb_ejabberd']['manage_packages'] }
24+
package_name lazy {
25+
['ejabberd'] + node['fb_ejabberd']['extra_packages']
26+
}
27+
action :upgrade
28+
end
29+
30+
template '/etc/ejabberd/ejabberd.yml' do
31+
owner 'ejabberd'
32+
group 'ejabberd'
33+
mode '0640'
34+
notifies :restart, 'service[ejabberd]'
35+
end
36+
37+
template '/etc/default/ejabberd' do
38+
source 'sysconfig.erb'
39+
owner node.root_user
40+
group node.root_group
41+
mode '0644'
42+
notifies :restart, 'service[ejabberd]'
43+
end
44+
45+
service 'ejabberd' do
46+
# if you try to restart ejabberd, often times epmd will still
47+
# be holding it's port open. If you stop epmd.service (which doesn't
48+
# stop its socket), and restart ejabberd, that'll start everything
49+
# up properly
50+
restart_command '
51+
systemctl stop ejabberd
52+
systemctl stop epmd
53+
systemctl restart ejabberd'
54+
action [:enable, :start]
55+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is controlled by Chef, do not modify!
2+
<%= node['fb_ejabberd']['config'].to_yaml %>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file is controlled by Chef, do not modify!
2+
<%
3+
# Per fb-style standards, the paths to configs are non-configurable,
4+
# so we hard-code them here
5+
{
6+
'ejabberd_config_path' => '/etc/ejabberd/ejabberd.yml',
7+
'contrib_modules_conf_dir' => '/etc/ejabberd/modules.d',
8+
}.each do |key, val|
9+
node.rm(:fb_ejabberd, :sysconfig, key.to_sym)
10+
%>
11+
<%= key.upcase %>="<%= val %>"
12+
<% end %>
13+
<% node['fb_ejabberd']['sysconfig'].each do |key, val| %>
14+
<%= key.upcase %>="<%= val %>"
15+
<% end %>

cookbooks/test_services/metadata.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
supports 'centos'
1010
depends 'fb_apache'
1111
depends 'fb_apt_cacher'
12+
depends 'fb_ejabberd'
1213
depends 'fb_reprepro'
1314
depends 'fb_smokeping'
1415
depends 'fb_spamassassin'

0 commit comments

Comments
 (0)