I Built a Web Application on AWS With Zero Inbound Ports โ€” Then Tried to Break Its Security
DEV Community

I Built a Web Application on AWS With Zero Inbound Ports - Then Tried to Break Its Security

The Challenge: Can a Website Be Publicly Accessible Without Exposing Its Server?

Building CloudSecure with AWS, Cloudflare Tunnel, Terraform, Python, and evidence-driven security validation.

By George Koufie | AWS Community Builder - Networking & Content Delivery

Every organization faces a difficult security challenge: applications must be accessible to users, but the infrastructure hosting those applications must be protected from unauthorized access.

A traditional web application architecture often exposes a load balancer or web server through ports 80 and 443. Security groups, firewalls, network segmentation, and web application firewalls help manage that exposure. But what if we could remove inbound access to the application server entirely?

That question became the foundation of my latest project: CloudSecure, a hands-on cloud security lab built using Amazon Web Services (AWS), Cloudflare, Terraform, and Python. I wanted to do more than build infrastructure. I wanted to demonstrate a complete security engineering workflow:

  • Deploy an application with a reduced attack surface.
  • Assess its security configuration across two platforms.
  • Deliberately introduce a controlled security misconfiguration.
  • Detect the problem using automated security checks.
  • Remediate the configuration using Infrastructure as Code.
  • Collect evidence showing whether the remediation actually worked.

On November 26, 2026, I deployed the lab in AWS, performed the assessments and security tests, and then dismantled the environment to avoid unnecessary charges. The results demonstrated why security needs to be tested rather than assumed.

The Business Problem

For organizations operating internet-facing applications, cloud security is not simply about deploying firewalls. Security teams must understand whether:

  • Servers are unnecessarily exposed to inbound connections.
  • Network security rules enforce the intended access restrictions.
  • Encryption configurations meet organizational requirements.
  • Administrative access is properly controlled and auditable.
  • Cloud security misconfigurations can be detected reliably.
  • Security remediation can be validated with evidence.

These concerns become especially important in regulated environments, including organizations that process payment information.

Misconfigurations can also arise gradually. A security group might be modified during troubleshooting, a TLS configuration might accept outdated protocols, or a web application firewall rule might fail to recognize alternate request formats. A control that exists is not necessarily a control that works.

The goal of CloudSecure was to build a small, reproducible environment where these security questions could be answered through actual testing.

Solution Architecture

CloudSecure combines AWS infrastructure security with Cloudflare edge protection.

The AWS environment includes:

  • Amazon VPC with separate application and isolated subnets.
  • Amazon EC2 running a Python demonstration application.
  • Security groups with no inbound access rules.
  • AWS IAM roles for workload permissions.
  • AWS Systems Manager for administrative access.
  • Amazon CloudWatch for session and network logging.
  • Encrypted Amazon EBS storage.
  • Terraform for infrastructure provisioning and changes.

Cloudflare provides:

  • DNS and proxy services.
  • Cloudflare Tunnel for application connectivity.
  • TLS configuration and HTTPS enforcement.
  • Custom web application firewall rules.
  • Security analytics.

A Python assessment tool uses the AWS and Cloudflare APIs to examine selected security configurations and generate JSON evidence.

[Insert architecture diagram from the GitHub README here.]

How Requests Reach the Application

A visitor connects to Cloudflare over HTTPS. Cloudflare evaluates the request against its configured edge security controls and forwards permitted traffic through Cloudflare Tunnel. The tunnel connector, cloudflared, runs on the AWS instance and initiates outbound connectivity to Cloudflare.

The application itself listens only on:

127.0.0.1:8080

This means the application does not bind to the EC2 instance's external network interface. The EC2 security group also has no inbound rules. Consequently, visitors can use the application through the Cloudflare hostname, but cannot directly connect to the application's origin ports.

This design reduces exposure without requiring inbound SSH access or an internet-facing application load balancer.

Engineering Decision: Cloudflare Tunnel Instead of an Internet-Facing Origin

