GSEC Container Security Practice Question
Which of the following is the most effective way to prevent secrets (such as API keys) from being leaked via container images?
⚠ Common exam trap
Candidates frequently select multi-stage builds or container image scanning, forgetting that while these reduce image size or find bugs, they do not prevent secrets from persisting in image layers.
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 orchestrator-native secret management to inject secrets at runtime.
Secrets should never be baked into container images because they remain in the image layers even if deleted in later steps. Once an image is pushed to a registry, those secrets are accessible to anyone with pull access. Using orchestrator-native secret management (like Kubernetes Secrets or Vault) ensures that sensitive data is injected at runtime, keeping it out of the persistent image layers and the source control history.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Encrypt the Dockerfile using a secret key before building.
Why it's wrong here
Encrypting the Dockerfile does not protect secrets inside the resulting image layers. When the container builds, the secret must be provided in plaintext to the build environment. Furthermore, the final image manifest and layers will contain the decrypted version of the data, making it retrievable by any container runtime user.
- ✓
Use orchestrator-native secret management to inject secrets at runtime.
Why this is correct
Runtime injection ensures that secrets reside only in the memory of the container and are not persisted in the image layers. This prevents secrets from being exposed through registry access or image analysis, allowing for easier rotation and centralized auditing of secret usage within the containerized application environment.
- ✗
Delete the secrets in a subsequent RUN layer during the build.
Why it's wrong here
Deleting a file in a later Dockerfile layer does not remove the data from the underlying image history. The data persists in previous layers and can be easily recovered using image inspection tools. To remove data truly, one must use multi-stage builds where secrets are never present in the final image.
- ✗
Set the file permissions on the secret to 600 after copying it.
Why it's wrong here
Setting file permissions inside the container only restricts access to the file for processes running within that container. It does not prevent an attacker or an administrator from extracting the secret from the container image itself, as the file content is still stored permanently in the image layer metadata.
About these practice questions
This GSEC question is part of Courseiva's 351-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official GIAC exam blueprint
This GSEC practice question is part of Courseiva's free GIAC 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 GSEC exam.