LAB 56 (Stateless vs Statefull Security List) - arunsinghchauhan38-arch/CLOUDARCHITECTDOC GitHub Wiki

Stateful vs. Stateless Security Rules in OCI

1. What is a Stateful Security Rule?

A stateful security rule maintains information about the state of an active network connection. Once a connection is permitted by a stateful rule, the corresponding return traffic is automatically allowed without requiring a separate rule for the return path.

In OCI Security Lists:

Stateless = No → Stateful Rule

xample: SSH Connection

Assume a Linux instance has SSH enabled on TCP port 22.

Ingress Rule:

image

The traffic flow is:

Laptop
   |
   | SSH Request → TCP/22
   ↓
Security List
   |
   | ALLOW
   ↓
OCI Linux Instance
   |
   | Return Traffic
   ↓
Laptop

Because the rule is stateful, OCI tracks the established connection and automatically permits the corresponding return traffic.

Key Point

Stateful = Connection tracking + Return traffic is automatically permitted.

2. What is a Stateless Security Rule?

A stateless security rule does not maintain connection state. Each packet is evaluated independently according to the applicable security rules.

Therefore, when using stateless rules, the required traffic must be explicitly permitted in the appropriate direction.

In OCI Security Lists:

Stateless = Yes → Stateless Rule

Example: SSH Connection

Ingress Rule:

image

The incoming SSH request may be permitted:

Laptop
   |
   | SSH Request → TCP/22
   ↓
OCI Linux Instance

The server's response travels in the opposite direction:

OCI Linux Instance
   |
   | TCP Response
   | Source Port: 22
   | Destination Port: Ephemeral
   ↓
Laptop

Because the original rule is stateless, OCI does not use connection tracking to automatically permit the response. An appropriate egress rule must therefore allow the return traffic.

Key Point

Stateless = No connection tracking + Required traffic must be explicitly permitted in each direction.

3. Stateful vs. Stateless Security Rules

image

4. SSH Example

Assume the Linux server has:

image

Stateful SSH Rule

Ingress Security Rule:

image

Traffic flow:

Client
   |
   | TCP
   | Destination Port: 22
   ↓
Server
   |
   | Return Traffic
   ↓
Client

     ↳ Automatically permitted

OCI tracks the connection and permits the corresponding return traffic.

Stateless SSH Rule

Ingress Security Rule:

image

Traffic flow:

Client | | TCP | Destination Port: 22 ↓ Linux Server | | Return Traffic | Source Port: 22 | Destination Port: Ephemeral ↓ Client

 ↳ Appropriate EGRESS rule required

The return traffic must be explicitly permitted by an appropriate egress security rule.

5. Why is Stateful Commonly Used?

Stateful rules are commonly used because they simplify security configuration.

For example, when an administrator connects to an OCI Linux instance:

ssh opc@

The connection involves traffic flowing in both directions.

With a stateful SSH rule, OCI tracks the connection and automatically permits the corresponding return traffic.

This reduces the number of rules that administrators need to configure and maintain.

6. Why Use Stateless Rules?

Stateless rules are useful when administrators require explicit control over traffic in each direction.

They allow inbound and outbound traffic to be controlled independently through separate security rules.

This can provide more granular control over network communication, although it requires more careful configuration.

7. Important OCI Interview Question

Question:

What is the difference between Stateful and Stateless Security Rules in OCI?

Professional Answer:

A stateful security rule tracks the state of a network connection. When an allowed connection is established, OCI automatically permits the corresponding return traffic. In OCI, Stateless = No represents a stateful rule.

A stateless security rule does not track connection state. Therefore, the required traffic must be explicitly permitted in the appropriate directions using ingress and egress rules. In OCI, Stateless = Yes represents a stateless rule.

8. Simple Real-World Analogy

Stateful

Think of a security guard who remembers you after checking you in.

You enter → Guard verifies you → Guard remembers you ↓ Return access permitted

The connection is tracked.

Stateless

Think of a security guard who checks you every time you pass.

Entering → Check required Returning → Check required

Each direction is evaluated independently.

9. One-Line Revision

Stateless = No 
     ↓
Connection Tracking 
     ↓ 
Return Traffic Automatically Allowed

Stateless

Stateless = Yes 
      ↓ 
No Connection Tracking 
      ↓ 
Traffic Must Be Explicitly Allowed 
      ↓ 
Appropriate Ingress + Egress Rules

Lab — Stateful vs. Stateless Security Lists Using SSH

Lab Objective

The objective of this lab is to understand the behavior and configuration differences between Stateful and Stateless Security List rules in Oracle Cloud Infrastructure (OCI).

Using the existing Bastion Server and Target Server, we will establish SSH connectivity, modify the security rules from Stateful to Stateless, observe the resulting connectivity behavior, and then configure the required return-traffic rules to restore SSH connectivity.

