ArchitectMind
  1. Home
  2. Java Ecosystem
  3. Book 8 · Architecture Quality Attributes
  4. Volume V
  5. Security Architecture
Book 8 · Volume V — Security, Privacy & Compliance · Topic 1.2

Security Architecture

Trust boundaries · attack surfaces

10 min readStage 3 · Systems10 interview questions
Chapter
Chapter 1 — Security as a Quality Attribute
Prerequisites
Topic 1.1
You will be able to
Identify trust boundaries in an architecture, assign security zones, define the controls every boundary crossing requires, inventory and measure attack surface, reduce it systematically, and document security architecture views that reviewers and auditors can follow
Covers
Trust boundaries · Attack surfaces
On this page
  1. 1. Concept / Definition
  2. 2. Why It Exists
  3. 3. Core Concepts
  4. 4. How It Works Internally — Reducing Attack Surface
  5. 4A. Deep Dive — Security Architecture Views
  6. 5. APIs / Features / Syntax
  7. 6. Practical Examples
  8. 7. Common Problems & Mistakes
  9. 8. Performance & Production Considerations
  10. 9. Architecture & Design Considerations
  11. 10. Interview Questions & Answers

1Concept / Definition

Security architecture describes how a system's structure enforces its security requirements: where trust changes (trust boundaries), what an attacker can reach or influence (attack surface), and which controls sit at each point.

TermDefinition
Trust boundaryA point where data or control passes between components with different trust levels
Security zoneA group of components with the same trust level and controls
Attack surfaceThe sum of entry points (network, API, human, supply chain, data) an attacker can use
ControlA mechanism that enforces a security requirement at a point
Table 1 — Vocabulary
Trust boundaries — ShopNow
Figure 1 — Trust boundaries — ShopNow

2Why It Exists

Attackers don't attack "the system"; they attack an entry point and move across boundaries. Making boundaries and surfaces explicit tells you where controls go and what to shrink.

Perimeter vs boundaries everywhere
Figure 2 — Perimeter vs boundaries everywhere

3Core Concepts

3.1 Trust Boundaries

Boundary (ShopNow)From → toWhy trust changes
TB1Internet → edgeAnonymous, hostile traffic
TB2Edge → API gatewayUntrusted payloads, user tokens
TB3Gateway → servicesInternal but must be authenticated (zero trust)
TB4Services → data storesHighest-value assets
TB5Services → partners (PayGrid, SMS)External organisations
TB6Staff/admin → productionPrivileged humans
TB7CI/CD → productionCode and images entering
Table 2 — Boundaries at ShopNow
Security zones
Figure 3 — Security zones
Controls at each boundary
Figure 4 — Controls at each boundary
Crossing checklistQuestion
AuthenticateWho is the caller (user, service, partner)?
AuthoriseMay this caller do this action on this resource?
ValidateIs input well-formed, bounded, expected (schema, size, type)?
EncryptIs the channel protected (TLS/mTLS)?
LogIs the crossing recorded for detection and audit?
LimitCan the caller overwhelm the next zone (rate, size)?
Table 3 — Six checks at every boundary

3.2 Attack Surfaces

Attack surface
Figure 5 — Attack surface
SurfaceShopNow inventoryReduction levers
NetworkCloudFront, 2 ALBs, bastions (removed)Private subnets, PrivateLink, no public IPs
API480 endpoints (2024)Deprecate, gateway-only exposure, internal-only routes
HumanStaff, sellers, contractorsSSO + MFA, JIT access, phishing-resistant keys
Supply chain1,900 libraries, 60 base imagesSBOM, pinning, minimal images
DataExports, backups, logs, stagingRedaction, expiry, masked non-prod
Admin/control planeAWS console, k8s API, CI/CDSSO, least privilege, private endpoints
Table 4 — Surface inventory

4How It Works Internally — Reducing Attack Surface

Attack surface reduction (2024 → 2026)
Figure 6 — Attack surface reduction (2024 → 2026)
TacticExample
RemoveDelete unused endpoints, feature flags, old API versions
HideInternal APIs not routable from the internet; private EKS API endpoint
MinimiseDistroless images; disable unused HTTP methods
ConsolidateAll public traffic via CloudFront → ALB (no direct ALB access)
RestrictSecurity groups referencing SGs, not CIDR 0.0.0.0/0
MeasureMonthly inventory diff; alert on new public resources
Table 5 — Surface-reduction tactics

4ADeep Dive — Security Architecture Views

