Kaynağa Gözat

- NATS TLS und Authentifizierung eingebaut
- RPM build für Centos 7 eingbaut

Tobias Begalke 7 yıl önce
ebeveyn
işleme
fd62c6a8af

+ 2 - 0
after-install-trigger-centos7.sh

@@ -0,0 +1,2 @@
+#!/bin/sh
+

+ 4 - 0
before-uninstall-trigger-centos7.sh

@@ -0,0 +1,4 @@
+#!/bin/sh
+
+systemctl stop munchclient
+systemctl disable munchclient

+ 53 - 0
build-rpm-centos7.sh

@@ -0,0 +1,53 @@
+#!/bin/bash
+
+DESTDIR=./dist
+VERSION=$(git describe --tag | sed 's/^v//')
+ITERATION=1
+BINARY=munchclient
+DEFAULTS_FILE="$BINARY"
+CONFIG_FILE="$BINARY.toml"
+SERVICE_FILE="$BINARY.service"
+PKG_TYPE=rpm
+DESCR="ScraperWall traffic collector"
+RPM_DIR=/opt/rpm.scraperwall.com/centos7
+
+
+rm -rf $DESTDIR
+install -d $DESTDIR/{usr/bin,etc/systemd/system,etc/default,etc/munchclient,usr/share/$BINARY}
+make
+
+install -v -m 755 $BINARY $DESTDIR/usr/bin/
+install -v -m 644 defaults/$DEFAULTS_FILE $DESTDIR/etc/default/
+install -v -m 644 defaults/$DEFAULTS_FILE $DESTDIR/usr/share/$BINARY/$DEFAULTS_FILE.defaults
+install -v -m 644 $SERVICE_FILE $DESTDIR/etc/systemd/system
+install -v -m 644 $BINARY.toml $DESTDIR/etc/$BINARY/
+install -v -m 644 $BINARY.toml $DESTDIR/usr/share/$BINARY/
+install -v -m 644 ca-chain.cert.pem $DESTDIR/etc/$BINARY/
+
+
+fpm -s dir -t $PKG_TYPE -C $DESTDIR --name $BINARY \
+  --version $VERSION \
+  --iteration $ITERATION \
+  --description "$DESCR" \
+  --config-files "etc/default/$BINARY" \
+  --config-files "etc/$BINARY/$CONFIG_FILE" \
+  --rpm-trigger-after-install "[]$BINARY: ./after-install-trigger-centos7.sh" \
+  --rpm-trigger-before-uninstall "[]$BINARY: ./before-uninstall-trigger-centos7.sh" \
+  -p rpms-centos7 \
+  --rpm-sign
+
+ok=$?
+
+rm -rf $DESTDIR
+
+exit
+
+rpm_file="$BINARY-$VERSION-$ITERATION.x86_64.rpm"
+if [ $ok -eq 0 -a -f "$rpm_file" ]; then
+	rm -f "$RPM_DIR/$BINARY-*.rpm"
+  cp "$rpm_file" "$RPM_DIR"
+
+	(cd "$RPM_DIR" && \
+   createrepo -v . && \
+   rsync -av --progress --delete . fender.spyz.org:/srv/http-vhosts/rpm.scraperwall.com/)
+fi

+ 1 - 0
build-rpm.sh

@@ -21,6 +21,7 @@ install -v -m 644 defaults/$DEFAULTS_FILE $DESTDIR/etc/default/
 install -v -m 644 logrotate.d/munchclient $DESTDIR/etc/logrotate.d/
 install -v -m 644 munchclient.toml $DESTDIR/etc/
 install -v -m 644 munchclient.toml $DESTDIR/usr/share/munchclient/
+install -v -m 644 ca-bundle.cert.pem $DESTDIR/usr/share/munchclient/
 install -v -m 644 defaults/$DEFAULTS_FILE $DESTDIR/usr/share/munchclient/$DEFAULTS_FILE.defaults
 
 

+ 68 - 0
ca-chain.cert.pem

@@ -0,0 +1,68 @@
+-----BEGIN CERTIFICATE-----
+MIIF3jCCA8agAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwfjELMAkGA1UEBhMCREUx
+DzANBgNVBAgMBkJheWVybjEUMBIGA1UEBwwLV2VuZGVsc3RlaW4xFDASBgNVBAoM
+C1NjcmFwZXJXYWxsMQswCQYDVQQLDAJJVDElMCMGCSqGSIb3DQEJARYWdG9iaWFz
+QHNjcmFwZXJ3YWxsLmNvbTAeFw0xNzA5MTgwOTA0NTNaFw0yNzA5MTYwOTA0NTNa
+MH4xCzAJBgNVBAYTAkRFMQ8wDQYDVQQIDAZCYXllcm4xFDASBgNVBAoMC1NjcmFw
+ZXJXYWxsMQswCQYDVQQLDAJJVDEUMBIGA1UEAwwLU2NyYXBlcldhbGwxJTAjBgkq
+hkiG9w0BCQEWFnRvYmlhc0BzY3JhcGVyd2FsbC5jb20wggIiMA0GCSqG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VFqH+H6mdzRQ+npLJv6SlYWQVipDEhLW
+bgjYDG4RFPS7Z/Ov1tnToP/3w1JX0GPVmaciZzUFI0RkVVeE1xQ0y2xZoTP6vOCU
+sz5XtcHfVm5Yy2Jif7gKRJsgxZ+nZIYz3v1A1qQUBg7LInHRiOOpPWC3tNozHItG
+x7P5wnrlOonzBP0cVb/H6PseJiG8LcIV/wpBoDkI3xQeL6MpGZo/JVxce5nvo/wY
+4O4j0ZkaQ+nRuwURzSYEReJ9OZ6hI7SF05tbgLFWsCC2gbamjR1HlJbIvKWIrk9N
+DTgSBVQllZBBXGhA3sUtFwkK5kBspiSvJq69MgyNTaeWGhcQUxsCuLDauCdQoEkx
+i+RpSV9AFOppV84bdkb1p3dFw7kODmdYjYGRZKeXfEr22A3LdEMqnQG5aMM9nZhn
+FX5dpthz4spuQlN99y0xYMqT6fRD+xbywyNiUTxkn+huOsWB9CvN7Xcy3qfiQDPg
+5ssLsSm1nRwc9YF3pqWl4pcd8mJdSg==
+-----END CERTIFICATE-----

