Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit d5169f9

Browse files
committed
Merge pull request #71 from jehiah/cookie_secure_flag_71
Rename flag to set secure (https) cookies
2 parents e67f2d5 + de04e0c commit d5169f9

5 files changed

Lines changed: 35 additions & 25 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ Usage of google_auth_proxy:
6464
-config="": path to config file
6565
-cookie-domain="": an optional cookie domain to force cookies to (ie: .yourcompany.com)*
6666
-cookie-expire=168h0m0s: expire timeframe for cookie
67-
-cookie-httponly=true: set HttpOnly cookie
68-
-cookie-https-only=true: set HTTPS only cookie
67+
-cookie-httponly=true: set HttpOnly cookie flag
68+
-cookie-https-only=true: set secure (HTTPS) cookies (deprecated. use --cookie-secure setting)
6969
-cookie-secret="": the seed string for secure cookies
70+
-cookie-secure=true: set secure (HTTPS) cookie flag
71+
-custom-templates-dir="": path to custom html templates
7072
-display-htpasswd-form=true: display username / password login form if an htpasswd file is provided
7173
-google-apps-domain=: authenticate against the given Google apps domain (may be given multiple times)
7274
-htpasswd-file="": additionally authenticate against a htpasswd file. Entries must be created with "htpasswd -s" for SHA encryption
@@ -75,7 +77,6 @@ Usage of google_auth_proxy:
7577
-pass-host-header=true: pass the request Host Header to upstream
7678
-redirect-url="": the OAuth Redirect URL. ie: "https://internalapp.yourcompany.com/oauth2/callback"
7779
-skip-auth-regex=: bypass authentication for requests path's that match (may be given multiple times)
78-
-custom templates-dir="": path to custom html templates
7980
-upstream=: the http url(s) of the upstream endpoint. If multiple, routing is based on path
8081
-version=false: print version string
8182
```
@@ -120,7 +121,7 @@ The command line to run `google_auth_proxy` would look like this:
120121
--google-apps-domain="yourcompany.com" \
121122
--upstream=http://127.0.0.1:8080/ \
122123
--cookie-secret=... \
123-
--cookie-https-only=true \
124+
--cookie-secure=true \
124125
--client-id=... \
125126
--client-secret=...
126127
```

contrib/google_auth_proxy.cfg.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949
# cookie_secret = ""
5050
# cookie_domain = ""
5151
# cookie_expire = "168h"
52-
# cookie_https_only = true
52+
# cookie_secure = true
5353
# cookie_httponly = true

