git.iko.soy/typeable/oauth2-proxy
on master help sign in
added an option to enable GCP healthcheck endpoints
3476daftimothy-spencer
@@ -24,6 +24,23 @@ func (s *Server) ListenAndServe() {
24 }
24 }
25}
25}
26
26
27+// gcpHealthcheck handles healthcheck queries from GCP
28+func gcpHealthcheck(h http.Handler) http.Handler {
29+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
30+ if r.URL.EscapedPath() == "/liveness_check" {
31+ w.WriteHeader(http.StatusOK)
32+ w.Write([]byte("OK"))
33+ return
34+ }
35+ if r.URL.EscapedPath() == "/readiness_check" {
36+ w.WriteHeader(http.StatusOK)
37+ w.Write([]byte("OK"))
38+ return
39+ }
40+ h.ServeHTTP(w, r)
41+ })
42+}
43+
27// ServeHTTP constructs a net.Listener and starts handling HTTP requests
44// ServeHTTP constructs a net.Listener and starts handling HTTP requests
28func (s *Server) ServeHTTP() {
45func (s *Server) ServeHTTP() {
29 HTTPAddress := s.Opts.HTTPAddress
46 HTTPAddress := s.Opts.HTTPAddress
main.go+9−1
@@ -5,6 +5,7 @@ import (
5 "fmt"
5 "fmt"
6 "log"
6 "log"
7 "math/rand"
7 "math/rand"
8+ "net/http"
8 "os"
9 "os"
9 "runtime"
10 "runtime"
10 "strings"
11 "strings"
@@ -92,6 +93,7 @@ func main() {
92 flagSet.String("acr-values", "http://idmanagement.gov/ns/assurance/loa/1", "acr values string: optional, used by login.gov")
93 flagSet.String("acr-values", "http://idmanagement.gov/ns/assurance/loa/1", "acr values string: optional, used by login.gov")
93 flagSet.String("jwt-key", "", "private key used to sign JWT: required by login.gov")
94 flagSet.String("jwt-key", "", "private key used to sign JWT: required by login.gov")
94 flagSet.String("pubjwk-url", "", "JWK pubkey access endpoint: required by login.gov")
95 flagSet.String("pubjwk-url", "", "JWK pubkey access endpoint: required by login.gov")
96+ flagSet.Bool("gcp-healthchecks", false, "Enable GCP healthcheck endpoints")
95
97
96 flagSet.Parse(os.Args[1:])
98 flagSet.Parse(os.Args[1:])
97
99
@@ -139,8 +141,14 @@ func main() {
139
141
140 rand.Seed(time.Now().UnixNano())
142 rand.Seed(time.Now().UnixNano())
141
143
144+ var myhandler http.Handler
145+ if opts.GCPHealthChecks {
146+ myhandler = gcpHealthcheck(LoggingHandler(os.Stdout, oauthproxy, opts.RequestLogging, opts.RequestLoggingFormat))
147+ } else {
148+ myhandler = LoggingHandler(os.Stdout, oauthproxy, opts.RequestLogging, opts.RequestLoggingFormat)
149+ }
142 s := &Server{
150 s := &Server{
143− Handler: LoggingHandler(os.Stdout, oauthproxy, opts.RequestLogging, opts.RequestLoggingFormat),
151+ Handler: myhandler,
144 Opts: opts,
152 Opts: opts,
145 }
153 }
146 s.ListenAndServe()
154 s.ListenAndServe()
options.go+5−4
@@ -86,10 +86,11 @@ type Options struct {
86 RequestLogging bool `flag:"request-logging" cfg:"request_logging" env:"OAUTH2_PROXY_REQUEST_LOGGING"`
86 RequestLogging bool `flag:"request-logging" cfg:"request_logging" env:"OAUTH2_PROXY_REQUEST_LOGGING"`
87 RequestLoggingFormat string `flag:"request-logging-format" cfg:"request_logging_format" env:"OAUTH2_PROXY_REQUEST_LOGGING_FORMAT"`
87 RequestLoggingFormat string `flag:"request-logging-format" cfg:"request_logging_format" env:"OAUTH2_PROXY_REQUEST_LOGGING_FORMAT"`
88
88
89− SignatureKey string `flag:"signature-key" cfg:"signature_key" env:"OAUTH2_PROXY_SIGNATURE_KEY"`
89+ SignatureKey string `flag:"signature-key" cfg:"signature_key" env:"OAUTH2_PROXY_SIGNATURE_KEY"`
90− AcrValues string `flag:"acr-values" cfg:"acr_values" env:"OAUTH2_PROXY_ACR_VALUES"`
90+ AcrValues string `flag:"acr-values" cfg:"acr_values" env:"OAUTH2_PROXY_ACR_VALUES"`
91− JWTKey string `flag:"jwt-key" cfg:"jwt_key" env:"OAUTH2_PROXY_JWT_KEY"`
91+ JWTKey string `flag:"jwt-key" cfg:"jwt_key" env:"OAUTH2_PROXY_JWT_KEY"`
92− PubJWKURL string `flag:"pubjwk-url" cfg:"pubjwk_url" env:"OAUTH2_PROXY_PUBJWK_URL"`
92+ PubJWKURL string `flag:"pubjwk-url" cfg:"pubjwk_url" env:"OAUTH2_PROXY_PUBJWK_URL"`
93+ GCPHealthChecks bool `flag:"gcp-healthchecks" cfg:"gcp_healthchecks" env:"OAUTH2_PROXY_GCP_HEALTHCHECKS"`
93
94
94 // internal values that are set after config validation
95 // internal values that are set after config validation
95 redirectURL *url.URL
96 redirectURL *url.URL