git.iko.soy/typeable/oauth2-proxy
on master help sign in
fix: systemd socket support build handling for windows
8dd2cbetuunit
CHANGELOG.md+1
@@ -33,6 +33,7 @@
33- [#2800](https://github.com/oauth2-proxy/oauth2-proxy/pull/2800) doc: add some opencontainer labels to docker image (@halkeye)
33- [#2800](https://github.com/oauth2-proxy/oauth2-proxy/pull/2800) doc: add some opencontainer labels to docker image (@halkeye)
34- [#2755](https://github.com/oauth2-proxy/oauth2-proxy/pull/2755) feat: add X-Envoy-External-Address as supported header (@bjencks)
34- [#2755](https://github.com/oauth2-proxy/oauth2-proxy/pull/2755) feat: add X-Envoy-External-Address as supported header (@bjencks)
35- [#1985](https://github.com/oauth2-proxy/oauth2-proxy/pull/1985) feat: add support for systemd socket (@isodude)
35- [#1985](https://github.com/oauth2-proxy/oauth2-proxy/pull/1985) feat: add support for systemd socket (@isodude)
36+- [#2916](https://github.com/oauth2-proxy/oauth2-proxy/pull/2916) fix: systemd socket support build handling for windows (@tuunit)
36- [#2300](https://github.com/oauth2-proxy/oauth2-proxy/pull/2300) fix: add fix for websocket path rewrite (@rekup)
37- [#2300](https://github.com/oauth2-proxy/oauth2-proxy/pull/2300) fix: add fix for websocket path rewrite (@rekup)
37- [#2821](https://github.com/oauth2-proxy/oauth2-proxy/pull/2821) feat: add CF-Connecting-IP as supported real ip header (@ondrejsika)
38- [#2821](https://github.com/oauth2-proxy/oauth2-proxy/pull/2821) feat: add CF-Connecting-IP as supported real ip header (@ondrejsika)
38- [#2620](https://github.com/oauth2-proxy/oauth2-proxy/pull/2620) fix: update code_verifier to use recommended method (@vishvananda)
39- [#2620](https://github.com/oauth2-proxy/oauth2-proxy/pull/2620) fix: update code_verifier to use recommended method (@vishvananda)
pkg/http/server.go+4−41
@@ -8,24 +8,14 @@ import (
8 "net"
8 "net"
9 "net/http"
9 "net/http"
10 "os"
10 "os"
11− "strconv"
12 "strings"
11 "strings"
13 "time"
12 "time"
14
13
15− "github.com/coreos/go-systemd/activation"
14+ "golang.org/x/sync/errgroup"
15+
16 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
16 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
17 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options/util"
17 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options/util"
18 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
18 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
19− "golang.org/x/sync/errgroup"
20−)
21−
22−// listenFdsStart corresponds to `SD_LISTEN_FDS_START`.
23−// Since the 3 first file descriptors in every linux process is
24−// stdin, stdout and stderr. The first usable file descriptor is 3.
25−// systemd-socket-activate will always assume that the first socket will be
26−// 3 and the rest follow.
27−const (
28− listenFdsStart = 3
29)
19)
30
20
31// Server represents an HTTP or HTTPS server.
21// Server represents an HTTP or HTTPS server.
@@ -83,27 +73,6 @@ type server struct {
83 fdFiles []*os.File
73 fdFiles []*os.File
84}
74}
85
75
86−// convert a string filedescriptor to an actual listener
87−func (s *server) fdToListener(bindAddress string) (net.Listener, error) {
88− fd, err := strconv.Atoi(bindAddress)
89− if err != nil {
90− return nil, fmt.Errorf("listen failed: fd with name is not implemented yet")
91− }
92− fdIndex := fd - listenFdsStart
93−
94− if len(s.fdFiles) == 0 {
95− s.fdFiles = activation.Files(true)
96− }
97−
98− l := len(s.fdFiles)
99−
100− if fdIndex < 0 || fdIndex >= l || l == 0 {
101− return nil, fmt.Errorf("listen failed: fd outside of range of available file descriptors")
102− }
103−
104− return net.FileListener(s.fdFiles[fdIndex])
105−}
106−
107// setupListener sets the server listener if the HTTP server is enabled.
76// setupListener sets the server listener if the HTTP server is enabled.
108// The HTTP server can be disabled by setting the BindAddress to "-" or by
77// The HTTP server can be disabled by setting the BindAddress to "-" or by
109// leaving it empty.
78// leaving it empty.
@@ -120,13 +89,7 @@ func (s *server) setupListener(opts Opts) error {
120 // to the program is indeed a net.Listener and starts using it
89 // to the program is indeed a net.Listener and starts using it
121 // without setting up a new listener.
90 // without setting up a new listener.
122 if strings.HasPrefix(strings.ToLower(opts.BindAddress), "fd:") {
91 if strings.HasPrefix(strings.ToLower(opts.BindAddress), "fd:") {
123− listenAddr := opts.BindAddress[3:]
92+ return s.checkSystemdSocketSupport(opts)
124− listener, err := s.fdToListener(listenAddr)
125− if err != nil {
126− err = fmt.Errorf("listen (%s, %s) failed: %v", "file", listenAddr, err)
127− }
128− s.listener = listener
129− return err
130 }
93 }
131
94
132 networkType := getNetworkScheme(opts.BindAddress)
95 networkType := getNetworkScheme(opts.BindAddress)
@@ -134,7 +97,7 @@ func (s *server) setupListener(opts Opts) error {
134
97
135 listener, err := net.Listen(networkType, listenAddr)
98 listener, err := net.Listen(networkType, listenAddr)
136 if err != nil {
99 if err != nil {
137− return fmt.Errorf("listen (%s, %s) failed: %v", networkType, listenAddr, err)
100+ return fmt.Errorf("listen (%s, %s) failed: %w", networkType, listenAddr, err)
138 }
101 }
139 s.listener = listener
102 s.listener = listener
140
103
pkg/http/systemd_socket.gonew file+55
@@ -0,0 +1,55 @@
1+//go:build !windows
2+// +build !windows
3+
4+package http
5+
6+import (
7+ "errors"
8+ "fmt"
9+ "net"
10+ "strconv"
11+
12+ "github.com/coreos/go-systemd/activation"
13+)
14+
15+// listenFdsStart corresponds to `SD_LISTEN_FDS_START`.
16+// Since the 3 first file descriptors in every linux process is
17+// stdin, stdout and stderr. The first usable file descriptor is 3.
18+// systemd-socket-activate will always assume that the first socket will be
19+// 3 and the rest follow.
20+const (
21+ listenFdsStart = 3
22+)
23+
24+// convert a string filedescriptor to an actual listener
25+func (s *server) fdToListener(bindAddress string) (net.Listener, error) {
26+ fd, err := strconv.Atoi(bindAddress)
27+ if err != nil {
28+ return nil, errors.New("listen failed: fd with name is not implemented yet")
29+ }
30+ fdIndex := fd - listenFdsStart
31+
32+ if len(s.fdFiles) == 0 {
33+ s.fdFiles = activation.Files(true)
34+ }
35+
36+ l := len(s.fdFiles)
37+
38+ if fdIndex < 0 || fdIndex >= l || l == 0 {
39+ return nil, errors.New("listen failed: fd outside of range of available file descriptors")
40+ }
41+
42+ return net.FileListener(s.fdFiles[fdIndex])
43+}
44+
45+func (s *server) checkSystemdSocketSupport(opts Opts) error {
46+ listenAddr := opts.BindAddress[3:]
47+ listener, err := s.fdToListener(listenAddr)
48+ if err != nil {
49+ err = fmt.Errorf("listen (file, %s) failed: %w", listenAddr, err)
50+ return err
51+ }
52+
53+ s.listener = listener
54+ return nil
55+}
pkg/http/systemd_unsupported.gonew file+17
@@ -0,0 +1,17 @@
1+//go:build windows
2+// +build windows
3+
4+package http
5+
6+import (
7+ "fmt"
8+ "strings"
9+)
10+
11+func (s *server) checkSystemdSocketSupport(opts Opts) error {
12+ if strings.HasPrefix(strings.ToLower(opts.BindAddress), "fd:") {
13+ listenAddr := opts.BindAddress[3:]
14+ return fmt.Errorf("listen (file, %s) failed: systemd sockets are not supported on windows", listenAddr)
15+ }
16+ return nil
17+}