Files
wekan/client/components/settings/authProviderSettings.js
T
Lauri Ojansivu 0314406656 Read login secrets from *_FILE, and let the Admin Panel override DEFAULT_AUTHENTICATION_METHOD.
LDAP_AUTHENTIFICATION_PASSWORD_FILE and OAUTH2_SECRET_FILE were listed in the
Dockerfile, snap, docker-compose and start-wekan since #5724, but no code read
them, so a password could only be an environment variable. WeKan now reads the
file itself, at each login (a rotated secret applies at once), so the password
is never in the environment - the point of Docker / Kubernetes secrets. The
order is the Admin Panel, the variable, then its file; one trailing line break
is dropped. The application code is the same on every platform, so it works in
Docker, the snap (files under /var/snap/wekan/common), bundles, AppImage,
Flatpak, Mac and Windows. Admin Panel / People shows when the password comes
from the file and when the file cannot be read, never the path or content.
The path itself is an environment variable only: settable in the Admin Panel
next to the LDAP host or the OAuth2 token endpoint, it would let the server
read any file and send it there as the password.

DEFAULT_AUTHENTICATION_METHOD is a field of the Login pane's settings form.
Choosing a method overrides the variable; Default gives it back. Before, the
variable rewrote the stored method at every start, so an administrator's
choice was lost on restart. The published method is now the override, else the
variable, else password. On upgrade, a method chosen with the old dropdown
while no variable was set becomes the override, once, so it is not lost. The
old dropdown is removed: two controls for one setting on one page.

The snap key for the LDAP password file was spelled
ldap-authentification-password-file, unlike its siblings and its help text;
it is ldap-authentication-password-file now (it had no effect before).
MAIL_SERVICE_PASSWORD_FILE, MONGO_PASSWORD_FILE and S3_SECRET_FILE are still
not read by WeKan; secrets/README.md says so.

Thanks to Roemer, CrashOverride-lab, ww-daniel-mora and xet7 !
2026-10-05 21:11:12 +03:00

115 lines
5.1 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { TAPi18n } from '/imports/i18n';
import './authProviderSettings.jade';
// `section` set: the catalog methods take the section name first
// (getAuthConfigSources / saveAuthConfigSettings, server/lib/authConfig.js).
// Unset: a method of its own, as SAML has.
function callWithSection(data, method, ...args) {
return data.section ? Meteor.call(method, data.section, ...args) : Meteor.call(method, ...args);
}
Template.authProviderSettings.onCreated(function () {
this.loaded = new ReactiveVar(false);
this.busy = new ReactiveVar(false);
this.error = new ReactiveVar('');
this.config = new ReactiveVar({});
this.refresh = () => callWithSection(this.data, this.data.loadMethod, (error, result) => {
if (error) this.error.set(error.reason || TAPi18n.__('error'));
else { this.config.set(result); this.loaded.set(true); }
});
this.refresh();
});
Template.authProviderSettings.helpers({
loaded() { return Template.instance().loaded; },
busy() { return Template.instance().busy; },
error() { return Template.instance().error; },
fields() {
const { overrides = {}, sources = {} } = Template.instance().config.get();
return this.fields.map(field => {
const value = overrides[field.key];
const source = sources[field.key] || {};
const secretField = field.type === 'secret';
return { ...field, value: value ?? '', effective: String(source.value ?? ''),
booleanField: field.type === 'boolean', multiline: field.type === 'textarea',
choiceField: field.type === 'choice', numberField: field.type === 'number',
secretField,
// The server reports a secret only as { source, hasValue }.
secretStoredHere: secretField && source.source === 'admin',
// A secret's line names where it comes from - the Admin Panel, the
// variable, or the file <NAME>_FILE points at - and says so when that
// file cannot be read; the server never sends the value or the path.
secretStatus: !secretField ? ''
: source.source === 'file-error' ? `${field.fileVar}: ${TAPi18n.__('error')}`
: !source.hasValue ? TAPi18n.__('unset-color')
: `${TAPi18n.__('password')}: ${source.source === 'admin' ? TAPi18n.__('admin-panel')
: source.source === 'file' ? field.fileVar : field.envVar}`,
choiceOptions: (field.choices || []).map(choice => ({ value: choice, selected: value === choice })),
inherit: value === undefined, enabled: value === true, disabled: value === false,
sourceLabel: source.source === 'admin' ? TAPi18n.__('admin-panel')
: source.source === 'env' ? field.envVar
// SAML fields left at Default follow the identity-provider profile.
: source.source === 'profile' ? 'SAML_IDP_PROFILE' : TAPi18n.__('default') };
});
},
urls() { return Object.values(Template.instance().config.get().urls || {}).map(url => ({ url })); },
});
Template.authProviderSettings.events({
'submit .js-auth-provider-settings'(event, instance) {
event.preventDefault();
if (instance.busy.get()) return;
const input = {};
for (const field of instance.findAll('.js-auth-config-field')) {
input[field.dataset.key] = field.dataset.boolean && field.value !== ''
? field.value === 'true' : field.value;
}
const clearSecrets = instance.findAll('.js-auth-secret-clear')
.filter(box => box.checked).map(box => box.dataset.key);
if (clearSecrets.length) input.clearSecrets = clearSecrets;
instance.busy.set(true);
instance.error.set('');
callWithSection(instance.data, instance.data.saveMethod, input, error => {
instance.busy.set(false);
// A typed secret is never kept in the page after it was sent.
for (const field of instance.findAll('input[type="password"].js-auth-config-field')) field.value = '';
if (error) instance.error.set(error.reason || TAPi18n.__('error'));
else instance.refresh();
});
},
});
Template.ldapTestConnection.onCreated(function () {
this.result = new ReactiveVar('');
this.success = new ReactiveVar(true);
});
Template.ldapTestConnection.helpers({
result() { return Template.instance().result; },
resultClass() {
return Template.instance().success.get() ? 'ldap-test-success' : 'ldap-test-error';
},
});
Template.ldapTestConnection.events({
// "It should be possible to test at admin panel, does for example LDAP login
// work": the admin-gated ldap_test_connection method
// (packages/wekan-ldap/server/testConnection.js) against whichever value is
// in effect, Admin Panel or environment variable.
'click button.js-ldap-test-connection'(event, tpl) {
tpl.result.set('...');
Meteor.call('ldap_test_connection', (err) => {
if (err) {
tpl.success.set(false);
tpl.result.set(
TAPi18n.__('ldap-test-connection-error', {
sprintf: [err.reason || err.message || ''],
}),
);
} else {
tpl.success.set(true);
tpl.result.set(TAPi18n.__('ldap-test-connection-success'));
}
});
},
});