Exposed Amplify branch Basic Auth password

Putting an Amplify branch Basic Auth password in a template leaves branch credentials in code.

Description

Reference the Amplify branch’s BasicAuthConfig.Password from Secrets Manager. Keep the actual password out of the template and parameter defaults.

Potential impact

An exposed username and password can grant access to the protected branch and any other branches that reuse those credentials.

Remediation

Replace an exposed password and update the affected AWS::Amplify::Branch resource. Changing the secret alone leaves the old value on the branch. Verify the new sign-in on that branch.

Examples

Set AmplifyAppId and BranchName to the existing app and target branch. The second example generates a password for that branch and references it alongside the username.

Before

yaml
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  AmplifyAppId:
    Type: String
  BranchName:
    Type: String
Resources:
  NewAmpApp1:
    Type: AWS::Amplify::Branch
    Properties:
      AppId: !Ref AmplifyAppId
      BranchName: !Ref BranchName
      EnableAutoBuild: false
      EnablePerformanceMode: false
      EnablePullRequestPreview: false
      BasicAuthConfig:
        EnableBasicAuth: true
        Password: "@skdsjdk0234!AB"
        Username: admin

After

yaml
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  AmplifyAppId:
    Type: String
  BranchName:
    Type: String
Resources:
  NewAmpApp1:
    Type: AWS::Amplify::Branch
    Properties:
      AppId: !Ref AmplifyAppId
      BranchName: !Ref BranchName
      EnableAutoBuild: false
      EnablePerformanceMode: false
      EnablePullRequestPreview: false
      BasicAuthConfig:
        EnableBasicAuth: true
        Password: !Sub '{{resolve:secretsmanager:${MyAmpAppSecretManagerRotater}:SecretString:password}}'
        Username: !Sub '{{resolve:secretsmanager:${MyAmpAppSecretManagerRotater}:SecretString:username}}'
  MyAmpAppSecretManagerRotater:
    Type: AWS::SecretsManager::Secret
    Properties:
      GenerateSecretString:
        SecretStringTemplate: '{"username": "admin"}'
        GenerateStringKey: password
        PasswordLength: 16

References