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
CriticalAddress
Compliance, SecurityCompliance 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
Remediation
Using Console
Using Console
To remediate “OCI Network Security Groups Should Not Allow Public SSH Access” using the OCI Console:
-
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).
-
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.
-
Review ingress (inbound) rules
- In the NSG details page, click the Ingress Rules tab.
- Look for any rule that:
- Uses Destination Port Range =
22(or22-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).
- Uses Destination Port Range =
-
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/0with a specific CIDR, e.g.203.0.113.10/32.
- Replace
- Remove direct SSH entirely (recommended when using OCI Bastion, Session Manager, or other jump hosts):
- Delete the rule that allows SSH from the internet.
- Restrict SSH to trusted IP ranges (e.g., your office VPN or bastion host):
-
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.
- Change Source Type to
- 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).
- Source Type:
- Click Add Ingress Rule.
- If editing:
- Click Edit (if available) or delete and recreate:
- To delete:
- On the Ingress Rules tab:
-
Check for IPv6 exposure (if applicable)
- Still on Ingress Rules, confirm there is no rule with:
- Source CIDR =
::/0 - Protocol
TCP - Destination port
22.
- Source CIDR =
- If present, remove or restrict it the same way as for IPv4.
- Still on Ingress Rules, confirm there is no rule with:
-
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/0or::/0. - No “All protocols / All ports” rule is using
0.0.0.0/0or::/0for the same NSG.
- No NSG ingress rule allows port 22 from
-
(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.
- OCI Bastion:
- If you removed public SSH, consider:
Using CLI
Using CLI
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:
Note the
You’re looking for ingress rules with:
This removes the public SSH rule from that NSG.
Optionally use If that command returns nothing, your NSG no longer allows public SSH.
If you share a sample
- You have OCI CLI installed and configured.
- You know the
compartment-ocid(and optionallyvcn-id).
1. List Network Security Groups (NSGs)
id of the NSG(s) you want to check.Optionally filter by VCN:2. List Security Rules in Each NSG
For each NSG:direction = INGRESSprotocol = 6(TCP)source = 0.0.0.0/0(or::/0for IPv6)tcpOptions.destinationPortRange.min = 22and.max = 22(or range covering 22)
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., itsisStateless, protocol, source, tcpOptions, etc.), because OCI NSG rules are updated by replacing the full rule set.- Get current rules into a file:
-
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).
- is
updated_rules.json. The JSON to send toupdatemust be just the array of rules, e.g.: - Remove any rule object that:
- Apply the new rule set:
Option B – Restrict SSH to a specific source (e.g., your office IP range)
Instead of deleting, you can adjust thesource from 0.0.0.0/0 to a trusted CIDR, like 203.0.113.0/24.- Same as above, export rules:
-
In
current_rules.json:- Find the rule with:
direction: "INGRESS"protocol: "6"source: "0.0.0.0/0"- TCP port 22
- Change
sourceto your allowed CIDR, for example:
Save asupdated_rules.jsonin the same wrapper structure: - Find the rule with:
- Apply:
4. Verify That Public SSH Is Blocked
Re-list NSG rules and confirm there is no ingress rule withsource 0.0.0.0/0 (or ::/0) and TCP destination port 22:jq:If you share a sample
oci network nsg rules list JSON output, I can craft the exact updated_rules.json you should apply.Using Python
Using Python
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)
- OCI Python SDK installed:
- You want to:
- Find NSG rules that allow SSH (TCP/22) from
0.0.0.0/0 - Remove or adjust them programmatically
- Find NSG rules that allow SSH (TCP/22) from
1. Decide your remediation strategy
You have two main options:-
Delete the offending rule(s)
– safest default if you don’t know the intended source. -
Restrict CIDR instead of deleting (e.g. change
0.0.0.0/0tox.y.z.0/24)
– safer operationally if you know the correct IP ranges.
2. Python script: identify & remediate NSG rules
3. How to use this in a monitoring/remediation workflow
-
Monitoring-only mode
- Set
DRY_RUN = Trueto 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.
- Set
-
Auto-remediation mode
- Set
DRY_RUN = False - Choose:
RESTRICT_INSTEAD_OF_DELETE = Falseto delete insecure rules, orRESTRICT_INSTEAD_OF_DELETE = Trueand setNEW_ALLOWED_CIDRto your admin or bastion IP range.
- Set
-
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.
Using Terraform
Using Terraform
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.
