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

[Bug]: extra760 results in success despite errors #1014

Closed
lorchda opened this issue Jan 31, 2022 · 9 comments
Closed

[Bug]: extra760 results in success despite errors #1014

lorchda opened this issue Jan 31, 2022 · 9 comments
Labels
bug severity/medium Results in some unexpected or undesired behavior. status/waiting-for-revision Waiting for maintainer's revision

Comments

@lorchda
Copy link
Contributor

lorchda commented Jan 31, 2022

What happened?

In check extra760, the lambda:GetFunction returns a permission denied error, but the function returns a PASS. See logs below (Account ID masked, but otherwise log output captured as-is).

This is a follow-up to #940. The fix mentioned there only considers lambda:ListFunction, but not the lambda:GetFunction, which is the actual culprit.

Error message

7.60 [extra760] Find secrets in Lambda functions code  - lambda [Critical]
An error occurred (AccessDeniedException) when calling the GetFunction operation: User: arn:aws:sts::1234567890:assumed-role/ProwlerXA-CBRole/ProwlerAssessmentSession is not authorized to perform: lambda:GetFunction on resource: arn:aws:lambda:eu-central-1:1234567890:function:CustomControlTowerDeploymentLambda because no identity-based policy allows the lambda:GetFunction action
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
unzip:  cannot find or open ./prowler/secrets-1234567890/extra760-CustomControlTowerDeploymentLambda-eu-central-1/CustomControlTowerDeploymentLambda-code.zip, ./prowler/secrets-1234567890/extra760-CustomControlTowerDeploymentLambda-eu-central-1/CustomControlTowerDeploymentLambda-code.zip.zip or ./prowler/secrets-1234567890/extra760-CustomControlTowerDeploymentLambda-eu-central-1/CustomControlTowerDeploymentLambda-code.zip.ZIP.
       PASS! eu-central-1: No secrets found in Lambda function CustomControlTowerDeploymentLambda code

How to reproduce it

Run prowler with check extra760 on an environment with Control Tower.

Expected behavior
A clear and concise description of what you expected to happen.

FAIL! instead of PASS!, and also less noise on the output (curl errors etc.)

Screenshots or Logs
If applicable, add screenshots to help explain your problem.
Also, you can add logs (anonymize them first!). Here a command that may help to share a log
bash -x ./prowler -options > debug.log 2>&1 then attach here debug.log

From where are you running Prowler?
Please, complete the following information:

  • Resource: CodeBuild task
  • OS: Amazon Linux 2
  • AWS-CLI Version [aws --version]:
  • Prowler Version [./prowler -V]: Prowler 2.7.0-24January2022
  • Shell and version:
  • Others:

Additional context
Add any other context about the problem here.

@lorchda lorchda added the bug label Jan 31, 2022
@lazize
Copy link
Contributor

lazize commented Feb 2, 2022

Could you check if your role ProwlerXA-CBRole has the same permissions according to the file below?

As you can see, action lambda:GetFunction was added on 2.7 version.

- 'lambda:GetFunction'

@lazize
Copy link
Contributor

lazize commented Feb 3, 2022

This check has a grep for AccessDenied as below

    if [[ $(echo "$LIST_OF_FUNCTIONS" | grep AccessDenied) ]]; then
      textInfo "$regx: Access Denied trying to list Lambda functions" "$regx" "$lambdafunction"
      continue
    fi

But other checks has a grep with more options, like below

    if [[ $(echo "$SSM_DOCS" | grep -E 'AccessDenied|UnauthorizedOperation|AuthorizationError') ]]; then
        textInfo "$regx: Access Denied trying to list documents" "$regx"
        continue
    fi

Should all grep checks for AccessDenied looks like the second one?

@lazize
Copy link
Contributor

lazize commented Feb 3, 2022

This check uses curl -s.
Should it be like curl -s --show-error as suggested on curl documentation? In case of error on curl it will not be suppressed.

   -s, --silent
          Silent or quiet mode. Don't show progress meter or error messages.  Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect
          it.

          Use -S, --show-error in addition to this option to disable progress meter but still show error messages.

@lorchda
Copy link
Contributor Author

lorchda commented Feb 3, 2022

@lazize thank you for the pointer, I confirm the lambda:GetFunction is missing in my role. I initially was thinking that an SCP could be the culprit and didn't check the permissions myself - thank you.

It appears that the role descriptions are not in sync. I am using prowler/util/org-multi-account/serverless_codebuild/templates/ProwlerRole.yaml which did not get the update. See these files:

@lazize
Copy link
Contributor

lazize commented Feb 3, 2022

Those files you mention has much more permissions than others. Even though they are not in sync.

Keep all those files in sync is a very hard job to do it manually. I believe it will need a better mechanism to handle this situation. Just rely on people is not good enough.

@lazize
Copy link
Contributor

lazize commented Feb 4, 2022

@toniblyx How about the questions above about curl and check for AccessDenied?

@jfagoagas jfagoagas added status/needs-triage Issue pending triage severity/medium Results in some unexpected or undesired behavior. status/waiting-for-revision Waiting for maintainer's revision and removed status/needs-triage Issue pending triage labels Feb 14, 2022
@toniblyx
Copy link
Member

toniblyx commented Mar 4, 2022

@lazize @lorchda sorry for the late response, yes, we have to fine tune that check and parse the curl error in a better way. Let's see if that can be addressed before 2.8 is release.

@toniblyx
Copy link
Member

toniblyx commented Mar 4, 2022

Thanks @lazize we will review and merge it next week.

@jfagoagas
Copy link
Member

Pull Request #1055 has been merged, thank you @lorchda @lazize for this awesome work!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug severity/medium Results in some unexpected or undesired behavior. status/waiting-for-revision Waiting for maintainer's revision
Projects
None yet
Development

No branches or pull requests

4 participants