ViewShowsAudience
Context + boundariesExternal actors, TBsEveryone
Data-flow with classificationWhere Sensitive data flowsPrivacy, auditors
Network/zonesVPCs, subnets, SGs, endpointsPlatform, auditors
Identity viewWho authenticates where, token flowsEngineers
Control mappingRequirement → control → evidenceCompliance
Table 6 — Views to document (Book 8 Vol I views)

5APIs / Features / Syntax

YAML
# Istio: only the gateway and checkout may call pricing (TB3 enforced per identity)
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata: { name: pricing-allow, namespace: pricing }
spec:
  selector: { matchLabels: { app: pricing } }
  action: ALLOW
  rules:
    - from:
        - source:
            principals:
              - cluster.local/ns/checkout/sa/checkout
              - cluster.local/ns/gateway/sa/gateway
      to:
        - operation: { methods: ["POST"], paths: ["/v1/quotes"] }
HCL
# TB4: database reachable only from app security group, no public access
resource "aws_security_group_rule" "orders_db_from_app" {
  type                     = "ingress"
  from_port                = 5432
  to_port                  = 5432
  protocol                 = "tcp"
  security_group_id        = aws_security_group.orders_db.id
  source_security_group_id = aws_security_group.checkout_pods.id
}
JAVA
// TB2: strict input validation at the edge of the service (records + Bean Validation)
public record AddToCartRequest(
        @NotBlank @Pattern(regexp = "^[A-Z0-9-]{6,32}$") String sku,
        @Min(1) @Max(10) int quantity) {}
 
@PostMapping("/cart/items")
ResponseEntity<Void> add(@Valid @RequestBody AddToCartRequest req, Principal user) { … }

6Practical Examples

6.1 The forgotten boundary

A seller-portal "bulk upload" endpoint accepted CSV files and passed them to an internal import service. The internal service assumed its callers were trusted and didn't validate file size or formulas; a crafted CSV caused formula injection in exported reports. The upload was treated as a new boundary: size limits, schema validation, formula escaping and malware scanning.

6.2 Public ALB bypassing WAF

A scan found an ALB reachable directly from the internet, bypassing CloudFront and WAF. Fix: ALB only accepts CloudFront (managed prefix list + secret header), and a config rule alerts on new internet-facing load balancers.

6.3 Attack surface diet

ChangeResult
Retired v1 mobile APIs−210 endpoints
Moved internal admin APIs off public gateway−120 endpoints
Bastions replaced by SSM Session Manager0 SSH ports open
Distroless base imagesCVEs per image −78%
Table 7 — Measured reduction

6.4 Worked example — boundary crossing analysis (checkout → PayGrid)

CheckControl
AuthenticateOAuth2 client credentials (private_key_jwt) + mTLS
AuthorisePayGrid scopes: payments:write for ShopNow client
ValidatePayGrid schema validation; ShopNow validates responses
EncryptTLS 1.3, pinned CA
LogRequest ids, no card data
LimitClient-side limiter to contracted TPS
Table 8 — Six checks applied

6.5 Worked example — zone assignment

ComponentZone
CloudFront, WAFPublic
API gateway, BFFsDMZ
Checkout, pricing, orders servicesApplication
Aurora, Valkey, MSKData
KMS admin, break-glass roles, CI signing keysRestricted
Table 9 — Every component has a zone

6.6 Worked example — attack surface inventory metrics

Metric20242026
Internet-facing endpoints48096
Resources with public IPs370
Humans with prod write access649 (JIT for others)
Third-party scripts on checkout page143 (SRI + CSP)
Table 10 — Surface as a tracked metric

6.7 Worked example — interview whiteboard

PromptAnswer outline
"How do you approach the security architecture of a new system?""Draw the context and data flows, mark trust boundaries — internet, gateway, service-to-service, data, partners, admin, CI/CD — and group components into zones. At each crossing apply six checks: authenticate, authorise, validate, encrypt, log and limit. Inventory the attack surface across network, APIs, humans, supply chain and data, reduce it by removing, hiding and minimising, and track it as a metric with alerts for new public resources."
Table 11 — Structured answer

6.8 Worked example — admin boundary (TB6)

ControlImplementation
IdentityWorkforce SSO with FIDO2 keys
AccessRead-only by default; JIT elevation (1 h) with ticket
ChannelSSM Session Manager (no SSH), private EKS endpoint via VPN
AuditCloudTrail, session recordings
Break-glassSealed accounts, alarm on use
Table 12 — Privileged humans are a boundary too

6.9 Worked example — CI/CD boundary (TB7)

ThreatControl
Compromised dependencySCA, pinned versions, SBOM
Malicious pipeline changeProtected branches, reviewed workflow changes
Stolen deploy credentialsOIDC federation to AWS (no static keys)
Unsigned imagesAdmission controller verifies Cosign signature
Table 13 — The pipeline is an attack surface

