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

automate bootstrapping of integrations tests #1289

Merged
merged 4 commits into from
May 22, 2024
Merged

Conversation

petrkalos
Copy link
Contributor

@petrkalos petrkalos commented May 20, 2024

Feature or Bugfix

  • Feature

Detail

  • introduce an SSM param that holds the test userdata
  • migrate ConfigureCognito step from a frontend codebuild step to a TriggerFunction that runs after the deployment of the CognitoClient
  • add logic in ConfigureCognito to create the test users and assigned them to groups if with_approval_tests=True (reads info from SSM param)
    • minor: change prints to logging
  • tests are reading the userdata from the SSM param
  • if with_approval_tests=True Cognito allows ALLOW_USER_PASSWORD_AUTH auth flow

Security

Please answer the questions below briefly where applicable, or write N/A. Based on
OWASP 10.

  • Does this PR introduce or modify any input fields or queries - this includes
    fetching data from storage outside the application (e.g. a database, an S3 bucket)?
    • Is the input sanitized?
    • What precautions are you taking before deserializing the data you consume?
    • Is injection prevented by parametrizing queries?
    • Have you ensured no eval or similar functions are used?
  • Does this PR introduce any functionality or component that requires authorization?
    • How have you ensured it respects the existing AuthN/AuthZ mechanisms?
    • Are you logging failed auth attempts?
  • Are you using or adding any cryptographic features?
    • Do you use a standard proven implementations?
    • Are the used keys controlled by the customer? Where are they stored?
  • Are you introducing any new policies/roles/users?
    • Have you used the least-privilege principle? How?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

* introduce a secret that holds the test userdata
* move ConfigureCognito step from frontend to backend
* add logic in ConfigureCognito to create the test users and assigned them to groups if `with_approval_tests=True` (reads info from the secret)
* tests are reading the userdata from the secret
@petrkalos petrkalos requested a review from dlpzx May 20, 2024 14:57
@@ -3,7 +3,18 @@ The purpose of these tests is to automatically validate functionalities of data.

## Pre-requisites
- A real deployment of data.all in AWS
- 4 Cognito users (at the moment only Cognito is supported) like the ones defined in `conftest`(e.g. `testUser1` with password `Pass1Word!`)
- A SecretManager secret (`'{self.resource_prefix}-{target_env["envname"]}-cognito-test-users'`) with the followings contents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need SecretManager here? We don't need auto rotation or so, I think SSM Parameter store is enough, also it's free.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I am not an expert but my go-to is that when a password is involved I use SecretsManager (even if it's just for tests). Apart from the pricing aspect I don't see a downside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had issues in the past with checkov flagging some secrets in SecretsManager because some best practices dictate that encrypted Secrets in secret manager should be rotated at least annually and encrypted with a KMS key. So if we add a secret, it needs to be encrypted with KMS and with rotation enabled. So as @SofiaSazonova was saying if it does not rotate, we might go for SSM. The question is, do we need to rotate them? what can happen if the password gets exposed?

In the scenario where a malicious user:

  • knows that a company uses data.all. Tries to guess the cloudfront domain that might be something like .dataall.com
  • tries to hit the domain with the default test user password (company is careless and did not change it)
  • can overflood a company CICD pipeline with requests?

Copy link
Contributor Author

@petrkalos petrkalos May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing with @dlpzx offline we decided to use SSM params for simplicity. Thanks for the spot on commend Sofia :)

@@ -3,7 +3,18 @@ The purpose of these tests is to automatically validate functionalities of data.

## Pre-requisites
- A real deployment of data.all in AWS
- 4 Cognito users (at the moment only Cognito is supported) like the ones defined in `conftest`(e.g. `testUser1` with password `Pass1Word!`)
- A SecretManager secret (`'{self.resource_prefix}-{target_env["envname"]}-cognito-test-users'`) with the followings contents
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, that's for test purposes, but why expose it in code (especially opensource)? May be it's better just to leave comment like: userdata with username, password and groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just gave an example password, real deployments should use a different one. Is your concern that people will just copy and paste the example and hence make themselves vulnerable?

"testUser4": {"password": "yourPassword", "groups": ["testGroup4"]}
}
```
- If you are not using Cognito then you must manually create the users/groups
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not using Cognito, they still need to create the secret to store the passwords right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, if they are not using Cognito they must create the users manually and then create the secret for the CodeBuild job to read from. Will fix

else:
raise e

print('Updating Canaries user password...')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prints logs referencing CW canaries. Can we replace prints by logs?


cognito = boto3.client('cognito-idp', region_name=region)
try:
user_pool = cognito.describe_user_pool_client(UserPoolId=user_pool_id, ClientId=app_client)
user_pool = cognito.describe_user_pool_client(UserPoolId=user_pool_id, ClientId=app_client)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed the general try/except because if it fails then the stack will rollback right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I removed it because it was only catching the exception printing and throwing it again which isn't required as the exception will currently bubble up and print the exact same information...

 except ClientError as e:
        print(f'Failed to setup cognito due to: {e}')
        raise e

Copy link
Contributor

@dlpzx dlpzx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@petrkalos petrkalos merged commit e2b70cb into main May 22, 2024
10 checks passed
@petrkalos petrkalos deleted the feature/test_users branch May 22, 2024 07:15
petrkalos added a commit that referenced this pull request May 22, 2024
)

### Feature or Bugfix
- Bugfix

### Detail
Integration tests are running from a CodeBuild job in the tooling
account but the `cognito-test-users` param exists in the environment
account.

### Relates
Fixes an issue introduced #1289 

### Security
Please answer the questions below briefly where applicable, or write
`N/A`. Based on
[OWASP 10](https://owasp.org/Top10/en/).

- Does this PR introduce or modify any input fields or queries - this
includes
fetching data from storage outside the application (e.g. a database, an
S3 bucket)?
  - Is the input sanitized?
- What precautions are you taking before deserializing the data you
consume?
  - Is injection prevented by parametrizing queries?
  - Have you ensured no `eval` or similar functions are used?
- Does this PR introduce any functionality or component that requires
authorization?
- How have you ensured it respects the existing AuthN/AuthZ mechanisms?
  - Are you logging failed auth attempts?
- Are you using or adding any cryptographic features?
  - Do you use a standard proven implementations?
  - Are the used keys controlled by the customer? Where are they stored?
- Are you introducing any new policies/roles/users?
  - Have you used the least-privilege principle? How?


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants