Compare commits

..

4 Commits

Author SHA1 Message Date
85fd24180a
Remove deprecated features from config example 2025-03-19 22:36:46 +01:00
b2e3632b56
Update README 2025-03-19 22:35:33 +01:00
73dce3d1f3
Update Dockerfile 2025-03-19 22:28:28 +01:00
d86bc2be07
Remove Makefile 2025-03-19 22:08:45 +01:00
4 changed files with 39 additions and 132 deletions

View File

@ -1,12 +1,16 @@
FROM node:latest as frontend-builder FROM node:alpine as frontend-builder
RUN mkdir -p /app/frontend WORKDIR /app
COPY web/frontend/yarn.lock /app/frontend/yarn.lock COPY frontend/package.json /app
COPY web/frontend/package.json /app/frontend/package.json COPY frontend/package-lock.json /app
WORKDIR /app/frontend RUN npm install
RUN yarn install COPY frontend .
COPY web/frontend /app/frontend RUN npm run build
WORKDIR /app/frontend
RUN GENERATE_SOURCEMAP=false yarn build FROM alpine:latest as geoip-fetcher
RUN apk add --no-cache git
WORKDIR /app
RUN git clone https://github.com/geoacumen/geoacumen-country.git
RUN find .
FROM golang:latest as builder FROM golang:latest as builder
WORKDIR /app WORKDIR /app
@ -14,16 +18,15 @@ COPY go.mod /app/go.mod
COPY go.sum /app/go.sum COPY go.sum /app/go.sum
RUN go mod download RUN go mod download
COPY . /app COPY . /app
RUN rm -rf /app/server/frontend COPY --from=geoip-fetcher /app/geoacumen-country/Geoacumen-Country.mmdb honeypot/ssh
COPY --from=frontend-builder /app/frontend/dist /app/web/frontend/dist COPY --from=frontend-builder /app/dist /app/web/frontend/dist
RUN CGO_ENABLED=0 INSTALL_PREFIX=/app make install RUN CGO_ENABLED=0 go build -tags embed cmd/apiary/apiary.go
FROM alpine:latest FROM alpine:latest
RUN apk add --no-cache curl RUN apk add --no-cache curl
WORKDIR /app WORKDIR /app
COPY --from=builder /app/etc/apiary/apiary.toml /app/apiary.toml COPY --from=builder /app/apiary.toml /app/apiary.toml
COPY --from=builder /app/bin/apiary /app/apiary COPY --from=builder /app/apiary /app/apiary
EXPOSE 8080 EXPOSE 8080
EXPOSE 2222 EXPOSE 2222
HEALTHCHECK --interval=1m --timeout=10s --start-period=5s --retries=3 CMD curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/api/health || exit 1
CMD ["/app/apiary", "serve"] CMD ["/app/apiary", "serve"]

View File

@ -1,62 +0,0 @@
NAME = apiary
.DEFAULT_GOAL := all
.PHONY: all clean
INSTALL_PREFIX ?= /usr/local
VERSION = $(shell cat version.go |grep "Version"| head -n 1 |cut -d "=" -f2| tr -d "\" ")
ARCH = $(shell go env | grep GOHOSTARCH | cut -d"=" -f2 | tr -d "\"")
OS = $(shell go env | grep GOHOSTOS | cut -d"=" -f2 | tr -d "\"")
GIT_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DIR = build/binary/current
BUILD_OUTPUT = $(BUILD_DIR)/$(NAME)-$(VERSION)-$(OS)-$(ARCH)
BUILD_FLAGS = -tags embed -ldflags "-X git.t-juice.club/torjus/apiary.Build=$(GIT_COMMIT)" -o $(BUILD_OUTPUT)
GEODB_URL = https://raw.githubusercontent.com/geoacumen/geoacumen-country/master/Geoacumen-Country.mmdb
GEODB_PATH = honeypot/Geoacumen-Country.mmdb
FRONTEND_BUILD_DIR = web/frontend/dist
ifeq ($(INSTALL_PREFIX), /)
INSTALL_BIN_DIR=/usr/bin
INSTALL_ETC_DIR=/etc/$(NAME)
else
INSTALL_BIN_DIR=$(INSTALL_PREFIX)/bin
INSTALL_ETC_DIR=$(INSTALL_PREFIX)/etc/$(NAME)
endif
$(GEODB_PATH):
curl $(GEODB_URL) -o $(GEODB_PATH)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(FRONTEND_BUILD_DIR):
cd web/frontend && yarn install && yarn build
$(BUILD_OUTPUT): $(BUILD_DIR) $(GEODB_PATH) $(FRONTEND_BUILD_DIR)
CGO_ENABLED=0 go build $(BUILD_FLAGS) cmd/apiary.go
frontend:
cd web/frontend && yarn install && yarn build
clean:
rm -rv $(BUILD_DIR)
rm -rv $(FRONTEND_BUILD_DIR)
geodb: $(GEODB_PATH)
build: $(BUILD_OUTPUT)
install: build
mkdir -p $(INSTALL_BIN_DIR)
mkdir -p $(INSTALL_ETC_DIR)
install -m 755 $(BUILD_OUTPUT) $(INSTALL_BIN_DIR)/$(NAME)
install -m 755 apiary.toml $(INSTALL_ETC_DIR)/apiary.toml
uninstall:
rm -v $(INSTALL_ETC_DIR)/apiary.toml
rmdir -v $(INSTALL_ETC_DIR)
rm -v $(INSTALL_BIN_DIR)/$(NAME)

