Skip to content

Commit

Permalink
Fix canary user pw creation (#718)
Browse files Browse the repository at this point in the history
In rare cases the current way of generating a Canary user password in
Cognito can result in a string containing no numerical values, hence
following error is thrown during deployment ( requires
**enable_cw_canaries** config parameter set to True in cdk.json):
`botocore.errorfactory.InvalidPasswordException: An error occurred
(InvalidPasswordException) when calling the AdminCreateUser operation:
Password did not conform with password policy: Password must have
numeric characters`

Changing the password creation to contain at least 1 uppercase and 1
numerical character.


### Feature or Bugfix
- Bugfix


### Detail
- <feature1 or bug1>
- <feature2 or bug2>

### Relates
- <URL or Ticket>

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

n/a

- 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.
  • Loading branch information
dbalintx authored Aug 31, 2023
1 parent 43eb082 commit af860f6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions deploy/configs/cognito_urls_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from botocore.exceptions import ClientError


def shuffle_password(pwd):
chars = list(pwd)
random.shuffle(chars)
return ''.join(chars)

def setup_cognito(
region,
resource_prefix,
Expand Down Expand Up @@ -110,11 +115,15 @@ def setup_cognito(
{'Name': 'email', 'Value': f'{username}@amazonaws.com'}
],
TemporaryPassword='da@'
+ ''.join(
random.SystemRandom().choice(
string.ascii_uppercase + string.digits
+ shuffle_password(
random.SystemRandom().choice(string.ascii_uppercase)
+ random.SystemRandom().choice(string.digits)
+ ''.join(
random.SystemRandom().choice(
string.ascii_uppercase + string.digits
)
for _ in range(11)
)
for _ in range(13)
),
MessageAction='SUPPRESS',
)
Expand Down

0 comments on commit af860f6

Please sign in to comment.