15 "github.com/BurntSushi/toml"
16 "github.com/mreiferson/go-options"
20 flagSet := flag.NewFlagSet("google_auth_proxy", flag.ExitOnError)
22 googleAppsDomains := StringArray{}
23 upstreams := StringArray{}
24 skipAuthRegex := StringArray{}
26 config := flagSet.String("config", "", "path to config file")
27 showVersion := flagSet.Bool("version", false, "print version string")
29 flagSet.String("http-address", "127.0.0.1:4180", "[http://]<addr>:<port> or unix://<path> to listen on for HTTP clients")
30 flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
31 flagSet.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint. If multiple, routing is based on path")
32 flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
33 flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream")
34 flagSet.Var(&skipAuthRegex, "skip-auth-regex", "bypass authentication for requests path's that match (may be given multiple times)")
36 flagSet.Var(&googleAppsDomains, "google-apps-domain", "authenticate against the given Google apps domain (may be given multiple times)")
37 flagSet.String("client-id", "", "the Google OAuth Client ID: ie: \"123456.apps.googleusercontent.com\"")
38 flagSet.String("client-secret", "", "the OAuth Client Secret")
39 flagSet.String("authenticated-emails-file", "", "authenticate against emails via file (one per line)")
40 flagSet.String("htpasswd-file", "", "additionally authenticate against a htpasswd file. Entries must be created with \"htpasswd -s\" for SHA encryption")
41 flagSet.Bool("display-htpasswd-form", true, "display username / password login form if an htpasswd file is provided")
42 flagSet.String("custom-templates-dir", "", "path to custom html templates")
44 flagSet.String("cookie-secret", "", "the seed string for secure cookies")
45 flagSet.String("cookie-domain", "", "an optional cookie domain to force cookies to (ie: .yourcompany.com)*")
46 flagSet.Duration("cookie-expire", time.Duration(168)*time.Hour, "expire timeframe for cookie")
47 flagSet.Bool("cookie-https-only", true, "set secure (HTTPS) cookies (deprecated. use --cookie-secure setting)")
48 flagSet.Bool("cookie-secure", true, "set secure (HTTPS) cookie flag")
49 flagSet.Bool("cookie-httponly", true, "set HttpOnly cookie flag")
51 flagSet.Bool("request-logging", true, "Log requests to stdout")
53 flagSet.Parse(os.Args[1:])
56 fmt.Printf("google_auth_proxy v%s (built with %s)\n", VERSION, runtime.Version())
62 cfg := make(EnvOptions)
64 _, err := toml.DecodeFile(*config, &cfg)
66 log.Fatalf("ERROR: failed to load config file %s - %s", *config, err)
69 cfg.LoadEnvForStruct(opts)
70 options.Resolve(opts, flagSet, cfg)
72 err := opts.Validate()
78 validator := NewValidator(opts.GoogleAppsDomains, opts.AuthenticatedEmailsFile)
79 oauthproxy := NewOauthProxy(opts, validator)
81 if len(opts.GoogleAppsDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
82 if len(opts.GoogleAppsDomains) > 1 {
83 oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using one of the following domains: %v", strings.Join(opts.GoogleAppsDomains, ", "))
85 oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using %v", opts.GoogleAppsDomains[0])
89 if opts.HtpasswdFile != "" {
90 log.Printf("using htpasswd file %s", opts.HtpasswdFile)
91 oauthproxy.HtpasswdFile, err = NewHtpasswdFromFile(opts.HtpasswdFile)
92 oauthproxy.DisplayHtpasswdForm = opts.DisplayHtpasswdForm
94 log.Fatalf("FATAL: unable to open %s %s", opts.HtpasswdFile, err)
98 u, err := url.Parse(opts.HttpAddress)
100 log.Fatalf("FATAL: could not parse %#v: %v", opts.HttpAddress, err)
103 var networkType string
108 networkType = u.Scheme
110 listenAddr := strings.TrimPrefix(u.String(), u.Scheme+"://")
112 listener, err := net.Listen(networkType, listenAddr)
114 log.Fatalf("FATAL: listen (%s, %s) failed - %s", networkType, listenAddr, err)
116 log.Printf("listening on %s", listenAddr)
118 server := &http.Server{Handler: LoggingHandler(os.Stdout, oauthproxy, opts.RequestLogging)}
119 err = server.Serve(listener)
120 if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
121 log.Printf("ERROR: http.Serve() - %s", err)
124 log.Printf("HTTP: closing %s", listener.Addr())
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list