Skip to content

Commit e32f549

Browse files
authored
Merge pull request crowdsecurity#13 from sbs2001/debian
Add debian packaging for the bouncer
2 parents 2ee936a + bfa928f commit e32f549

17 files changed

+135
-60
lines changed

.github/workflows/build-binary-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ jobs:
2222
- name: Upload to release
2323
uses: JasonEtco/upload-to-release@master
2424
with:
25-
args: cs-custom-bouncer.tgz application/x-gzip
25+
args: crowdsec-custom-bouncer.tgz application/x-gzip
2626
env:
2727
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ GOGET=$(GOCMD) get
88

99
PREFIX?="/"
1010
PID_DIR = $(PREFIX)"/var/run/"
11-
BINARY_NAME=cs-custom-bouncer
11+
BINARY_NAME=crowdsec-custom-bouncer
1212

1313

1414
#Current versioning information from env
1515
BUILD_VERSION?="$(shell git describe --tags `git rev-list --tags --max-count=1`)"
1616
BUILD_GOVERSION="$(shell go version | cut -d " " -f3 | sed -r 's/[go]+//g')"
1717
BUILD_TIMESTAMP=$(shell date +%F"_"%T)
1818
BUILD_TAG="$(shell git rev-parse HEAD)"
19-
export LD_OPTS=-ldflags "-s -w -X github.com/crowdsecurity/cs-custom-bouncer/pkg/version.Version=$(BUILD_VERSION) \
20-
-X github.com/crowdsecurity/cs-custom-bouncer/pkg/version.BuildDate=$(BUILD_TIMESTAMP) \
21-
-X github.com/crowdsecurity/cs-custom-bouncer/pkg/version.Tag=$(BUILD_TAG) \
22-
-X github.com/crowdsecurity/cs-custom-bouncer/pkg/version.GoVersion=$(BUILD_GOVERSION)"
19+
export LD_OPTS=-ldflags "-s -w -X github.com/crowdsecurity/crowdsec-custom-bouncer/pkg/version.Version=$(BUILD_VERSION) \
20+
-X github.com/crowdsecurity/crowdsec-custom-bouncer/pkg/version.BuildDate=$(BUILD_TIMESTAMP) \
21+
-X github.com/crowdsecurity/crowdsec-custom-bouncer/pkg/version.Tag=$(BUILD_TAG) \
22+
-X github.com/crowdsecurity/crowdsec-custom-bouncer/pkg/version.GoVersion=$(BUILD_GOVERSION)"
2323

24-
RELDIR = "cs-custom-bouncer-${BUILD_VERSION}"
24+
RELDIR = "crowdsec-custom-bouncer-${BUILD_VERSION}"
2525

2626

2727
all: clean test build
@@ -38,7 +38,7 @@ test:
3838
clean:
3939
@rm -f $(BINARY_NAME)
4040
@rm -rf ${RELDIR}
41-
@rm -f cs-custom-bouncer.tgz || ""
41+
@rm -f crowdsec-custom-bouncer.tgz || ""
4242

4343

4444
.PHONY: release
@@ -55,5 +55,5 @@ release: build
5555
@chmod +x $(RELDIR)/install.sh
5656
@chmod +x $(RELDIR)/uninstall.sh
5757
@chmod +x $(RELDIR)/upgrade.sh
58-
@tar cvzf cs-custom-bouncer.tgz $(RELDIR)
58+
@tar cvzf crowdsec-custom-bouncer.tgz $(RELDIR)
5959

README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img src="https://github.com/crowdsecurity/cs-custom-bouncer/raw/main/docs/assets/crowdsec_custom_logo.png" alt="CrowdSec" title="CrowdSec" width="280" height="300" />
2+
<img src="https://github.com/crowdsecurity/crowdsec-custom-bouncer/raw/main/docs/assets/crowdsec_custom_logo.png" alt="CrowdSec" title="CrowdSec" width="280" height="300" />
33
</p>
44
<p align="center">
55
<img src="https://img.shields.io/badge/build-pass-green">
@@ -12,19 +12,19 @@
1212
</p>
1313

1414

15-
# cs-custom-bouncer
15+
# crowdsec-custom-bouncer
1616
Crowdsec bouncer written in golang for custom scripts.
1717

