-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pentest #1566
Merged
+195
−9
Merged
Pentest #1566
Changes from all commits
Commits
Show all changes
89 commits
Select commit
Hold shift + click to select a range
4ec9da8
add logging
anyoussefinia a29a5ef
try adding cognito trigger lambda
anyoussefinia 1fc58a5
export.main
anyoussefinia e479739
modify lambda response for version 2
anyoussefinia ec0318f
rename main to handler
anyoussefinia bcae194
go back to version one
anyoussefinia 1ba363c
added logger for decoded ID token
anyoussefinia dae1ad5
log user role in lambda trigger
anyoussefinia 21b496c
remove lint error
anyoussefinia 906b2d3
try using async await
anyoussefinia 80db87f
switch branch
anyoussefinia e98d55b
test if batch job is possible
anyoussefinia 124562a
fix lint errors
anyoussefinia 71b385a
fix lint errors
anyoussefinia 2d1d3ec
fix lint errors
anyoussefinia 46dd3a5
access Users nested property
anyoussefinia ee2b4d7
added await logic to trigger funciton
anyoussefinia f13baad
try adding roles in response ID token
anyoussefinia bdb4aa4
added logging
anyoussefinia 49bdbc5
modify isAdminUser logic
anyoussefinia 43a31f2
remove function
anyoussefinia 296c703
ignore lint
anyoussefinia dfb8b58
ignore lint
anyoussefinia 1a063d6
fix for in to for of
anyoussefinia b3e2b3c
modify UserPage to use idToken email instead of app context userProf…
anyoussefinia 1ee9531
add in needed import
anyoussefinia 9c2cf4b
modify isAdminUser check
anyoussefinia 482b372
remove .some from admin user check logic
anyoussefinia 241359a
modify isAdminUser to parse the string array coming from idToken
anyoussefinia d44ff81
added logging
anyoussefinia 6053e1f
added logging
anyoussefinia 3c6114b
fix for loop statement
anyoussefinia 11a3f36
fix for loop statement
anyoussefinia a3910d0
remove logging
anyoussefinia 27602b5
add protection for query param
anyoussefinia cddf88a
import Redirect react router
anyoussefinia ba77a1a
remove duplicate import
anyoussefinia 196e274
move funciton inside component
anyoussefinia 38096e8
eslint fix
anyoussefinia 402cef2
fix lint error
anyoussefinia 429365a
ignore lint
anyoussefinia 00e0c26
fix
anyoussefinia e6fda5e
lint
anyoussefinia e23b30b
lint
anyoussefinia 05e73da
redirect user not found
anyoussefinia 4749749
ignore lint
anyoussefinia c97d0d5
added trigger function to serverless
anyoussefinia f3b26a8
remove !GettAtt from serverless.yml
anyoussefinia 7f05351
try adding lambda arn
anyoussefinia 38572ef
try ref instead of arn
anyoussefinia 680f6a6
try Fn::GetAtt
anyoussefinia d80e3a6
try putting resources after functions
anyoussefinia c57e21c
try admin-${self:custom.stage}-addPropertyToJWT
anyoussefinia 046a1ee
try arn refference again
anyoussefinia 946c06f
remove resource
anyoussefinia eee0331
try removing resource
anyoussefinia c2a1904
try using user pool id
anyoussefinia 3a6e6e8
test
anyoussefinia 2f3d84e
revert
anyoussefinia 4605e2a
try with existing: true to prevent duplicate pools
anyoussefinia 5246834
try adding iam create roll permissions
anyoussefinia 615a44a
try iam:passRole
anyoussefinia cf6a916
revert
anyoussefinia d23bb62
revert
anyoussefinia b1990bd
add back trigger function
anyoussefinia bff86f0
remove existing: true
anyoussefinia af24ad7
try to allow iam:create role in permission boundary
anyoussefinia 9b93afc
add back existing true
anyoussefinia c827c39
remove existing true to get working
anyoussefinia 78e514f
bring in latest develop and fix conflicts
anyoussefinia 15c27a2
remove allow create role
anyoussefinia 1888c43
remove add pre token auth trigger from serverless
anyoussefinia 4bb4252
change to custom:user_roles
anyoussefinia e7f3619
try batch job
anyoussefinia e7eb97b
remove unused var
anyoussefinia fd8c5a5
test
anyoussefinia 169ec77
test
anyoussefinia b97f818
test
anyoussefinia 2574960
added batch function
anyoussefinia fd4b0dd
lint
anyoussefinia 943f46f
duplicate user pools
anyoussefinia ee808f0
hard code user pool Id
anyoussefinia 9c8316b
hard code user pool Id
anyoussefinia 9c09938
add back keyword custom
anyoussefinia 4d16d78
add additional logging for how many users had roles in batch job
anyoussefinia 8a3debe
remove unneeded logging, pr cleanup
anyoussefinia 9580202
add better logging in batch funciton
anyoussefinia 2933f8e
PR cleanup
anyoussefinia 81bc3d8
Merge branch 'develop' into pentest
bflynn-cms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { getUser } from "../../app-api/getUser"; | ||
|
||
const handler = async (event) => { | ||
console.log("JWT claims before modification:", JSON.stringify(event)); | ||
try{ | ||
const userEmail = event.request.userAttributes.email; | ||
const user = await getUser(userEmail); | ||
const roles = []; | ||
for (const role of user.roleList) { | ||
roles.push(role.role) | ||
} | ||
event.response = event.response || {}; | ||
event.response.claimsOverrideDetails = event.response.claimsOverrideDetails || {}; | ||
event.response.claimsOverrideDetails.claimsToAddOrOverride = event.response.claimsOverrideDetails.claimsToAddOrOverride || {}; | ||
|
||
// Example of adding roles dynamically from DynamoDB to the JWT claims | ||
event.response.claimsOverrideDetails.claimsToAddOrOverride['custom:user_roles'] = JSON.stringify(roles); // Add user roles | ||
} catch(e) { | ||
console.log("error updating id token claims", e) | ||
} | ||
console.log("JWT claims after modification:", JSON.stringify(event)); | ||
return event; | ||
}; | ||
|
||
export { handler }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import AWS from "aws-sdk"; | ||
const cognito = new AWS.CognitoIdentityServiceProvider(); | ||
import { getUser } from "../../app-api/getUser"; | ||
|
||
async function updateUserAttribute(userPoolId, username, roles) { | ||
const params = { | ||
UserPoolId: userPoolId, | ||
Username: username, | ||
UserAttributes: [ | ||
{ | ||
Name: 'custom:user_roles', | ||
Value: JSON.stringify(roles) | ||
} | ||
] | ||
}; | ||
|
||
await cognito.adminUpdateUserAttributes(params).promise(); | ||
} | ||
|
||
async function processCognitoUsers() { | ||
const userPoolId = process.env.USER_POOL_ID; | ||
console.log("user pool id: ", userPoolId) | ||
let paginationToken = null; | ||
let counter = 0; | ||
let hasRolesCounter = 0; | ||
let noRolesCounter =0; | ||
do { | ||
const params = { | ||
UserPoolId: userPoolId, | ||
AttributesToGet: ['email'], | ||
PaginationToken: paginationToken | ||
}; | ||
|
||
const listUsersResponse = await cognito.listUsers(params).promise(); | ||
console.log(listUsersResponse.Users.length + " users found") | ||
|
||
for (const user of listUsersResponse.Users) { | ||
const emailAttribute = user.Attributes.find(attr => attr.Name === 'email'); | ||
if (emailAttribute) { | ||
const userEmail = emailAttribute.Value; | ||
|
||
try { | ||
const externalUser = await getUser(userEmail); | ||
let roles = [""]; | ||
let roleList; | ||
try{ | ||
roleList = externalUser.roleList; | ||
}catch(error) { | ||
noRolesCounter ++ | ||
console.log(userEmail + " has no roles"); | ||
} | ||
if (roleList && roleList.length > 0 && roleList[0] != null) { | ||
roles = externalUser.roleList.map(role => role.role); | ||
hasRolesCounter ++; | ||
} else { | ||
console.log("user parsing error for user" + userEmail) | ||
} | ||
await updateUserAttribute(userPoolId, user.Username, roles); | ||
} catch (error) { | ||
console.error(`Error processing user ${userEmail}:`, error); | ||
} | ||
} | ||
counter++; | ||
} | ||
|
||
paginationToken = listUsersResponse.PaginationToken; | ||
} while (paginationToken); | ||
console.log(counter+ "users modified, "+ hasRolesCounter + "users had roles and "+ noRolesCounter + " users had no roles") | ||
} | ||
|
||
|
||
export const main = async () => { | ||
await processCognitoUsers().catch(console.error); | ||
console.log("function complete") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for turning this into a whitelist of allowed roles!