diff --git a/CHANGELOG.md b/CHANGELOG.md index bd635065..f1f3dde1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ## Changes since v7.0.1 +- [#1056](https://github.com/oauth2-proxy/oauth2-proxy/pull/1056) Add option for custom logos on the sign in page (@JoelSpeed) - [#1054](https://github.com/oauth2-proxy/oauth2-proxy/pull/1054) Update to Go 1.16 (@JoelSpeed) - [#1052](https://github.com/oauth2-proxy/oauth2-proxy/pull/1052) Update golangci-lint to latest version (v1.36.0) (@JoelSpeed) - [#1043](https://github.com/oauth2-proxy/oauth2-proxy/pull/1043) Refactor Sign In Page rendering and capture all page rendering code in pagewriter package (@JoelSpeed) diff --git a/docs/docs/configuration/overview.md b/docs/docs/configuration/overview.md index b9017977..66750004 100644 --- a/docs/docs/configuration/overview.md +++ b/docs/docs/configuration/overview.md @@ -40,6 +40,7 @@ An example [oauth2-proxy.cfg](https://github.com/oauth2-proxy/oauth2-proxy/blob/ | `--cookie-secure` | bool | set [secure (HTTPS only) cookie flag](https://owasp.org/www-community/controls/SecureFlag) | true | | `--cookie-samesite` | string | set SameSite cookie attribute (`"lax"`, `"strict"`, `"none"`, or `""`). | `""` | | `--custom-templates-dir` | string | path to custom html templates | | +| `--custom-sign-in-logo` | string | path to an custom image for the sign_in page logo. Use \"-\" to disable default logo. | | `--display-htpasswd-form` | bool | display username / password login form if an htpasswd file is provided | true | | `--email-domain` | string \| list | authenticate emails with the specified domain (may be given multiple times). Use `*` to authenticate any email | | | `--errors-to-info-log` | bool | redirects error-level logging to default log channel instead of stderr | | diff --git a/oauthproxy.go b/oauthproxy.go index 7bf524aa..82f89e6b 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -123,6 +123,7 @@ func NewOAuthProxy(opts *options.Options, validator func(string) bool) (*OAuthPr pageWriter, err := pagewriter.NewWriter(pagewriter.Opts{ TemplatesPath: opts.Templates.Path, + CustomLogo: opts.Templates.CustomLogo, ProxyPrefix: opts.ProxyPrefix, Footer: opts.Templates.Footer, Version: VERSION, diff --git a/pkg/apis/options/app.go b/pkg/apis/options/app.go index 76c4f84a..4d6353b8 100644 --- a/pkg/apis/options/app.go +++ b/pkg/apis/options/app.go @@ -11,6 +11,12 @@ type Templates struct { // If either file is missing, the default will be used instead. Path string `flag:"custom-templates-dir" cfg:"custom_templates_dir"` + // CustomLogo is the path to a logo that should replace the default logo + // on the sign_in page template. + // Supported formats are .svg, .png, .jpg and .jpeg. + // To disable the default logo, set this value to "-". + CustomLogo string `flag:"custom-sign-in-logo" cfg:"custom_sign_in_logo"` + // Banner overides the default sign_in page banner text. If unspecified, // the message will give users a list of allowed email domains. Banner string `flag:"banner" cfg:"banner"` @@ -34,6 +40,7 @@ func templatesFlagSet() *pflag.FlagSet { flagSet := pflag.NewFlagSet("templates", pflag.ExitOnError) flagSet.String("custom-templates-dir", "", "path to custom html templates") + flagSet.String("custom-sign-in-logo", "", "path to an custom image for the sign_in page logo. Use \"-\" to disable default logo.") flagSet.String("banner", "", "custom banner string. Use \"-\" to disable default banner.") flagSet.String("footer", "", "custom footer string. Use \"-\" to disable default footer.") flagSet.Bool("display-htpasswd-form", true, "display username / password login form if an htpasswd file is provided") diff --git a/pkg/app/pagewriter/default_logo.svg b/pkg/app/pagewriter/default_logo.svg new file mode 100644 index 00000000..37851c2a --- /dev/null +++ b/pkg/app/pagewriter/default_logo.svg @@ -0,0 +1 @@ + diff --git a/pkg/app/pagewriter/pagewriter.go b/pkg/app/pagewriter/pagewriter.go index fdc8ec30..ad79aee2 100644 --- a/pkg/app/pagewriter/pagewriter.go +++ b/pkg/app/pagewriter/pagewriter.go @@ -49,6 +49,10 @@ type Opts struct { // SignInMessage is the messge displayed above the login button. SignInMessage string + + // CustomLogo is the path to a logo to be displayed on the sign in page. + // The logo can be either PNG, JPG/JPEG or SVG. + CustomLogo string } // NewWriter constructs a Writer from the options given to allow @@ -59,6 +63,11 @@ func NewWriter(opts Opts) (Writer, error) { return nil, fmt.Errorf("error loading templates: %v", err) } + logoData, err := loadCustomLogo(opts.CustomLogo) + if err != nil { + return nil, fmt.Errorf("error loading logo: %v", err) + } + errorPage := &errorPageWriter{ template: templates.Lookup("error.html"), proxyPrefix: opts.ProxyPrefix, @@ -76,6 +85,7 @@ func NewWriter(opts Opts) (Writer, error) { footer: opts.Footer, version: opts.Version, displayLoginForm: opts.DisplayLoginForm, + logoData: logoData, } return &pageWriter{ diff --git a/pkg/app/pagewriter/sign_in.html b/pkg/app/pagewriter/sign_in.html index e148c2b5..652b674e 100644 --- a/pkg/app/pagewriter/sign_in.html +++ b/pkg/app/pagewriter/sign_in.html @@ -15,6 +15,9 @@ max-width: 400px; margin: 1.25rem auto; } + .logo-box { + margin: 1.5rem 3rem; + } footer a { text-decoration: underline; } @@ -40,6 +43,12 @@