Skip to content

Commit 7c780f7

Browse files
Merge branch 'dev' of github.com:fosrl/newt into dev
2 parents 6b1c1ed + 7a07437 commit 7c780f7

31 files changed

+3501
-199
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copy this file to .env and fill in your values
2+
# Required for connecting to Pangolin service
3+
PANGOLIN_ENDPOINT=https://example.com
4+
NEWT_ID=changeme-id
5+
NEWT_SECRET=changeme-secret

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM golang:1.25-alpine AS builder
22

3+
# Install git and ca-certificates
4+
RUN apk --no-cache add ca-certificates git tzdata
5+
36
# Set the working directory inside the container
47
WORKDIR /app
58

@@ -13,7 +16,7 @@ RUN go mod download
1316
COPY . .
1417

1518
# Build the application
16-
RUN CGO_ENABLED=0 GOOS=linux go build -o /newt
19+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /newt
1720

1821
FROM alpine:3.22 AS runner
1922

@@ -22,6 +25,9 @@ RUN apk --no-cache add ca-certificates tzdata
2225
COPY --from=builder /newt /usr/local/bin/
2326
COPY entrypoint.sh /
2427

28+
# Admin/metrics endpoint (Prometheus scrape)
29+
EXPOSE 2112
30+
2531
RUN chmod +x /entrypoint.sh
2632
ENTRYPOINT ["/entrypoint.sh"]
27-
CMD ["newt"]
33+
CMD ["newt"]

README.md

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,61 +33,108 @@ When Newt receives WireGuard control messages, it will use the information encod
3333

3434
## CLI Args
3535