main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func main() {
4343
flagSet.String("cookie-secret", "", "the seed string for secure cookies")
4444
flagSet.String("cookie-domain", "", "an optional cookie domain to force cookies to (ie: .yourcompany.com)*")
4545
flagSet.Duration("cookie-expire", time.Duration(168)*time.Hour, "expire timeframe for cookie")
46-
flagSet.Bool("cookie-https-only", true, "set HTTPS only cookie")
47-
flagSet.Bool("cookie-httponly", true, "set HttpOnly cookie")
46+
flagSet.Bool("cookie-https-only", true, "set secure (HTTPS) cookies (deprecated. use --cookie-secure setting)")
47+
flagSet.Bool("cookie-secure", true, "set secure (HTTPS) cookie flag")
48+
flagSet.Bool("cookie-httponly", true, "set HttpOnly cookie flag")
4849

4950
flagSet.Parse(os.Args[1:])
5051

oauthproxy.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const oauthStartPath = "/oauth2/start"
2424
const oauthCallbackPath = "/oauth2/callback"
2525

2626
type OauthProxy struct {
27-
CookieSeed string
28-
CookieKey string
29-
CookieDomain string
30-
CookieHttpsOnly bool
31-
CookieHttpOnly bool
32-
CookieExpire time.Duration
33-
Validator func(string) bool
27+
CookieSeed string
28+
CookieKey string
29+
CookieDomain string
30+
CookieSecure bool
31+
CookieHttpOnly bool
32+
CookieExpire time.Duration
33+
Validator func(string) bool
3434

3535
redirectUrl *url.URL // the url to receive requests at
3636
oauthRedemptionUrl *url.URL // endpoint to redeem the code
@@ -98,15 +98,21 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
9898
if domain == "" {
9999
domain = "<default>"
100100
}
101-
log.Printf("Cookie settings: https_only (SSL required): %v httponly: %v expiry: %s domain:%s", opts.CookieHttpsOnly, opts.CookieHttpOnly, opts.CookieExpire, domain)
101+
if !opts.CookieHttpsOnly {
102+
log.Printf("Warning: cookie-https-only setting is deprecated and will be removed in a future version. use cookie-secure")
103+
opts.CookieSecure = opts.CookieHttpsOnly
104+
}
105+
106+
log.Printf("Cookie settings: secure (https):%v httponly:%v expiry:%s domain:%s", opts.CookieSecure, opts.CookieHttpOnly, opts.CookieExpire, domain)
107+
102108
return &OauthProxy{
103-
CookieKey: "_oauthproxy",
104-
CookieSeed: opts.CookieSecret,
105-
CookieDomain: opts.CookieDomain,
106-
CookieHttpsOnly: opts.CookieHttpsOnly,
107-
CookieHttpOnly: opts.CookieHttpOnly,
108-
CookieExpire: opts.CookieExpire,
109-
Validator: validator,
109+
CookieKey: "_oauthproxy",
110+
CookieSeed: opts.CookieSecret,
111+
CookieDomain: opts.CookieDomain,
112+
CookieSecure: opts.CookieSecure,
113+
CookieHttpOnly: opts.CookieHttpOnly,
114+
CookieExpire: opts.CookieExpire,
115+
Validator: validator,
110116

111117
clientID: opts.ClientID,
112118
clientSecret: opts.ClientSecret,
@@ -130,7 +136,7 @@ func (p *OauthProxy) GetRedirectUrl(host string) string {
130136
var u url.URL
131137
u = *p.redirectUrl
132138
if u.Scheme == "" {
133-
if p.CookieHttpsOnly {
139+
if p.CookieSecure {
134140
u.Scheme = "https"
135141
} else {
136142
u.Scheme = "http"
@@ -265,7 +271,7 @@ func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val st
265271
Path: "/",
266272
Domain: domain,
267273
HttpOnly: p.CookieHttpOnly,
268-
Secure: p.CookieHttpsOnly,
274+
Secure: p.CookieSecure,
269275
Expires: time.Now().Add(p.CookieExpire),
270276
}
271277
http.SetCookie(rw, cookie)

options.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ type Options struct {
2424
CookieSecret string `flag:"cookie-secret" cfg:"cookie_secret" env:"GOOGLE_AUTH_PROXY_COOKIE_SECRET"`
2525
CookieDomain string `flag:"cookie-domain" cfg:"cookie_domain" env:"GOOGLE_AUTH_PROXY_COOKIE_DOMAIN"`
2626
CookieExpire time.Duration `flag:"cookie-expire" cfg:"cookie_expire" env:"GOOGLE_AUTH_PROXY_COOKIE_EXPIRE"`
27-
CookieHttpsOnly bool `flag:"cookie-https-only" cfg:"cookie_https_only"` // set secure cookie flag
27+
CookieHttpsOnly bool `flag:"cookie-https-only" cfg:"cookie_https_only"` // deprecated use cookie-secure
28+
CookieSecure bool `flag:"cookie-secure" cfg:"cookie_secure"`
2829
CookieHttpOnly bool `flag:"cookie-httponly" cfg:"cookie_httponly"`
2930

3031
Upstreams []string `flag:"upstream" cfg:"upstreams"`
@@ -43,6 +44,7 @@ func NewOptions() *Options {
4344
HttpAddress: "127.0.0.1:4180",
4445
DisplayHtpasswdForm: true,
4546
CookieHttpsOnly: true,
47+
CookieSecure: true,
4648
CookieHttpOnly: true,
4749
CookieExpire: time.Duration(168) * time.Hour,
4850
PassBasicAuth: true,

0 commit comments

Comments
 (0)