Production Security
Production security for TechLearningPRO Orders is layered defence, not a single Spring Security filter.
Introduction
Production security for TechLearningPRO Orders is layered defence, not a single Spring Security filter. On Boot 3 / Java 21 you still need HTTPS/HSTS, dependency and image scanning, secrets outside git, least-privilege IAM, rate limits at the gateway, and audit trails for money and admin actions.
Most breaches exploit basics: outdated libraries, leaked credentials, over-exposed Actuator, or containers running as root. The high-impact checklist is boring — and that is the point.
Security defaults should be the easy path: deny-by-default HTTP security, validated inputs, and CI gates that block known CVEs. Clever crypto does not compensate for a public /actuator/env.
This lesson turns Orders into a service you can put on the public internet without relying on obscurity.
Purpose of this lesson
Apply a production security checklist to Orders: TLS, scanning, secrets, container hardening, gateway controls, and audit.
Understanding the topic
Cheap, high-impact layers every Boot 3 app should ship.
- Transport: HTTPS everywhere; HSTS at the edge.
- Supply chain: Dependabot/Snyk on PRs; Trivy on images in CI.
- Secrets: vault / K8s Secrets; rotate on a schedule.
- Runtime: non-root container; read-only root FS where possible.
- Edge: WAF + rate limits; lock down Actuator.
- Identity: least-privilege DB and cloud roles per service.
- Audit: log login, admin, and payment-adjacent actions with trace ids.
Step-by-step explanation
- Terminate TLS at the gateway/ingress; enable HSTS.
- Turn on dependency and image scanning in CI; fail the build on high CVEs.
- Move all credentials to a secret store injected as env; delete committed secrets.
- Run the Orders image as non-root; restrict Actuator; add gateway rate limits and audit events for place-order and refunds.
Informative example
Security defaults sketch for Orders (Boot 3 + container).
// SecurityFilterChain — deny by default, CSRF off for pure token API@Configuration@EnableWebSecuritypublic class SecurityConfig {@BeanSecurityFilterChain api(HttpSecurity http) throws Exception {http.csrf(csrf -> csrf.disable()).sessionManagement(s -> s.sessionCreationPolicy(STATELESS)).authorizeHttpRequests(auth -> auth.requestMatchers("/actuator/health", "/actuator/info").permitAll().requestMatchers("/actuator/**").hasRole("OPS").requestMatchers("/api/orders/**").authenticated().anyRequest().denyAll());return http.build();}}# Dockerfile excerpt — non-rootFROM eclipse-temurin:21-jreRUN useradd -r -u 10001 ordersUSER 10001COPY target/orders.jar /app/orders.jarENTRYPOINT ["java","-jar","/app/orders.jar"]
Real-world use
An Orders Actuator path was briefly exposed without auth during a misconfigured ingress. Attackers enumerated env property names before the hole closed. TechLearningPRO now requires network policies plus role-gated Actuator and treats public management endpoints as a sev-1.
Security implications
This lesson is the security posture — enforce it in code and pipeline.
- Never commit real passwords, API tokens, or private keys in samples.
- Rotate credentials after any suspected leak; assume screenshots are public.
- Keep jakarta validation and authz on every write path — including internal admin APIs.
Best practices
- Make secure defaults the path of least resistance in starters and templates.
- Separate IAM roles per service; never share a cluster-admin-like DB user.
- Pair rate limits with auth — anonymous routes get stricter quotas.
Common mistakes
- Shipping with default or example credentials still in config.
- Running containers as root 'just for local parity' in prod.
- Ignoring transitive CVEs because 'it still compiles'.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhat is defence in depth for a Spring Boot API?+
Answer
2IntermediateQuestionWhy run containers as non-root?+
Answer
3IntermediateQuestionWhy audit money and admin actions?+
Answer
Hands-on exercise
Lab. Harden Orders: non-root image, Actuator locked except health, CI Trivy/Snyk gate, and an audit log line on place that includes principal and order id — never card PANs or raw tokens.
Summary
Production security makes Orders safe to expose. Next: engineer performance with SLOs so hardening does not become guesswork.