Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOGL-8753 : Implemented user blocking for incorrect password #1397

Merged
merged 26 commits into from
Jun 24, 2024
Merged

Conversation

gnandan
Copy link
Contributor

@gnandan gnandan commented Jun 12, 2024

No description provided.

Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
@gnandan gnandan requested a review from ashish-jabble June 12, 2024 09:48
Copy link
Member

@ashish-jabble ashish-jabble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dry run review!
Unit tests are failing and good to have new tests for existing API as user update have been touched!

Comment on lines 694 to 697
if int(user_id) == 1:
msg = "Restricted for Super Admin user."
_logger.warning(msg)
raise web.HTTPForbidden(reason=msg, body=json.dumps({"message": msg}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we block Super Admin user? I believe NO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we do not currently. We should make this any user with admin right in future and allowing blocking of admin users as long as there is always one unblocked admin user. This is not for the current change however.

['id', '=', user_id]).payload()
storage_client = connect.get_storage_async()
old_result = await storage_client.query_tbl_with_payload('users', payload)
if len(old_result['rows']) == 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 'rows' Key is not available then? raise Storage Server Exception

@@ -602,6 +602,8 @@ CREATE TABLE fledge.users (
enabled boolean NOT NULL DEFAULT TRUE,
pwd_last_changed timestamp(6) with time zone NOT NULL DEFAULT now(),
access_method character varying(5) CHECK( access_method IN ('any','pwd','cert') ) NOT NULL DEFAULT 'any',
failed_attempts integer DEFAULT 0,
block_until timestamp(6) DEFAULT now(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with timezone?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best tp use etc as the user might change timezones, especially should not be based on the timezone of the caller of the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarkRiddoch While login user can only provide id and password. There is no way user can provide any information related to time. API does all the calculation for block time on the basis of information stored into the database. So we are safe here even if user changes timezone. so is it good now?

gnandan and others added 3 commits June 13, 2024 11:34
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
@gnandan gnandan requested a review from ashish-jabble June 13, 2024 14:24
gnandan added 3 commits June 14, 2024 12:49
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
@gnandan gnandan marked this pull request as ready for review June 14, 2024 12:23
Copy link
Contributor

@MarkRiddoch MarkRiddoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good - we should probably address the timezone issue however.

@@ -602,6 +602,8 @@ CREATE TABLE fledge.users (
enabled boolean NOT NULL DEFAULT TRUE,
pwd_last_changed timestamp(6) with time zone NOT NULL DEFAULT now(),
access_method character varying(5) CHECK( access_method IN ('any','pwd','cert') ) NOT NULL DEFAULT 'any',
failed_attempts integer DEFAULT 0,
block_until timestamp(6) DEFAULT now(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best tp use etc as the user might change timezones, especially should not be based on the timezone of the caller of the API.

@gnandan gnandan requested a review from MarkRiddoch June 17, 2024 06:58
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
MarkRiddoch
MarkRiddoch previously approved these changes Jun 17, 2024
@ashish-jabble
Copy link
Member

Audit API tests are also failing with the given change

@ashish-jabble
Copy link
Member

VERSION file is also missing. It should be with version 72

…atus

Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
@@ -1,4 +1,5 @@
ALTER TABLE fledge.users ADD COLUMN failed_attempts INTEGER DEFAULT 0;
ALTER TABLE fledge.users ADD COLUMN block_until DATETIME DEFAULT "2024-01-01 10:10:10.55";
ALTER TABLE fledge.users ADD COLUMN block_until DATETIME DEFAULT NULL;
UPDATE fledge.users SET block_until=current_timestamp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sqlite: CURRENT_TIMESTAMP is in GMT, not the timezone of the machine.

UPDATE users SET block_until=(SELECT STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW', 'localtime'))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not setting null? TS should be only if blocked.

Copy link
Contributor

@MarkRiddoch MarkRiddoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve timezone issue and then I think this is probably ok

Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
@gnandan gnandan requested a review from ashish-jabble June 24, 2024 10:34
MarkRiddoch
MarkRiddoch previously approved these changes Jun 24, 2024
Copy link
Contributor

@MarkRiddoch MarkRiddoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, ideally address comments from Ashish before checkin

Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
gnandan and others added 2 commits June 24, 2024 17:20
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
raise web.HTTPForbidden

user_id = request.match_info.get('user_id')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type cast of user_id only once

Comment on lines +380 to +381
if datetime.strptime(block_until, DATE_FORMAT) > datetime.strptime(curr_time, DATE_FORMAT):
diff = datetime.strptime(block_until, DATE_FORMAT) - datetime.strptime(curr_time, DATE_FORMAT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block_until_datetime_formatter = datetime.strptime(block_until, DATE_FORMAT)
current_datetime_formatter = datetime.strptime(curr_time, DATE_FORMAT)

Comment on lines +383 to +387
hours_left = ""
if hours == 1 :
hours_left = "{} hour ".format(hours)
elif hours > 1:
hours_left = "{} hours ".format(hours)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hours_left = "{} hour ".format(hours) if hours == 1 else "{} hours ".format(hours)

Comment on lines +390 to +392
minutes_left = " 1 minute" #Show minutes 1 or less than 1 as "1 minute"
if minutes > 1:
minutes_left = " {} minutes ".format(minutes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be break into single statement

Copy link
Member

@ashish-jabble ashish-jabble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review done!

@gnandan gnandan merged commit 60272c5 into develop Jun 24, 2024
3 checks passed
@gnandan gnandan deleted the FOGL-8753 branch June 24, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants