/
crowdsec-firewall-bouncer.spec
186 lines (142 loc) · 4.81 KB
/
crowdsec-firewall-bouncer.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Name: crowdsec-firewall-bouncer-iptables
Version: %(echo $VERSION)
Release: %(echo $PACKAGE_NUMBER)%{?dist}
Summary: Firewall bouncer for Crowdsec (iptables+ipset configuration)
License: MIT
URL: https://crowdsec.net
Source0: https://github.com/crowdsecurity/%{name}/archive/v%(echo $VERSION).tar.gz
Source1: 80-crowdsec-firewall-bouncer.preset
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: make
%{?fc33:BuildRequires: systemd-rpm-macros}
Requires: gettext,iptables,ipset,ipset-libs
%define debug_package %{nil}
%define version_number %(echo $VERSION)
%define releasever %(echo $RELEASEVER)
%global local_version v%{version_number}-%{releasever}-rpm
%global name crowdsec-firewall-bouncer
%global __mangle_shebangs_exclude_from /usr/bin/env
%prep
%setup -q -T -b 0 -n %{name}-%{version_number}
%build
BUILD_VERSION=%{local_version} make
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_bindir}
install -m 755 %{name} %{buildroot}%{_bindir}/%{name}
# symlink for compatibility with old versions
mkdir -p %{buildroot}/usr/sbin
ln -s %{_bindir}/%{name} %{buildroot}/usr/sbin/%{name}
mkdir -p %{buildroot}/etc/crowdsec/bouncers
install -m 600 config/%{name}.yaml %{buildroot}/etc/crowdsec/bouncers/%{name}.yaml
mkdir -p %{buildroot}/usr/lib/%{name}
install -m 600 scripts/_bouncer.sh %{buildroot}/usr/lib/%{name}/_bouncer.sh
mkdir -p %{buildroot}%{_unitdir}
BIN=%{_bindir}/%{name} CFG=/etc/crowdsec/bouncers envsubst '$BIN $CFG' < config/%{name}.service | install -m 0644 /dev/stdin %{buildroot}%{_unitdir}/%{name}.service
mkdir -p %{buildroot}%{_presetdir}
install -D -m 644 %{SOURCE1} %{buildroot}%{_presetdir}/
%clean
rm -rf %{buildroot}
%changelog
* Tue Feb 16 2021 Manuel Sabban <manuel@crowdsec.net>
- First initial packaging
# ------------------------------------
# iptables
# ------------------------------------
%description -n %{name}-iptables
%files -n %{name}-iptables
%defattr(-,root,root,-)
%{_bindir}/%{name}
/usr/lib/%{name}/_bouncer.sh
%{_unitdir}/%{name}.service
%config(noreplace) /etc/crowdsec/bouncers/%{name}.yaml
%config(noreplace) %{_presetdir}/80-crowdsec-firewall-bouncer.preset
%post -n %{name}-iptables
systemctl daemon-reload
. /usr/lib/%{name}/_bouncer.sh
START=1
if grep -q '${BACKEND}' "$CONFIG"; then
newconfig=$(BACKEND="iptables" envsubst '$BACKEND' < "$CONFIG")
echo "$newconfig" | install -m 0600 /dev/stdin "$CONFIG"
fi
if [ "$1" = "1" ]; then
if need_api_key; then
if ! set_api_key; then
START=0
fi
fi
fi
set_local_port
%systemd_post %{name}.service
if [ "$START" -eq 0 ]; then
echo "no api key was generated, you can generate one on your LAPI Server by running 'cscli bouncers add <bouncer_name>' and add it to '$CONFIG'" >&2
else
%if 0%{?fc35}
systemctl enable "$SERVICE"
%endif
systemctl start "$SERVICE"
fi
echo "$BOUNCER has been successfully installed"
%preun -n %{name}-iptables
. /usr/lib/%{name}/_bouncer.sh
if [ "$1" = "0" ]; then
systemctl stop "$SERVICE" || echo "cannot stop service"
systemctl disable "$SERVICE" || echo "cannot disable service"
delete_bouncer
fi
%postun -n %{name}-iptables
if [ "$1" = "1" ]; then
systemctl restart %{name} || echo "cannot restart service"
fi
# ------------------------------------
# nftables
# ------------------------------------
%package -n %{name}-nftables
Summary: Firewall bouncer for Crowdsec (nftables configuration)
Requires: nftables,gettext
%description -n %{name}-nftables
%files -n %{name}-nftables
%defattr(-,root,root,-)
%{_bindir}/%{name}
/usr/sbin/%{name}
/usr/lib/%{name}/_bouncer.sh
%{_unitdir}/%{name}.service
%config(noreplace) /etc/crowdsec/bouncers/%{name}.yaml
%config(noreplace) %{_presetdir}/80-crowdsec-firewall-bouncer.preset
%post -n %{name}-nftables
systemctl daemon-reload
. /usr/lib/%{name}/_bouncer.sh
START=1
if grep -q '${BACKEND}' "$CONFIG"; then
newconfig=$(BACKEND="nftables" envsubst '$BACKEND' < "$CONFIG")
echo "$newconfig" | install -m 0600 /dev/stdin "$CONFIG"
fi
if [ "$1" = "1" ]; then
if need_api_key; then
if ! set_api_key; then
START=0
fi
fi
fi
set_local_port
%systemd_post %{name}.service
if [ "$START" -eq 0 ]; then
echo "no api key was generated, you can generate one on your LAPI Server by running 'cscli bouncers add <bouncer_name>' and add it to '$CONFIG'" >&2
else
%if 0%{?fc35}
systemctl enable "$SERVICE"
%endif
systemctl start "$SERVICE"
fi
echo "$BOUNCER has been successfully installed"
%preun -n %{name}-nftables
. /usr/lib/%{name}/_bouncer.sh
if [ "$1" = "0" ]; then
systemctl stop "$SERVICE" || echo "cannot stop service"
systemctl disable "$SERVICE" || echo "cannot disable service"
delete_bouncer
fi
%postun -n %{name}-nftables
if [ "$1" = "1" ]; then
systemctl restart %{name} || echo "cannot restart service"
fi