Skip to content

Commit

Permalink
fix: set write permissions for group and other
Browse files Browse the repository at this point in the history
Fixes #1403.
  • Loading branch information
enocom committed Sep 13, 2022
1 parent be2d14f commit 11b0b7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,20 @@ func newSocketMount(ctx context.Context, conf *Config, pc *portConfig, inst Inst
}
address = UnixAddress(address, ".s.PGSQL.5432")
}

}

lc := net.ListenConfig{KeepAlive: 30 * time.Second}
ln, err := lc.Listen(ctx, network, address)
if err != nil {
return nil, err
}
// Change file permisions to allow access for user, group, and other.
if network == "unix" {
// Best effort. If this call fails, group and other won't have write
// access.
_ = os.Chmod(address, 0777)
}
opts := conf.DialOptions(inst)
m := &socketMount{inst: inst.Name, dialOpts: opts, listener: ln}
return m, nil
Expand Down
8 changes: 8 additions & 0 deletions internal/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ func TestClientInitialization(t *testing.T) {
}

for _, addr := range tc.wantUnixAddrs {
fi, err := os.Stat(addr)
if err != nil {
t.Fatalf("os.Stat(%v): %v", addr, err)
}
if fm := fi.Mode(); fm != 0777|os.ModeSocket {
t.Fatalf("file mode: want = %v, got = %v", 0777|os.ModeSocket, fm)
}

conn, err := net.Dial("unix", addr)
if err != nil {
t.Fatalf("want error = nil, got = %v", err)
Expand Down

0 comments on commit 11b0b7b

Please sign in to comment.