6.10 Worked example — browser boundary

ControlSetting
Content-Security-Policyscript-src 'self' + 3 hashed vendors
Subresource IntegrityOn third-party scripts
CookiesHttpOnly, Secure, SameSite=Lax
Clickjackingframe-ancestors 'none'
Table 14 — The user's browser runs your code on a hostile boundary

6.11 Worked example — partner boundary (TB5) at PayGrid

Inbound partner callControl
IdentityOAuth2 client credentials with private_key_jwt; optional mTLS for top partners
Tenant scopingpartner_id from token, never from request body
ValidationOpenAPI schema validation at gateway; size ≤ 64 KB
RatePer-partner token bucket
Outbound webhooksSigned (HMAC), egress proxy blocks private IP ranges (SSRF)
Table 15 — Boundaries with other organisations need the strictest checks

6.12 Worked example — data boundary (TB4) review

FindingFix
Reporting tool connects to writer with superuserRead-only role on replica
Lambda has rds:* on all clustersScoped to one cluster, IAM auth
S3 exports bucket readable by analytics accountBucket policy with VPC endpoint condition
Table 16 — Data boundaries leak through over-broad permissions

7Common Problems & Mistakes

MistakeFix
Trusting internal callersAuthenticate every hop
Unknown public resourcesInventory + config rules
Validation only in UIValidate at every boundary
Forgetting human/CI boundariesTreat as TBs
Flat networksZones and SG references
Surface grows silentlyMetrics and alerts
Table 17 — Mistakes and fixes

8Performance & Production Considerations

ConsiderationPractice
mTLS overhead~3% per hop; acceptable
Validation costCheap; reject early
Continuous checksAWS Config, Security Hub, external scans
Change reviewsNew boundaries flagged in design review
Table 18 — Operating security architecture

Security controls at boundaries cost little at run time compared with the risk they remove. Istio mTLS adds a few per cent of CPU and well under a millisecond per hop with current sidecars or ambient mode, and schema validation is cheap, especially when it rejects bad input before any business logic runs. The bigger production concern is drift: new public resources, widened security groups and forgotten test endpoints appear with ordinary releases. Run AWS Config rules and Security Hub standards continuously, alert on any new internet-facing load balancer or public IP, and schedule external attack-surface scans. Treat certificate and secret rotation as automated operations rather than manual tasks, because expired certificates on internal mTLS are a common cause of self-inflicted outages. Finally, flag every design change that introduces a new boundary so that it gets a security review.

9Architecture & Design Considerations

GuidelineDetail
Minimise boundaries crossed by Sensitive dataKeep it in few services
Single, controlled entry pointsCloudFront → gateway
Explicit zones in IaCTags, SGs, namespaces
Views in architecture docsBoundaries, zones, identity
Table 19 — Design guidance

10Interview Questions & Answers

Q1L1 · BasicConcept

What is a trust boundary?

A trust boundary is a point where data or control passes between components with different levels of trust, so the receiving side cannot assume the input or the caller is legitimate. Typical boundaries are internet to edge, edge to API gateway, gateway to services, services to data stores, calls to and from partners, privileged humans entering production, and the CI/CD pipeline deploying code. They are where most vulnerabilities live: an unvalidated input, an unauthenticated call or data leaving unencrypted. Drawing them on the context and data-flow diagrams is the first step of security architecture, because every crossing then gets the same explicit set of controls.

Q2L1 · BasicConcept

What is an attack surface?

The attack surface is the sum of all entry points an attacker can reach or influence, not just open ports. It includes the network surface, such as public load balancers and IPs; the API surface, every exposed endpoint and version; the human surface, staff, sellers and contractors with access; the supply chain of libraries, base images and pipelines; data copies, such as exports, backups, logs and staging databases; and the control plane, meaning the cloud console, Kubernetes API and CI/CD. The larger it is, the more places need controls. ShopNow tracks it as a metric and cut internet-facing endpoints from 480 to 96 between 2024 and 2026.

Q3L2 · IntermediateConcept

What controls belong at a boundary?

Six checks belong at every crossing. Authenticate: establish who the caller is, whether user, service or partner, through tokens or mTLS identity. Authorise: decide whether this caller may perform this action on this resource. Validate: ensure the input is well formed, bounded in size and matches the expected type and schema. Encrypt: protect the channel with TLS 1.3 or mTLS. Log: record the crossing for detection and audit, without sensitive data such as card numbers. Limit: rate-limit and cap sizes so a caller cannot overwhelm the next zone. Applying the same checklist everywhere makes reviews consistent and makes a missing control obvious.

