Merge pull request #56 from fosrl/dev

Make Docker Socket Opt-In and Add Version Printout
This commit is contained in:
Owen Schwartz
2025-06-05 22:41:53 -04:00
committed by GitHub
2 changed files with 24 additions and 5 deletions

View File

@@ -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:
@@ -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.

24
main.go
View File

@@ -392,7 +392,7 @@ 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
@@ -400,9 +400,12 @@ func main() {
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()
@@ -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)
@@ -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 {