One of the most important design decisions was to use Cloudflare Tunnel. Traditional approaches often require an internet-facing entry point, with inbound traffic allowed on selected ports. CloudSecure takes a different approach: the server establishes the connection outward, while Cloudflare handles incoming user requests.

The Terraform security group contains outbound rules for required services and tunnel connectivity, but no inbound rules.

resource "aws_security_group" "origin" {
  name_prefix = "cloudsecure-origin-"
  description = "No inbound access; outbound TLS and tunnel"
  vpc_id= aws_vpc.lab.id
  egress {
    description = "HTTPS to SSM, package repos and Cloudflare API"
    from_port = 443
    to_port = 443
    protocol= "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

The complete configuration also permits the required Cloudflare Tunnel connections on port 7844.

During testing, the public application responded successfully through Cloudflare using TLS 1.3. However, an attempt to connect directly to the instance's public IP on the application's port received no response. VPC Flow Logs also recorded more than 2,000 rejected connection attempts against the instance.

This demonstrated two things:

First, the application remained reachable through the intended route. Second, the security group prevented inbound connections from reaching the origin directly.

There is an important architectural distinction here: the EC2 instance still used a public IPv4 address for outbound connectivity to avoid NAT Gateway expenses. The server was not deployed in a fully private subnet. For a production deployment, I would favor private subnets, controlled egress, and multiple tunnel connectors to improve defense in depth and availability.

[Insert screenshot: EC2 security group with no inbound rules.]

[Insert screenshot: Cloudflare Tunnel healthy connector.]

Eliminating SSH: AWS Systems Manager for Administration

A second design decision was to avoid traditional SSH access. Instead of opening port 22 or distributing private SSH keys, I configured AWS Systems Manager Session Manager. This allowed administration through authenticated AWS access without enabling inbound SSH connections.

The EC2 instance uses an IAM role with the AWS-managed AmazonSSMManagedInstanceCore policy. CloudSecure also configures CloudWatch logging for administrative sessions.

This approach provides several operational advantages:

  • No inbound SSH port is required.
  • Access is controlled through IAM permissions.
  • Administrative access can be revoked centrally.
  • Session activity can be logged.
  • Engineers can perform maintenance and troubleshooting without managing SSH keys.

For organizations managing multiple cloud servers, centralized access management and operational evidence are important parts of reducing administrative risk.

Building a Security Assessment Engine With Python

Protecting infrastructure is only one part of cloud security. I also wanted a way to verify that the expected controls remained in place. For this, I developed a Python security assessment engine using boto3 and the Cloudflare API.

The scanner examines selected AWS and Cloudflare configurations, including:

Platform Security checks

  • AWS IMDSv2 enforcement
  • AWS Security group exposure
  • AWS EBS encryption
  • Cloudflare Proxied tunnel DNS configuration
  • Cloudflare Minimum TLS version
  • Cloudflare HTTPS enforcement

The assessment results are written to a timestamped JSON report.

One of the most important design principles was how the scanner handles uncertainty. The tool supports four statuses:

  • PASS: The selected control meets the expected configuration.
  • FAIL: The configuration does not meet the expected requirement.
  • ERROR: The scanner could not complete the check.
  • NOT_TESTED: The control was not evaluated.

Why is that distinction important? Because a security tool should never report a passing result simply because it was unable to access the information needed to perform an assessment.

A real permission failure During the initial combined assessment, the Cloudflare API token lacked the permission needed to read zone security settings. The Cloudflare API returned 403 Forbidden. Instead of crashing or treating the unavailable information as secure, the scanner recorded an ERROR and continued evaluating the remaining checks.

After correcting the token's permissions, the affected checks completed successfully. This reinforced a principle that matters in security engineering: An assessment result is only useful when it accurately reflects what was actually verified.

Testing the Web Application Firewall - and Finding Bypasses

Another valuable part of the project involved Cloudflare's web application firewall. I configured a custom rule to block requests targeting a test path: /blocked-test

Initially, the rule matched the exact path. A normal request to /blocked-test returned HTTP 403, indicating that Cloudflare blocked it.

However, I did not stop with the first successful test. I submitted variations of the same request to determine whether the rule could be bypassed.

Two variations passed through the first rule:

  • /blocked-test/
  • /BLOCKED-TEST

The application returned 404 for these requests, showing that they had reached the application rather than being blocked at the edge. This was not the intended security behavior.

I revised the firewall expression to normalize the case and match the beginning of the request path:

(starts_with(lower(http.request.uri.path), "/blocked-test"))

After the change, the documented retest blocked all seven bypass attempts. Legitimate requests to /health and /api/transactions continued to return HTTP 200.

This was an important lesson. A firewall rule can appear effective while still containing gaps that only become visible through negative testing.

[Insert screenshots: initial WAF rule, blocked request, and Cloudflare security events.]

The Most Important Experiment: Breaking and Restoring IMDSv2

The strongest security validation in CloudSecure was a controlled break-and-fix exercise involving the EC2 Instance Metadata Service. AWS uses the Instance Metadata Service to make instance information and temporary IAM role credentials available to workloads. IMDSv2 improves protection by requiring callers to obtain a session token before accessing metadata.

For the lab, I deployed the EC2 instance with IMDSv2 required. The baseline assessment showed:

7 PASS ยท 0 FAIL ยท 0 ERROR

Then I deliberately changed the Terraform configuration:

http_tokens = "optional"

This allowed requests using the older, tokenless metadata interface. Before applying the change, I reviewed the Terraform plan. It showed one in-place change, with no new resources and no destroyed resources.

After applying the change, I ran the security scanner again. The IMDSv2 check correctly changed from PASS to FAIL.

But I wanted more than a failed configuration check.

Demonstrating the actual security impact Using AWS Systems Manager, I tested whether the instance metadata endpoint would respond without an IMDSv2 token.

During the misconfigured state:

  • Tokenless IMDS request: HTTP 200
  • Tokenless credentials-path request: HTTP 200

The results demonstrated that the token requirement was no longer protecting the metadata endpoint.

I then restored the secure Terraform configuration:

http_tokens = "required"

After applying the remediation, I repeated the tests.

  • Tokenless IMDS request: HTTP 401
  • Tokenless credentials-path request: HTTP 401
  • Valid IMDSv2 request: HTTP 200

This provided evidence that:

  • The scanner detected the deliberately introduced misconfiguration.
  • The insecure metadata access path became accessible during the drill.
  • Terraform successfully restored the intended configuration.
  • Tokenless requests were rejected after remediation.
  • Legitimate IMDSv2 requests continued working.

Finally, Terraform reported no outstanding changes, confirming that the deployed configuration matched the code.

For me, this was the most valuable part of the project. It demonstrated not just security configuration, but detection, controlled change management, remediation, and post-change validation.

[Insert screenshot: IMDSv2 required in AWS.]

[Insert screenshot or formatted excerpt: before-and-after evidence from the drill.]

Security Assessment Results

CloudSecure's documented deployment produced the following results:

  • Validation Result Combined AWS and Cloudflare assessment 7 of 7 checks passed
  • Direct access to application origin Blocked
  • Cloudflare application availability HTTP 200
  • TLS 1.0 and 1.1 after remediation Rejected
  • TLS 1.2 and 1.3 Accepted
  • Revised WAF bypass tests 7 of 7 blocked
  • IMDSv2 misconfiguration Detected
  • IMDSv2 remediation Validated
  • Rejected inbound network attempts More than 2,000 recorded
  • Automated scanner unit tests 14

These results describe the tested controls in this particular lab. They do not establish that the environment is fully secure or compliant with every applicable standard. Nevertheless, they provide a useful example of how security teams can move from configuration assumptions to verifiable evidence.

Mapping Security Evidence to PCI DSS

I also created a starter control mapping aligned with selected requirements of PCI DSS v4.0. The mapping connects implemented and tested controls to security objectives such as network protection, secure system configuration, encryption, access management, logging, and security testing.

Examples include:

PCI DSS requirement area CloudSecure evidence Requirement 1 - Network security controls Security group restrictions and tun

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.