In this lab, we will:

  • Verify SSH connectivity using Stateful Security List rules.
  • Convert the SSH rules to Stateless.
  • Test SSH connectivity and analyze the failure.
  • Configure explicit return-traffic rules.
  • Re-test SSH connectivity.
  • Understand TCP source and destination ports during an SSH session.
  • Compare Stateful and Stateless security behavior in OCI.
image image

Part 1 — Verify Stateful SSH Connectivity

Step 1 — Verify the Target Server Security List

OCI Console → Networking → VCN → asus_sl → Security Rules → Ingress Rules

SSH Ingress Rule

image

Explanation

In OCI:

Stateless = No ↓ Stateful Security Rule

The rule permits TCP traffic destined for port 22 from the Bastion subnet.

Because the rule is Stateful, OCI maintains connection state and automatically permits the corresponding return traffic for the established SSH connection.

Verification

Confirm that:

Stateless = No

This verifies that the SSH ingress rule is Stateful.

image

Step 2 — Verify the Bastion Server Security List

Navigate to:

OCI Console → Networking → VCN → hub_publicsub_sl → Security Rules → Egress Rules

Locate the SSH egress rule.

SSH Egress Rule

image image

This rule permits the Bastion Server to initiate SSH traffic toward the Target Server.

Because the rule is Stateful, OCI automatically permits the corresponding return traffic associated with the established connection.

Verification

Confirm that:

Stateless = No

Step 3 — Test Stateful SSH Connectivity

From the Bastion Server, initiate an SSH connection to the Target Server:

ssh opc@<TARGET_PRIVATE_IP>

Expected Result SSH Login Successful

Successful authentication confirms that SSH connectivity between the Bastion Server and Target Server is functioning correctly with Stateful Security List rules.

Verify the Target Server

After logging in, verify the server identity:

hostname

Optionally, verify the assigned IP address:

hostname -I

After completing the verification, exit the Target Server:

exit
image image

Part 2 — Convert SSH Rules to Stateless

Step 4: Change Target Server SSH Rule

Navigate to asus_sl → Ingress Rules → TCP/22 Rule → Edit

Update:

Stateless: No → Yes

Keep all other values unchanged.

Click Save Changes.

✅ Target Server ingress rule updated.

image image

Step 5: Change Bastion SSH Rule

Navigate to hub_publicsub_sl → Egress Rules → TCP/22 Rule → Edit

Update:

Stateless: No → Yes

Keep all other values unchanged.

Click Save Changes.

✅ Bastion egress rule updated.

image image

Part 3 — Test Stateless SSH

Step 6: Test SSH with Stateless Rules

From the Bastion Server:

ssh opc@<TARGET_PRIVATE_IP>

Expected Result:

Connection fails with Connection timed out.

image

Why does it fail?

  • Request: Bastion → Target (Destination Port: 22)

  • Response: Target → Bastion (Source Port: 22 → Destination Port: Ephemeral)

  • Stateless rules do not automatically track connection state.

  • Return traffic must be explicitly allowed.

Part 4 — Configure Return Traffic

Step 7: Add Return Traffic Rule (Target Server)

Navigate to asus_sl → Security Rules → Egress Rules → Add Egress Rule

Configure:

Destination CIDR: 10.0.0.0/25

Protocol: TCP

Source Port Range: 22

Destination Port Range: 1024–65535

Stateless: Yes

Click Add Egress Rule.

✅ Return traffic rule added on Target.

image image

Step 8: Add Corresponding Return Rule (Bastion Side)

Navigate to hub_publicsub_sl → Security Rules → Ingress Rules → Add Ingress Rule

Configure:

Source CIDR: 10.0.1.0/26

Protocol: TCP

Source Port Range: 22

Destination Port Range: 1024–65535

Stateless: Yes

Click Add Ingress Rule.

✅ Return traffic rule added on Bastion.

image image

🔑 Why Port 22 and 1024–65535?

  • Port 22 → SSH server port.

  • 1024–65535 → Ephemeral client port range.

  • SSH Request: Bastion → Target (Ephemeral → 22)

  • SSH Response: Target → Bastion (22 → Ephemeral)

📌 Easy memory trick:

  • 22 = SSH Server Port

  • 1024–65535 = Client Ephemeral Port Range

Part 5 — Test Stateless SSH Again

Step 9: Initiate New SSH Connection

From the Bastion Server:

ssh opc@<TARGET_PRIVATE_IP>
ssh -i ~/keys/privkey.pem [email protected]

Expected Result:

✅ SSH Login Successful

Traffic in both directions explicitly permitted.

image Copilot_20261006_223236 Copilot_20261006_223420
⚠️ **GitHub.com Fallback** ⚠️