View File

@ -2,45 +2,40 @@
SSH honeypot with web-frontend. SSH honeypot with web-frontend.
## TODO
* Fix janky ass Makefile
## Requirements ## Requirements
* `go >= 1.16` * `go >= 1.16`
* `node >= 22`
Requires a postgres database if you want data to persist through server restart. Requires a postgres database if you want data to persist through server restart.
## Build ## Build using nix
```text ```console
# make frontend $ nix build .#
# make build
$ ./result/bin/apiary --version
apiary version v0.2.1-d86bc2be079c6b18a9f941752ebad45d925366d1 (go1.23.6)
``` ```
## Build without nix
See [Dockerfile](./Dockerfile) for how to build frontend and backend. Or use Dockerfile
and copy binary from image.
## Install ## Install
```text ```text
# Build and install # Build or download binary
INSTALL_PREFIX=/ sudo make install $ cp ./apiary /usr/local/bin/apiary
# Edit config file # Edit config file, should use postgres if you want persistent storage.
vim /etc/apiary/apiary.toml # See example config for the different options.
$ vim /etc/apiary/apiary.toml
# Run # Run
/usr/bin/apiary serve $ /usr/bin/apiary serve
# 2021-04-10T11:27:42.783+0200 INFO APP Starting SSH server 2021-04-10T11:27:42.783+0200 INFO APP Starting SSH server
# 2021-04-10T11:27:42.783+0200 INFO APP Starting web server 2021-04-10T11:27:42.783+0200 INFO APP Starting web server
``` ```
## Development
Run postgres-tests by running a postgres container:
```text
podman run -d -q -e POSTGRES_PASSWORD=apiary -e POSTGRES_USER=apiary -e POSTGRES_DB=apiary --rm --name apiary-test-db -p5432:5432 postgres:latest
export APIARY_TEST_POSTGRES_DSN="postgresql://apiary:apiary@localhost/apiary"
go test ./...
```

View File

@ -38,7 +38,7 @@ LogLevel = "INFO"
# Enable access logging # Enable access logging
# Default: true # Default: true
AccessLogEnable = true AccessLogEnable = true
# Disable logging of successful requests to metrics endpoint # Disable logging of requests to metrics endpoint
# Default: false # Default: false
AccessLogIgnoreMetrics = false AccessLogIgnoreMetrics = false
# Address and port to listen to # Address and port to listen to
@ -63,32 +63,3 @@ CacheDir = "/var/apiary/certs"
# Default: true # Default: true
RedirectHTTP = true RedirectHTTP = true
[Ports]
# Enable the port listener.
# Default: false
Enable = false
# Which address to listen on.
# Default: "" (listen to all addresses)
Addr = ""
# Which TCP ports to listen to.
# Default: []
TCPPorts = ["25"]
# Which UDP ports to listen to.
# Default: []
UDPPorts = ["25"]
[SMTP]
# Enable the port listener.
# Default: false
Enable = true
# Which address and port to listen on.
# Default: ":25"
Addr = ":25"
# Enable collecting prometheus metrics
# Default: false
EnableMetrics = true