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

Lines changed: 135 additions & 60 deletions

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 17 additions & 17 deletions
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

Lines changed: 1 addition & 1 deletion
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
Lines changed: 1 addition & 1 deletion
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]

debian/changelog

Lines changed: 5 additions & 0 deletions
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 <shivam@crowdsec.net> Mon Jun 28 10:52:32 2021 +0530

debian/compat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11

debian/control

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Source: crowdsec-custom-bouncer
2+
Maintainer: Crowdsec Team <debian@crowdsec.net>
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

Lines changed: 33 additions & 0 deletions
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' "

0 commit comments

Comments
 (0)