Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Here’s how to remediate this using the AWS Console by removing credentials from the Bitbucket URL and using proper authentication.
1. Identify the misconfigured CodeBuild project
- Sign in to the AWS Management Console.
- Go to CodeBuild:
Services→ search for CodeBuild → open CodeBuild. - In the left menu, select Build projects.
- Click the project name that is using Bitbucket and has a URL like:
https://username:password@bitbucket.org/workspace/repo.git.
2. Edit the project source configuration
- In the project details page, click Edit (top right).
- In the Source section, verify:
- Source provider: should be Bitbucket (not “Git” with a raw HTTPS URL).
- If Source provider is currently set to Git:
- Change Source provider to Bitbucket.
- In the Repository field, specify the repo using a clean URL (no credentials), e.g.:
https://bitbucket.org/workspace/repo.git
or, if it’s an option in the UI, just select the repository from the Bitbucket connection (recommended).
3. Connect CodeBuild to Bitbucket without embedding credentials in URL
A. If Bitbucket OAuth / integration is available
- In the Source section (with provider = Bitbucket), look for an option like:
- Connect to Bitbucket, Connect using OAuth, or Connect to source provider.
- Click that and follow the prompts:
- You will be redirected to Bitbucket to authorize AWS CodeBuild.
- Approve the permissions so AWS can clone the repo.
- Back in CodeBuild, select the Bitbucket repository from the list (if presented).
- Ensure the repository URL now shows without credentials.
B. If you must use HTTPS with an app password/personal token
Do not put the token in the URL. Use environment variables + Secrets Manager or SSM.- In Bitbucket:
- Create an App Password or personal access token with minimally required scopes.
- In AWS:
- Go to AWS Secrets Manager.
- Store the username and app password in a secret (e.g.,
bitbucket/codebuild/creds).
- Back in CodeBuild project → Edit:
- Scroll to Environment section.
- Add environment variables like:
BITBUCKET_USERNAME= (value from Secrets Manager, as a secrets-managed variable)BITBUCKET_APP_PASSWORD= (also from Secrets Manager)
- Use the “Secrets Manager” option for value type, and select your secret/JSON key.
- In your buildspec.yml, replace any direct
git clone https://user:pass@...with something like:This way, the URL never contains literal credentials in the CodeBuild configuration.
4. Save the project
- After updating the source and/or environment configuration, scroll down and click Update build project (or Save).
5. Remove leaked credentials from Bitbucket URL and rotate them
- In Bitbucket, revoke or delete:
- Any username/password or app password that was embedded in the URL.
- If that password is used elsewhere, change/rotate it.
- If the credential was committed into any repository:
- Remove it from the code (commit a change that removes it).
- Consider history rewriting and rotating the credential, depending on your security policy.
6. Verify
- In CodeBuild, start a new build of the edited project.
- Confirm:
- The build successfully pulls from Bitbucket.
- No credentials appear in the repository URL shown in the project settings.
- Logs don’t print credentials (check any echo/print commands).
Using CLI
Using CLI
Here’s how to remediate “Sign-in Credentials Should Not Be In Bitbucket Source Repository URL” for an AWS CodeBuild project using the AWS CLI.You must:
You’ll edit a copy rather than hand‑construct the full JSON.
This returns a
Replace it with (example using imported source credentials):Keep all other top-level fields (environment, artifacts, etc.) exactly as they were.Save this as
If your shell doesn’t support process substitution easily, you can pull
Check:
0. Understand the problem
Right now your CodeBuild project’ssource.location likely looks like this:- Remove
username:password@from the URL. - Use a proper auth mechanism (CodeStar Connection or OAuth/source credentials).
- Rotate/revoke the exposed credentials.
1. Rotate/revoke exposed Bitbucket credentials
Do this in Bitbucket first:- Revoke the username/password (or app password) that was embedded in the URL.
- Create a new, properly scoped credential if still needed (e.g., app password or OAuth token).
2. Get current CodeBuild project config
3. Decide on proper auth mechanism
Option A (recommended): Use CodeStar Connections
-
In the AWS Console:
Developer Tools → Connections → Create connection → Bitbucket
Get the connection ARN, e.g.: -
In CodeBuild, you then use
GITas source and specifysourceIdentifieras this connection. However, with CLI, this is done viasourceconfiguration usingsourceType=BITBUCKET+authOR through “Git repository in CodeStar Connections” (varies by region/console). The more universal approach is to use GIT + CodeStar connection via environment variable forCODEBUILD_SOURCE_REPO_URLand connection in CodePipeline; but for direct CodeBuild project, you can do: UseBITBUCKETwithauth.type=OAUTHor use CodePipeline + CodeStar connection as the frontend. If you already have a working CodePipeline+Connection, you can just change CodeBuild project toCODEPIPELINEsource and let the pipeline handle Bitbucket auth.
- Use CodePipeline + CodeStar Connections, with CodeBuild’s
source.type=CODEPIPELINE.
Option B: Use CodeBuild source credentials (OAUTH / personal token)
Create a Bitbucket app password or token and register it with CodeBuild:arn:aws:codebuild:...:sourceCredential/....You then configure your CodeBuild project to use:source.type = BITBUCKETsource.location = https://bitbucket.org/org/repo.git(no credentials)source.auth.type = PERSONAL_ACCESS_TOKEN(orOAUTH)source.auth.resource = <source-credential-ARN>
4. Edit the project JSON (remove credentials from URL and add auth)
Opencurrent-project.json and locate the "source" block. You’ll see something like:updated-project.json.Note: If you prefer OAuth, use"type": "OAUTH"inauthand set"resource"to the appropriate credential ARN returned byimport-source-credentials.
5. Update the CodeBuild project via CLI
Now run:source into its own file:update-project only needs the --name and the part(s) you’re modifying; here it’s just the source.6. Confirm the URL no longer contains credentials
locationishttps://bitbucket.org/org/repo.git(nousername:password@).authis present and correctly set.
7. (Optional) Clean up any stored plaintext credentials in configs
- Check buildspecs and environment variables for embedded Bitbucket usernames/passwords.
- Rotate any other secrets that may have been exposed the same way.
Using Python
Using Python
You need to (1) stop using credential‑embedded Bitbucket URLs in CodeBuild, (2) rotate/revoke the exposed credentials, and (3) update the project to use a safe auth method. Below is how to do that with Python (boto3).
Credentials in
The exact way Bitbucket auth is wired for CodeBuild is usually done in the console via OAuth; programmatically you typically still ensure that
What this script does:
1. What’s wrong now
Your CodeBuild project likely has a source like:location is the misconfiguration.2. Immediate security actions
-
Rotate/revoke the exposed Bitbucket credentials
- Log in to Bitbucket.
- Go to Personal settings → App passwords (or wherever those credentials were created).
- Revoke the exposed password/token.
- Create a new app password / token with minimum required scopes.
-
Search for other leaks
- Search your CodeBuild buildspecs, environment variables, and parameter store for the same username/password or token and remove/rotate them too.
3. Fix the CodeBuild project configuration
Option A (recommended when possible): Use CodeStar Connections via CodePipeline
If you can use CodePipeline, the most secure way is:- Create a CodeStar Connection to Bitbucket in the AWS Console (Developer Tools → Connections).
- Use that connection in CodePipeline as the source.
- Have CodePipeline trigger your CodeBuild project; then your CodeBuild
sourcetype isCODEPIPELINE(no URL, no credentials).
Option B: Use a clean URL and managed auth for BITBUCKET source
If you must keep CodeBuild directly pulling from Bitbucket:- The
locationmust not contain credentials. - Configure authentication using
source.authand store any tokens/credentials in a secure store (e.g., Secrets Manager), not in the URL.
location value:location is clean and that no credentials are in environment variables or buildspecs.4. Python (boto3) remediation script
Below is an example Python script that:- Finds CodeBuild projects whose source URL contains
@with credentials. - Rewrites
locationto remove the credential portion. - Leaves all other settings intact.
- (You still must handle token/OAuth setup separately as above.)
- Ensures
source.locationno longer containsusername:password@ortoken@. - Does not put any new secret into the URL.
- Leaves room for you to configure proper Bitbucket auth via:
- CodeStar Connections + CodePipeline (preferred), or
- Console-based OAuth setup for BITBUCKET source and/or use of secrets (never hard-coded).
5. Final checklist
- Revoke old Bitbucket credentials and create new ones.
- Remove credentials from:
- CodeBuild
source.location - buildspec files
- environment variables / Parameter Store values (if plaintext)
- CodeBuild
- Configure secure auth:
- Prefer CodeStar Connections via CodePipeline, or
- Use Bitbucket OAuth / tokens stored in Secrets Manager, never in URLs.
- Run the Python/boto3 script to clean all affected CodeBuild projects.
Using Terraform
Using Terraform
source.location to remove embedded credentials and updating source.auth to type = "OAUTH" is an in-place update for aws_codebuild_project (no replacement of the project itself, but builds will use the new connection).To verify, terraform plan should show updates only to the source.location (removing credentials if previously present) and the source.auth block (setting type = "OAUTH" and pointing resource at the OAuth connection ARN), with no -/+ replacement for aws_codebuild_project.CODEBUILD_PROJECT.
