# Ensure Secrets Are Not Passed as Container Environment Variables in Amazon ECS Task Definitions

- Source: https://support.icompaas.com/support/solutions/articles/62000233987-ensure-secrets-are-not-passed-as-container-environment-variables-in-amazon-ecs-task-definitions
- Section: [Solutions](https://support.icompaas.com/support/solutions) › [CIS AWS Compute Services Benchmark v1.1.0](https://support.icompaas.com/support/solutions/62000112682) › [AWS Compute Services Benchmark v1.1.0](https://support.icompaas.com/support/solutions/folders/62000169228)
- Last updated: 2026-05-29
- Publisher: iCompaas, Inc. (https://www.icompaas.com)

**Profile Applicability:**  

-   Level 1

**Description:**  
Ensure that sensitive secrets, such as AWS\_ACCESS\_KEY\_ID, AWS\_SECRET\_ACCESS\_KEY, and ECS\_ENGINE\_AUTH\_DATA, are not passed as environment variables in Amazon ECS task definitions. Instead, use secure methods such as AWS Secrets Manager or AWS Systems Manager Parameter Store to inject these credentials into containers.

**Rationale:** Passing secrets directly as environment variables can expose sensitive data to potential compromise, as it can be accessed by any process within the container or unauthorized users. Storing secrets using managed services like AWS Secrets Manager or AWS Systems Manager Parameter Store provides better security and control over sensitive information.

**Impact:  
 Pros:**

-   Enhanced security by using managed services to handle sensitive data.  
    
-   Reduced risk of data leakage from containers or unauthorized processes.  
    
-   Compliance with best practices for secrets management.  
    

Cons:

-   Administrative effort is required to configure and integrate secrets management services.  
    
-   Operational overhead for managing and rotating secrets.  
    

**Default Value:** By default, secrets should not be stored as container environment variables in ECS task definitions. This is a best practice, and AWS recommends using AWS Secrets Manager or AWS Systems Manager Parameter Store for sensitive data management.

**Pre-requisites:**

-   AWS IAM permissions to manage ECS task definitions and Secrets Manager/Systems Manager:  
     ecs:DescribeTaskDefinition, ecs:UpdateTaskDefinition, secretsmanager:GetSecretValue, ssm:GetParameter
    

**Remediation:**

**Test Plan:**

**Using AWS Console:**

1.  Log in to the ECS Console at [AWS ECS Console](https://console.aws.amazon.com/ecs/).  
    
2.  In the left panel, click Task Definitions.  
    
3.  Click the name of the task definition to review.  
    
4.  Click on the latest active revision of the task definition.  
    
5.  Click JSON to view the raw configuration.  
    
6.  For each element under containerDefinitions, ensure that no environment variables contain sensitive information, such as AWS\_ACCESS\_KEY\_ID, AWS\_SECRET\_ACCESS\_KEY, or ECS\_ENGINE\_AUTH\_DATA.  
    
7.  If any secrets are found, refer to the remediation below.  
    
8.  Repeat steps 1–7 for all task definitions across all AWS regions.  
    

**Using AWS CLI:**

1.  Run the following command to list all task definitions:  
    
    aws ecs list-task-definitions
    
2.  For each task definition, run the following command to describe it:  
    
    aws ecs describe-task-definition --task-definition <task-definition-arn> --query 'taskDefinition.containerDefinitions\[\*\].environment\[\*\].name'
    
3.  Ensure that no environment variables contain AWS\_ACCESS\_KEY\_ID, AWS\_SECRET\_ACCESS\_KEY, or ECS\_ENGINE\_AUTH\_DATA. If found, refer to the remediation below.
    
4.  Repeat steps 1–3 for all task definitions and AWS regions.  
    

**Implementation Plan:**

**Using AWS Console:**

1.  Log in to the ECS Console at [AWS ECS Console](https://console.aws.amazon.com/ecs/).  
    
2.  In the left panel, click Task Definitions.  
    
3.  Click the name of the task definition that needs modification.  
    
4.  Click on the latest active revision of the task definition.  
    
5.  Click Create new revision.
    
6.  In the JSON editor, remove any environment variables that contain secrets (e.g., AWS\_ACCESS\_KEY\_ID, AWS\_SECRET\_ACCESS\_KEY, or ECS\_ENGINE\_AUTH\_DATA):  
      
    
    "environment": \[
      {
        "name": "AWS\_ACCESS\_KEY\_ID",
        "value": "your-secret-key"
      },
      {
        "name": "AWS\_SECRET\_ACCESS\_KEY",
        "value": "your-secret-access-key"
      }
    \]
    

7.  Instead, replace those environment variables with a reference to Secrets Manager or Systems Manager Parameter Store to securely inject the secrets.
    
8.  Click Create to save the new task definition.
    
9.  Repeat steps 1–8 for any other task definitions requiring remediation.
    

**Using AWS CLI:**

1.  For each task definition that needs to be updated, run the following command to register a new task definition without the sensitive environment variables:  
    
    aws ecs register-task-definition \\
      --family <task-family-name> \\
      --container-definitions '\[{"name": "container-name", "image": "image-name", "environment": \[{"name": "AWS\_SECRET", "valueFrom": "arn:aws:ssm:region:account-id:parameter/secret-name"}\]}\]'
    

2.  This will ensure that sensitive data like AWS\_ACCESS\_KEY\_ID and AWS\_SECRET\_ACCESS\_KEY is managed securely.  
    
3.  After updating the task definitions, redeploy the ECS tasks using the new task definition.  
    

**Backout Plan:**

**Using AWS Console:**

1.  If issues arise after updating the task definitions, revert to the previous revision of the task definition that contained the environment variables.
    
2.  Redeploy ECS tasks using the previous task definition.
    

**Using AWS CLI:**

1.  To restore the original configuration, run the following command to register a new task definition and reintroduce the environment variables:  
    
    aws ecs register-task-definition \\
      --family <task-family-name> \\
      --container-definitions '\[{"name": "container-name", "image": "image-name", "environment": \[{"name": "AWS\_ACCESS\_KEY\_ID", "value": "secret-key"}\]}\]'
    

2.  Redeploy ECS tasks using the older task definition if necessary.
    

**References:**

1.  [AWS ECS: Specifying Sensitive Data  
    ](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifyingsensitive-data.html)
    
2.  [AWS CLI: describe-task-definition  
    ](https://aws.amazon.com/cli/latest/reference/ecs/describe-task-definition.html)
    
3.  [AWS CLI: register-task-definition  
    ](https://aws.amazon.com/cli/latest/reference/ecs/register-task-definition.html)
    
4.  [AWS Secrets Manager: Storing and Retrieving Secrets  
    ](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html)
    
5.  [AWS Systems Manager Parameter Store  
    ](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)
    

**CIS Controls:**

<table style="border:none;border-collapse:collapse;font-family:&quot;Helvetica Neue&quot;"><colgroup style="font-family:&quot;Helvetica Neue&quot;"><col style="font-family:&quot;Helvetica Neue&quot;"><col style="font-family:&quot;Helvetica Neue&quot;"><col style="font-family:&quot;Helvetica Neue&quot;"></colgroup><tbody style="font-family:&quot;Helvetica Neue&quot;"><tr style="height:38.5pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;text-align:justify;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">Version</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;text-align:justify;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">Control ID</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;text-align:justify;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">Control Description</span></span></span></p></td></tr><tr style="height:64.75pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">v8</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">3.1</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">Establish and maintain a data management process&nbsp;that ensures sensitive data, such as secrets, is stored securely, using services like AWS Secrets Manager or Systems Manager Parameter Store rather than as environment variables.</span></span></span></p></td></tr><tr style="height:51.25pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">v8</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">3.2</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">Establish and maintain a data inventory&nbsp;of sensitive information and ensure that it is securely handled, ensuring compliance with best practices for secrets management.</span></span></span></p></td></tr><tr style="height:51.25pt;font-family:&quot;Helvetica Neue&quot;"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">v7</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">16.4</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:justify"><span style="font-size:14px"><span style="font-family:Helvetica Neue"><span style="color:rgb(0, 0, 0);font-family:&quot;Helvetica Neue&quot;">Encrypt or hash all authentication credentials</span><span style="color:rgb(0, 0, 0);font-weight:400;font-family:&quot;Helvetica Neue&quot;">&nbsp;to prevent leakage or compromise, ensuring secrets are not stored in plaintext in ECS task definitions.</span></span></span></p></td></tr></tbody></table>

## Related compliance guidance

- [SOC 2 compliance: a practical implementation guide for cloud-native SaaS teams](https://support.icompaas.com/compliance/soc-2-trust-services-criteria): Configuration checks like this one are the technical half of a SOC 2 / ISO 27001 programme — the guide shows where they fit, what else an auditor expects, and how to evidence them.
- [ISO/IEC 27001:2022 compliance: a practical implementation guide](https://support.icompaas.com/compliance/iso-27001-2022): ISO 27001 Annex A.8 (technological controls) is where cloud hardening evidence lands; the guide shows how to run the ISMS around it.
