← Back to list

Container Security in DevSecOps: From Image Scan to Runtime Protection

Containers have become a normal part of modern DevOps.

Puja Maheshvari · 2026-06-08 21:03 · 0 claps · 8.2 min read
#devsecops #container-security #kubernetes #cicd #docker
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud

Container Security in DevSecOps: From Image Scan to Runtime Protection

Containers have become a normal part of modern DevOps.

They make applications easier to package, deploy, scale, and move across environments. Whether the application runs on Docker, Kubernetes, ECS, EKS, AKS, GKE, or OpenShift, containers help teams release faster and manage applications more consistently.

But containers also bring security responsibility.

A container image may look small and simple, but it can contain application code, open-source packages, operating system libraries, secrets, configuration files, and runtime permissions. If any of these are weak, the container can become a security risk.

That is why container security should not be treated as only an image scan before deployment.

Image scanning is important, but it is only one part of the story.

Real container security starts from the Dockerfile and continues through the CI/CD pipeline, image registry, Kubernetes deployment, runtime behavior, logging, and incident response.

In DevSecOps, the goal is simple:

Build secure images. Deploy them safely. Monitor them at runtime. Respond quickly when something looks suspicious.

Why Container Security Matters

Containers move fast.

A developer can create an image, push it to a registry, and deploy it to Kubernetes within minutes. This speed is powerful, but it also means security issues can reach production quickly if there are no proper controls.

For example:

A Docker image may contain a vulnerable package. A secret may be copied into the image by mistake. A container may run as root. A Kubernetes pod may have privileged access. An image may come from an untrusted registry. A container may start making suspicious network connections at runtime.

These issues are not only application security issues. They are DevSecOps, cloud security, and runtime security issues.

Container security needs to cover the full lifecycle.

1. Start With a Secure Dockerfile

Container security begins before the image is even built.

A Dockerfile decides what goes into the image, which base image is used, what user the container runs as, which files are copied, and what command starts the application.

A weak Dockerfile can create risk from the beginning.

For example, common Dockerfile mistakes include:

Using a large or outdated base image. Installing unnecessary packages. Running the container as root. Copying secrets into the image. Not pinning versions. Leaving package manager cache inside the image. Using latest tags without control.

A better approach is to keep images small, clean, and predictable.

For example:

Use minimal base images where possible. Avoid running containers as root. Copy only required files. Remove unnecessary tools and packages. Use multi-stage builds. Avoid storing secrets in the image. Pin image versions instead of using only latest.

A secure Dockerfile reduces the attack surface before the image even reaches the pipeline.

2. Choose Trusted Base Images

Base images are the foundation of container security.

If the base image has vulnerabilities, every image built from it may inherit those issues.

For example, a team may write secure application code, but if the base image contains outdated operating system packages, the final container can still be vulnerable.

This is why teams should use trusted and approved base images.

Good practices include:

Use official or internally approved base images. Keep base images updated. Prefer minimal images when possible. Avoid random images from public registries. Scan base images regularly. Maintain a standard set of secure images for teams.

For larger organizations, platform or DevSecOps teams can provide hardened base images. This helps developers start from a safer foundation without having to solve everything themselves.

3. Scan Images in the CI/CD Pipeline

Image scanning is one of the most common container security controls.

Before an image is pushed to a registry or deployed to production, the pipeline should scan it for vulnerabilities.

Image scanning can detect:

Operating system vulnerabilities. Package vulnerabilities. Known CVEs. Risky libraries. Outdated components. Some misconfigurations.

Common tools include Trivy, Grype, Snyk, Prisma Cloud, Aqua Security, Anchore, Docker Scout, and cloud-native scanning tools.

A simple pipeline flow may look like this:

Developer commits code. Pipeline builds the container image. Image scan runs. Critical findings are reviewed. Image is pushed to the registry only if it meets policy. Deployment continues only if the image is approved.

But scanning alone is not enough.

The pipeline also needs a clear policy.

For example:

Block critical exploitable vulnerabilities in production images. Create tickets for medium findings. Allow temporary exceptions with approval and expiration date. Ignore false positives only with documented reason. Rescan images regularly because new CVEs are discovered over time.

