Skip to content

Make Docker Socket Opt-In and Add Version Printout #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ When Newt receives WireGuard control messages, it will use the information encod
- `log-level` (optional): The log level to use. Default: INFO
- `updown` (optional): A script to be called when targets are added or removed.
- `tls-client-cert` (optional): Client certificate (p12 or pfx) for mTLS. See [mTLS](#mtls)
- `docker-socket` (optional): Override the Docker socket integration
- `docker-socket` (optional): Set the Docker socket to use the container discovery integration

- Example:

Expand Down Expand Up @@ -82,8 +82,7 @@ Newt can integrate with the Docker socket to provide remote inspection of Docker

**Configuration:**

- By default, Newt will look for the Docker socket at `/var/run/docker.sock`.
- You can specify a custom socket path using the `--docker-socket` CLI argument or by setting the `DOCKER_SOCKET` environment variable.
You can specify the Docker socket path using the `--docker-socket` CLI argument or by setting the `DOCKER_SOCKET` environment variable. On most linux systems the socket is `/var/run/docker.sock`

If the Docker socket is not available or accessible, Newt will gracefully disable Docker integration and continue normal operation.

Expand Down
24 changes: 22 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,20 @@ func main() {
flag.StringVar(&tlsPrivateKey, "tls-client-cert", "", "Path to client certificate used for mTLS")
}
if dockerSocket == "" {
flag.StringVar(&dockerSocket, "docker-socket", "/var/run/docker.sock", "Path to Docker socket")
flag.StringVar(&dockerSocket, "docker-socket", "", "Path to Docker socket (typically /var/run/docker.sock)")
}

// do a --version check
version := flag.Bool("version", false, "Print the version")

flag.Parse()

newtVersion := "Newt version replaceme"
if *version {
fmt.Println("Newt version replaceme")
fmt.Println(newtVersion)
os.Exit(0)
} else {
logger.Info(newtVersion)
}

logger.Init()
Expand Down Expand Up @@ -636,6 +639,18 @@ persistent_keepalive_interval=5`, fixKey(privateKey.String()), fixKey(wgData.Pub
client.RegisterHandler("newt/socket/check", func(msg websocket.WSMessage) {
logger.Info("Received Docker socket check request")

if dockerSocket == "" {
logger.Info("Docker socket path is not set")
err := client.SendMessage("newt/socket/status", map[string]interface{}{
"available": false,
"socketPath": dockerSocket,
})
if err != nil {
logger.Error("Failed to send Docker socket check response: %v", err)
}
return
}

// Check if Docker socket is available
isAvailable := docker.CheckSocket(dockerSocket)

Expand All @@ -655,6 +670,11 @@ persistent_keepalive_interval=5`, fixKey(privateKey.String()), fixKey(wgData.Pub
client.RegisterHandler("newt/socket/fetch", func(msg websocket.WSMessage) {
logger.Info("Received Docker container fetch request")

if dockerSocket == "" {
logger.Info("Docker socket path is not set")
return
}

// List Docker containers
containers, err := docker.ListContainers(dockerSocket)
if err != nil {
Expand Down