Skip to content

Commit cb6c405

Browse files
authored
Merge pull request #6 from vsilent/dev
Dev
2 parents e17e57b + b724897 commit cb6c405

File tree

95 files changed

+8033
-781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+8033
-781
lines changed

.github/workflows/docker.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ jobs:
1717
uses: dtolnay/rust-toolchain@stable
1818
with:
1919
components: rustfmt, clippy
20+
targets: x86_64-unknown-linux-musl
2021

2122
- name: Cache Rust dependencies
2223
uses: Swatinem/rust-cache@v2
2324

25+
- name: Install cross
26+
run: cargo install cross --git https://github.com/cross-rs/cross
27+
2428
- name: Generate Secret Key
2529
run: head -c16 /dev/urandom > src/secret.key
2630

@@ -36,8 +40,10 @@ jobs:
3640
- name: Test
3741
run: cargo test
3842

39-
- name: Build release
40-
run: cargo build --release
43+
- name: Build static release
44+
env:
45+
CARGO_TARGET_DIR: target-cross
46+
run: cross build --release --target x86_64-unknown-linux-musl
4147

4248
- name: Build frontend
4349
working-directory: ./web
@@ -52,7 +58,7 @@ jobs:
5258
- name: Package app
5359
run: |
5460
mkdir -p app/stackdog/dist
55-
cp target/release/stackdog app/stackdog/
61+
cp target-cross/x86_64-unknown-linux-musl/release/stackdog app/stackdog/
5662
cp -a web/dist/. app/stackdog/
5763
cp docker/prod/Dockerfile app/Dockerfile
5864
touch app/.env

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stackdog"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["Vasili Pascal <info@try.direct>"]
55
edition = "2021"
66
description = "Security platform for Docker containers and Linux servers"
@@ -55,6 +55,7 @@ zstd = "0.13"
5555

5656
# Stream utilities
5757
futures-util = "0.3"
58+
lettre = { version = "0.11", default-features = false, features = ["tokio1", "tokio1-rustls-tls", "builder", "smtp-transport"] }
5859

5960
# eBPF (Linux only)
6061
[target.'cfg(target_os = "linux")'.dependencies]
@@ -78,6 +79,8 @@ ebpf = []
7879
# Testing
7980
tokio-test = "0.4"
8081
tempfile = "3"
82+
actix-test = "0.1"
83+
awc = "3"
8184

8285
# Benchmarking
8386
criterion = { version = "0.5", features = ["html_reports"] }

README.md

Lines changed: 98 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stackdog Security
22

