Skip to main content

More Info:

Compute instances should not have public IP addresses assigned. Public IPs expose instances directly to internet-based attacks and should be avoided in favor of load balancers or bastion hosts.

Risk Level

Critical

Address

Compliance, Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • AWS Startup Security Baseline
  • AWS Well Architected Framework
  • 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)
  • FedRAMP
  • HIPAA
  • HITRUST CSF
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST CSF
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • PCI
  • Reserve Bank of India (RBI) Cyber Security Framework
  • SOC2
  • 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

Below are step‑by‑step console instructions to remediate “OCI Compute Instances Should Not Have Public IP Addresses.”

1. Identify Instances With Public IPs

  1. Sign in to OCI Console.
  2. Choose the correct Region (top right).
  3. Open the navigation menu → ComputeInstances.
  4. Select the Compartment where your instances reside.
  5. For each instance:
    • Click the instance name.
    • Under Resources (left side), click Attached VNICs.
    • Click the primary VNIC.
    • In the VNIC details, check:
      • Public IP field
      • If present, note the Public IP address and whether it’s ephemeral or reserved.
You will remediate each instance/VNIC that has a Public IP.

2. Remove Public IP From the Instance (VNIC)

You cannot detach a primary VNIC, but you can remove or change its Public IP.
For safety, stop the instance if it’s production and you want to avoid connection issues during change.
  1. On the instance details page, click Stop.
  2. Wait until the state is Stopped.

2.2 Remove or Change the Public IP

  1. On the same instance page, under Resources, click Attached VNICs.
  2. Click the primary VNIC (usually named something like instance-name (Primary VNIC)).
  3. In the VNIC details page:
    • Locate the IPv4 Addresses section.
    • Find the Primary private IP row.
    • In the Public IP column:
      • Click the Actions menu (three dots) or the link for the public IP.
Depending on the type:

If it’s an Ephemeral Public IP:

  1. In the Public IP details, click Edit or ActionsUnassign / Remove.
  2. Confirm the unassignment.
    • After this, the Primary private IP will show No public IP address.

If it’s a Reserved Public IP:

  1. In the Public IP details, click Edit or ActionsUnassign.
  2. Confirm.
  3. (Optional cleanup) If you no longer need that reserved IP:
    • Go to navigation menu → NetworkingPublic IPs.
    • Choose the correct Compartment.
    • Find that Reserved Public IP, click its name.
    • Click Release Public IP to return it to the pool.

2.3 Start the Instance (if you stopped it)

  1. Return to the instance page.
  2. Click Start.
  3. Confirm that applications are reachable via private paths (VPN, FastConnect, Bastion, etc.).

3. Prevent Future Public IP Assignment at Subnet Level

To avoid new instances in that subnet getting public IPs:
  1. Open navigation menu → NetworkingVirtual Cloud Networks.
  2. Select the VCN where the instance’s subnet resides.
  3. Under Resources, click Subnets.
  4. Click the subnet that was used by your instance.
  5. Click Edit.
  6. Set:
    • Public IP address:
      • Uncheck or choose option that disables public IP assignment (wording may be “Do not assign public IPv4 addresses” or similar).
  7. Click Save changes.
New instances or VNICs in this subnet will not be allowed to have public IPs.

4. (Optional) Use OCI Bastion for Private-Only Access

If you used the public IP for SSH/RDP:
  1. Open navigation menu → Identity & SecurityBastion.
  2. Create a Bastion in:
    • The same Region.
    • A public subnet with proper security list/NSG rules.
  3. Configure a Session (SSH, RDP, etc.) from your workstation through the Bastion to the private IP of your instance.
  4. Confirm you can connect without needing a public IP on the instance.

5. Confirm Remediation for Monitoring/Compliance

To ensure OCI monitoring/compliance tools recognize the remediation:
  1. Wait for the next evaluation cycle (usually a few minutes up to an hour, depending on the security/monitoring service).
  2. In your OCI Security/Monitoring or Cloud Guard dashboards, confirm that:
    • The problem “Compute Instances Should Not Have Public IP Addresses” for those instances is either:
      • Marked Resolved, or
      • No longer shown as active.
You have now removed public IP addresses from your OCI Compute instances and hardened the subnet to prevent new public IPs from being assigned.
Below is a focused, step‑by‑step way to remediate “OCI Compute Instances Should Not Have Public IP Addresses” using the OCI CLI. The core actions are:
  1. Identify instances with public IPs
  2. Remove public IPs from their VNICs
  3. Prevent new public IP assignment at subnet level

1. Prerequisites

  • OCI CLI installed and configured (oci setup config)
  • You know:
    • Your compartment-ocid
    • The region you’re working in (--region if different from default)