36+
### Core Configuration
37+
3638
- `id`: Newt ID generated by Pangolin to identify the client.
3739
- `secret`: A unique secret (not shared and kept private) used to authenticate the client ID with the websocket in order to receive commands.
3840
- `endpoint`: The endpoint where both Gerbil and Pangolin reside in order to connect to the websocket.
39-
40-
- `mtu` (optional): MTU for the internal WG interface. Default: 1280
41-
- `dns` (optional): DNS server to use to resolve the endpoint. Default: 9.9.9.9
41+
- `blueprint-file` (optional): Path to blueprint file to define Pangolin resources and configurations.
42+
- `no-cloud` (optional): Don't fail over to the cloud when using managed nodes in Pangolin Cloud. Default: false
4243
- `log-level` (optional): The log level to use (DEBUG, INFO, WARN, ERROR, FATAL). Default: INFO
43-
- `enforce-hc-cert` (optional): Enforce certificate validation for health checks. Default: false (accepts any cert)
44+
45+
### Docker Integration
46+
4447
- `docker-socket` (optional): Set the Docker socket to use the container discovery integration
45-
- `ping-interval` (optional): Interval for pinging the server. Default: 3s
46-
- `ping-timeout` (optional): Timeout for each ping. Default: 5s
47-
- `updown` (optional): A script to be called when targets are added or removed.
48-
- `tls-client-cert` (optional): Client certificate (p12 or pfx) for mTLS. See [mTLS](#mtls)
49-
- `tls-client-cert` (optional): Path to client certificate (PEM format, optional if using PKCS12). See [mTLS](#mtls)
50-
- `tls-client-key` (optional): Path to private key for mTLS (PEM format, optional if using PKCS12)
51-
- `tls-ca-cert` (optional): Path to CA certificate to verify server (PEM format, optional if using PKCS12)
5248
- `docker-enforce-network-validation` (optional): Validate the container target is on the same network as the newt process. Default: false
53-
- `health-file` (optional): Check if connection to WG server (pangolin) is ok. creates a file if ok, removes it if not ok. Can be used with docker healtcheck to restart newt
49+
50+
### Accpet Client Connection
51+
5452
- `accept-clients` (optional): Enable WireGuard server mode to accept incoming newt client connections. Default: false
5553
- `generateAndSaveKeyTo` (optional): Path to save generated private key
5654
- `native` (optional): Use native WireGuard interface when accepting clients (requires WireGuard kernel module and Linux, must run as root). Default: false (uses userspace netstack)
5755
- `interface` (optional): Name of the WireGuard interface. Default: newt
5856
- `keep-interface` (optional): Keep the WireGuard interface. Default: false
59-
- `blueprint-file` (optional): Path to blueprint file to define Pangolin resources and configurations.
60-
- `no-cloud` (optional): Don't fail over to the cloud when using managed nodes in Pangolin Cloud. Default: false
57+
58+
### Metrics & Observability
59+
60+
- `metrics` (optional): Enable Prometheus /metrics exporter. Default: true
61+
- `otlp` (optional): Enable OTLP exporters (metrics/traces) to OTEL_EXPORTER_OTLP_ENDPOINT. Default: false
62+
- `metrics-admin-addr` (optional): Admin/metrics bind address. Default: 127.0.0.1:2112
63+
- `metrics-async-bytes` (optional): Enable async bytes counting (background flush; lower hot path overhead). Default: false
64+
- `region` (optional): Optional region resource attribute for telemetry and metrics.
65+
66+
### Network Configuration
67+
68+
- `mtu` (optional): MTU for the internal WG interface. Default: 1280
69+
- `dns` (optional): DNS server to use to resolve the endpoint. Default: 9.9.9.9
70+
- `ping-interval` (optional): Interval for pinging the server. Default: 3s
71+
- `ping-timeout` (optional): Timeout for each ping. Default: 5s
72+
73+
### Security & TLS
74+
75+
- `enforce-hc-cert` (optional): Enforce certificate validation for health checks. Default: false (accepts any cert)
76+
- `tls-client-cert` (optional): Client certificate (p12 or pfx) for mTLS or path to client certificate (PEM format). See [mTLS](#mtls)
77+
- `tls-client-key` (optional): Path to private key for mTLS (PEM format, optional if using PKCS12)
78+
- `tls-ca-cert` (optional): Path to CA certificate to verify server (PEM format, optional if using PKCS12)
79+
80+
### Monitoring & Health
81+
82+
- `health-file` (optional): Check if connection to WG server (pangolin) is ok. creates a file if ok, removes it if not ok. Can be used with docker healtcheck to restart newt
83+
- `updown` (optional): A script to be called when targets are added or removed.
6184

6285
## Environment Variables
6386

6487
All CLI arguments can be set using environment variables as an alternative to command line flags. Environment variables are particularly useful when running Newt in containerized environments.
6588

89+
### Core Configuration
90+
6691
- `PANGOLIN_ENDPOINT`: Endpoint of your pangolin server (equivalent to `--endpoint`)
6792
- `NEWT_ID`: Newt ID generated by Pangolin (equivalent to `--id`)
6893
- `NEWT_SECRET`: Newt secret for authentication (equivalent to `--secret`)
69-
- `MTU`: MTU for the internal WG interface. Default: 1280 (equivalent to `--mtu`)
70-
- `DNS`: DNS server to use to resolve the endpoint. Default: 9.9.9.9 (equivalent to `--dns`)
94+
- `CONFIG_FILE`: Load the config json from this file instead of in the home folder.
95+
- `BLUEPRINT_FILE`: Path to blueprint file to define Pangolin resources and configurations. (equivalent to `--blueprint-file`)
96+
- `NO_CLOUD`: Don't fail over to the cloud when using managed nodes in Pangolin Cloud. Default: false (equivalent to `--no-cloud`)
7197
- `LOG_LEVEL`: Log level (DEBUG, INFO, WARN, ERROR, FATAL). Default: INFO (equivalent to `--log-level`)
98+
99+
### Docker Integration
100+
72101
- `DOCKER_SOCKET`: Path to Docker socket for container discovery (equivalent to `--docker-socket`)
73-
- `PING_INTERVAL`: Interval for pinging the server. Default: 3s (equivalent to `--ping-interval`)
74-
- `PING_TIMEOUT`: Timeout for each ping. Default: 5s (equivalent to `--ping-timeout`)
75-
- `UPDOWN_SCRIPT`: Path to updown script for target add/remove events (equivalent to `--updown`)
76-
- `TLS_CLIENT_CERT`: Path to client certificate for mTLS (equivalent to `--tls-client-cert`)
77-
- `TLS_CLIENT_CERT`: Path to client certificate for mTLS (equivalent to `--tls-client-cert`)
78-
- `TLS_CLIENT_KEY`: Path to private key for mTLS (equivalent to `--tls-client-key`)
79-
- `TLS_CA_CERT`: Path to CA certificate to verify server (equivalent to `--tls-ca-cert`)
80102
- `DOCKER_ENFORCE_NETWORK_VALIDATION`: Validate container targets are on same network. Default: false (equivalent to `--docker-enforce-network-validation`)
81-
- `ENFORCE_HC_CERT`: Enforce certificate validation for health checks. Default: false (equivalent to `--enforce-hc-cert`)
82-
- `HEALTH_FILE`: Path to health file for connection monitoring (equivalent to `--health-file`)
103+
104+
### Accept Client Connections
105+
83106
- `ACCEPT_CLIENTS`: Enable WireGuard server mode. Default: false (equivalent to `--accept-clients`)
84107
- `GENERATE_AND_SAVE_KEY_TO`: Path to save generated private key (equivalent to `--generateAndSaveKeyTo`)
85108
- `USE_NATIVE_INTERFACE`: Use native WireGuard interface (Linux only). Default: false (equivalent to `--native`)
86109
- `INTERFACE`: Name of the WireGuard interface. Default: newt (equivalent to `--interface`)
87110
- `KEEP_INTERFACE`: Keep the WireGuard interface after shutdown. Default: false (equivalent to `--keep-interface`)
88-
- `CONFIG_FILE`: Load the config json from this file instead of in the home folder.
89-
- `BLUEPRINT_FILE`: Path to blueprint file to define Pangolin resources and configurations. (equivalent to `--blueprint-file`)
90-
- `NO_CLOUD`: Don't fail over to the cloud when using managed nodes in Pangolin Cloud. Default: false (equivalent to `--no-cloud`)
111+
112+
### Monitoring & Health
113+
114+
- `HEALTH_FILE`: Path to health file for connection monitoring (equivalent to `--health-file`)
115+
- `UPDOWN_SCRIPT`: Path to updown script for target add/remove events (equivalent to `--updown`)
116+
117+
### Metrics & Observability
118+
119+
- `NEWT_METRICS_PROMETHEUS_ENABLED`: Enable Prometheus /metrics exporter. Default: true (equivalent to `--metrics`)
120+
- `NEWT_METRICS_OTLP_ENABLED`: Enable OTLP exporters (metrics/traces) to OTEL_EXPORTER_OTLP_ENDPOINT. Default: false (equivalent to `--otlp`)
121+
- `NEWT_ADMIN_ADDR`: Admin/metrics bind address. Default: 127.0.0.1:2112 (equivalent to `--metrics-admin-addr`)
122+
- `NEWT_METRICS_ASYNC_BYTES`: Enable async bytes counting (background flush; lower hot path overhead). Default: false (equivalent to `--metrics-async-bytes`)
123+
- `NEWT_REGION`: Optional region resource attribute for telemetry and metrics (equivalent to `--region`)
124+
125+
### Network Configuration
126+
127+
- `MTU`: MTU for the internal WG interface. Default: 1280 (equivalent to `--mtu`)
128+
- `DNS`: DNS server to use to resolve the endpoint. Default: 9.9.9.9 (equivalent to `--dns`)
129+
- `PING_INTERVAL`: Interval for pinging the server. Default: 3s (equivalent to `--ping-interval`)
130+
- `PING_TIMEOUT`: Timeout for each ping. Default: 5s (equivalent to `--ping-timeout`)
131+
132+
### Security & TLS
133+
134+
- `ENFORCE_HC_CERT`: Enforce certificate validation for health checks. Default: false (equivalent to `--enforce-hc-cert`)
135+
- `TLS_CLIENT_CERT`: Path to client certificate for mTLS (equivalent to `--tls-client-cert`)
136+
- `TLS_CLIENT_KEY`: Path to private key for mTLS (equivalent to `--tls-client-key`)
137+
- `TLS_CA_CERT`: Path to CA certificate to verify server (equivalent to `--tls-ca-cert`)
91138

92139
## Loading secrets from files
93140

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
services:
2+
newt:
3+
build: .
4+
image: newt:dev
5+
env_file:
6+
- .env
7+
environment:
8+
- NEWT_METRICS_PROMETHEUS_ENABLED=false # important: disable direct /metrics scraping
9+
- NEWT_METRICS_OTLP_ENABLED=true # OTLP to the Collector
10+
# optional:
11+
# - NEWT_METRICS_INCLUDE_TUNNEL_ID=false
12+
# When using the Collector pattern, do NOT map the Newt admin/metrics port
13+
# (2112) on the application service. Mapping 2112 here can cause port
14+
# conflicts and may result in duplicated Prometheus scraping (app AND
15+
# collector being scraped for the same metrics). Instead either:
16+
# - leave ports unset on the app service (recommended), or
17+
# - map 2112 only on a dedicated metrics/collector service that is
18+
# responsible for exposing metrics to Prometheus.
19+
# Example: do NOT map here
20+
# ports: []
21+
# Example: map 2112 only on a collector service
22+
# collector:
23+
# ports:
24+
# - "2112:2112" # collector's prometheus exporter (scraped by Prometheus)
25+
26+
otel-collector:
27+
image: otel/opentelemetry-collector-contrib:latest
28+
command: ["--config=/etc/otelcol/config.yaml"]
29+
volumes:
30+
- ./examples/otel-collector.yaml:/etc/otelcol/config.yaml:ro
31+
ports:
32+
- "4317:4317" # OTLP gRPC
33+
- "8889:8889" # Prometheus Exporter (scraped by Prometheus)
34+
35+
prometheus:
36+
image: prom/prometheus:latest
37+
volumes:
38+
- ./examples/prometheus.with-collector.yml:/etc/prometheus/prometheus.yml:ro
39+
ports:
40+
- "9090:9090"
41+

docker-compose.metrics.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Newt-Metrics
2+
services:
3+
# Recommended Variant A: Direct Prometheus scrape of Newt (/metrics)
4+
# Optional: You may add the Collector service and enable OTLP export, but do NOT
5+
# scrape both Newt and the Collector for the same process.
6+
7+
newt:
8+
build: .
9+
image: newt:dev
10+
env_file:
11+
- .env
12+
environment:
13+
OTEL_SERVICE_NAME: newt
14+
NEWT_METRICS_PROMETHEUS_ENABLED: "true"
15+
NEWT_METRICS_OTLP_ENABLED: "false" # avoid double-scrape by default
16+
NEWT_ADMIN_ADDR: ":2112"
17+
# Base NEWT configuration
18+
PANGOLIN_ENDPOINT: ${PANGOLIN_ENDPOINT}
19+
NEWT_ID: ${NEWT_ID}
20+
NEWT_SECRET: ${NEWT_SECRET}
21+
LOG_LEVEL: "DEBUG"
22+
ports:
23+
- "2112:2112"
24+
25+
# Optional Variant B: Enable the Collector and switch Prometheus scrape to it.
26+
# collector:
27+
# image: otel/opentelemetry-collector-contrib:0.136.0
28+
# command: ["--config=/etc/otelcol/config.yaml"]
29+
# volumes:
30+
# - ./examples/otel-collector.yaml:/etc/otelcol/config.yaml:ro
31+
# ports:
32+
# - "4317:4317" # OTLP gRPC in
33+
# - "8889:8889" # Prometheus scrape out
34+
35+
prometheus:
36+
image: prom/prometheus:v3.6.0
37+
volumes:
38+
- ./examples/prometheus.yml:/etc/prometheus/prometheus.yml:ro
39+
ports:
40+
- "9090:9090"
41+
42+
grafana:
43+
image: grafana/grafana:12.2.0
44+
container_name: newt-metrics-grafana
45+
restart: unless-stopped
46+
environment:
47+
- GF_SECURITY_ADMIN_USER=admin
48+
- GF_SECURITY_ADMIN_PASSWORD=admin
49+
ports:
50+
- "3005:3000"
51+
depends_on:
52+
- prometheus
53+
volumes:
54+
- ./examples/grafana/provisioning/datasources:/etc/grafana/provisioning/datasources:ro
55+
- ./examples/grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro
56+
- ./examples/grafana/dashboards:/var/lib/grafana/dashboards:ro

0 commit comments

Comments
 (0)