Skip to content

feat: add forward for port-forwarding sessions - #26

Merged
adrianmross merged 1 commit into
mainfrom
feat/forward-port-forwarding
Sep 9, 2026
Merged

feat: add forward for port-forwarding sessions#26
adrianmross merged 1 commit into
mainfrom
feat/forward-port-forwarding

Conversation

@adrianmross

Copy link
Copy Markdown
Owner

Companion to adrianmross/bastion-session#28, which adds the underlying session type.

Why

Every existing command is host-shaped — ensure, ssh, repair, track all resolve a <host> and give it an SSH alias. That shape rests on MANAGED_SSH sessions, which need an OS user and the Bastion plugin enabled on a compute instance:

InvalidParameter: To create a Managed SSH session, the Bastion plugin must be enabled on
the target instance.

Plenty of things worth reaching are not compute: a private OKE API endpoint, a database, an internal HTTP service. Those need a port-forwarding session — a different OCI session type, with no plugin requirement and no target user.

What

oci-hop forward --private-ip 10.20.0.4 --target-port 6443 --local-port 16443

A deliberately thin pass-through to bastion-session forward. bastion-session owns session lifecycle, reuse, ssh option hardening and the readiness wait; duplicating any of that here would let the two drift.

--region / --profile are passed through because without a region the OCI CLI falls back to its own default and fails with NotAuthorizedOrNotFound — which reads like a permissions problem rather than a wrong-region one. I hit exactly that while testing.

Measured outcome

Against a live bastion and a real private-endpoint OKE cluster:

oci-hop forward --region us-sanjose-1 --bastion-id <id> --private-ip 10.20.0.4 --target-port 6443 --local-port 16443
forwarding 127.0.0.1:16443 -> 10.20.0.4:6443 via ocid1.bastionsession...@host.bastion.us-sanjose-1.oci.oraclecloud.com
session ocid1.bastionsession... (expires 2026-09-09T00:53:41Z). Ctrl-C to close.
kubectl --context metis --server https://127.0.0.1:16443 get nodes --no-headers
10.20.4.30    Ready   node    52d    v1.33.1
10.20.4.67    Ready   <none>  7d23h  v1.33.1

Child failures surface correctly rather than being swallowed — verified accidentally, by running it against a released bastion-session that lacks the subcommand:

unknown command "forward" for "bastion-session"
bastion-session forward exited non-zero

go build, go vet, go test ./... all clean; gofmt applied.

Dependency

Needs bastion-session with forward support, so this should land after #28 and after a bastion-session release. Until then the command exists but exits non-zero with the message above, which is at least self-explaining.

Every existing command is host-shaped: ensure auth, a MANAGED_SSH
session and an SSH alias for a compute instance. That cannot reach
things which are not compute -- a private OKE API endpoint, a database,
an internal service -- because MANAGED_SSH requires an OS user and the
Bastion plugin on the target. Those need a port-forwarding session,
which is a different OCI session type.

`oci-hop forward --private-ip X --target-port N` wraps
`bastion-session forward`. It stays a thin pass-through on purpose:
bastion-session owns session lifecycle, reuse, ssh option hardening and
the readiness wait, and duplicating any of that here would let the two
drift.

--region/--profile are passed through because without a region the OCI
CLI falls back to its own default and fails NotAuthorizedOrNotFound,
which reads like a permissions problem rather than a wrong-region one.

Requires bastion-session with forward support
(adrianmross/bastion-session#28).
Copilot AI lite review requested due to automatic review settings September 9, 2026 00:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new forward command has confirmed CLI contract inconsistencies (exit codes/flag forwarding/output handling) that can cause incorrect behavior or surprising automation differences.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a new oci-hop forward subcommand to support OCI Bastion port-forwarding sessions (non-host-shaped targets like private Kubernetes API endpoints, databases, and internal services) by delegating to bastion-session forward.

Changes:

  • Registers a new forward cobra subcommand in the root CLI.
  • Introduces cmd/oci-hop/forward.go implementing a thin argv pass-through to bastion-session forward, including region/profile override flags and stdio streaming for long-lived tunnels.
File summaries
File Description
cmd/oci-hop/main.go Wires the new forward command into the root command tree.
cmd/oci-hop/forward.go Implements the oci-hop forward command and forwards flags/stdio to bastion-session forward.
Review details
  • Files reviewed: 2/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cmd/oci-hop/forward.go
Comment on lines +44 to +50
RunE: func(cmd *cobra.Command, args []string) error {
if strings.TrimSpace(privateIP) == "" {
return fmt.Errorf("--private-ip is required")
}
if targetPort <= 0 {
return fmt.Errorf("--target-port is required")
}
Comment thread cmd/oci-hop/forward.go
Comment on lines +71 to +73
if strings.TrimSpace(identityFile) != "" {
argv = append(argv, "--ssh-private-key", identityFile)
}
Comment thread cmd/oci-hop/forward.go
Comment on lines +86 to +88
if f := strings.ToLower(strings.TrimSpace(format)); f == "json" || f == "yaml" || f == "yml" {
argv = append(argv, "-o", f)
}
@adrianmross
adrianmross merged commit 91160b3 into main Sep 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants