Skip to content

Commit df38614

Browse files
committed
Drop privileges after enabling DNS server
As @dfangl pointed out: Binding port 53 might require root permissions for binding port < 1024 depending on the Docker version moby/moby#41030
1 parent 3c60bf3 commit df38614

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

cmd/localstack/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ func main() {
6262
log.SetLevel(log.DebugLevel)
6363
log.SetReportCaller(true)
6464

65+
// download code archive if env variable is set
66+
if err := DownloadCodeArchives(lsOpts.CodeArchives); err != nil {
67+
log.Fatal("Failed to download code archives")
68+
}
69+
// enable dns server
70+
dnsServerContext, stopDnsServer := context.WithCancel(context.Background())
71+
go RunDNSRewriter(lsOpts, dnsServerContext)
72+
6573
// Switch to non-root user and drop root privileges
6674
if IsRootUser() && lsOpts.User != "" {
6775
uid := 993
@@ -75,13 +83,6 @@ func main() {
7583
UserLogger().Debugln("Process running as non-root user.")
7684
}
7785

78-
// download code archive if env variable is set
79-
if err := DownloadCodeArchives(lsOpts.CodeArchives); err != nil {
80-
log.Fatal("Failed to download code archives")
81-
}
82-
// enable dns server
83-
dnsServerContext, stopDnsServer := context.WithCancel(context.Background())
84-
go RunDNSRewriter(lsOpts, dnsServerContext)
8586
// parse CLI args
8687
opts, args := getCLIArgs()
8788
bootstrap, handler := getBootstrap(args, opts)

0 commit comments

Comments
 (0)