Designing a Fortress: Architecting a Private React Application Infrastructure with Terraform

A private React application can mean two different things: its source files are hidden from the public internet, or its API and user data are accessible only to authenticated, authorized people. Those are separate controls. A React bundle delivered to a browser is visible to that browser, even if the origin bucket is private. The architecture must protect assets, requests, identities, and data independently.

Start with the trust boundary, not with Terraform resources

Imagine an internal operations dashboard with employee records. Its browser interface is compiled into HTML, JavaScript, and CSS, and its API returns permission-scoped business data. The requirements are: only staff can use the interface, each employee sees only authorized records, infrastructure changes are reproducible, access can be revoked, and operational changes are auditable.

Writing “private = true” in a configuration does not meet these requirements. The reviewer needs to know whether “private” refers to the storage bucket, the delivery endpoint, a network path, or the business authorization checks. Draw four boundaries first: browser delivery, user identity, API entry, and persistence.

Secure the React artifact and its delivery path

Store compiled assets in an S3 bucket with Block Public Access enabled. Keep the bucket private and allow your CloudFront distribution to retrieve objects through origin access control (OAC). AWS recommends OAC over older origin access identity (OAI) for regular S3 origins. The S3 bucket policy should scope access to the intended CloudFront distribution, not to every distribution in the account.

OAC solves origin bypass. It does not automatically restrict who can request the CloudFront URL. If the user-facing app must be restricted, apply a separate viewer-access mechanism. For content that should be available only to authenticated users, CloudFront signed cookies or signed URLs are supported options, issued only after an identity and entitlement check. Other patterns use an identity-aware proxy or an authentication-aware edge/application layer. The choice must match the access model and browser behavior.

For an app with many static resources, signed cookies can avoid generating a signed URL for every script, image, and stylesheet. But do not assume a signed cookie protects an API hosted elsewhere; API authorization remains independent. See AWS’s guides to restricting access to an S3 origin and choosing signed URLs or cookies.

Decide whether the API is public with authorization or network-private

For employees working from browsers on ordinary home networks, an API Gateway private REST API is not a direct public-browser endpoint. AWS documents private REST APIs as callable from within a VPC using an interface endpoint, with appropriate hybrid connectivity where applicable. If a browser must call the API from the public internet, use an intentionally internet-reachable entry point with strong authentication, authorization, throttling, logging, and network controls. Do not describe that configuration as network-private.

A different requirement—an entirely private API reachable only over VPN, Direct Connect, or a controlled corporate route—can justify a private API Gateway endpoint and VPC endpoints. That requirement also constrains where the browser runs. Confirm the connectivity path with a network diagram and an actual test from both authorized and unauthorized networks. AWS describes these constraints in its private REST API documentation.

Authenticate the user and authorize each object

Authentication proves an identity; authorization answers what that identity may do. The API should validate tokens or session credentials, establish a stable principal, and check authorization at each data access. A valid token from one user does not authorize access to another employee’s record. Avoid trusting a record owner ID, tenant ID, or role string sent by the React client without server-side verification.

For a concrete test, create two synthetic departments with separate records and staff accounts. A request by Department A for Department B’s record should fail even when it uses a valid A token. Repeat the test against list endpoints, direct object endpoints, exports, and file downloads; horizontal authorization failures often hide in “download all” or search features.

Separate Terraform state and secrets from the browser build

Use Terraform to declare infrastructure resources, policies, and dependencies. Store state remotely under restricted access with versioning or other recoverability mechanisms appropriate to the backend, restrict administrative roles, and lock state updates to prevent concurrent changes. A Terraform plan can reveal sensitive resource details; treat it as an operational artifact, not a public website asset.

The React build must never embed AWS access keys, backend secrets, signing private keys, or privileged service tokens. Any variable exposed to the client bundle should be assumed readable. Server-side workloads can obtain short-lived credentials through their execution roles and managed secret stores. This separation is more important than choosing a particular React state-management library.

Example access matrix and deployment checks

Control Authorized scenario Failure scenario to test
S3 origin CloudFront distribution fetches built assets Anonymous direct S3 object URL is denied
Viewer access Entitled employee receives app assets Unauthenticated or expired signed access is denied
API identity Valid staff identity calls the correct operation Absent, invalid, or expired token is rejected
Object authorization User accesses permitted synthetic records Same user cannot retrieve another department’s record
Deployment change Reviewed plan applies and app health passes Unexpected public policy change fails the approval check

Include the full chain in a test: login; retrieve a scoped record; refresh the page; expire the session; attempt an object from another department; confirm the API does not leak sensitive details in error responses. Review cache behavior and prevent personal API responses from being inadvertently shared between users at CDN or reverse-proxy layers.

Observability and failure recovery

Capture deployment identifiers, IAM changes, authorization failures, API error rates, latency, and relevant access logs without logging full sensitive payloads or tokens. Establish an owner and alert threshold for unexpected changes to bucket policy, CloudFront distribution, or API permission. Monitor both the runtime and the infrastructure configuration drift.

Rollback means more than reverting a JavaScript file. Record the previous content artifact, Terraform state revision, IAM and edge configuration, and database migration compatibility. Test restoring the previous application artifact against the current API contract before relying on it as a production safety net.

Choose a topology that matches the real audience

  • Publicly reachable app with restricted staff login: CDN and API may be internet-facing, but both require a clear access-control design; the storage origin can still remain private.
  • Corporate network-only application: employees use a VPN or equivalent private route and both delivery and API paths are restricted accordingly.
  • Highly sensitive application: use stronger device/session controls, explicit per-object authorization, additional auditing, and carefully bounded exports; “private S3” alone is insufficient.

The successful private React architecture is the one whose trust boundaries can be drawn, tested, and independently challenged. Terraform makes the design reproducible; it cannot substitute for identity, authorization, viewer access control, or an incident-ready operating model.

img