diff --git a/src/lib/__snapshots__/create-config.test.ts.snap b/src/lib/__snapshots__/create-config.test.ts.snap index 1e9e7e484b..eaf23ee16f 100644 --- a/src/lib/__snapshots__/create-config.test.ts.snap +++ b/src/lib/__snapshots__/create-config.test.ts.snap @@ -74,6 +74,7 @@ exports[`should create default config 1`] = ` "embedProxy": true, "embedProxyFrontend": true, "featuresExportImport": false, + "loginEventLog": false, "maintenance": false, "maintenanceMode": false, "messageBanner": false, @@ -96,6 +97,7 @@ exports[`should create default config 1`] = ` "embedProxy": true, "embedProxyFrontend": true, "featuresExportImport": false, + "loginEventLog": false, "maintenance": false, "maintenanceMode": false, "messageBanner": false, diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index c16b28931d..f2b5d844f6 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -67,6 +67,10 @@ const flags = { false, ), notifications: parseEnvVarBoolean(process.env.NOTIFICATIONS, false), + loginEventLog: parseEnvVarBoolean( + process.env.UNLEASH_LOGIN_EVENT_LOG, + false, + ), }; export const defaultExperimentalOptions: IExperimentalOptions = { diff --git a/src/migrations/20230222084211-add-login-events-table.js b/src/migrations/20230222084211-add-login-events-table.js new file mode 100644 index 0000000000..f369fdba0a --- /dev/null +++ b/src/migrations/20230222084211-add-login-events-table.js @@ -0,0 +1,27 @@ +exports.up = function (db, cb) { + db.runSql( + ` + CREATE TABLE IF NOT EXISTS login_events ( + id SERIAL PRIMARY KEY NOT NULL, + username TEXT NOT NULL, + auth_type TEXT NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + successful BOOLEAN NOT NULL, + ip INET, + failure_reason TEXT + ); + CREATE INDEX IF NOT EXISTS login_events_ip_idx ON login_events(ip); + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + DROP INDEX IF EXISTS login_events_ip_idx; + DROP TABLE IF EXISTS login_events; + `, + cb, + ); +};