git.iko.soy/typeable/oauth2-proxy
on master help sign in
added an option to enable GCP healthcheck endpoints
commit3476daf32226f890fdc9a1dae2ace8d8bed401e3 authortimothy-spencer <timothy.spencer@gsa.gov> dateWed 20 Mar 2019, 14:29 (8 years ago) parentca89bb8
3 files changed+31−5
http.go+17 main.go+9−1 options.go+5−4
http.go+17
@@ -24,6 +24,23 @@ func (s *Server) ListenAndServe() {
2424 }
2525}
2626
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+
2744// ServeHTTP constructs a net.Listener and starts handling HTTP requests
2845func (s *Server) ServeHTTP() {
2946 HTTPAddress := s.Opts.HTTPAddress
main.go+9−1
@@ -5,6 +5,7 @@ import (
55 "fmt"
66 "log"
77 "math/rand"
8+ "net/http"
89 "os"
910 "runtime"
1011 "strings"
@@ -92,6 +93,7 @@ func main() {
9293 flagSet.String("acr-values", "http://idmanagement.gov/ns/assurance/loa/1", "acr values string: optional, used by login.gov")
9394 flagSet.String("jwt-key", "", "private key used to sign JWT: required by login.gov")
9495 flagSet.String("pubjwk-url", "", "JWK pubkey access endpoint: required by login.gov")
96+ flagSet.Bool("gcp-healthchecks", false, "Enable GCP healthcheck endpoints")
9597
9698 flagSet.Parse(os.Args[1:])
9799
@@ -139,8 +141,14 @@ func main() {
139141
140142 rand.Seed(time.Now().UnixNano())
141143
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+ }
142150 s := &Server{
143− Handler: LoggingHandler(os.Stdout, oauthproxy, opts.RequestLogging, opts.RequestLoggingFormat),
151+ Handler: myhandler,
144152 Opts: opts,
145153 }
146154 s.ListenAndServe()
options.go+5−4
@@ -86,10 +86,11 @@ type Options struct {
8686 RequestLogging bool `flag:"request-logging" cfg:"request_logging" env:"OAUTH2_PROXY_REQUEST_LOGGING"`
8787 RequestLoggingFormat string `flag:"request-logging-format" cfg:"request_logging_format" env:"OAUTH2_PROXY_REQUEST_LOGGING_FORMAT"`
8888
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"`
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"`
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"`
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"`
93+ GCPHealthChecks bool `flag:"gcp-healthchecks" cfg:"gcp_healthchecks" env:"OAUTH2_PROXY_GCP_HEALTHCHECKS"`
9394
9495 // internal values that are set after config validation
9596 redirectURL *url.URL