2. Identify Compute Instances with Public IPs

2.1. List instances in a compartment

For each instance, get its VNICs and public IPs.

2.2. For each instance, get its VNIC attachments

2.3. For each VNIC, check if it has a public IP

If public-ip is not null, that VNIC currently has a public IP.

3. Remove Public IP Addresses from VNICs

There are two types of public IPs: ephemeral and reserved. You unassign them differently.

3.1. Determine the public IP object (ephemeral vs reserved)

Use the VNIC’s public-ip from the previous step (IP address string).
If it returns a resource with an OCID and "lifetime": "RESERVED", it’s a reserved public IP.
If it doesn’t return anything, it’s likely an ephemeral public IP associated directly to the VNIC.

3.2. If the public IP is ephemeral (most common)

Use vnic update to remove the public IP:
This detaches the ephemeral public IP from the VNIC.

3.3. If the public IP is reserved

First, unassign the reserved public IP from the VNIC, then optionally delete it.

3.3.1. Find the reserved public IP OCID

Save it:

3.3.2. Unassign the reserved public IP from the VNIC

Some older API patterns require you to update the private-ip-id to null (or assign to a different private IP). If the above fails, you can:
  1. Get the private IP behind the VNIC:
  2. Use oci network public-ip update to dissociate or reassign as required (depends on tenancy policy and version). If removing directly is not allowed, you may need to reassign to some “holding” private IP that is not used by a compute instance.

3.3.3. Optionally delete the reserved public IP (to avoid reuse)


4. Prevent Future Public IP Assignment at Subnet Level

To ensure instances in a subnet cannot get public IPs:

4.1. Get subnet details and current setting

If prohibit-public-ip-on-vnic is false, change it to true.

4.2. Update the subnet

From now on, new VNICs in this subnet cannot have public IPs. Existing VNICs with public IPs are not automatically stripped; you must remediate them as in steps 2–3.

5. Bulk / Scripted Remediation Pattern (Optional)

To remediate all instances in a compartment:
  1. List all VNICs that currently have a public-ip:
  2. Then update subnets as in section 4 to prevent re‑introduction.

If you share your compartment OCID / subnet structure (sanitized), I can help format exact ready‑to‑run commands for your layout.
Below is a concise, Python‑based approach to detect and remediate OCI Compute instances that have public IPs by unassigning those IPs from their VNICs.Assumptions:
  • You have oci Python SDK installed (pip install oci).
  • Your ~/.oci/config is set up, or you otherwise pass config programmatically.
  • You understand that unassigning public IPs may break connectivity (SSH/RDP) to those instances.

1. Install and Import OCI SDK


2. Create OCI Clients


3. List Instances and Their VNICs

Now get each instance’s VNIC attachments:

4. Detect VNICs with Public IPs

At this point you have all VNICs with public IPs.

5. Unassign the Public IPs

There are two cases in OCI:
  1. Ephemeral Public IPs (assigned directly to VNIC).
  2. Reserved Public IPs (separate OCI resource, associated with a private IP).

5.1. Unassign Ephemeral Public IP

Note: For ephemeral public IPs, they are modeled as a PublicIp resource of type EPHEMERAL. Deleting that PublicIp unassigns it from the private IP.

5.2. Unassign Reserved Public IPs

Reserved public IPs may be attached to specific private IPs. Detection is similar; identify the PublicIp resource and delete or “unassign” it.

6. Wrap into a “Remediation Script”

Combine the logic into a script that:
  1. Lists instances and their VNICs.
  2. Finds all VNICS/private IPs with public IPs.
  3. Resolves the corresponding PublicIp resources.
  4. Deletes (unassigns) those PublicIp resources.
Skeleton:

7. (Optional) Monitoring / Alerting

To integrate this with “compute monitoring”:
  1. Use OCI Monitoring / Alarms or Cloud Guard to detect instances with public IPs (e.g., via IAM/Config rules or Cloud Guard detector).
  2. Configure an Alarm or Cloud Guard Responder that triggers a Notification (OCI Events + Functions or OCI Notifications to a function).
  3. That Function can run the Python logic above (packaged into a function) to automatically remediate.
If you specify whether you want a standalone script, OCI Function code, or integration with Cloud Guard/Events, I can give a tailored Python example for that environment.
Setting assign_public_ip = "false" (or omitting it when the subnet is private-by-default) prevents the instance from receiving a public IP; changing this on an existing instance forces replacement (destroy and recreate) of the instance/VNIC in Terraform.After the change, terraform plan should show the assign_public_ip argument changing from "true" (or "yes") to "false" with a planned -/+ replacement for the oci_core_instance resource.