Q4L2 · IntermediateTricky

Why authenticate internal calls?

Because the network perimeter is not a guarantee of trust. If internal services accept any call from inside the VPC, one compromised pod, leaked credential or SSRF bug gives the attacker free lateral movement to everything, including the data stores. Zero trust treats gateway-to-service and service-to-service hops as real boundaries: each call carries a workload identity through Istio mTLS and is authorised per caller and operation with an AuthorizationPolicy, so at ShopNow only the gateway and checkout may call the pricing quote endpoint. It also limits the blast radius of internal mistakes, such as a misconfigured batch job, and produces an audit trail of who called what.

Q5L3 · Senior EngineerDesign

How do you reduce attack surface?

Work through a cycle of remove, hide, minimise, consolidate, restrict and measure. Remove unused endpoints, old API versions, stale feature flags and idle resources. Hide internal APIs so they are not routable from the internet, and use private endpoints for the EKS API and AWS services. Minimise what runs, with distroless base images, disabled HTTP methods and fewer libraries. Consolidate public traffic through one path, CloudFront then ALB. Restrict network paths with security groups that reference other security groups rather than 0.0.0.0/0. Then measure, with a monthly inventory diff and alerts on new public resources. ShopNow removed 330 endpoints and every open SSH port this way.

Q6L3 · Senior EngineerScenario

How do you prevent WAF bypass?

Make the origin reachable only through CloudFront, so there is no direct path around the WAF. Restrict the ALB's security group to the AWS-managed CloudFront origin-facing prefix list, and have CloudFront add a secret custom header that an ALB listener rule checks, rejecting requests without it; rotate that secret regularly. Better still, use CloudFront VPC origins, so the ALB sits in private subnets with no public exposure at all. Then detect regressions with an AWS Config rule or Security Hub control that alerts on any new internet-facing load balancer, plus regular external scans. ShopNow found its bypassing ALB through exactly such a scan.

Q7L4 · Technical ArchitectTricky

Which non-network surfaces matter?

The ones teams forget because no port scan shows them. Humans: staff, sellers and contractors with production access, protected by SSO, phishing-resistant MFA and just-in-time elevation. The supply chain: hundreds of open-source libraries and base images, controlled with SBOMs, pinned versions, scanning and signatures. CI/CD: a pipeline that can deploy to production is effectively an administrator, so it needs protected branches, reviewed workflow changes and OIDC federation instead of static keys. Data copies: exports, backups, logs and staging databases often hold production data under weaker controls. The browser is another surface, where third-party scripts run on your own checkout page.

Q8L4 · Technical ArchitectConcept

What's a security zone?

A security zone is a group of components that share the same trust level and the same set of controls, so boundaries lie between zones rather than between every pair of components. ShopNow uses five: public for CloudFront and WAF; a DMZ for the API gateway and BFFs; application for checkout, pricing and orders; data for Aurora, Valkey and MSK; and restricted for KMS administration, break-glass roles and CI signing keys. Each component is assigned exactly one zone, and the zone defines who may talk to it and how. Zones are expressed in infrastructure as code through subnets, security groups, Kubernetes namespaces and tags.

Q9L5 · Solution ArchitectDesign

How do you keep surface under control over time?

Treat attack surface as a tracked metric with automated detection, not a one-off review. Keep an inventory of internet-facing endpoints, public IPs, privileged humans and third-party scripts, compare it every month, and set a target for each figure. Enforce guardrails continuously with AWS Config rules, Security Hub and external scans that alert on new public resources or overly wide security group rules. Add a design-review question for any change that creates a new boundary, such as a file upload or a partner integration. Retire old API versions on a published schedule. Assign an owner, because without one the surface quietly grows with every release.

Q10L5 · Solution ArchitectDesign

What views document security architecture?

Five views, each serving a different audience. A context view with trust boundaries shows external actors and where trust changes, for everyone. A data-flow view with classification shows where sensitive data travels and is stored, for privacy teams and auditors. A network and zone view shows VPCs, subnets, security groups and endpoints, for the platform team and auditors. An identity view shows who authenticates where and how tokens flow, for engineers. A control-mapping view links each requirement to a control and its evidence, for compliance frameworks such as PCI-DSS v4. Keep them in the architecture documentation and update them whenever a boundary changes.

Test your knowledge on this topic →Flashcards from this topic's 10 questions, filtered by level and type.

Free question pack

Get 100 free Core Java interview questions

Subscribe for the Book 1 question pack (PDF, every answer explained) and new tutorials once a week. No spam, unsubscribe anytime. What is in the pack?

Almost done! Check your inbox and click the confirmation link. Your download link arrives as soon as you confirm.