-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
$PROFILE_OPT empty when working with assumed roles #938
Comments
Thanks for reporting this issue and discuss it over Discord as well @DB-Vincent. |
I'm having the same issue and I found out that the latest version that works with assume_role seems to be prowler-2.3.0-18122020. |
Thanks @halfluke that is a very helpful finding. I'll give it a look and see what is going on but please feel free to add here possible fixes if you find them. |
I can confirm, |
@halfluke as per @DB-Vincent finding, can you test it by making this change in prowler file? line 136, from this:
to this:
Not sure if this is the best way to solve the issue, however I have to diff 2.3 and latest to see what changes added this bug. |
my gut feeling says that could be when I added the feature of renewing temporary credentials... |
I feel obligated to mention that this is just a work around and that this probably isn't best practice. But it's a start! |
it doesn't seem to work either... I spent some hours trying to troubleshoot but no luck tbh A csv file is generated with the correct account name but it has only one line... |
Ok, I have tested this diff in my environment and it is working fine for this command
Could you guys test it? Don't change anything in prowler file code. |
sorry but... what do I change in assume_role? |
grab it from here, it is easier :) https://gist.github.com/toniblyx/8d4e5e2420b2185332ab35af067f8470 |
Access Denied trying to describe regions! Review permissions as described here: https://github.com/toniblyx/prowler/#requirements-and-installation the regions error is handled differently in Prowler 2.3.0.xxxx: I still get it but the script proceeds I bet the real problem is the second one: the newest versions try to generate credentials report for the CALLER account, not for the "assumed role" account. I think you don't notice that because you have permissions on the caller account as well... but I don't in my environment |
are you replacing that file in the latest release from master branch? Can you share the exact command you are running. when running |
can you share what permission do you have in the source account? I'll try to replicate |
unfortunately it's on a client account that I cannot change. The role I assume has SecurityAudit in the target account. The keys I have are for a user that can "switch role" and assume the role I need to audit in the target account. With the 2.3.0 version of Prowler I have: An error occurred (UnauthorizedOperation) when calling the DescribeRegions operation: You are not authorized to perform this operation. Date: Thu Nov 25 11:18:15 AM EST 2021 This report is being generated using credentials below: AWS-CLI Profile: [Profile] AWS API Region: [us-east-1] AWS Filter Region: [all] |
ok, the source account has permissions only to assume a role targed account. I have to test that, also remember that with SecurityAudit role only Prowler may be unable to make all checks. |
oh and yes, I replaced the file of the gist in the latest release of course. I had reached that point with my experiments. |
@toniblyx I just tested this in my environment, and I do not get any error messages. However, the checks get executed on the |
ok, I could finally replicate that case in the latest version and seen that initial credentials are unset that is why assume role works first then gets unset due to a bug in the reload credentials logic. |
Just to clarify for other users. This bug, initially only affects to those users running Prowler manually in account A that assumes a role in account B by using a custom profile set up in thir own ~/.aws/credentials. For those using EC2 instance or containers with a role attached it does not affect them. |
great stuff, i was not able to figure out the "unset" part and the fact that I also have limited permissions mixed things up. But you are the author for a reason :) |
Hi @DB-Vincent, Can you execute it again with the following
|
to resume: in my environment with limited permission for the caller account: Latest assume_role above: Can't the same logic as in Prowler 2.3.0.xxx , re-implemented in the current version? |
My fix (no PR yet but let me know if you wish):
if (( $MINIMUM_REMAINING_TIME_ALLOWED > $SESSION_TIME_REMAINING )); then
You can remove the 'echo' that I left for debugging purposes. The wrong comparison with [[ ]] would refresh assume_role for each check, but you should see that the whole process now works in all cases (single and multiple assume_role). Hopefully. |
Really good catch @halfluke !!!! 👏👏👏👏👏 Please open a PR with all of theses changes 🙏 |
I will do. Just running one more time, a complete run with all the extras. |
Really really good!!!! Impressive 👏👏 |
I've just tested @halfluke's setup and I can confirm it also works on my machine. Seems like the issues is solved with those fixes. |
Awesome work @halfluke, thanks a lot for the effort put here to you all! Let me know if you can send the PR, I'm going to test it here as well. |
Hi yes I will submit the PR today or tomorrow... unless you notice something wrong in your test? |
I can't manage to make it work but re-testing it again, feel free to send the PR and I'll keep my tests, probably I didn't do the copy/paste correctly |
ok I will submit the PR today. Perhaps check if you added |
quick question @halfluke the role or user of the profile you are using, what actions have allowed? I'm testing with a role that has only sts:assumerole and getting |
@toniblyx nope, that was one of the problems but it works now. That's why I put some echo to debug it. Old version of prowler would continue even without getting regions, newer versions stop and exit. Not sure of the permissions of my user in the caller account as I cannot read them ( sts:assumerole for sure) |
I have merged @halfluke suggestions into the latest branch in 2.7 to test. Once is all right I´ll remove echoes in code. |
I can confirm that the 2.7 branch works in my environment. |
awesome, it is working fine for me as well so far. Thanks! |
did you find out what your problem with regions was? In the end after all the time it took me, I've noticed that the changes I made are really minimal: the [[ -> (( comparison and a backup of profile_opt to be restored when we re-assume a role :-) |
yep, it was a really good catch @halfluke! The region issue is fixed now as far as I can see, still testing with different options. |
This issue has been fixed. Anything related or additional please open a new issue for better handling. |
Hi,
Can you please clarify in which version of prowler it is fixed?
Thanks
|
branch 2.7. That will be the next release, it is the devel branch at this point.
|
* Extra7161 EFS encryption at rest check * Added check_extra7162 which checks if Log groups have 365 days retention * fixed code to handle all regions and formatted output * changed check title, resource type and service name as well as making the code more dynamic * Extra7161 EFS encryption at rest check * New check_extra7163 Secrets Manager key rotation enabled * New check7160 Enabled AutomaticVersionUpgrade on RedShift Cluster * Update ProwlerRole.yaml to have same permissions as util/org-multi-account/ProwlerRole.yaml * Fix link to quicksight dashboard * Install detect-secrets (e.g. for check_extra742) * Updating check_extra7163 with requested changes * fix(assumed-role): Check if -T and -A options are set * docs(Readme): `-T` option is not mandatory * fix(assume-role): Handle AWS STS CLI errors * fix(assume-role): Handle AWS STS CLI errors * Update group25_FTR When trying to run the group 25 (Amazon FTR related security checks) nothing happens, after looking at the code there is a misconfiguration in 2 params: GROUP_RUN_BY_DEFAULT[9] and GROUP_CHECKS[9]. Updating values to 25 fixed the issue. * Update README.md broken link for capital letters in group file (group25_FTR) * #938 issue assume_role multiple times should be fixed * Label 2.7.0-1December2021 for tests * Fixed error that appeared if the number of findings was very high. * Adjusted the batch to only do 50 at a time. 100 caused capacity issues. Also added a check for an edge case where if the updated findings was a multiple of the batch size, it would throw an error for attempting to import 0 findings. * Added line to delete the temp folder after everything is done. * New check 7164 Check if Cloudwatch log groups are protected by AWS KMS@maisenhe * updated CHECK_RISK * Added checks extra7160,extra7161,extra7162,extra7163 to group Extras * Added checks extra7160,extra7161,extra7162,extra7163 to group Extras * Added issue templates * New check 7165 DynamoDB: DAX encrypted at rest @Daniel-Peladeau * New check 7165 DynamoDB: DAX encrypted at rest @Daniel-Peladeau * Fix #963 check 792 to force json in ELB queries * Fix #957 check 763 had us-east-1 region hardcoded * Fix #962 check 7147 ALTERNATE NAME * Fix #940 handling error when can not list functions * Added new checks 7164 and 7165 to group extras * Added invalid check or group id to the error message #962 * Fix Broken Link * Add docker volume example to README.md * Updated Dockerfile to use amazonlinux container * Updated Dockerfile with AWS cli v2 * Added upgrade to the RUN * Added cache purge to Dockerfile * Backup AWS Credentials before AssumeRole and Restore them before CopyToS3 * exporting the ENV variables * fixed bracket * Improved documentation for install process * fix checks with comma issues * Added -D option to copy to S3 with the initial AWS credentials * Cosmetic variable name change * Added $PROFILE_OPT to CopyToS3 commands * remove commas * removed file as it is not needed * Improved help usage options -h * Fixed CIS LEVEL on 7163 through 7165 * When performing a restoreInitialAWSCredentials, unset the credentials ENV variables if they were never set * New check 7166 Elastic IP addresses with associations are protected by AWS Shield Advanced * New check 7167 Cloudfront distributions are protected by AWS Shield Advanced * New check 7168 Route53 hosted zones are protected by AWS Shield Advanced * New check 7169 Global accelerators are protected by AWS Shield Advanced * New check 7170 Application load balancers are protected by AWS Shield Advanced * New check 7171 Classic load balancers are protected by AWS Shield Advanced * Include example for global resources * Add AWS Advance Shield protection checks corrections * Added Shield actions GetSubscriptionState and DescribeProtection * Added Shield actions GetSubscriptionState and DescribeProtection * docs(templates): Improve bug template with more info (#982) * Removed echoes after role chaining fix * Changed Route53 checks7152 and 7153 to INFO when no domains found * Changed Route53 checks 7152 and 7153 title to clarify * Added passed security groups in output to check 778 * Added passed security groups and updated title to check 777 * Added FAIL as error handling when SCP prevents queries to regions * Label version 2.7.0-6January2022 * Updated .dockerignore with .github/ * Fix: issue #758 and #984 * Fix: issue #741 CloudFront and real-time logs * Fix issues #971 set all as INFO instead of FAIL when no access to resource * Fix: issue #986 * Add additional action permissions for Glue and Shield Advanced checks @lazize * Add extra shield action permission Allows the shield:GetSubscriptionState action * Add permission actions Make sure all files where permission actions are necessary will have the same actions * Fix: Credential chaining from environment variables @lazize #996f If profile is not defined, restore original credentials from environment variables, if they exists, before assume-role * Lable version 2.7.0-24January2022 Co-authored-by: Lee Myers <[email protected]> Co-authored-by: Chinedu Obiakara <[email protected]> Co-authored-by: Daniel Peladeau <[email protected]> Co-authored-by: Jonathan Lozano <[email protected]> Co-authored-by: Daniel Lorch <[email protected]> Co-authored-by: Pepe Fagoaga <[email protected]> Co-authored-by: Israel <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: nikirby <[email protected]> Co-authored-by: Joel Maisenhelder <[email protected]> Co-authored-by: RT <[email protected]> Co-authored-by: Andrea Di Fabio <[email protected]> Co-authored-by: Joseph de CLERCK <[email protected]> Co-authored-by: Michael Dickinson <[email protected]> Co-authored-by: Pepe Fagoaga <[email protected]> Co-authored-by: Leonardo Azize Martins <[email protected]>
Hi,
I'm trying to get Prowler working with assumed roles when executing the
./prowler -c checkXX -M html -p awsProfileWithSwitchRole -r region -A targetAccountId -R AssumedRole
from my local machine. The issue is that I get 'Unable to locate credentials. You can configure credentials by running "aws configure".' and 'parse error: Invalid numeric literal at line 2, column 7' error messages.From what we've found so far we can say the following things:
include/assume_role
The text was updated successfully, but these errors were encountered: