DevSecOps & Security Basics 2026 - Shift-Left Security and Kubernetes Protection
DevSecOps fundamentals: building security into the pipeline, the shift-left approach, common scanning tools, and the basics of securing Kubernetes (RBAC, secrets, network policies, image scanning).
In modern DevOps, security is not a final gate - it is built in from the first commit. That practice is DevSecOps.
What is DevSecOps?
DevSecOps integrates security into the DevOps pipeline from the start, so vulnerabilities are caught during development and CI/CD rather than after release.
Why shift-left?
"Shift-left" means moving security earlier in the lifecycle. Fixing a vulnerability in code review costs a fraction of fixing it in production - earlier is cheaper, faster and safer.
There is a second reason that matters more day to day: a finding raised while the developer still has the code in their head gets fixed in minutes. The same finding raised six weeks later by a quarterly scan becomes a ticket, then a backlog item, then an exception.
The four kinds of scanning, and what each catches
These get used interchangeably in job descriptions and they are not the same thing. Knowing which is which is a common interview separator.
| Type | What it looks at | Catches | Tools |
|---|---|---|---|
| SAST | Your source code, without running it | Injection flaws, unsafe patterns | SonarQube, Semgrep |
| SCA | Your dependencies | Known CVEs in libraries you pulled in | Snyk, Dependabot |
| Container scan | The built image, layer by layer | Vulnerable OS packages in the base image | Trivy, Grype |
| DAST | The running application | Issues only visible at runtime | OWASP ZAP |
Most vulnerabilities in a typical service are not in code the team wrote - they are in the dependency tree and the base image. That is why SCA and container scanning usually deliver more than SAST in the first year of a security programme.
Common DevSecOps tools
- Trivy: scans container images for known vulnerabilities.
- SonarQube: static code analysis for bugs and security issues.
- Snyk: finds and fixes vulnerabilities in dependencies.
These run automatically in CI/CD so insecure code never reaches production unchecked.
Wiring a scan into a pipeline
An image scan as a GitHub Actions step, failing the build on high-severity findings:
- name: Scan image
uses: aquasecurity/trivy-action@<release-commit-sha> # pin a release, never a branch
with:
image-ref: myapp:1.2.0
format: table
exit-code: '1'
severity: HIGH,CRITICAL
ignore-unfixed: true
Two of those options are the difference between a gate people respect and one they route around. exit-code: 1 makes the scan actually fail the build rather than print a wall of text nobody reads. ignore-unfixed: true suppresses findings with no available patch - without it the first run reports hundreds of unfixable issues, the team concludes the tool is noise, and the gate gets disabled within a fortnight.
Start by failing only on CRITICAL, get the count to zero, then tighten to HIGH. A gate that is on and narrow beats a gate that is broad and switched off.
The supply chain: what you pull in is part of your code
The scan above checks your image. It does not check the tools that build it. In March 2025 a widely used GitHub Action, tj-actions/changed-files, was compromised and its version tags were repointed at code that dumped CI secrets into build logs (CVE-2025-30066). Thousands of repositories referenced it by tag, so they ran the malicious version without changing a line of their own.
Three habits close most of that gap:
- Pin third-party actions to a full commit SHA, not a tag or a branch. A tag can be moved; a SHA cannot. Dependabot can still propose updates, and you review them like any other change. That is why the Trivy step above says
@<release-commit-sha>rather than@master. - Give the workflow token only what it needs. Set
permissions:explicitly at the top of each workflow, read-only by default, and grant write access only to the job that needs it. - Know what is in your image. Generate an SBOM, a list of every package in the image, at build time with Syft or Trivy, and sign the image with Cosign, so the cluster can refuse anything that did not come out of your pipeline.
What to fix first when the first scan finds hundreds of issues
It will. The first container scan of an older service routinely reports a few hundred CVEs, and teams that try to work through them in list order give up. An order that works:
- Leaked secrets, whatever the scanner calls them. Rotate first, investigate second.
- Change the base image. Moving from a full OS image to a slim or distroless one, or simply to a current tag, often clears most findings in one commit, because most of them sit in packages the app never uses.
- Critical findings that have a fix and sit in internet-facing services. That is usually a short list.
- Everything else goes into a tracked backlog with an owner, and the pipeline gate stays narrow (CRITICAL only) until that backlog is under control.
Write down why you accepted a finding, for example "not reachable, no fix available, review in 30 days". That record matters as much as the fixes, because auditors and future teammates will both ask.
Secrets are the failure that actually happens
Most real incidents at small companies are not exotic exploits. They are a cloud key committed to a repository. Three habits prevent nearly all of it:
- Scan for secrets before the commit lands - gitleaks or the platform's own push protection.
- Assume any leaked key is burned. Deleting the commit does not help; the value is in the history and probably in someone's clone. Rotate it.
- Prefer short-lived credentials. A CI job that assumes a role gets credentials that expire. A stored access key does not.
Kubernetes security basics
Containers and Kubernetes need their own protections:
- RBAC: role-based access control - grant least privilege to users and services.
- Secrets management: never bake passwords or keys into images; use Kubernetes Secrets or a vault.
- Network policies: restrict which pods can talk to which - default-deny, then allow only what is needed.
- Image scanning: only deploy trusted, scanned images from a known registry.
- Pod security: avoid running containers as root and limit their capabilities.
The pod-level settings that do the most work, and cost nothing to add:
securityContext:
runAsNonRoot: true
runAsUser: 1000
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
One caveat worth knowing before you apply it: readOnlyRootFilesystem breaks applications that write temporary files, which is more of them than you would expect. The fix is a writable emptyDir volume mounted at the path it needs, not turning the setting off.
A note on Kubernetes Secrets specifically: by default they are base64-encoded, not encrypted. Anyone with read access to the namespace can decode them. Enable encryption at rest, or use an external secrets store, and do not assume the name means more than it does.
Indian rules that shape DevSecOps work
If you run infrastructure for a company in India, two sets of rules decide part of what your logging, access control and incident process have to do. It is usually a DevOps engineer who ends up implementing them.
| Rule | What it asks for | What it means for the platform team |
|---|---|---|
| CERT-In directions (April 2022) | Report listed cyber incidents to CERT-In within 6 hours of noticing them. Keep logs of all ICT systems for a rolling 180 days, within Indian jurisdiction. Sync system clocks to NIC or NPL time servers, or to servers traceable to them. | Set retention on every log store to at least 180 days; 30 days, a common choice to save storage, falls short. Bake the NTP source into your base images so timestamps from different systems line up during an investigation. |
| DPDP Rules, 2025 | Notified in November 2025, with most obligations applying 18 months later, from May 2027 (PIB). Rule 6 lists safeguards such as encryption or masking, access control, and logs and monitoring that can detect unauthorised access, with those logs and the personal data kept for a year. A detailed breach report goes to the Data Protection Board within 72 hours (summary of the Rules). | Keep real customer data out of test and staging, or mask it first. Give production database access to named, logged accounts instead of a shared password. Build the alert that would spot a bulk export before the deadline, not after the first incident. |
Two habits follow. Write the six-hour CERT-In clock into the on-call runbook, naming who reports and how, because the DevOps team is often the first to see an incident. And where retention periods differ, apply the longer one rather than tracking which log falls under which rule. The Act's highest penalty, up to ₹250 crore, is for failing to keep reasonable security safeguards. This is an engineer's summary, not legal advice: your security or legal team decides how the rules apply to your company.
The mindset
Security is everyone's job in DevOps. Automating scans and applying least privilege everywhere is what keeps fast-moving systems safe.
The practical version: make the secure path the easy path. A template repository with scanning already wired in and a base image that is already hardened will do more for an organisation's security than any amount of policy documentation.
Ready to Start Your DevOps Career?
Join our comprehensive DevOps + GenAI course with hands-on projects, live mentorship, and placement support