The goal is not to block every build with noise. The goal is to prevent real risk from reaching production.

4. Protect the Container Registry

The container registry is where images are stored before deployment.

If the registry is not protected, attackers may push malicious images, replace existing images, or pull sensitive internal images.

Registry security should include:

Strong authentication. Role-based access control. Image signing where possible. Immutable tags for production images. Private registries for internal workloads. Scan results attached to images. Audit logs for image push and pull activity. Only approved pipelines allowed to push production images.

One important practice is to avoid relying only on mutable tags like latest.

If production pulls latest, the image can change without clear tracking. A better approach is to deploy using immutable tags or image digests.

This improves traceability.

During an incident, teams should be able to answer:

Which image version is running? Who built it? Which commit created it? Which scan results were attached? When was it deployed?

Good registry security improves both prevention and investigation.

5. Secure Kubernetes Deployment Configuration

A secure image can still become risky if it is deployed with unsafe Kubernetes settings.

Container security and Kubernetes security are closely connected.

A pod may be risky if it:

Runs as root. Uses privileged mode. Mounts the host filesystem. Has too many Linux capabilities. Uses host networking. Has no resource limits. Can access secrets it does not need. Uses a service account with broad permissions.

A safer Kubernetes deployment should include:

Run as non-root. Drop unnecessary capabilities. Use read-only root filesystem where possible. Set CPU and memory limits. Use proper liveness and readiness probes. Apply Kubernetes RBAC least privilege. Use network policies. Restrict secret access. Avoid privileged containers unless truly required.

For example, a deployment should not use a powerful default service account if the application does not need Kubernetes API access.

Least privilege should apply not only to users, but also to workloads.

6. Use Admission Controls and Policy-as-Code

Manual review is helpful, but it does not scale well.

In a busy DevOps environment, teams may deploy many containers every day. This is why automated guardrails are important.

Admission controls and policy-as-code can help prevent unsafe workloads from being deployed.

For example, policies can block:

Containers running as root. Privileged containers. Images from untrusted registries. Images without scan approval. Pods without resource limits. HostPath volume mounts. Use of the latest tag in production. Missing security context.

Tools like OPA Gatekeeper, Kyverno, Kubernetes admission controllers, Prisma Cloud, Aqua, and cloud-native policy tools can help enforce these controls.

The benefit is simple:

Instead of finding unsafe workloads after deployment, the platform blocks them before they enter the cluster.

This is a strong DevSecOps control because it prevents risky behavior without needing manual review every time.

7. Manage Secrets Properly

Secrets should never be baked into container images.

This is a serious mistake.

Secrets can include API keys, database passwords, tokens, cloud credentials, private keys, and certificates.

Common secret mistakes include:

Copying .env files into the image. Adding secrets in Dockerfile build arguments. Committing secrets to Git. Printing secrets in pipeline logs. Mounting too many secrets into a pod. Using the same secret across environments.

A better approach is to use proper secret management.

Depending on the environment, teams can use HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, Google Secret Manager, Kubernetes Secrets with encryption enabled, or external secrets operators.

Good practices include:

Inject secrets only at runtime. Limit which workloads can access each secret. Rotate secrets regularly. Avoid printing secrets in logs. Use separate secrets for each environment. Audit secret access.

Secrets management is one of the most important parts of container security because one leaked credential can expose much more than one container.

8. Add Runtime Protection

Many teams stop at image scanning, but security does not stop after deployment.

A scanned image can still behave suspiciously at runtime.

For example:

A container may start a shell unexpectedly. A process may try to access sensitive files. A workload may make unusual outbound connections. A container may try privilege escalation. A compromised app may attempt to scan the internal network. Someone may exec into a production pod without proper reason.

Runtime protection helps detect and respond to suspicious behavior while the container is running.

Useful runtime controls include:

Monitoring process activity. Detecting unexpected shell execution. Watching access to sensitive files. Monitoring network connections. Detecting privilege escalation attempts. Tracking Kubernetes audit logs. Alerting on unusual workload behavior.

Tools like Falco, Sysdig, Aqua Security, Prisma Cloud, Datadog, and cloud-native threat detection tools can help.

