-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(codepipeline): add codepipeline_pipeline_no_secrets_in_definitio… #11842
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
Open
Sid-0602
wants to merge
1
commit into
prowler-cloud:master
Choose a base branch
from
Sid-0602:feat/codepipeline-pipeline-no-secrets-in-definition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
48 changes: 48 additions & 0 deletions
48
...ine_no_secrets_in_definition/codepipeline_pipeline_no_secrets_in_definition.metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| { | ||
| "Provider": "aws", | ||
| "CheckID": "codepipeline_pipeline_no_secrets_in_definition", | ||
| "CheckTitle": "CodePipeline pipeline has no secrets in its definition", | ||
| "CheckType": [ | ||
| "Software and Configuration Checks/AWS Security Best Practices", | ||
| "TTPs/Credential Access", | ||
| "Effects/Data Exposure", | ||
| "Sensitive Data Identifications/Security" | ||
| ], | ||
| "ServiceName": "codepipeline", | ||
| "SubServiceName": "", | ||
| "ResourceIdTemplate": "arn:partition:codepipeline:region:account-id:pipeline-name", | ||
| "Severity": "high", | ||
| "ResourceType": "AwsCodePipelinePipeline", | ||
| "ResourceGroup": "devops", | ||
| "Description": "**AWS CodePipeline pipeline definitions** (stage action configurations) are scanned for **hardcoded secrets** such as API keys, tokens, and passwords. Pipeline definitions are readable by many CI/CD roles and embedded credentials enable lateral movement across AWS accounts and third-party services.", | ||
| "Risk": "Hardcoded secrets in pipeline action configurations can be read by any principal with `codepipeline:GetPipeline` permission. Exposed credentials enable unauthorized access to downstream systems, artifact stores, and deployment targets, leading to data exfiltration and supply-chain compromise.", | ||
| "RelatedUrl": "", | ||
| "AdditionalURLs": [ | ||
| "https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference.html", | ||
| "https://docs.aws.amazon.com/secretsmanager/latest/userguide/integrating_how-services-use-secrets_codepipeline.html", | ||
| "https://docs.aws.amazon.com/systems-manager/latest/userguide/integration-ps-secretsmanager.html", | ||
| "https://github.com/prowler-cloud/prowler/issues/3085" | ||
| ], | ||
| "Remediation": { | ||
| "Code": { | ||
| "CLI": "aws codepipeline get-pipeline --name <pipeline-name>\naws codepipeline update-pipeline --pipeline file://updated-pipeline.json", | ||
| "NativeIaC": "```yaml\nResources:\n MyPipeline:\n Type: AWS::CodePipeline::Pipeline\n Properties:\n Stages:\n - Name: Deploy\n Actions:\n - Name: DeployAction\n ActionTypeId:\n Category: Deploy\n Owner: AWS\n Provider: CloudFormation\n Version: 1\n Configuration:\n # CRITICAL: reference secrets from Parameter Store or Secrets Manager\n # never embed raw credentials here\n ParameterOverrides: |\n {\"ApiKey\": \"{{resolve:secretsmanager:my-secret:SecretString:api_key}}\"}\n```", | ||
| "Other": "1. In the AWS Console, navigate to CodePipeline and open the affected pipeline.\n2. Click Edit and locate the stage/action that contains the hardcoded secret.\n3. Remove the plaintext credential from the action configuration.\n4. Store the secret in AWS Secrets Manager or AWS Systems Manager Parameter Store.\n5. Reference the secret using dynamic references (e.g. `{{resolve:secretsmanager:secret-name}}`), or pass it via a Lambda invoke or environment variable backed by a secure store.\n6. Save the pipeline and verify the action still functions correctly.", | ||
| "Terraform": "```hcl\nresource \"aws_codepipeline\" \"example\" {\n name = \"my-pipeline\"\n role_arn = aws_iam_role.codepipeline.arn\n\n stage {\n name = \"Deploy\"\n action {\n name = \"DeployAction\"\n category = \"Deploy\"\n owner = \"AWS\"\n provider = \"CloudFormation\"\n version = \"1\"\n configuration = {\n # CRITICAL: never embed raw credentials; use dynamic references instead\n ParameterOverrides = jsonencode({\n ApiKey = \"{{resolve:secretsmanager:my-secret:SecretString:api_key}}\"\n })\n }\n }\n }\n}\n```" | ||
| }, | ||
| "Recommendation": { | ||
| "Text": "Remove hardcoded credentials from all CodePipeline action configurations. Store secrets in **AWS Secrets Manager** or **AWS Systems Manager Parameter Store** and reference them via dynamic references or secure environment injection. Apply least-privilege IAM policies to the pipeline execution role and audit pipeline definitions regularly.", | ||
| "Url": "https://hub.prowler.com/check/codepipeline_pipeline_no_secrets_in_definition" | ||
| } | ||
| }, | ||
| "Categories": [ | ||
| "secrets", | ||
| "ci-cd" | ||
| ], | ||
| "DependsOn": [], | ||
| "RelatedTo": [ | ||
| "codebuild_project_no_secrets_in_variables", | ||
| "codepipeline_project_repo_private" | ||
| ], | ||
| "Notes": "Severity is High by default. It may be treated as Critical if the detected secret is validated as active. This check scans all stage action configurations using the detect-secrets library. False positives can be suppressed via the secrets_ignore_patterns audit config." | ||
| } |
68 changes: 68 additions & 0 deletions
68
...eline_pipeline_no_secrets_in_definition/codepipeline_pipeline_no_secrets_in_definition.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import json | ||
| from typing import List | ||
|
|
||
| from prowler.lib.check.models import Check, Check_Report_AWS | ||
| from prowler.lib.utils.utils import detect_secrets_scan | ||
| from prowler.providers.aws.services.codepipeline.codepipeline_client import ( | ||
| codepipeline_client, | ||
| ) | ||
|
|
||
|
|
||
| class codepipeline_pipeline_no_secrets_in_definition(Check): | ||
| """Ensure CodePipeline pipeline definitions do not contain hardcoded secrets. | ||
|
|
||
| Scans all stage action configurations for embedded credentials such as API keys, | ||
| tokens, or passwords. Pipeline definitions are readable by many CI/CD roles and | ||
| embedded credentials enable lateral movement. | ||
|
|
||
| - PASS: No secrets are detected in any stage action configuration. | ||
| - FAIL: A secret is detected in one or more stage action configurations. | ||
| """ | ||
|
|
||
| def execute(self) -> List[Check_Report_AWS]: | ||
| """Execute the CodePipeline pipeline secrets check. | ||
|
|
||
| Iterates over all discovered pipelines, scans each stage action | ||
| configuration with detect-secrets, and reports any findings. | ||
|
|
||
| Returns: | ||
| List[Check_Report_AWS]: A list of report objects with check results. | ||
| """ | ||
| findings = [] | ||
| secrets_ignore_patterns = codepipeline_client.audit_config.get( | ||
| "secrets_ignore_patterns", [] | ||
| ) | ||
| for pipeline in codepipeline_client.pipelines.values(): | ||
| report = Check_Report_AWS(metadata=self.metadata(), resource=pipeline) | ||
| report.status = "PASS" | ||
| report.status_extended = f"CodePipeline pipeline {pipeline.name} does not have secrets in its definition." | ||
| secrets_found = [] | ||
| has_verified_secret = False | ||
|
|
||
| for stage in pipeline.stages: | ||
| for action in stage.actions: | ||
| if action.configuration: | ||
| detect_secrets_output = detect_secrets_scan( | ||
| data=json.dumps(action.configuration), | ||
| excluded_secrets=secrets_ignore_patterns, | ||
| detect_secrets_plugins=codepipeline_client.audit_config.get( | ||
| "detect_secrets_plugins" | ||
| ), | ||
| ) | ||
| if detect_secrets_output: | ||
| for secret in detect_secrets_output: | ||
| secrets_found.append( | ||
| f"{secret['type']} in stage {stage.name} action {action.name}" | ||
| ) | ||
| if secret.get("is_verified"): | ||
| has_verified_secret = True | ||
|
|
||
| if secrets_found: | ||
| report.status = "FAIL" | ||
| report.status_extended = f"CodePipeline pipeline {pipeline.name} has secrets in its definition: {', '.join(secrets_found)}." | ||
| if has_verified_secret: | ||
| report.check_metadata.Severity = "critical" | ||
|
|
||
| findings.append(report) | ||
|
|
||
| return findings | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.