Skip to main content

More Info:

Network Security Groups should not allow SSH (port 22) access from 0.0.0.0/0. Public SSH endpoints are continuously targeted by automated brute-force attacks.

Risk Level

Critical

Address

Compliance, Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • BSI C5 (Germany)
  • Brazil LGPD
  • CCPA / CPRA (California)
  • CIS Critical Security Controls v8
  • CMMC 2.0
  • CSA Cloud Controls Matrix v4
  • DPDPA
  • Digital Operational Resilience Act (EU)
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • Securities and Exchange Board of India (SEBI) - Cloud Security Adoption Framework
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

To remediate “OCI Network Security Groups Should Not Allow Public SSH Access” using the OCI Console:
  1. Identify the offending NSG rule
    • In the OCI Console, open the navigation menu.
    • Go to Logging & Monitoring → Security → Cloud Guard (or Security Zones / your monitoring tool) and open the detector or finding that reports:
      • “Network Security Groups Should Not Allow Public SSH Access” (or similar).
    • From the finding details, note:
      • The Compartment
      • The VCN
      • The Network Security Group (NSG) name or OCID
    • Click the NSG link if available, or navigate manually (next steps).
  2. Navigate to the Network Security Group
    • Open the navigation menu.
    • Go to Networking → Virtual Cloud Networks.
    • Select the compartment where the VCN/NSG resides.
    • Click the VCN that contains the NSG.
    • In the VCN details page, under Resources, click Network Security Groups.
    • Click the NSG identified in the finding.
  3. Review ingress (inbound) rules
    • In the NSG details page, click the Ingress Rules tab.
    • Look for any rule that:
      • Uses Destination Port Range = 22 (or 22-22)
      • AND Source Type = CIDR
      • AND Source CIDR is:
        • 0.0.0.0/0 (IPv4 public)
        • or ::/0 (IPv6 public)
      • AND protocol is TCP (or All protocols).
  4. Decide remediation approach You have two secure options:
    • Restrict SSH to trusted IP ranges (e.g., your office VPN or bastion host):
      • Replace 0.0.0.0/0 with a specific CIDR, e.g. 203.0.113.10/32.
    • Remove direct SSH entirely (recommended when using OCI Bastion, Session Manager, or other jump hosts):
      • Delete the rule that allows SSH from the internet.
  5. Edit or delete the problematic rule
    • On the Ingress Rules tab:
      • To delete:
        • Click the menu (⋯) or Delete icon next to the SSH rule.
        • Confirm deletion.
      • To edit (if you need SSH but only from specific sources):
        • Click Edit (if available) or delete and recreate:
          • If editing:
            • Change Source Type to CIDR.
            • Set Source CIDR to your trusted IP/CIDR (e.g. 198.51.100.0/24).
            • Ensure IP Protocol is TCP.
            • Ensure Destination Port Range is 22 (or a custom SSH port if you changed it).
            • Click Save Changes.
          • If recreating:
            • Click Add Ingress Rule.
            • Set:
              • Source Type: CIDR
              • Source CIDR: your secure range (e.g., VPN range)
              • IP Protocol: TCP
              • Destination Port Range: 22
              • Optionally set Stateless = No (default).
            • Click Add Ingress Rule.
  6. Check for IPv6 exposure (if applicable)
    • Still on Ingress Rules, confirm there is no rule with:
      • Source CIDR = ::/0
      • Protocol TCP
      • Destination port 22.
    • If present, remove or restrict it the same way as for IPv4.
  7. Validate remediation in Monitoring/Cloud Guard
    • Go back to Cloud Guard → Detector Findings (or your monitoring view).
    • Locate the original finding.
    • After a short interval (detection schedule), the finding should:
      • Move to Resolved (or similar status),
      • Or disappear from the active list.
    • If it still persists, confirm again that:
      • No NSG ingress rule allows port 22 from 0.0.0.0/0 or ::/0.
      • No “All protocols / All ports” rule is using 0.0.0.0/0 or ::/0 for the same NSG.
  8. (Optional) Add safer access method
    • If you removed public SSH, consider:
      • OCI Bastion:
        • Navigation: Identity & Security → Bastion.
        • Create a bastion in the same VCN and subnet, then use it for SSH sessions.
      • Or a VPN/Private connectivity plus NSG rules that only allow SSH from that private network.
