git.iko.soy/typeable/oauth2-proxy
on master help sign in
Break legacy upstream options into LegacyUpstreams struct
71dc702Joel Speed
pkg/apis/options/legacy_options.go+34−15
@@ -7,31 +7,30 @@ import (
7 "time"
7 "time"
8
8
9 "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
9 "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
10+ "github.com/spf13/pflag"
10)
11)
11
12
12type LegacyOptions struct {
13type LegacyOptions struct {
13 // Legacy options related to upstream servers
14 // Legacy options related to upstream servers
14− LegacyFlushInterval time.Duration `flag:"flush-interval" cfg:"flush_interval"`
15+ LegacyUpstreams LegacyUpstreams `cfg:",squash"`
15− LegacyPassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
16− LegacyProxyWebSockets bool `flag:"proxy-websockets" cfg:"proxy_websockets"`
17− LegacySSLUpstreamInsecureSkipVerify bool `flag:"ssl-upstream-insecure-skip-verify" cfg:"ssl_upstream_insecure_skip_verify"`
18− LegacyUpstreams []string `flag:"upstream" cfg:"upstreams"`
19
16
20 Options Options `cfg:",squash"`
17 Options Options `cfg:",squash"`
21}
18}
22
19
23func NewLegacyOptions() *LegacyOptions {
20func NewLegacyOptions() *LegacyOptions {
24 return &LegacyOptions{
21 return &LegacyOptions{
25− LegacyPassHostHeader: true,
22+ LegacyUpstreams: LegacyUpstreams{
26− LegacyProxyWebSockets: true,
23+ PassHostHeader: true,
24+ ProxyWebSockets: true,
27− LegacyFlushInterval: time.Duration(1) * time.Second,
25+ FlushInterval: time.Duration(1) * time.Second,
26+ },
28
27
29 Options: *NewOptions(),
28 Options: *NewOptions(),
30 }
29 }
31}
30}
32
31
33func (l *LegacyOptions) ToOptions() (*Options, error) {
32func (l *LegacyOptions) ToOptions() (*Options, error) {
34− upstreams, err := convertLegacyUpstreams(l.LegacyUpstreams, l.LegacySSLUpstreamInsecureSkipVerify, l.LegacyPassHostHeader, l.LegacyProxyWebSockets, l.LegacyFlushInterval)
33+ upstreams, err := l.LegacyUpstreams.convert()
35 if err != nil {
34 if err != nil {
36 return nil, fmt.Errorf("error converting upstreams: %v", err)
35 return nil, fmt.Errorf("error converting upstreams: %v", err)
37 }
36 }
@@ -40,10 +39,30 @@ func (l *LegacyOptions) ToOptions() (*Options, error) {
40 return &l.Options, nil
39 return &l.Options, nil
41}
40}
42
41
43−func convertLegacyUpstreams(upstreamStrings []string, skipVerify, passHostHeader, proxyWebSockets bool, flushInterval time.Duration) (Upstreams, error) {
42+type LegacyUpstreams struct {
43+ FlushInterval time.Duration `flag:"flush-interval" cfg:"flush_interval"`
44+ PassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
45+ ProxyWebSockets bool `flag:"proxy-websockets" cfg:"proxy_websockets"`
46+ SSLUpstreamInsecureSkipVerify bool `flag:"ssl-upstream-insecure-skip-verify" cfg:"ssl_upstream_insecure_skip_verify"`
47+ Upstreams []string `flag:"upstream" cfg:"upstreams"`
48+}
49+
50+func legacyUpstreamsFlagSet() *pflag.FlagSet {
51+ flagSet := pflag.NewFlagSet("upstreams", pflag.ExitOnError)
52+
53+ flagSet.Duration("flush-interval", time.Duration(1)*time.Second, "period between response flushing when streaming responses")
54+ flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream")
55+ flagSet.Bool("proxy-websockets", true, "enables WebSocket proxying")
56+ flagSet.Bool("ssl-upstream-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS upstreams")
57+ flagSet.StringSlice("upstream", []string{}, "the http url(s) of the upstream endpoint, file:// paths for static files or static://<status_code> for static response. Routing is based on the path")
58+
59+ return flagSet
60+}
61+
62+func (l *LegacyUpstreams) convert() (Upstreams, error) {
44 upstreams := Upstreams{}
63 upstreams := Upstreams{}
45
64
46− for _, upstreamString := range upstreamStrings {
65+ for _, upstreamString := range l.Upstreams {
47 u, err := url.Parse(upstreamString)
66 u, err := url.Parse(upstreamString)
48 if err != nil {
67 if err != nil {
49 return nil, fmt.Errorf("could not parse upstream %q: %v", upstreamString, err)
68 return nil, fmt.Errorf("could not parse upstream %q: %v", upstreamString, err)
@@ -57,10 +76,10 @@ func convertLegacyUpstreams(upstreamStrings []string, skipVerify, passHostHeader
57 ID: u.Path,
76 ID: u.Path,
58 Path: u.Path,
77 Path: u.Path,
59 URI: upstreamString,
78 URI: upstreamString,
60− InsecureSkipTLSVerify: skipVerify,
79+ InsecureSkipTLSVerify: l.SSLUpstreamInsecureSkipVerify,
61− PassHostHeader: passHostHeader,
80+ PassHostHeader: l.PassHostHeader,
62− ProxyWebSockets: proxyWebSockets,
81+ ProxyWebSockets: l.ProxyWebSockets,
63− FlushInterval: &flushInterval,
82+ FlushInterval: &l.FlushInterval,
64 }
83 }
65
84
66 switch u.Scheme {
85 switch u.Scheme {
pkg/apis/options/legacy_options_test.go+14−6
@@ -17,11 +17,11 @@ var _ = Describe("Legacy Options", func() {
17
17
18 // Set upstreams and related options to test their conversion
18 // Set upstreams and related options to test their conversion
19 flushInterval := 5 * time.Second
19 flushInterval := 5 * time.Second
20− legacyOpts.LegacyFlushInterval = flushInterval
20+ legacyOpts.LegacyUpstreams.FlushInterval = flushInterval
21− legacyOpts.LegacyPassHostHeader = true
21+ legacyOpts.LegacyUpstreams.PassHostHeader = true
22− legacyOpts.LegacyProxyWebSockets = true
22+ legacyOpts.LegacyUpstreams.ProxyWebSockets = true
23− legacyOpts.LegacySSLUpstreamInsecureSkipVerify = true
23+ legacyOpts.LegacyUpstreams.SSLUpstreamInsecureSkipVerify = true
24− legacyOpts.LegacyUpstreams = []string{"http://foo.bar/baz", "file://var/lib/website#/bar"}
24+ legacyOpts.LegacyUpstreams.Upstreams = []string{"http://foo.bar/baz", "file://var/lib/website#/bar"}
25
25
26 opts.UpstreamServers = Upstreams{
26 opts.UpstreamServers = Upstreams{
27 {
27 {
@@ -133,7 +133,15 @@ var _ = Describe("Legacy Options", func() {
133
133
134 DescribeTable("convertLegacyUpstreams",
134 DescribeTable("convertLegacyUpstreams",
135 func(o *convertUpstreamsTableInput) {
135 func(o *convertUpstreamsTableInput) {
136− upstreams, err := convertLegacyUpstreams(o.upstreamStrings, skipVerify, passHostHeader, proxyWebSockets, flushInterval)
136+ legacyUpstreams := LegacyUpstreams{
137+ Upstreams: o.upstreamStrings,
138+ SSLUpstreamInsecureSkipVerify: skipVerify,
139+ PassHostHeader: passHostHeader,
140+ ProxyWebSockets: proxyWebSockets,
141+ FlushInterval: flushInterval,
142+ }
143+
144+ upstreams, err := legacyUpstreams.convert()
137
145
138 if o.errMsg != "" {
146 if o.errMsg != "" {
139 Expect(err).To(HaveOccurred())
147 Expect(err).To(HaveOccurred())
pkg/apis/options/options.go+1−6
@@ -4,7 +4,6 @@ import (
4 "crypto"
4 "crypto"
5 "net/url"
5 "net/url"
6 "regexp"
6 "regexp"
7− "time"
8
7
9 oidc "github.com/coreos/go-oidc"
8 oidc "github.com/coreos/go-oidc"
10 ipapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/ip"
9 ipapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/ip"
@@ -185,14 +184,12 @@ func NewFlagSet() *pflag.FlagSet {
185 flagSet.String("tls-key-file", "", "path to private key file")
184 flagSet.String("tls-key-file", "", "path to private key file")
186 flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
185 flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
187 flagSet.Bool("set-xauthrequest", false, "set X-Auth-Request-User and X-Auth-Request-Email response headers (useful in Nginx auth_request mode)")
186 flagSet.Bool("set-xauthrequest", false, "set X-Auth-Request-User and X-Auth-Request-Email response headers (useful in Nginx auth_request mode)")
188− flagSet.StringSlice("upstream", []string{}, "the http url(s) of the upstream endpoint, file:// paths for static files or static://<status_code> for static response. Routing is based on the path")
189 flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
187 flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
190 flagSet.Bool("set-basic-auth", false, "set HTTP Basic Auth information in response (useful in Nginx auth_request mode)")
188 flagSet.Bool("set-basic-auth", false, "set HTTP Basic Auth information in response (useful in Nginx auth_request mode)")
191 flagSet.Bool("prefer-email-to-user", false, "Prefer to use the Email address as the Username when passing information to upstream. Will only use Username if Email is unavailable, eg. htaccess authentication. Used in conjunction with -pass-basic-auth and -pass-user-headers")
189 flagSet.Bool("prefer-email-to-user", false, "Prefer to use the Email address as the Username when passing information to upstream. Will only use Username if Email is unavailable, eg. htaccess authentication. Used in conjunction with -pass-basic-auth and -pass-user-headers")
192 flagSet.Bool("pass-user-headers", true, "pass X-Forwarded-User and X-Forwarded-Email information to upstream")
190 flagSet.Bool("pass-user-headers", true, "pass X-Forwarded-User and X-Forwarded-Email information to upstream")
193 flagSet.String("basic-auth-password", "", "the password to set when passing the HTTP Basic Auth header")
191 flagSet.String("basic-auth-password", "", "the password to set when passing the HTTP Basic Auth header")
194 flagSet.Bool("pass-access-token", false, "pass OAuth access_token to upstream via X-Forwarded-Access-Token header")
192 flagSet.Bool("pass-access-token", false, "pass OAuth access_token to upstream via X-Forwarded-Access-Token header")
195− flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream")
196 flagSet.Bool("pass-authorization-header", false, "pass the Authorization Header to upstream")
193 flagSet.Bool("pass-authorization-header", false, "pass the Authorization Header to upstream")
197 flagSet.Bool("set-authorization-header", false, "set Authorization response headers (useful in Nginx auth_request mode)")
194 flagSet.Bool("set-authorization-header", false, "set Authorization response headers (useful in Nginx auth_request mode)")
198 flagSet.StringSlice("skip-auth-regex", []string{}, "bypass authentication for requests path's that match (may be given multiple times)")
195 flagSet.StringSlice("skip-auth-regex", []string{}, "bypass authentication for requests path's that match (may be given multiple times)")
@@ -200,8 +197,6 @@ func NewFlagSet() *pflag.FlagSet {
200 flagSet.Bool("skip-provider-button", false, "will skip sign-in-page to directly reach the next step: oauth/start")
197 flagSet.Bool("skip-provider-button", false, "will skip sign-in-page to directly reach the next step: oauth/start")
201 flagSet.Bool("skip-auth-preflight", false, "will skip authentication for OPTIONS requests")
198 flagSet.Bool("skip-auth-preflight", false, "will skip authentication for OPTIONS requests")
202 flagSet.Bool("ssl-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS providers")
199 flagSet.Bool("ssl-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS providers")
203− flagSet.Bool("ssl-upstream-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS upstreams")
204− flagSet.Duration("flush-interval", time.Duration(1)*time.Second, "period between response flushing when streaming responses")
205 flagSet.Bool("skip-jwt-bearer-tokens", false, "will skip requests that have verified JWT bearer tokens (default false)")
200 flagSet.Bool("skip-jwt-bearer-tokens", false, "will skip requests that have verified JWT bearer tokens (default false)")
206 flagSet.StringSlice("extra-jwt-issuers", []string{}, "if skip-jwt-bearer-tokens is set, a list of extra JWT issuer=audience pairs (where the issuer URL has a .well-known/openid-configuration or a .well-known/jwks.json)")
201 flagSet.StringSlice("extra-jwt-issuers", []string{}, "if skip-jwt-bearer-tokens is set, a list of extra JWT issuer=audience pairs (where the issuer URL has a .well-known/openid-configuration or a .well-known/jwks.json)")
207
202
@@ -232,7 +227,6 @@ func NewFlagSet() *pflag.FlagSet {
232 flagSet.String("proxy-prefix", "/oauth2", "the url root path that this proxy should be nested under (e.g. /<oauth2>/sign_in)")
227 flagSet.String("proxy-prefix", "/oauth2", "the url root path that this proxy should be nested under (e.g. /<oauth2>/sign_in)")
233 flagSet.String("ping-path", "/ping", "the ping endpoint that can be used for basic health checks")
228 flagSet.String("ping-path", "/ping", "the ping endpoint that can be used for basic health checks")
234 flagSet.String("ping-user-agent", "", "special User-Agent that will be used for basic health checks")
229 flagSet.String("ping-user-agent", "", "special User-Agent that will be used for basic health checks")
235− flagSet.Bool("proxy-websockets", true, "enables WebSocket proxying")
236 flagSet.String("session-store-type", "cookie", "the session storage provider to use")
230 flagSet.String("session-store-type", "cookie", "the session storage provider to use")
237 flagSet.Bool("session-cookie-minimal", false, "strip OAuth tokens from cookie session stores if they aren't needed (cookie session store only)")
231 flagSet.Bool("session-cookie-minimal", false, "strip OAuth tokens from cookie session stores if they aren't needed (cookie session store only)")
238 flagSet.String("redis-connection-url", "", "URL of redis server for redis session storage (eg: redis://HOST[:PORT])")
232 flagSet.String("redis-connection-url", "", "URL of redis server for redis session storage (eg: redis://HOST[:PORT])")
@@ -272,6 +266,7 @@ func NewFlagSet() *pflag.FlagSet {
272
266
273 flagSet.AddFlagSet(cookieFlagSet())
267 flagSet.AddFlagSet(cookieFlagSet())
274 flagSet.AddFlagSet(loggingFlagSet())
268 flagSet.AddFlagSet(loggingFlagSet())
269+ flagSet.AddFlagSet(legacyUpstreamsFlagSet())
275
270
276 return flagSet
271 return flagSet
277}
272}