18-
cs-custom-bouncer will periodically fetch new and expired/removed decisions from CrowdSec Local API and will pass them as arguments to a custom user script.
18+
crowdsec-custom-bouncer will periodically fetch new and expired/removed decisions from CrowdSec Local API and will pass them as arguments to a custom user script.
1919

2020
## Installation
2121

2222
### With installer
2323

24-
First, download the latest [`cs-custom-bouncer` release](https://github.com/crowdsecurity/cs-custom-bouncer/releases).
24+
First, download the latest [`crowdsec-custom-bouncer` release](https://github.com/crowdsecurity/crowdsec-custom-bouncer/releases).
2525

2626
```sh
27-
$ tar xzvf cs-custom-bouncer.tgz
27+
$ tar xzvf crowdsec-custom-bouncer.tgz
2828
$ sudo ./install.sh
2929
```
3030

@@ -33,28 +33,28 @@ $ sudo ./install.sh
3333
Run the following commands:
3434

3535
```bash
36-
git clone https://github.com/crowdsecurity/cs-custom-bouncer.git
37-
cd cs-custom-bouncer/
36+
git clone https://github.com/crowdsecurity/crowdsec-custom-bouncer.git
37+
cd crowdsec-custom-bouncer/
3838
make release
39-
tar xzvf cs-custom-bouncer.tgz
40-
cd cs-custom-bouncer-v*/
39+
tar xzvf crowdsec-custom-bouncer.tgz
40+
cd crowdsec-custom-bouncer-v*/
4141
sudo ./install.sh
4242
```
4343

4444
### Start
4545

4646
If your bouncer runs on the same machine as your crowdsec local API, you can start the service directly since the `install.sh` took care of the configuration.
4747
```sh
48-
sudo systemctl start cs-custom-bouncer
48+
sudo systemctl start crowdsec-custom-bouncer
4949
```
5050

5151
## Upgrade
5252

53-
If you already have `cs-custom-bouncer` installed, please download the [latest release](https://github.com/crowdsecurity/cs-custom-bouncer/releases) and run the following commands to upgrade it:
53+
If you already have `crowdsec-custom-bouncer` installed, please download the [latest release](https://github.com/crowdsecurity/crowdsec-custom-bouncer/releases) and run the following commands to upgrade it:
5454

5555
```bash
56-
tar xzvf cs-custom-bouncer.tgz
57-
cd cs-custom-bouncer-v*/
56+
tar xzvf crowdsec-custom-bouncer.tgz
57+
cd crowdsec-custom-bouncer-v*/
5858
sudo ./upgrade.sh
5959
```
6060

@@ -83,11 +83,11 @@ custom_binary.sh del 1.2.3.4/32 3600 "test blacklist"
8383

8484
## Configuration
8585

86-
Before starting the `cs-custom-bouncer` service, please edit the configuration to add your API url and key.
87-
The default configuration file is located under : `/etc/crowdsec/cs-custom-bouncer/`
86+
Before starting the `crowdsec-custom-bouncer` service, please edit the configuration to add your API url and key.
87+
The default configuration file is located under : `/etc/crowdsec/crowdsec-custom-bouncer/`
8888

8989
```sh
90-
$ vim /etc/crowdsec/custom-bouncer/cs-custom-bouncer.yaml
90+
$ vim /etc/crowdsec/custom-bouncer/crowdsec-custom-bouncer.yaml
9191
```
9292

9393
```yaml
@@ -105,5 +105,5 @@ api_key: <API_KEY> # Add your API key generated with `cscli bouncers add --name
105105
You can then start the service:
106106
107107
```sh
108-
sudo systemctl start cs-custom-bouncer
108+
sudo systemctl start crowdsec-custom-bouncer
109109
```

config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewConfig(configPath string) (*bouncerConfig, error) {
5959
config.LogDir = "/var/log/"
6060
}
6161
LogOutput = &lumberjack.Logger{
62-
Filename: config.LogDir + "/cs-custom-bouncer.log",
62+
Filename: config.LogDir + "/crowdsec-custom-bouncer.log",
6363
MaxSize: 500, //megabytes
6464
MaxBackups: 3,
6565
MaxAge: 28, //days

config/cs-custom-bouncer.service config/crowdsec-custom-bouncer.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ After=syslog.target network.target remote-fs.target nss-lookup.target crowdsec.s
55

66
[Service]
77
Type=notify
8-
ExecStart=${BIN} -c ${CFG}/cs-custom-bouncer.yaml
8+
ExecStart=${BIN} -c ${CFG}/crowdsec-custom-bouncer.yaml
99
ExecStartPost=/bin/sleep 0.1
1010

1111
[Install]
File renamed without changes.

debian/changelog

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
crowdsec-custom-bouncer (1.0.0) UNRELEASED; urgency=medium
2+
3+
* Initial debian packaging
4+
5+
-- Shivam Sandbhor <[email protected]> Mon Jun 28 10:52:32 2021 +0530

debian/compat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11

debian/control

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Source: crowdsec-custom-bouncer
2+
Maintainer: Crowdsec Team <[email protected]>
3+
Build-Depends: debhelper, bash
4+
5+
Package: crowdsec-custom-bouncer
6+
Provides: crowdsec-custom-bouncer
7+
Description: Custom bouncer for Crowdsec
8+
Architecture: any
9+
10+
11+

debian/postinst

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
systemctl daemon-reload
3+
4+
5+
START=0
6+
7+
dpkg -l crowdsec | grep -q ^ii >/dev/null
8+
9+
if [ "$?" -eq "0" ] ; then
10+
START=1
11+
echo "cscli/crowdsec is present, generating API key"
12+
unique=`date +%s`
13+
API_KEY=`cscli -oraw bouncers add CustomBouncer-${unique}`
14+
if [ $? -eq 1 ] ; then
15+
echo "failed to create API token, service won't be started."
16+
START=0
17+
API_KEY="<API_KEY>"
18+
else
19+
echo "API Key : ${API_KEY}"
20+
fi
21+
fi
22+
23+
24+
TMP=`mktemp -p /tmp/`
25+
cp /etc/crowdsec/crowdsec-custom-bouncer/crowdsec-custom-bouncer.yaml ${TMP}
26+
API_KEY=${API_KEY} envsubst < ${TMP} > /etc/crowdsec/crowdsec-custom-bouncer/crowdsec-custom-bouncer.yaml
27+
rm ${TMP}
28+
29+
if [ ${START} -eq 0 ] ; then
30+
echo "no api key was generated"
31+
fi
32+
33+
echo "please enter the binary path in '/etc/crowdsec/crowdsec-custom-bouncer/crowdsec-custom-bouncer.yaml' and start the bouncer via 'sudo systemctl start crowdsec-custom-bouncer' "

debian/prerm

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
systemctl stop crowdsec-custom-bouncer || echo "cannot stop service"
2+
systemctl disable crowdsec-custom-bouncer || echo "cannot disable service"

debian/rules

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/make -f
2+
3+
export DEB_VERSION=$(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
4+
export BUILD_VERSION=v${DEB_VERSION}-debian-pragmatic
5+
export GO111MODULE=on
6+
7+
8+
%:
9+
dh $@
10+
11+
override_dh_systemd_start:
12+
echo "Not running dh_systemd_start"
13+
override_dh_auto_clean:
14+
override_dh_auto_test:
15+
override_dh_auto_build:
16+
override_dh_auto_install:
17+
make
18+
mkdir -p debian/crowdsec-custom-bouncer/usr/sbin
19+
cp crowdsec-custom-bouncer debian/crowdsec-custom-bouncer/usr/sbin
20+
mkdir -p debian/crowdsec-custom-bouncer/etc/systemd/system/
21+
mkdir -p debian/crowdsec-custom-bouncer/etc/crowdsec/crowdsec-custom-bouncer/
22+
BIN=/sbin/crowdsec-custom-bouncer CFG=/etc/crowdsec/crowdsec-custom-bouncer envsubst < config/crowdsec-custom-bouncer.service > debian/crowdsec-custom-bouncer/etc/systemd/system/crowdsec-custom-bouncer.service
23+
cp config/crowdsec-custom-bouncer.yaml debian/crowdsec-custom-bouncer/etc/crowdsec/crowdsec-custom-bouncer/

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/crowdsecurity/cs-custom-bouncer
1+
module github.com/crowdsecurity/crowdsec-custom-bouncer
22

33
go 1.14
44

main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"github.com/coreos/go-systemd/daemon"
1212
log "github.com/sirupsen/logrus"
1313

14-
"github.com/crowdsecurity/cs-custom-bouncer/pkg/version"
14+
"github.com/crowdsecurity/crowdsec-custom-bouncer/pkg/version"
1515
csbouncer "github.com/crowdsecurity/go-cs-bouncer"
1616
"gopkg.in/tomb.v2"
1717
)
1818

1919
const (
20-
name = "cs-custom-bouncer"
20+
name = "crowdsec-custom-bouncer"
2121
)
2222

2323
var t tomb.Tomb
@@ -56,8 +56,8 @@ func HandleSignals(custom *customBouncer) {
5656

5757
func main() {
5858
var err error
59-
log.Infof("cs-custom-bouncer %s", version.VersionStr())
60-
configPath := flag.String("c", "", "path to cs-custom-bouncer.yaml")
59+
log.Infof("crowdsec-custom-bouncer %s", version.VersionStr())
60+
configPath := flag.String("c", "", "path to crowdsec-custom-bouncer.yaml")
6161
verbose := flag.Bool("v", false, "set verbose mode")
6262

6363
flag.Parse()

scripts/install.sh

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bash
2-
BIN_PATH_INSTALLED="/usr/local/bin/cs-custom-bouncer"
3-
BIN_PATH="./cs-custom-bouncer"
4-
CONFIG_DIR="/etc/crowdsec/cs-custom-bouncer/"
2+
BIN_PATH_INSTALLED="/usr/local/bin/crowdsec-custom-bouncer"
3+
BIN_PATH="./crowdsec-custom-bouncer"
4+
CONFIG_DIR="/etc/crowdsec/crowdsec-custom-bouncer/"
55
PID_DIR="/var/run/crowdsec/"
6-
SYSTEMD_PATH_FILE="/etc/systemd/system/cs-custom-bouncer.service"
6+
SYSTEMD_PATH_FILE="/etc/systemd/system/crowdsec-custom-bouncer.service"
77
API_KEY=""
88
BINARY_PATH=""
99

@@ -12,7 +12,7 @@ gen_apikey() {
1212
if [[ $? == 0 ]]; then
1313
echo "cscli found, generating bouncer api key."
1414
SUFFIX=`tr -dc A-Za-z0-9 </dev/urandom | head -c 8`
15-
API_KEY=`cscli bouncers add cs-custom-bouncer-${SUFFIX} -o raw`
15+
API_KEY=`cscli bouncers add crowdsec-custom-bouncer-${SUFFIX} -o raw`
1616
READY="yes"
1717
else
1818
echo "cscli not found, you will need to generate api key."
@@ -31,36 +31,36 @@ gen_binary_path() {
3131
install_custom_bouncer() {
3232
install -v -m 755 -D "${BIN_PATH}" "${BIN_PATH_INSTALLED}"
3333
mkdir -p "${CONFIG_DIR}"
34-
cp "./config/cs-custom-bouncer.yaml" "${CONFIG_DIR}cs-custom-bouncer.yaml"
35-
CFG=${CONFIG_DIR} PID=${PID_DIR} BIN=${BIN_PATH_INSTALLED} envsubst < ./config/cs-custom-bouncer.service > "${SYSTEMD_PATH_FILE}"
34+
cp "./config/crowdsec-custom-bouncer.yaml" "${CONFIG_DIR}crowdsec-custom-bouncer.yaml"
35+
CFG=${CONFIG_DIR} PID=${PID_DIR} BIN=${BIN_PATH_INSTALLED} envsubst < ./config/crowdsec-custom-bouncer.service > "${SYSTEMD_PATH_FILE}"
3636
systemctl daemon-reload
3737
}
3838

3939
gen_config_file() {
40-
API_KEY=${API_KEY} BINARY_PATH=${BINARY_PATH} envsubst < ./config/cs-custom-bouncer.yaml > "${CONFIG_DIR}cs-custom-bouncer.yaml"
40+
API_KEY=${API_KEY} BINARY_PATH=${BINARY_PATH} envsubst < ./config/crowdsec-custom-bouncer.yaml > "${CONFIG_DIR}crowdsec-custom-bouncer.yaml"
4141
}
4242

4343

4444
if ! [ $(id -u) = 0 ]; then
4545
echo "Please run the install script as root or with sudo"
4646
exit 1
4747
fi
48-
echo "Installing cs-custom-bouncer"
48+
echo "Installing crowdsec-custom-bouncer"
4949
install_custom_bouncer
5050
gen_apikey
5151
gen_binary_path
5252
gen_config_file
53-
systemctl enable cs-custom-bouncer.service
53+
systemctl enable crowdsec-custom-bouncer.service
5454
if ! [ -f "$BINARY_PATH" ]; then
55-
echo "$BINARY_PATH doesn't exist, can't start cs-custom-bouncer service."
56-
echo "Please edit ${CONFIG_DIR}cs-custom-bouncer.yaml with a real binary path and run 'sudo systemctl start cs-custom-bouncer'."
55+
echo "$BINARY_PATH doesn't exist, can't start crowdsec-custom-bouncer service."
56+
echo "Please edit ${CONFIG_DIR}crowdsec-custom-bouncer.yaml with a real binary path and run 'sudo systemctl start crowdsec-custom-bouncer'."
5757
exit 1
5858
fi
5959

6060
if [ "$READY" = "yes" ]; then
61-
systemctl start cs-custom-bouncer.service
61+
systemctl start crowdsec-custom-bouncer.service
6262
else
63-
echo "service not started. You need to get an API key and configure it in ${CONFIG_DIR}cs-custom-bouncer.yaml and then run systemctl start cs-custom-bouncer.service"
63+
echo "service not started. You need to get an API key and configure it in ${CONFIG_DIR}crowdsec-custom-bouncer.yaml and then run systemctl start crowdsec-custom-bouncer.service"
6464
fi
6565

66-
echo "cs-custom-bouncer service has been installed!"
66+
echo "crowdsec-custom-bouncer service has been installed!"

scripts/uninstall.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env bash
22

3-
SYSTEMD_PATH_FILE="/etc/systemd/system/cs-custom-bouncer.service"
4-
LOG_FILE="/var/log/cs-custom-bouncer.log"
5-
CONFIG_DIR="/etc/crowdsec/cs-custom-bouncer/"
6-
BIN_PATH_INSTALLED="/usr/local/bin/cs-custom-bouncer"
3+
SYSTEMD_PATH_FILE="/etc/systemd/system/crowdsec-custom-bouncer.service"
4+
LOG_FILE="/var/log/crowdsec-custom-bouncer.log"
5+
CONFIG_DIR="/etc/crowdsec/crowdsec-custom-bouncer/"
6+
BIN_PATH_INSTALLED="/usr/local/bin/crowdsec-custom-bouncer"
77

88
uninstall() {
9-
systemctl stop cs-custom-bouncer
9+
systemctl stop crowdsec-custom-bouncer
1010
rm -rf "${CONFIG_DIR}"
1111
rm -f "${SYSTEMD_PATH_FILE}"
1212
rm -f "${BIN_PATH_INSTALLED}"
@@ -15,4 +15,4 @@ uninstall() {
1515

1616
uninstall
1717

18-
echo "cs-custom-bouncer uninstall successfully"
18+
echo "crowdsec-custom-bouncer uninstall successfully"

scripts/upgrade.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
2-
BIN_PATH_INSTALLED="/usr/local/bin/cs-custom-bouncer"
3-
BIN_PATH="./cs-custom-bouncer"
2+
BIN_PATH_INSTALLED="/usr/local/bin/crowdsec-custom-bouncer"
3+
BIN_PATH="./crowdsec-custom-bouncer"
44

55

66
upgrade_bin() {
7-
rm "${BIN_PATH_INSTALLED}" || (echo "cs-custom-bouncer is not installed, exiting." && exit 1)
7+
rm "${BIN_PATH_INSTALLED}" || (echo "crowdsec-custom-bouncer is not installed, exiting." && exit 1)
88
install -v -m 755 -D "${BIN_PATH}" "${BIN_PATH_INSTALLED}"
99
}
1010

@@ -14,7 +14,7 @@ if ! [ $(id -u) = 0 ]; then
1414
exit 1
1515
fi
1616

17-
systemctl stop cs-custom-bouncer
17+
systemctl stop crowdsec-custom-bouncer
1818
upgrade_bin
19-
systemctl start cs-custom-bouncer
20-
echo "cs-custom-bouncer upgraded successfully."
19+
systemctl start crowdsec-custom-bouncer
20+
echo "crowdsec-custom-bouncer upgraded successfully."

0 commit comments

Comments
 (0)