By Gowthami | apps-dba.com | Oracle Cloud Infrastructure Series
Connecting to private OCI compute instances without a public IP is a common security requirement. OCI Bastion Service provides a fully managed, secure way to access private resources without requiring a jump server or VPN. This post walks through setting up and using OCI Bastion to connect to a private instance.
What Is OCI Bastion Service?
OCI Bastion is a managed service that provides restricted, time-limited SSH access to private resources in your VCN. Key features:
- No need for a public IP on the target instance
- Sessions are time-limited (max 3 hours by default)
- Access is logged and auditable via OCI Audit
- Supports SSH port forwarding for database connections
Prerequisites
- A private OCI compute instance (no public IP)
- OCI CLI installed and configured on your local machine
- An SSH key pair
- IAM policy allowing Bastion use
Step 1: Create the Bastion
- Navigate to Identity & Security > Bastion in OCI Console
- Click Create Bastion
- Provide:
- Name: e.g.,
demo-bastion - Target VCN and subnet (must be in same VCN as private instance)
- CIDR allowlist: your local IP (e.g.,
203.0.113.0/32)
- Name: e.g.,
- Click Create Bastion and wait for Active state
Step 2: Create a Managed SSH Session
- Select your Bastion and click Create Session
- Session type: Managed SSH session
- Enter:
- Username:
opc(Oracle Linux) orubuntu - Compute instance: select your private instance
- SSH public key: paste your public key content
- Session TTL: up to 10800 seconds (3 hours)
- Username:
- Click Create Session
Step 3: Connect Using the SSH Command
Once the session is Active, OCI provides a ready-to-use SSH command. Copy it from the session details. It looks like:
ssh -i <private_key_file> -o ProxyCommand='ssh -i <private_key_file> -W %h:%p -p 22 ocid1.bastionsession.oc1...@host.bastion.<region>.oci.oraclecloud.com' -p 22 opc@<private_instance_ip>
Paste and run this command in your local terminal.
Step 4: Port Forwarding for Database Access
To connect to a private Oracle Database (port 1521) through Bastion:
- Create a Port Forwarding Session instead of Managed SSH
- Target: private instance IP, port 1521
- Use the provided SSH command with local port forwarding:
ssh -i <private_key> -N -L 1521:<DB_PRIVATE_IP>:1521 -p 22 ocid1.bastionsession...@host.bastion.<region>.oci.oraclecloud.com
Then connect SQL*Plus to localhost:1521 as if it were local.
IAM Policy Required
Allow group DBAs to manage bastion-family in compartment <compartment_name>
Allow group DBAs to manage bastion-session in compartment <compartment_name>
No comments:
Post a Comment