# [05 Cloud Integration] Cloud Deployment Guide: Fronting Xage in AWS & Azure with Akamai

## Purpose & Scope

This implementation guide outlines the exact, step-by-step procedure for deploying and configuring **Akamai Intelligent Edge (App & API Protector or Enterprise Application Access)** to front a cloud-hosted **Xage Security Fabric** gateway running in Amazon Web Services (AWS) or Microsoft Azure.

Following this procedure ensures an enterprise-grade posture: the cloud origin is completely hidden from public internet scanning, protected against volumetric DDoS attacks, shielded by edge WAF inspection, and optimized for interactive WebSockets (SSH and RDP browser streaming).

---

## Architecture Overview

```
                                  [ Remote Users ]
                                         │
                                         ▼ (HTTPS / TCP 443)
┌─────────────────────────────────────────────────────────────────────────────────┐
│                           AKAMAI INTELLIGENT EDGE                               │
│  - Edge Hostname: access.company.com.edgekey.net (TLS 1.3 Terminated via CPS)  │
│  - App & API Protector: Adaptive Security Engine + Credential Stuffing Defense  │
│  - WebSockets Enabled: 300s Idle Timeout, Buffer Bypass                         │
│  - Header Injection: True-Client-IP, X-Forwarded-For, X-Forwarded-Proto         │
│  - Routing: Site Shield Persistent Egress VIPs                                  │
└────────────────────────────────────────┬────────────────────────────────────────┘
                                         │
                 Protected Transit via Site Shield CIDR Blocks
                                         │
                                         ▼ (TCP 443 Only)
┌─────────────────────────────────────────────────────────────────────────────────┐
│               CLOUD INGRESS (AWS VPC / Azure Virtual Network)                   │
│  - Cloud Security Group: Allow TCP 443 ONLY from Akamai Site Shield CIDRs       │
│  - Cloud Application Load Balancer (ALB / App Gateway):                         │
│    • Target Group: Multi-AZ Xage Fabric Nodes (Port 443)                        │
│    • Sticky Sessions: 8-hour Application Cookie (`XAGE_SESSION`)                │
│    • Health Check: HTTPS GET /healthz (Status 200)                              │
└────────────────────────────────────────┬────────────────────────────────────────┘
                                         │
                                         ▼ (Internal Private VPC Subnet)
┌─────────────────────────────────────────────────────────────────────────────────┐
│                          XAGE FABRIC CLOUD GATEWAY                              │
│  - Multi-AZ Xage Node Cluster (Node-01, Node-02)                                │
│  - Translates WebSockets to Internal SSH / RDP / OT Commands                    │
│  - Inter-Node Mesh Synchronization (Private Subnet Ports 8443 / 8080)           │
│  - Connects out to Remote Industrial Sites & On-Premise Asset Enclaves          │
└─────────────────────────────────────────────────────────────────────────────────┘
```

---

## Phase 1: Deploy Xage Infrastructure in Cloud VPC

### 1.1 VPC and Subnet Layout
Deploy Xage nodes across at least two (2) Availability Zones for high availability:
- **Public/DMZ Subnet:** Hosts the Cloud Application Load Balancer (ALB).
- **Private Subnet:** Hosts the Xage Fabric virtual machines or container instances.

### 1.2 Cloud Load Balancer Configuration (AWS ALB / Azure App Gateway)
1. **Listener:** Configure an HTTPS listener on **TCP port 443**.
2. **TLS Certificate:** Install an internal or public SSL/TLS certificate issued to `access.company.com`.
3. **Target Group:** Register the private IP addresses of the Xage nodes on port 443.
4. **Health Check Settings:**
   - Protocol: `HTTPS`
   - Path: `/healthz` (or `/api/v1/health`)
   - Interval: 15 seconds
   - Healthy Threshold: 2 consecutive passes
   - Unhealthy Threshold: 3 consecutive failures
5. **Session Stickiness:**
   - Enable **Sticky Sessions (Application-Based or Duration-Based)**.
   - Set expiration to match your standard workday (e.g., 28,800 seconds / 8 hours).
   - *Rationale:* Xage maintains active in-memory session states for interactive SSH/RDP WebSockets. Flipping requests across different nodes mid-session will sever the connection.

---

## Phase 2: Configure Akamai Property Manager

Log in to the **Akamai Control Center** and open **Property Manager**. Create or edit the property for `access.company.com`.

### 2.1 General Settings
- **Edge Hostname:** Assign a secure Edge Hostname (`access.company.com.edgekey.net`) backed by an Enhanced TLS certificate provisioned through Akamai CPS.
- **Protocol Optimization:** Enable **HTTP/2** and **HTTP/3 (QUIC)** for accelerated browser delivery.

### 2.2 Origin Server Behavior
Configure the Origin Server settings in the Default Rule:
- **Origin Type:** `Your Origin`
- **Origin Server Hostname:** Enter the DNS name of the Cloud Load Balancer (e.g., `alb-xage-prod-12345.us-east-1.elb.amazonaws.com`).
- **Forward Host Header:** Select `Incoming Host Header` (preserves `access.company.com`).
- **Cache Key Hostname:** `Incoming Host Header`.
- **Verification:** Enable **Third-Party CA** or **Akamai CA** verification to validate the origin SSL certificate.
- **Mutual TLS (mTLS):** Enable client certificate authentication from Akamai to Origin if required by compliance standards.