Runtime security is important because not every risk can be found during build time.

Some issues only appear when the container is actually running.

9. Logging and Monitoring for Containers

Good container security also needs visibility.

If something goes wrong, teams need logs and metrics to investigate quickly.

Important things to monitor include:

Container restarts. CrashLoopBackOff events. OOMKilled events. Image pull failures. Unexpected process activity. Network connections. Authentication failures. Kubernetes audit events. Privileged pod creation. Changes to RBAC or service accounts. Security tool alerts.

Monitoring should help answer:

Which container is affected? What image is running? Which namespace is involved? What changed recently? Was there a new deployment? Did the container start behaving differently? Was a suspicious command executed? Was a secret accessed?

Without visibility, container security becomes guesswork.

Good logs, metrics, and alerts reduce investigation time during incidents.

10. Create a Container Security Response Plan

Detection is only useful if the team knows what to do next.

When a container security issue is found, teams should have a clear response process.

For example, if a critical vulnerability is found in a production image:

Identify where the image is running. Check whether the vulnerability is exploitable. Build a patched image. Deploy the fixed image. Remove or block the old image. Track remediation evidence.

If suspicious runtime behavior is detected:

Identify the pod, namespace, image, and node. Collect logs and events. Check recent deployments. Review network activity. Isolate the workload if needed. Rotate secrets if exposure is suspected. Open an incident ticket. Perform root cause analysis.

A clear response plan helps teams act quickly and calmly.

Container Security Across the DevSecOps Lifecycle

Container security works best when it is applied across the full lifecycle.

During development:

Use secure Dockerfiles. Avoid secrets in code. Use approved base images. Run local scans where possible.

During CI/CD:

Run image scans. Run secret scans. Scan dependencies. Sign images. Push only approved images.

During deployment:

Use admission controls. Enforce Kubernetes security settings. Restrict registries. Use least privilege. Apply network policies.

During runtime:

Monitor container behavior. Detect suspicious activity. Track logs and audit events. Respond to alerts. Patch and redeploy quickly.

This layered approach is much stronger than relying on one tool or one scan.

Real Example

Imagine a team builds a new container image for a payment service.

The image passes unit tests and is ready for deployment.

Without strong container security, the image may go directly to production even if it contains a critical vulnerability, runs as root, uses the latest tag, and has access to unnecessary secrets.

With a DevSecOps approach, the pipeline works differently.

The Dockerfile is checked. The image is built from an approved base image. Secret scanning runs. The image is scanned for vulnerabilities. Critical findings block production deployment. The image is pushed to a private registry. Deployment uses an immutable image digest. Kubernetes policy blocks privileged settings. The container runs as non-root. Runtime monitoring watches for suspicious behavior.

This does not slow the team down unnecessarily.

It gives the team confidence that the container is safer before and after deployment.

Final Thoughts

Container security is not just image scanning.

Image scanning is important, but it only answers one question:

“What known vulnerabilities exist in this image right now?”

Real container security asks more questions:

Was the image built securely? Is the base image trusted? Are secrets protected? Is the registry secure? Is the deployment configuration safe? Are Kubernetes permissions limited? Can risky workloads be blocked before deployment? Is runtime behavior monitored? Can the team respond quickly if something suspicious happens?

In DevSecOps, container security should follow the full path from image build to production runtime.

A secure container strategy is built with layers: secure Dockerfiles, trusted base images, scanning, registry controls, Kubernetes hardening, policy-as-code, runtime monitoring, and incident response.

Because in production, it is not enough to know that an image was scanned.

We also need to know that the container is running safely.


메타데이터
post_id
c9ae36cbcc25
slug
container-security-in-devsecops-from-image-scan-to-runtime-protection-c9ae36cbcc25
url
https://medium.com/@pujamaheshvari5/container-security-in-devsecops-from-image-scan-to-runtime-protection-c9ae36cbcc25
canonical_url
https://medium.com/@pujamaheshvari5/container-security-in-devsecops-from-image-scan-to-runtime-protection-c9ae36cbcc25
author_url
https://medium.com/@pujamaheshvari5
status
ok
fetched_at
2026-06-10 10:12:36