DOP-C02 Security and Compliance Practice Question
A DevOps engineer is designing a secure CI/CD pipeline. Which TWO of the following are best practices for securing secrets in the pipeline?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use encrypted environment variables in CodeBuild.
Options A and E are correct. Option A: CodeBuild allows environment variables to be encrypted using AWS KMS, which is a secure way to handle secrets in the pipeline. Option E: AWS Secrets Manager is a dedicated service for securely storing and retrieving secrets, and integrating it with the pipeline ensures secrets are not exposed. Option B is incorrect because storing secrets in a parameter file in the source repository exposes them to anyone with repository access, violating security best practices. Option C is incorrect because hardcoding secrets in CloudFormation template parameters can lead to exposure in logs or template outputs, and is not secure. Option D is incorrect because while S3 bucket policies can restrict access, they do not encrypt the secrets themselves, and S3 is not designed for managing secrets; AWS Secrets Manager or Parameter Store are better choices.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Use encrypted environment variables in CodeBuild.
Why this is correct
CodeBuild allows you to define environment variables that are encrypted at rest with a customer-managed or AWS-managed KMS key and are never stored in buildspec or source control. These values are decrypted automatically in the build container at runtime, so the build commands can use them without exposing plaintext in the pipeline artifacts. Because CodeBuild also supports referencing Systems Manager Parameter Store or Secrets Manager values as environment variables, this approach centralizes secret access while retaining per-environment changes.
- ✗
Store secrets in a parameter file in the source repository.
Why it's wrong here
Storing secrets in a parameter file checked into the source repository violates the core tenet of keeping credentials out of version control. Every user or CI tool with repository access can read the file, and even after deleting it, the secret remains in Git history and in any forks, caches, or mirror copies. This creates a permanent credential exposure that automated scanners may detect, and there is no central way to rotate or audit usage.
- ✗
Hardcode secrets in CloudFormation template parameters.
Why it's wrong here
Hardcoding secrets as CloudFormation template parameters embeds sensitive data directly in the infrastructure-as-code artifact and any change set or stack template history. Although the NoEcho property can mask parameter values from console output, it does not encrypt them at rest or prevent them from appearing in API calls or logs, and the plaintext secret remains in the template body. This tightly couples credential management to stack deployment, making rotation and least-privilege controls difficult.
- ✗
Use S3 bucket policies to restrict access to secret files.
Why it's wrong here
An S3 bucket policy only defines who can perform actions against the bucket; it is an authorization control, not an encryption mechanism. If secret files are stored in S3, the object data at rest is protected only if you separately configure server-side encryption, and requests to the bucket are still subject to transport-level risks unless you enforce HTTPS. Additionally, using S3 as a secrets repository requires you to build rotation and access auditing yourself, whereas purpose-built services handle those controls natively.
- ✓
Store secrets in AWS Secrets Manager and retrieve them during the build.
Why this is correct
AWS Secrets Manager provides a dedicated, encrypted store for database credentials, API keys, and other sensitive values, with automatic rotation and fine-grained IAM policies to scope who can retrieve each secret. In a CodeBuild pipeline, you can reference the secret directly using the Secrets Manager environment variable type or run `aws secretsmanager get-secret-value` in the buildspec, and the value is fetched over the AWS API using the build role's permissions. CloudTrail records every retrieval, giving an auditable trail, and rotation can happen without modifying pipeline definitions.
Quick reference
AWS S3 Storage Class Comparison
| Storage Class | Min Duration | Retrieval | Use Case |
|---|---|---|---|
| S3 Standard | None | Immediate | Frequently accessed data |
| S3 Standard-IA | 30 days | Immediate | Infrequent access, rapid retrieval |
| S3 One Zone-IA | 30 days | Immediate | Non-critical infrequent data |
| S3 Intelligent-Tiering | None | Immediate–hours | Unknown or changing access patterns |
| S3 Glacier Instant | 90 days | Milliseconds | Archive with instant retrieval |
| S3 Glacier Flexible | 90 days | Minutes–hours | Archive, flexible retrieval |
| S3 Glacier Deep Archive | 180 days | Hours | Long-term compliance archive |
Go deeper
Related to this question
About these practice questions
Courseiva writes every DOP-C02 question from scratch — 1,298 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DOP-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DOP-C02 exam.