If you share the specific rule format (screenshot or text), I can give you the exact field values to use when editing it.
Below are concise, step‑by‑step OCI CLI instructions to find and fix NSG rules that allow public SSH (TCP/22 from 0.0.0.0/0).Assumptions:
  • You have OCI CLI installed and configured.
  • You know the compartment-ocid (and optionally vcn-id).

1. List Network Security Groups (NSGs)

Note the id of the NSG(s) you want to check.Optionally filter by VCN:

2. List Security Rules in Each NSG

For each NSG:
You’re looking for ingress rules with:
  • direction = INGRESS
  • protocol = 6 (TCP)
  • source = 0.0.0.0/0 (or ::/0 for IPv6)
  • tcpOptions.destinationPortRange.min = 22 and .max = 22 (or range covering 22)
Example JSON view:

3. Remove or Restrict the Public SSH Rule

You have two main options:

Option A – Delete the offending rule

You must know the rule defined in the NSG (i.e., its isStateless, protocol, source, tcpOptions, etc.), because OCI NSG rules are updated by replacing the full rule set.
  1. Get current rules into a file:
  1. Edit current_rules.json:
    • Remove any rule object that:
      • is direction: "INGRESS"
      • and matches protocol: "6" with TCP port 22
      • and has source: "0.0.0.0/0" (or ::/0).
    Keep only the safe rules. Save as updated_rules.json. The JSON to send to update must be just the array of rules, e.g.:
  2. Apply the new rule set:
This removes the public SSH rule from that NSG.

Option B – Restrict SSH to a specific source (e.g., your office IP range)

Instead of deleting, you can adjust the source from 0.0.0.0/0 to a trusted CIDR, like 203.0.113.0/24.
  1. Same as above, export rules:
  1. In current_rules.json:
    • Find the rule with:
      • direction: "INGRESS"
      • protocol: "6"
      • source: "0.0.0.0/0"
      • TCP port 22
    • Change source to your allowed CIDR, for example:
    Save as updated_rules.json in the same wrapper structure:
  2. Apply:

4. Verify That Public SSH Is Blocked

Re-list NSG rules and confirm there is no ingress rule with source 0.0.0.0/0 (or ::/0) and TCP destination port 22:
Optionally use jq:
If that command returns nothing, your NSG no longer allows public SSH.
If you share a sample oci network nsg rules list JSON output, I can craft the exact updated_rules.json you should apply.
Below is a practical way to detect and remediate “public SSH” from OCI Network Security Groups using Python and the OCI SDK.Assumptions:
  • You already have:
    • OCI Python SDK installed: pip install oci
    • Config file at ~/.oci/config (or equivalent) with a profile (e.g. DEFAULT)
  • You want to:
    • Find NSG rules that allow SSH (TCP/22) from 0.0.0.0/0
    • Remove or adjust them programmatically

1. Decide your remediation strategy

You have two main options:
  1. Delete the offending rule(s)
    – safest default if you don’t know the intended source.
  2. Restrict CIDR instead of deleting (e.g. change 0.0.0.0/0 to x.y.z.0/24)
    – safer operationally if you know the correct IP ranges.
The script below shows both, with a toggle.

2. Python script: identify & remediate NSG rules


3. How to use this in a monitoring/remediation workflow

  1. Monitoring-only mode
    • Set DRY_RUN = True to run this script on a schedule (e.g., via OCI Functions + Events or an external scheduler) as a monitor and just log/report policy violations.
  2. Auto-remediation mode
    • Set DRY_RUN = False
    • Choose:
      • RESTRICT_INSTEAD_OF_DELETE = False to delete insecure rules, or
      • RESTRICT_INSTEAD_OF_DELETE = True and set NEW_ALLOWED_CIDR to your admin or bastion IP range.
  3. Integrate with Cloud Guard or other monitoring:
    • Use Cloud Guard to generate findings for “NSG with public SSH”.
    • Trigger this script via OCI Functions or an external automation pipeline when such findings appear.
If you tell me how you’re currently doing “OCI Networking Monitoring” (Cloud Guard, custom scripts, Functions, etc.), I can adapt this to plug directly into that workflow.
If you currently have an oci_core_network_security_group_security_rule for SSH with source = "0.0.0.0/0", change its source to a non-public CIDR (as above) or remove that rule resource entirely; changing the rule will force replacement of the security rule itself but not the NSG.For verification, terraform plan should show the NSG security rule with source changing from "0.0.0.0/0" to your restricted CIDR, or the public SSH rule being destroyed with no replacement.