### 2.3 Header Injection Behaviors
Add the following downstream header rules:
- **True-Client-IP:** Injected automatically (`True-Client-IP: {{builtin.AKAMAI_TRUE_CLIENT_IP}}`).
- **X-Forwarded-For:** Enable standard append behavior.
- **X-Forwarded-Proto:** Set static value to `https`.

### 2.4 Caching Rules (Bypass Caching)
Because Xage is an administrative security portal handling dynamic authenticated sessions and live streams, **caching must be disabled globally**:
- Set **Caching Option** to `Bypass Cache` / `no-store` for all paths (`/*`).

### 2.5 WebSockets Behavior Rule (CRITICAL)
Create a new rule named **"Xage WebSockets Support"**:
- **Criteria (Match):**
  - Path matches one of: `/ws/*`, `/api/v1/sessions/*`, `*/tunnel*`, OR
  - Request Header `Upgrade` is present and contains `websocket`.
- **Behaviors:**
  - **WebSockets:** Set to `Enabled`.
  - **Idle Timeout:** Increase from default (60s) to **300 seconds (5 minutes)**.
  - **Buffer Management:** Disable response buffering (`Buffering: Off`).
  - *Validation:* Failing to set this rule will cause SSH and RDP sessions inside the Xage browser portal to terminate or lag severely.

---

## Phase 3: Lock Down Cloud Security Groups via Akamai Site Shield

To guarantee that traffic only reaches the cloud load balancer from Akamai edge nodes:

1. In Akamai Control Center, navigate to **Site Shield** and identify your assigned Site Shield Map (e.g., `s123.siteshield.akamai.net`).
2. Retrieve the assigned list of IPv4 and IPv6 CIDR blocks.
3. In AWS or Azure, navigate to the **Security Group** or **Network Security Group** assigned to the public-facing Load Balancer.
4. **Edit Inbound Rules:**
   - Protocol: `TCP`
   - Port: `443`
   - Source: Add each Akamai Site Shield CIDR block (e.g., `23.32.0.0/18`, `104.64.0.0/18`, etc.).
   - Remove `0.0.0.0/0` (Anywhere) from inbound rules.
5. All direct internet probes, Shodan scans, and botnet port scans hitting your load balancer’s public IP will now be dropped at the cloud VPC edge.

---

## Phase 4: Configure App & API Protector (WAF & Rate Limiting)

1. Associate the Property with your **App & API Protector Security Configuration**.
2. **Adaptive Security Engine (ASE):**
   - Set all Core Rule Groups (SQLi, XSS, Command Injection, LFI/RFI) to **Deny (403 Forbidden)**.
3. **Rate Limiting / DoS Protection:**
   - **Login Endpoint Protection:** Match path `/api/v1/auth/*` or `/login`.
   - Threshold: Maximum **20 requests per minute** per Client IP.
   - Action: **Drop / Alert & Deny**.
4. **Bot Management:**
   - Enable **Browser Validation**. Enforce JavaScript challenges on initial connection to eliminate headless automated scripts while allowing standard web browsers transparent passage.
   - Enable **Malicious Bot Blocking** (scrapers, scanners, automated exploit toolkits).

---

## Phase 5: Verification, Testing & Day-2 Operations

Execute the following verification checklist before opening the system to production users:

### 1. Edge DNS Resolution
Verify that DNS resolves directly to Akamai edge servers:
```bash
dig access.company.com +short
# Output should return Akamai Edge CNAMEs (e.g., access.company.com.edgekey.net) and Akamai Anycast IPs
```

### 2. Direct Origin Bypass Test (Verifying Site Shield)
Attempt to send an HTTPS request directly to the Cloud Load Balancer’s IP or AWS DNS hostname from an unwhitelisted internet connection:
```bash
curl -kv https://<ALB-DIRECT-DNS-NAME>/healthz
# Expected result: Connection timeout or connection dropped (SYN packet dropped by Security Group)
```

### 3. Edge Routing and Header Verification
Send a request through Akamai and verify headers:
```bash
curl -Iv https://access.company.com/healthz
# Expected result: HTTP/2 200 OK, Server: AkamaiGHost
```

### 4. Interactive WebSocket Session Verification
1. Log in to the Xage portal via web browser: `https://access.company.com`.
2. Launch an active **SSH terminal session** to a Linux asset. Run interactive commands (`top`, `vim`, `htop`).
3. Leave the terminal idle for **180 seconds (3 minutes)**. Type a command to ensure the session did not disconnect.
4. Launch an active **RDP session** to a Windows server. Verify mouse movement and window dragging responsiveness.

### 5. Audit Log Validation
Log in to the Xage Administrator Console and inspect the Audit Logs. Verify that the **Source IP** recorded for your login session matches your actual public IP address (passed via `True-Client-IP`), not an internal Akamai proxy IP.
