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

Issue #LR-676 feat: Delete User #3923

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions kubernetes/opa/userorg/policies.rego
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ urls_to_action_mapping := {
"/v1/user/consent/update": "updateUserConsent",
"/v2/org/preferences/read": "readTenantPreferences",
"/v2/org/preferences/create": "createTenantPreferences",
"/v2/org/preferences/update": "updateTenantPreferences"
"/v2/org/preferences/update": "updateTenantPreferences",
"/v1/user/delete": "deleteUser"
}

# Tnc API policy updates to handle different scenarios as explained below
Expand Down Expand Up @@ -304,4 +305,18 @@ updateTenantPreferences {
roles := ["ORG_ADMIN"]
super.acls_check(acls)
super.role_check(roles)
}
}


deleteUser {
super.public_role_check
input.parsed_body.request.userId == super.userid
}

# Org admin is allowed to delete any user info using the /v1/user/delete endpoint
deleteUser {
acls := ["updateUser","deleteUser","updateUserV2","userUpdate"]
roles := ["ORG_ADMIN"]
super.acls_check(acls)
super.role_check(roles)
}
51 changes: 50 additions & 1 deletion kubernetes/opa/userorg/policies_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -917,4 +917,53 @@ test_update_tenant_preferences {
}
}
}
}
}


test_delete_user_as_public_user {
data.main.allow.allowed
with data.common.current_time as current_time
with data.common.iss as iss
with input as
{
"attributes": {
"request": {
"http": {
"headers": {
"x-authenticated-user-token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImFjY2Vzc3YxX2tleTEifQ.eyJhdWQiOiJodHRwczovL3N1bmJpcmRlZC5vcmcvYXV0aC9yZWFsbXMvc3VuYmlyZCI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0MDIzNjEwMiwiaWF0IjoxNjQwMTQ5NzA1fQ.B3-TSdYSOlawPHjFdiRjXwvRbYQ_eH_HTiLKlH7vGS0rCOJ6HQbYyWOhZ7vbZPb3virkuyfhykFcYCEHBCkHY-fwGAeU58Pmhi0dnNJkR59Fa9y_75W98JXZW68HROp62ntEAKCA1oot_U4tYi-8UNoR17Gszj9iYzFEBc6TZA4Lrom_9gqhBOYzL0ISFWSS6oG94EaaKDYHyWzCSjU2nYRB_fn-tODmnVJ12GRJAc1oM9y54o8neNYsl4T_xPyD34v-CinUJM8jzDjFqK5_O3HnAbcmXvkZjFRgfk4mF1V4s5hlsTJGyhi2JOPh90C5N-HbAY8QsPBnzgYFQU_sww"
},
"path": "/v1/user/delete"
}
}
},
"parsed_body": {
"request": {
"userId": "28b0d08f-c2ea-40d1-bcd0-8ae00fca66be"
}
}
}
}

test_delete_user_as_org_admin {
data.main.allow.allowed
with data.common.current_time as current_time
with data.common.iss as iss
with input as
{
"attributes": {
"request": {
"http": {
"headers": {
"x-authenticated-user-token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImFjY2Vzc3YxX2tleTEifQ.eyJhdWQiOiJodHRwczovL3N1bmJpcmRlZC5vcmcvYXV0aC9yZWFsbXMvc3VuYmlyZCIsInN1YiI6ImY6NWJiNmM4N2MtN2M4OC00ZDJiLWFmN2UtNTM0YTJmZWY5NzhkOjI4YjBkMDhmLWMyZWEtNDBkMS1iY2QwLThhZTAwZmNhNjZiZSIsInJvbGVzIjpbeyJyb2xlIjoiQk9PS19DUkVBVE9SIiwic2NvcGUiOlt7Im9yZ2FuaXNhdGlvbklkIjoiMDEzNjk4Nzg3OTc1MDM2OTI4MTAifV19LHsicm9sZSI6IkNPTlRFTlRfQ1JFQVRPUiIsInNjb3BlIjpbeyJvcmdhbmlzYXRpb25JZCI6IjAxMzY5ODc4Nzk3NTAzNjkyODEwIn1dfSx7InJvbGUiOiJDT05URU5UX1JFVklFV0VSIiw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