Compare commits
	
		
			4 Commits
		
	
	
		
			39a682fd41
			...
			85fd24180a
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 85fd24180a | |||
| b2e3632b56 | |||
| 73dce3d1f3 | |||
| d86bc2be07 | 
							
								
								
									
										33
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								Dockerfile
									
									
									
									
									
								
							| @@ -1,12 +1,16 @@ | ||||
| FROM node:latest as frontend-builder | ||||
| RUN mkdir -p /app/frontend | ||||
| COPY web/frontend/yarn.lock /app/frontend/yarn.lock | ||||
| COPY web/frontend/package.json /app/frontend/package.json | ||||
| WORKDIR /app/frontend | ||||
| RUN yarn install | ||||
| COPY web/frontend /app/frontend | ||||
| WORKDIR /app/frontend | ||||
| RUN GENERATE_SOURCEMAP=false yarn build | ||||
| FROM node:alpine as frontend-builder | ||||
| WORKDIR /app | ||||
| COPY frontend/package.json /app | ||||
| COPY frontend/package-lock.json /app | ||||
| RUN npm install | ||||
| COPY frontend . | ||||
| RUN npm run 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 | ||||
| WORKDIR /app | ||||
| @@ -14,16 +18,15 @@ COPY go.mod /app/go.mod | ||||
| COPY go.sum /app/go.sum | ||||
| RUN go mod download | ||||
| COPY . /app | ||||
| RUN rm -rf /app/server/frontend | ||||
| COPY --from=frontend-builder /app/frontend/dist /app/web/frontend/dist | ||||
| RUN CGO_ENABLED=0 INSTALL_PREFIX=/app make install | ||||
| COPY --from=geoip-fetcher /app/geoacumen-country/Geoacumen-Country.mmdb honeypot/ssh | ||||
| COPY --from=frontend-builder /app/dist /app/web/frontend/dist | ||||
| RUN CGO_ENABLED=0 go build -tags embed cmd/apiary/apiary.go | ||||
|  | ||||
| FROM alpine:latest | ||||
| RUN apk add --no-cache curl | ||||
| WORKDIR /app | ||||
| COPY --from=builder /app/etc/apiary/apiary.toml /app/apiary.toml | ||||
| COPY --from=builder /app/bin/apiary /app/apiary | ||||
| COPY --from=builder /app/apiary.toml /app/apiary.toml | ||||
| COPY --from=builder /app/apiary /app/apiary | ||||
| EXPOSE 8080 | ||||
| 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"] | ||||
|   | ||||
							
								
								
									
										62
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								Makefile
									
									
									
									
									
								
							| @@ -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) | ||||
							
								
								
									
										45
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								README.md
									
									
									
									
									
								
							| @@ -2,45 +2,40 @@ | ||||
|  | ||||
| SSH honeypot with web-frontend. | ||||
|  | ||||
| ## TODO | ||||
|  | ||||
| * Fix janky ass Makefile | ||||
|  | ||||
| ## Requirements | ||||
|  | ||||
| * `go >= 1.16` | ||||
| * `node >= 22` | ||||
|  | ||||
| Requires a postgres database if you want data to persist through server restart. | ||||
|  | ||||
| ## Build | ||||
| ## Build using nix | ||||
|  | ||||
| ```text | ||||
| # make frontend | ||||
| # make build | ||||
| ```console | ||||
| $ nix 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 | ||||
|  | ||||
| ```text | ||||
| # Build and install | ||||
| INSTALL_PREFIX=/ sudo make install | ||||
| # Build or download binary | ||||
| $ cp ./apiary /usr/local/bin/apiary | ||||
|  | ||||
| # Edit config file | ||||
| vim /etc/apiary/apiary.toml | ||||
| # Edit config file, should use postgres if you want persistent storage. | ||||
| # See example config for the different options. | ||||
| $ vim /etc/apiary/apiary.toml | ||||
|  | ||||
| # Run | ||||
| /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 web server | ||||
| $ /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 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 ./... | ||||
| ``` | ||||
|   | ||||
							
								
								
									
										31
									
								
								apiary.toml
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								apiary.toml
									
									
									
									
									
								
							| @@ -38,7 +38,7 @@ LogLevel = "INFO" | ||||
| # Enable access logging | ||||
| # Default: true | ||||
| AccessLogEnable = true | ||||
| # Disable logging of successful requests to metrics endpoint | ||||
| # Disable logging of requests to metrics endpoint | ||||
| # Default: false | ||||
| AccessLogIgnoreMetrics = false | ||||
| # Address and port to listen to | ||||
| @@ -63,32 +63,3 @@ CacheDir = "/var/apiary/certs" | ||||
| # Default: 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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user