bcgov / nr-forests-access-management

Authorization solution for BC natural resource sector
Apache License 2.0
8 stars 2 forks source link

Defect when provisioning access to a deleted role assignment #552

Closed ArogeG closed 1 year ago

ArogeG commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'FAM TEST'
  2. Select FOM application
  3. Click on 'Grant Access screen'
  4. Create a new user (BCeID user) with FOM submitter role and Forest client (00082820)
  5. Once created, delete role assignment
  6. create user again by repeating step 3-6

Actual Result: Application Error has Occurred

Expected Result: User role assignment has been created successfully

image.png

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

MCatherine1994 commented 1 year ago

Debugging screenshot in Prod RDS database:

https://app.zenhub.com/files/486378283/3f084673-3e02-49ea-bebb-653a49a2dcfd/download

ianliuwk1019 commented 1 year ago

Added prod log from Basil. https://app.zenhub.com/files/486378283/81d5ecb1-790e-4473-8fbc-144343c120d2/download

ianliuwk1019 commented 1 year ago

From the log and prod data: Backend has a check on if user exists, based on 'user_type_code' (B or I) and 'user_name' (ilike - case insensitive), before creating a user. For this case from production database query, it shows 2 fam_user records ("DVALK" and "DValk"). So, backend returns error when the check found more than 1 user with "the same" name and type.

famdb=> select * from fam_user where UPPER(user_name)='DVALK';
 user_id |            user_guid             |                          cognito_user_id                          | user_name |                   create_user                   |
 create_date          |  update_user  |      update_date       | user_type_code
---------+----------------------------------+-------------------------------------------------------------------+-----------+-------------------------------------------------+---------
----------------------+---------------+------------------------+----------------
     552 | FDFEE614672C4B56A3E168CD91C790F7 | prod-bceidbusiness_fdfee614672c4b56a3e168cd91c790f7@bceidbusiness | DValk     | fam_proxy_api                                   | 2023-04-
12 00:00:00+00        | fam_proxy_api | 2023-04-12 00:00:00+00 | B
     551 |                                  |                                                                   | DVALK     | prod-idir_7f27542b4f1a45478f90b967ff34d74b@idir | 2023-04-
12 18:07:59.618679+00 |               |                        | B
(2 rows)



Need to discuss possible solutions for the two issues on this problem:


Likely we need to have code fix first, then apply datafix, so when user login again the auth-function can work correctly without adding second user again.

ianliuwk1019 commented 1 year ago

Note, my thinking are:

MCatherine1994 commented 1 year ago

Just add some notes:

In the future, if we integrate with the IDP web service lookup, we could always store the idp username to prevent this issue happen again

basilv commented 1 year ago

I don't understand these comments - the user name must be identical in both scenarios (or at least matched to the same user record), or FAM won't work as intended. Scenario 1: User John Smith logs into FAM. Their IDIR is supplied as JSmith. A user record is created (if it doesn't already exist), or is updated, matching on the user id (and domain). Scenario 2: An admin grants access to user John Smith. They likely type JSMITH or jsmith for the user id. A user record is created (if it doesn't already exist), and an access assignment is created linking to the user identified by the user id (and domain)

FAM must ensure that the user record in scenario 1 and scenario 2 are the same, irrespective of the order they occur in.

MCatherine1994 commented 1 year ago

Yes, so when create user through FAM UI, we call this method to check if there is an existing user, think it's case insensitive now Screen Shot 2023-04-18 at 4.55.56 PM.png

But when the user has been created through the auth function, as Ian mentioned above, it's checking the constraint fam_usr_uk, which is case sensitive

ALTER TABLE app_fam.fam_user ADD CONSTRAINT fam_usr_uk UNIQUE (user_type_code, user_name);
MCatherine1994 commented 1 year ago

I just document how we fixed the dev deployment here, we could move it to other place later:

To remove the KMS key, we need to use the terragrunt cli:

But Basil and I both have problems run the terragrunt command, it hangs there, so we got the help from Warren Uniewski, he helped us remove that bcsc kms key from the terragrunt state. So the key is still in the AWS scheduled for deletion, but terraform will ignore it

MCatherine1994 commented 1 year ago

In order to fix this problem,

ArogeG commented 1 year ago

Thanks all for working urgently on this, much appreciated.