Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Add a settings UI for OIDC.

Kailash Nadhe406b2516afc
diff --git a/cmd/handlers.go b/cmd/handlers.go
index b6ef05e1..e0ca9307 100644
--- a/cmd/handlers.go
+++ b/cmd/handlers.go
@@ -21,6 +21,8 @@ const (
sortAsc = "asc"
sortDesc = "desc"
+
+ basicAuthd = "basicauthd"
)
type okResp struct {
@@ -53,22 +55,23 @@ func initHTTPHandlers(e *echo.Echo, app *App) {
// Group of private handlers with BasicAuth.
var g *echo.Group
- if len(app.constants.OIDC.ClientID) > 0 && len(app.constants.OIDC.ClientSecret) > 0 {
- callbackURL, err := url.JoinPath(app.constants.RootURL, "/oidc/callback")
+ if app.constants.Security.OIDC.Enabled {
+ cbURL, err := url.JoinPath(app.constants.RootURL, "/auth/oidc")
if err != nil {
- panic(err)
+ lo.Fatalf("error preparing OIDC callback URL: %v", err)
}
- oidcConfig := oidc.Config{
- ProviderURL: app.constants.OIDC.Provider,
- ClientID: app.constants.OIDC.ClientID,
- ClientSecret: app.constants.OIDC.ClientSecret,
- RedirectURL: callbackURL,
+ oiCfg := oidc.Config{
+ ProviderURL: app.constants.Security.OIDC.Provider,
+ ClientID: app.constants.Security.OIDC.ClientID,
+ ClientSecret: app.constants.Security.OIDC.ClientSecret,
+ RedirectURL: cbURL,
}
- // if admin username and password are set, enable basic auth for api access
+ // If admin username and password are set in the config file,
+ // enable BasicAuth for /api/* handlers.
if len(app.constants.AdminUsername) > 0 && len(app.constants.AdminPassword) > 0 {
- basicAuthConfig := middleware.BasicAuthConfig{
- // check if authorization header is present and is basic auth if not skip basic auth
+ baCfg := middleware.BasicAuthConfig{
+ // If the Authorization header isn't BasicAuth (is OIDC), skip validation.
Skipper: func(c echo.Context) bool {
auth := c.Request().Header.Get(echo.HeaderAuthorization)
l := len("basic")
@@ -79,13 +82,15 @@ func initHTTPHandlers(e *echo.Echo, app *App) {
},
Validator: basicAuth,
}
- // skip oidc if basic auth succeded
- oidcConfig.Skipper = func(c echo.Context) bool {
- return c.Get("userAuthenticated") != nil && c.Get("userAuthenticated").(bool)
+
+ // Skip OIDC check if the request is already BasicAuth'd.
+ oiCfg.Skipper = func(c echo.Context) bool {
+ return c.Get(basicAuthd) != nil && c.Get(basicAuthd).(bool)
}
- g = e.Group("", middleware.BasicAuthWithConfig(basicAuthConfig), oidc.OIDCAuth(oidcConfig))
+
+ g = e.Group("", middleware.BasicAuthWithConfig(baCfg), oidc.OIDCAuth(oiCfg))
} else {
- g = e.Group("", oidc.OIDCAuth(oidcConfig))
+ g = e.Group("", oidc.OIDCAuth(oiCfg))
}
} else if len(app.constants.AdminUsername) > 0 && len(app.constants.AdminPassword) > 0 {
g = e.Group("", middleware.BasicAuth(basicAuth))
@@ -112,9 +117,8 @@ func initHTTPHandlers(e *echo.Echo, app *App) {
g.GET(path.Join(adminRoot, "/custom.js"), serveCustomAppearance("admin.custom_js"))
g.GET(path.Join(adminRoot, "/*"), handleAdminPage)
- // oauth callback
- g.GET("/oidc/callback", func(c echo.Context) error {
- // never gets executed because of the middleware
+ // OIDC oAuth callback. The execution is handled by the middleware.
+ g.GET("/auth/oidc", func(c echo.Context) error {
return nil
})
@@ -329,7 +333,8 @@ func basicAuth(username, password string, c echo.Context) (bool, error) {
if subtle.ConstantTimeCompare([]byte(username), app.constants.AdminUsername) == 1 &&
subtle.ConstantTimeCompare([]byte(password), app.constants.AdminPassword) == 1 {
- c.Set("userAuthenticated", true)
+ // Mark the request as BasicAuth'd so that the OIDC check (if enabled) is skipped.
+ c.Set(basicAuthd, true)
return true, nil
}
return false, nil
diff --git a/cmd/init.go b/cmd/init.go
index f8158df2..fcc3719e 100644
--- a/cmd/init.go
+++ b/cmd/init.go
@@ -79,6 +79,13 @@ type constants struct {
DomainBlocklist []string `koanf:"-"`
} `koanf:"privacy"`
Security struct {
+ OIDC struct {
+ Enabled bool `koanf:"enabled"`
+ Provider string `koanf:"provider_url"`
+ ClientID string `koanf:"client_id"`
+ ClientSecret string `koanf:"client_secret"`
+ } `koanf:"oidc"`
+
EnableCaptcha bool `koanf:"enable_captcha"`
CaptchaKey string `koanf:"captcha_key"`
CaptchaSecret string `koanf:"captcha_secret"`
@@ -86,12 +93,6 @@ type constants struct {
AdminUsername []byte `koanf:"admin_username"`
AdminPassword []byte `koanf:"admin_password"`
- OIDC struct {
- ClientID string `koanf:"client_id"`
- ClientSecret string `koanf:"client_secret"`
- Provider string `koanf:"provider"`
- } `koanf:"oidc"`
-
Appearance struct {
AdminCSS []byte `koanf:"admin.custom_css"`
AdminJS []byte `koanf:"admin.custom_js"`
@@ -388,12 +389,10 @@ func initConstants() *constants {
if err := ko.Unmarshal("privacy", &c.Privacy); err != nil {
lo.Fatalf("error loading app.privacy config: %v", err)
}
- if err := ko.Unmarshal("oidc", &c.OIDC); err != nil {
- lo.Fatalf("error loading app.oidc config: %v", err)
- }
if err := ko.Unmarshal("security", &c.Security); err != nil {
lo.Fatalf("error loading app.security config: %v", err)
}
+
if err := ko.UnmarshalWithConf("appearance", &c.Appearance, koanf.UnmarshalConf{FlatPaths: true}); err != nil {
lo.Fatalf("error loading app.appearance config: %v", err)
}
diff --git a/cmd/settings.go b/cmd/settings.go
index e6e03e2d..dca7258d 100644
--- a/cmd/settings.go
+++ b/cmd/settings.go
@@ -70,6 +70,7 @@ func handleGetSettings(c echo.Context) error {
s.UploadS3AwsSecretAccessKey = strings.Repeat(pwdMask, utf8.RuneCountInString(s.UploadS3AwsSecretAccessKey))
s.SendgridKey = strings.Repeat(pwdMask, utf8.RuneCountInString(s.SendgridKey))
s.SecurityCaptchaSecret = strings.Repeat(pwdMask, utf8.RuneCountInString(s.SecurityCaptchaSecret))
+ s.OIDC.ClientSecret = strings.Repeat(pwdMask, utf8.RuneCountInString(s.OIDC.ClientSecret))
s.BouncePostmark.Password = strings.Repeat(pwdMask, utf8.RuneCountInString(s.BouncePostmark.Password))
return c.JSON(http.StatusOK, okResp{s})
@@ -201,6 +202,9 @@ func handleUpdateSettings(c echo.Context) error {
if set.SecurityCaptchaSecret == "" {
set.SecurityCaptchaSecret = cur.SecurityCaptchaSecret
}
+ if set.OIDC.ClientSecret == "" {
+ set.OIDC.ClientSecret = cur.OIDC.ClientSecret
+ }
for n, v := range set.UploadExtensions {
set.UploadExtensions[n] = strings.ToLower(strings.TrimPrefix(strings.TrimSpace(v), "."))
diff --git a/cmd/upgrade.go b/cmd/upgrade.go
index 011ebbfd..5c42ee39 100644
--- a/cmd/upgrade.go
+++ b/cmd/upgrade.go
@@ -38,6 +38,7 @@ var migList = []migFunc{
{"v2.4.0", migrations.V2_4_0},
{"v2.5.0", migrations.V2_5_0},
{"v3.0.0", migrations.V3_0_0},
+ {"v3.1.0", migrations.V3_1_0},
}
// upgrade upgrades the database to the current version by running SQL migration files
diff --git a/frontend/fontello/config.json b/frontend/fontello/config.json
index 3a3782c8..90bcca42 100755
--- a/frontend/fontello/config.json
+++ b/frontend/fontello/config.json
@@ -594,6 +594,12 @@
"code"
]
},
+ {
+ "uid": "8f28d948aa6379b1a69d2a090e7531d4",
+ "css": "warning-empty",
+ "code": 59431,
+ "src": "typicons"
+ },
{
"uid": "f4ad3f6d071a0bfb3a8452b514ed0892",
"css": "vector-square",
diff --git a/frontend/src/assets/icons/fontello.css b/frontend/src/assets/icons/fontello.css
index 9078caaa..41a0f96e 100644
--- a/frontend/src/assets/icons/fontello.css
+++ b/frontend/src/assets/icons/fontello.css
@@ -40,6 +40,40 @@
/* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
}
+[class^="mdi-"]:before, [class*=" mdi-"]:before {
+ font-family: "fontello";
+ font-style: normal;
+ font-weight: normal;
+ speak: never;
+
+ display: inline-block;
+ text-decoration: inherit;
+ width: 1em;
+ margin-right: .2em;
+ text-align: center;
+ /* opacity: .8; */
+
+ /* For safety - reset parent styles, that can break glyph codes*/
+ font-variant: normal;
+ text-transform: none;
+
+ /* fix buttons height, for twitter bootstrap */
+ line-height: 1em;
+
+ /* Animation center compensation - margins should be symmetric */
+ /* remove if not needed */
+ margin-left: .2em;
+
+ /* you can be more comfortable with increased icons size */
+ /* font-size: 120%; */
+
+ /* Font smoothing. That was taken from TWBS */
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+
+ /* Uncomment for 3D effect */
+ /* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
+}
.mdi-view-dashboard-variant-outline:before { content: '\e800'; } /* '' */
.mdi-format-list-bulleted-square:before { content: '\e801'; } /* '' */
@@ -80,6 +114,7 @@
.mdi-chart-bar:before { content: '\e824'; } /* '' */
.mdi-email-bounce:before { content: '\e825'; } /* '' */
.mdi-speedometer:before { content: '\e826'; } /* '' */
+.mdi-warning-empty:before { content: '\e827'; } /* '' */
+.mdi-code:before { content: '󰅩'; } /* '\f0169' */
.mdi-logout-variant:before { content: '󰗽'; } /* '\f05fd' */
.mdi-wrench-outline:before { content: '󰯠'; } /* '\f0be0' */
-.mdi-code:before { content: '󰅩'; } /* '\f0169' */
diff --git a/frontend/src/assets/icons/fontello.woff2 b/frontend/src/assets/icons/fontello.woff2
index 2875eca2..caa51743 100755
Binary files a/frontend/src/assets/icons/fontello.woff2 and b/frontend/src/assets/icons/fontello.woff2 differ
diff --git a/frontend/src/views/Settings.vue b/frontend/src/views/Settings.vue
index bc412328..13f004a4 100644
--- a/frontend/src/views/Settings.vue
+++ b/frontend/src/views/Settings.vue
@@ -160,6 +160,12 @@ export default Vue.extend({
hasDummy = 'captcha';
}
+ if (this.isDummy(form['security.oidc.client_secret'])) {
+ form['security.oidc.client_secret'] = '';
+ } else if (this.hasDummy(form['security.oidc.client_secret'])) {
+ hasDummy = 'oidc';
+ }
+
if (this.isDummy(form['bounce.postmark'].password)) {
form['bounce.postmark'].password = '';
} else if (this.hasDummy(form['bounce.postmark'].password)) {
diff --git a/frontend/src/views/settings/security.vue b/frontend/src/views/settings/security.vue
index 6891a68d..6ee33c66 100644
--- a/frontend/src/views/settings/security.vue
+++ b/frontend/src/views/settings/security.vue
@@ -1,5 +1,32 @@
<template>
<div class="items">
+ <div class="columns">
+ <div class="column is-4">
+ <b-field :label="$t('settings.security.enableOIDC')" :message="$t('settings.security.OIDCHelp')">
+ <b-switch v-model="data['security.oidc']['enabled']" name="security.oidc" />
+ </b-field>
+ </div>
+ <div class="column is-8">
+ <b-field :label="$t('settings.security.OIDCURL')" label-position="on-border">
+ <b-input v-model="data['security.oidc']['provider_url']" name="oidc.provider_url"
+ placeholder="https://login.yoursite.com" :disabled="!data['security.oidc']['enabled']" :maxlength="300"
+ required type="url" pattern="https?://.*" />
+ </b-field>
+ <b-field :label="$t('settings.security.OIDCClientID')" label-position="on-border">
+ <b-input v-model="data['security.oidc']['client_id']" name="oidc.client_id"
+ :disabled="!data['security.oidc']['enabled']" :maxlength="200" required />
+ </b-field>
+ <b-field :label="$t('settings.security.OIDCClientSecret')" label-position="on-border">
+ <b-input v-model="data['security.oidc']['client_secret']" name="oidc.client_secret" type="password"
+ :disabled="!data['security.oidc']['enabled']" :maxlength="200" required />
+ </b-field>
+ <p class="is-size-7">
+ <b-icon icon="warning-empty" /> {{ $t('settings.security.OIDCWarning') }}
+ </p>
+ </div>
+ </div>
+
+ <hr />
<div class="columns">
<div class="column is-4">
<b-field :label="$t('settings.security.enableCaptcha')" :message="$t('settings.security.enableCaptchaHelp')">
@@ -9,8 +36,8 @@
<div class="column is-8">
<b-field :label="$t('settings.security.captchaKey')" label-position="on-border"
:message="$t('settings.security.captchaKeyHelp')">
- <b-input v-model="data['security.captcha_key']" name="captcha_key" :disabled="!data['security.enable_captcha']"
- :maxlength="200" required />
+ <b-input v-model="data['security.captcha_key']" name="captcha_key"
+ :disabled="!data['security.enable_captcha']" :maxlength="200" required />
</b-field>
<b-field :label="$t('settings.security.captchaSecret')" label-position="on-border">
<b-input v-model="data['security.captcha_secret']" name="captcha_secret" type="password"
@@ -19,6 +46,7 @@
</div>
</div>
</div>
+ </div>
</template>
<script>
diff --git a/i18n/en.json b/i18n/en.json
index 19f4eea0..0ee1a61a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -356,6 +356,12 @@
"public.unsubbedInfo": "You have unsubscribed successfully.",
"public.unsubbedTitle": "Unsubscribed",
"public.unsubscribeTitle": "Unsubscribe from mailing list",
+ "settings.security.enableOIDC": "Enable OIDC",
+ "settings.security.OIDCHelp": "Enable OpenID Connect OAuth2 login via an OAuth provider.",
+ "settings.security.OIDCWarning": "When OIDC is enabled, default password login is disabled. Invalid config can lock you out.",
+ "settings.security.OIDCURL": "Provider URL",
+ "settings.security.OIDCClientID": "Client ID",
+ "settings.security.OIDCClientSecret": "Client secret",
"settings.appearance.adminHelp": "Custom CSS to apply to the admin UI.",
"settings.appearance.adminName": "Admin",
"settings.appearance.customCSS": "Custom CSS",
diff --git a/models/settings.go b/models/settings.go
index 577ea48e..ef129aab 100644
--- a/models/settings.go
+++ b/models/settings.go
@@ -40,6 +40,13 @@ type Settings struct {
SecurityCaptchaKey string `json:"security.captcha_key"`
SecurityCaptchaSecret string `json:"security.captcha_secret"`
+ OIDC struct {
+ Enabled bool `json:"enabled"`
+ ProviderURL string `json:"provider_url"`
+ ClientID string `json:"client_id"`
+ ClientSecret string `json:"client_secret"`
+ } `json:"security.oidc"`
+
UploadProvider string `json:"upload.provider"`
UploadExtensions []string `json:"upload.extensions"`
UploadFilesystemUploadPath string `json:"upload.filesystem.upload_path"`
diff --git a/schema.sql b/schema.sql
index 12276e4d..6740cf71 100644
--- a/schema.sql
+++ b/schema.sql
@@ -246,6 +246,7 @@ INSERT INTO settings (key, value) VALUES
('security.enable_captcha', 'false'),
('security.captcha_key', '""'),
('security.captcha_secret', '""'),
+ ('security.oidc', '{"enabled": false, "provider_url": "", "client_id": "", "client_secret": ""}'),
('upload.provider', '"filesystem"'),
('upload.max_file_size', '5000'),
('upload.extensions', '["jpg","jpeg","png","gif","svg","*"]'),