1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat: store login events (#3185)

## About the changes
https://linear.app/unleash/issue/2-705/store-sign-on-events

Adds a migration for a new `login_events` table. Also adds the new
`loginEventLog` feature flag.

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#2951

---------

Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
This commit is contained in:
Nuno Góis 2023-02-23 10:49:01 +00:00 committed by GitHub
parent 194c07ec24
commit 25b7af30b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -74,6 +74,7 @@ exports[`should create default config 1`] = `
"embedProxy": true, "embedProxy": true,
"embedProxyFrontend": true, "embedProxyFrontend": true,
"featuresExportImport": false, "featuresExportImport": false,
"loginEventLog": false,
"maintenance": false, "maintenance": false,
"maintenanceMode": false, "maintenanceMode": false,
"messageBanner": false, "messageBanner": false,
@ -96,6 +97,7 @@ exports[`should create default config 1`] = `
"embedProxy": true, "embedProxy": true,
"embedProxyFrontend": true, "embedProxyFrontend": true,
"featuresExportImport": false, "featuresExportImport": false,
"loginEventLog": false,
"maintenance": false, "maintenance": false,
"maintenanceMode": false, "maintenanceMode": false,
"messageBanner": false, "messageBanner": false,

View File

@ -67,6 +67,10 @@ const flags = {
false, false,
), ),
notifications: parseEnvVarBoolean(process.env.NOTIFICATIONS, false), notifications: parseEnvVarBoolean(process.env.NOTIFICATIONS, false),
loginEventLog: parseEnvVarBoolean(
process.env.UNLEASH_LOGIN_EVENT_LOG,
false,
),
}; };
export const defaultExperimentalOptions: IExperimentalOptions = { export const defaultExperimentalOptions: IExperimentalOptions = {

View File

@ -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,
);
};