+ 20 - 1
main.go

@@ -35,7 +35,10 @@ var (
 	filter                = flag.String("filter", "tcp", "PCAP filter expression")
 	promiscuous           = flag.Bool("promiscuous", false, "Switch interface into promiscuous mode?")
 	natsURL               = flag.String("nats-url", "nats://127.0.0.1:4222", "The URL of the NATS server")
+	natsUser              = flag.String("nats-user", "", "The user for NATS authentication")
+	natsPassword          = flag.String("nats-password", "", "The password for NATS authentication")
 	natsQueue             = flag.String("nats-queue", "requests", "The NATS queue name")
+	natsCA                = flag.String("nats-ca", "", "CA chain for NATS TLS")
 	sleepFor              = flag.Duration("sleep", 0, "Sleep this long between sending data (only when replaying a file)")
 	requestsFile          = flag.String("requests", "", "CSV file containing requests (IP and URL)")
 	protocol              = flag.String("protocol", "http", "which protocol to parse: http or ajp13")
@@ -69,6 +72,9 @@ type Config struct {
 	Promiscuous           bool
 	NatsURL               string
 	NatsQueue             string
+	NatsUser              string
+	NatsPassword          string
+	NatsCA                string
 	SleepFor              duration
 	RequestsFile          string
 	UseXForwardedAsSource bool
@@ -96,6 +102,9 @@ func (c Config) print() {
 	fmt.Printf("Promiscuous:           %t\n", c.Promiscuous)
 	fmt.Printf("NatsURL:               %s\n", c.NatsURL)
 	fmt.Printf("NatsQueue:             %s\n", c.NatsQueue)
+	fmt.Printf("NatsUser:              %s\n", c.NatsUser)
+	fmt.Printf("NatsPassword:          %s\n", c.NatsPassword)
+	fmt.Printf("NatsCA:                %s\n", c.NatsCA)
 	fmt.Printf("SleepFor:              %s\n", c.SleepFor.String())
 	fmt.Printf("RequestsFile:          %s\n", c.RequestsFile)
 	fmt.Printf("Apache Log:            %s\n", c.ApacheLog)
@@ -136,7 +145,14 @@ func main() {
 		log.Fatal("No NATS URL specified (-nats-url)!")
 	}
 
-	natsConn, err := nats.Connect(config.NatsURL)
+	var natsConn *nats.Conn
+	var err error
+
+	if config.NatsUser != "" && config.NatsPassword != "" && config.NatsCA != "" {
+		natsConn, err = nats.Connect(config.NatsURL, nats.UserInfo(config.NatsUser, config.NatsPassword), nats.RootCAs(config.NatsCA))
+	} else {
+		natsConn, err = nats.Connect(config.NatsURL)
+	}
 	if err != nil {
 		log.Fatal(err)
 	}
@@ -541,6 +557,9 @@ func loadConfig() {
 	config.Promiscuous = *promiscuous
 	config.NatsURL = *natsURL
 	config.NatsQueue = *natsQueue
+	config.NatsUser = *natsUser
+	config.NatsPassword = *natsPassword
+	config.NatsCA = *natsCA
 	config.SleepFor.Duration = *sleepFor
 	config.RequestsFile = *requestsFile
 	config.UseXForwardedAsSource = *useXForwardedAsSource

+ 15 - 0
munchclient.service

@@ -0,0 +1,15 @@
+[Unit]
+Description=munch scraperwall blacklist processor
+After=network.target
+
+[Service]
+EnvironmentFile=-/etc/default/munchclient
+ExecStart=/usr/bin/munchclient -config /etc/munchclient/munchclient.toml
+User=root
+Group=root
+Restart=always
+RestartSec=1
+
+[Install]
+WantedBy=multi-user.target
+

+ 4 - 0
munchclient.toml

@@ -4,6 +4,10 @@
 # Filter = "tcp dst port 80"
 # Promiscuous = false
 # NatsURL = "nats://192.168.122.1:4222"
+# NatsURL = "tls://nats-eval.scw.systems:4222"
+# NatsUser = NatsUser
+# NatsPassword = NatsPassword
+# NatsCA = /etc/munchclient/munchclient/ca-chain.cert.pem
 # NatsQueue = "requests"
 # UseXForwardedAsSource = true
 # Quiet = true