3-
![Version](https://img.shields.io/badge/version-0.2.0-blue.svg)
3+
![Version](https://img.shields.io/badge/version-0.2.1-blue.svg)
44
![License](https://img.shields.io/badge/license-MIT-green.svg)
55
![Rust](https://img.shields.io/badge/rust-1.75+-orange.svg)
66
![Platform](https://img.shields.io/badge/platform-linux%20%7C%20macos%20%7C%20windows-lightgrey.svg)
@@ -71,6 +71,95 @@ cargo run
7171
cargo run -- serve
7272
```
7373

74+
### Run with Docker
75+
76+
Use the published container image for the quickest way to explore the API.
77+
If you are validating a fresh branch or waiting for Docker Hub to pick up the latest CI build,
78+
prefer the local-image flow below so you know you are running your current checkout:
79+
80+
```bash
81+
docker volume create stackdog-data
82+
83+
docker run --rm -it \
84+
--name stackdog \
85+
-p 5000:5000 \
86+
-e APP_HOST=0.0.0.0 \
87+
-e APP_PORT=5000 \
88+
-e DATABASE_URL=/data/stackdog.db \
89+
-v stackdog-data:/data \
90+
-v /var/run/docker.sock:/var/run/docker.sock \
91+
trydirect/stackdog:latest
92+
```
93+
94+
Then open another shell and hit the API:
95+
96+
```bash
97+
curl http://localhost:5000/api/security/status
98+
curl http://localhost:5000/api/threats
99+
curl http://localhost:5000/api/alerts
100+
```
101+
102+
Mount the Docker socket when you want Docker-aware features such as container listing, live stats,
103+
mail abuse guard polling, Docker log discovery, and Docker-backed quarantine/release flows.
104+
105+
If you do not want Stackdog to access the Docker daemon, disable the mail guard:
106+
107+
```bash
108+
STACKDOG_MAIL_GUARD_ENABLED=false
109+
```
110+
111+
To try log sniffing inside Docker against host log files, mount them read-only and run the
112+
`sniff` subcommand instead of the default HTTP server:
113+
114+
```bash
115+
docker run --rm -it \
116+
-e DATABASE_URL=/tmp/stackdog.db \
117+
-v /var/log:/host-logs:ro \
118+
trydirect/stackdog:latest \
119+
sniff --once --sources /host-logs/auth.log
120+
```
121+
122+
If you want to test your current checkout instead of the latest published image:
123+
124+
```bash
125+
docker build -f docker/backend/Dockerfile -t stackdog-local .
126+
127+
docker run --rm -it \
128+
--name stackdog-local \
129+
-p 5000:5000 \
130+
-e APP_HOST=0.0.0.0 \
131+
-e APP_PORT=5000 \
132+
-e DATABASE_URL=/data/stackdog.db \
133+
-v stackdog-data:/data \
134+
-v /var/run/docker.sock:/var/run/docker.sock \
135+
stackdog-local
136+
```
137+
138+
### Run backend + UI with Docker Compose
139+
140+
To run `stackdog serve` and the web UI as two separate services from your current checkout:
141+
142+
```bash
143+
docker compose -f docker-compose.app.yml up --build
144+
```
145+
146+
This starts:
147+
148+
- **API** at `http://localhost:5000`
149+
- **UI** at `http://localhost:3000`
150+
151+
The compose stack uses:
152+
153+
- `stackdog` service — builds `docker/backend/Dockerfile`, runs `stackdog serve`, and mounts `/var/run/docker.sock`
154+
- `stackdog-ui` service — builds the React app and serves it with Nginx
155+
- `stackdog-data` volume — persists the SQLite database between restarts
156+
157+
To stop it:
158+
159+
```bash
160+
docker compose -f docker-compose.app.yml down
161+
```
162+
74163
### Log Sniffing
75164

76165
```bash
@@ -120,11 +209,15 @@ for event in events {
120209
### Docker Development
121210

122211
```bash
123-
# Start development environment
124-
docker-compose up -d
212+
# Run the published image
213+
docker run --rm -it -p 5000:5000 trydirect/stackdog:latest
214+
215+
# Or, for the most reliable test of your current code, build and run your checkout
216+
docker build -f docker/backend/Dockerfile -t stackdog-local .
217+
docker run --rm -it -p 5000:5000 stackdog-local
125218

126-
# View logs
127-
docker-compose logs -f stackdog
219+
# Or run backend + UI together
220+
docker compose -f docker-compose.app.yml up --build
128221
```
129222

130223
---

VERSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.2.1

docker-compose.app.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
services:
2+
stackdog:
3+
build:
4+
context: .
5+
dockerfile: docker/backend/Dockerfile
6+
command: ["serve"]
7+
container_name: stackdog
8+
environment:
9+
APP_HOST: 0.0.0.0
10+
APP_PORT: 5000
11+
DATABASE_URL: /data/stackdog.db
12+
ports:
13+
- "5000:5000"
14+
volumes:
15+
- stackdog-data:/data
16+
- /var/run/docker.sock:/var/run/docker.sock
17+
18+
stackdog-ui:
19+
build:
20+
context: .
21+
dockerfile: docker/ui/Dockerfile
22+
args:
23+
REACT_APP_API_URL: http://localhost:5000/api
24+
REACT_APP_WS_URL: ws://localhost:5000/ws
25+
container_name: stackdog-ui
26+
depends_on:
27+
- stackdog
28+
ports:
29+
- "3000:80"
30+
31+
volumes:
32+
stackdog-data:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
echo "Starting Stackdog..."
2020
cargo run --bin stackdog
2121
ports:
22-
- "${APP_PORT:-8080}:${APP_PORT:-8080}"
22+
- "${APP_PORT:-5000}:${APP_PORT:-5000}"
2323
env_file:
2424
- .env
2525
environment:

docker/backend/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM rust:slim-bookworm AS build
2+
3+
RUN apt-get update && \
4+
apt-get install --no-install-recommends -y musl-tools pkg-config && \
5+
rm -rf /var/lib/apt/lists/*
6+
7+
RUN rustup target add x86_64-unknown-linux-musl
8+
9+
WORKDIR /app
10+
11+
COPY Cargo.toml Cargo.lock ./
12+
COPY migrations ./migrations
13+
COPY src ./src
14+
COPY .env.sample ./.env
15+
16+
RUN cargo build --release --target x86_64-unknown-linux-musl
17+
18+
FROM debian:bookworm-slim
19+
20+
WORKDIR /app
21+
22+
RUN apt-get update && \
23+
apt-get install --no-install-recommends -y ca-certificates sqlite3 && \
24+
rm -rf /var/lib/apt/lists/* && \
25+
mkdir -p /data
26+
27+
COPY --from=build /app/target/x86_64-unknown-linux-musl/release/stackdog /app/stackdog
28+
29+
EXPOSE 5000
30+
31+
ENTRYPOINT ["/app/stackdog"]

docker/ui/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM node:20-alpine AS build
2+
3+
WORKDIR /web
4+
5+
COPY web/package*.json ./
6+
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
7+
8+
COPY web/ ./
9+
10+
ARG REACT_APP_API_URL=
11+
ARG REACT_APP_WS_URL=
12+
ARG APP_PORT=
13+
ARG REACT_APP_API_PORT=
14+
15+
ENV REACT_APP_API_URL=${REACT_APP_API_URL}
16+
ENV REACT_APP_WS_URL=${REACT_APP_WS_URL}
17+
ENV APP_PORT=${APP_PORT}
18+
ENV REACT_APP_API_PORT=${REACT_APP_API_PORT}
19+
20+
RUN npm run build
21+
22+
FROM nginx:1.27-alpine
23+
24+
COPY docker/ui/nginx.conf /etc/nginx/conf.d/default.conf
25+
COPY --from=build /web/dist /usr/share/nginx/html
26+
27+
EXPOSE 80

docker/ui/nginx.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
root /usr/share/nginx/html;
6+
index index.html;
7+
8+
location / {
9+
try_files $uri $uri/ /index.html;
10+
}
11+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
target = ["bpfel-unknown-none"]
33

44
[target.bpfel-unknown-none]
5-
rustflags = ["-C", "link-arg=--Bstatic"]
5+
6+
[unstable]
7+
build-std = ["core"]

0 commit comments

Comments
 (0)