-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
75 lines (65 loc) · 1.92 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"os"
"strings"
"sync"
"github.com/docker/docker/client"
"github.com/flaviostutz/dockerwall/dockerwall"
"github.com/sirupsen/logrus"
)
func main() {
logLevel := flag.String("loglevel", "debug", "debug, info, warning, error")
gatewayNetworks := flag.String("gateway-networks", "", "Docker networks whose gateway access will be managed by DockerWall. If empty, all bridge networks will be used")
defaultOutbound := flag.String("default-outbound", "_dns_", "Domains and IPs that will be allowed by default. Use '!_dns_' to deny access to local dns server ip")
dryRun := flag.Bool("dry-run", false, "Don't block anything for real, but keep metrics showing which containers would have dropped packets")
flag.Parse()
switch *logLevel {
case "debug":
logrus.SetLevel(logrus.DebugLevel)
break
case "warning":
logrus.SetLevel(logrus.WarnLevel)
break
case "error":
logrus.SetLevel(logrus.ErrorLevel)
break
default:
logrus.SetLevel(logrus.InfoLevel)
}
logrus.Infof("====Starting Dockerwall====")
cli, err := client.NewClientWithOpts(client.WithVersion("1.38"))
if err != nil {
logrus.Errorf("Error creating Docker client instance. err=%s", err)
return
}
gatewayNets := make([]string, 0)
skipNets := make([]string, 0)
if *gatewayNetworks != "" {
gn := strings.Split(*gatewayNetworks, ",")
for _, v := range gn {
if len(v) > 1 {
if v[0] == '!' {
skipNets = append(skipNets, v[1:])
} else {
gatewayNets = append(gatewayNets, v)
}
}
}
}
swarmWaller := dockerwall.Waller{
DockerClient: cli,
UseDefaultNetworks: (len(gatewayNets) == 0),
GatewayNetworks: gatewayNets,
DefaultOutbound: *defaultOutbound,
DryRun: *dryRun,
SkipNetworks: skipNets,
CurrentMetrics: "",
M: &sync.Mutex{},
}
err = swarmWaller.Startup()
if err != nil {
logrus.Errorf("Startup error. Exiting. err=%s", err)
os.Exit(1)
}
}