Skip to content

A lightweight CLI that simplifies kubectl port-forward for everyday workflows. With pf, you can define named port-forward presets once and run multiple forwards in a single command

Notifications You must be signed in to change notification settings

alinemone/go-port-forward

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

31 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

pf - Port Forward Manager v2.1

Modern CLI tool for managing multiple port-forward connections with real-time monitoring and certificate support.

โœจ Features

  • ๐ŸŽจ Simple TUI - Clean terminal interface with real-time status
  • โšก Fast & Reliable - Detects connection failures quickly
  • ๐Ÿ”„ Auto-Reconnection - Automatically reconnects on failure
  • ๐Ÿงน Port Cleanup - Automatically kills conflicting processes
  • ๐Ÿ” Certificate Support - Built-in P12 certificate handling for kubectl
  • ๐Ÿ“Š Real-time Monitoring - Live status updates
  • ๐Ÿ›ก๏ธ Graceful Shutdown - Proper cleanup on exit or Ctrl+C
  • ๐Ÿ“ฆ Single Binary - No external dependencies
  • ๐ŸŒ Cross-Platform - Works on Windows, Linux, and macOS

๐Ÿ“ฅ Installation

From Source

Windows

go build -o pf.exe
# Optional: Move to a directory in PATH

Linux/macOS

go build -o pf
sudo mv pf /usr/local/bin/
sudo chmod +x /usr/local/bin/pf

From Releases

Download pre-built binaries from Releases.

๐Ÿš€ Quick Start

# Add a service
pf add db "kubectl port-forward service/postgres 5432:5432"

# Run the service
pf run db

# List all services
pf list

๐Ÿ“– Commands

Command Alias Description
add a Add new service
list l List all services
run r Run services with TUI
delete d Delete service
cleanup c Kill all kubectl/ssh processes
cert Manage certificates (add/list/remove)
help h Show help

๐Ÿ” Certificate Management

Add P12 certificates for secure kubectl connections:

# Add certificate (used for all kubectl services)
pf cert add "/path/to/certificate.p12"

# View configured certificate
pf cert list

# Remove certificate
pf cert remove

How it works:

  • Extracts certificate and private key from P12 file
  • Stores them securely in ~/.pf/certs/
  • Automatically injects --client-certificate and --client-key flags into kubectl commands
  • Password is only required during setup (not stored)

๐Ÿ’ก Usage Examples

Basic Service Management

# Add services
pf add db "kubectl -n prod port-forward service/postgres 5432:5432"
pf add redis "kubectl port-forward service/redis 6379:6379"
pf add api "kubectl port-forward deployment/api 8080:8080"

# List all services
pf list

# Run single service
pf run db

# Run multiple services
pf run db,redis,api

# Delete a service
pf delete redis

With Certificate

# 1. Add your P12 certificate
pf cert add company-vpn.p12
# Enter password when prompted

# 2. Add kubectl service (certificate will be auto-used)
pf add production "kubectl -n prod port-forward service/postgres 5432:5432"

# 3. Run the service
pf run production

Cleanup Stuck Ports

# Kill all kubectl/ssh processes
pf cleanup

๐ŸŽฎ TUI Controls

When running services:

  • q or Ctrl+C - Quit and stop all services
  • r - Manual refresh

๐Ÿ“‚ File Locations

~/.pf/
โ”œโ”€โ”€ certificate.json      โ†’ Certificate configuration
โ””โ”€โ”€ certs/
    โ”œโ”€โ”€ client-cert.pem   โ†’ Extracted certificate
    โ””โ”€โ”€ client-key.pem    โ†’ Private key

services.json             โ†’ Stored services (same directory as executable)

๐Ÿ—๏ธ Architecture

.
โ”œโ”€โ”€ main.go          โ†’ CLI entry point and commands
โ”œโ”€โ”€ manager.go       โ†’ Service lifecycle management
โ”œโ”€โ”€ storage.go       โ†’ Service persistence
โ”œโ”€โ”€ ui.go            โ†’ Terminal UI (Bubbletea)
โ””โ”€โ”€ cert/
    โ”œโ”€โ”€ p12.go       โ†’ P12 certificate extraction
    โ””โ”€โ”€ manager.go   โ†’ Certificate management

๐Ÿ”ง How It Works

  1. Port Management: Automatically detects and kills processes using target ports
  2. Service Storage: Services saved in services.json
  3. Auto-Reconnection: Automatically restarts failed connections
  4. Certificate Injection: For kubectl commands, automatically adds certificate flags
  5. Process Cleanup: Proper cleanup of all processes on exit

๐Ÿ›ก๏ธ Security

Certificate Handling

  • P12 password is only used during extraction (never stored)
  • Certificate and key files stored with 0600 permissions (owner-only)
  • Files stored in user's home directory (~/.pf/)

Antivirus Notice

This tool executes system commands (kubectl, ssh) and manages network connections, which may trigger antivirus false positives.

Recommendations:

  • Build from source to verify the code
  • Add exception in antivirus software if needed
  • Code is open source - audit anytime

๐Ÿ› Troubleshooting

Port already in use

Run pf cleanup to kill all kubectl/ssh processes.

Certificate not working

  • Verify the P12 file path is correct
  • Ensure you entered the correct password
  • Check certificate with: pf cert list

Service won't start

  • Check the command manually: kubectl port-forward ...
  • Verify kubectl context and permissions
  • Check if certificate is required

๐Ÿ’ป Development

Requirements

  • Go 1.21+
  • Dependencies:
    • github.com/charmbracelet/bubbletea - TUI framework
    • github.com/charmbracelet/lipgloss - Styling
    • software.sslmate.com/src/go-pkcs12 - P12 handling

Build

go build -o pf

Cross-Platform Build

# Windows
GOOS=windows GOARCH=amd64 go build -o pf.exe

# Linux
GOOS=linux GOARCH=amd64 go build -o pf

# macOS
GOOS=darwin GOARCH=amd64 go build -o pf

๐Ÿค Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest features
  • Submit pull requests

๐Ÿ“„ License

Open source - feel free to use and modify.


Simple. Secure. Reliable.

About

A lightweight CLI that simplifies kubectl port-forward for everyday workflows. With pf, you can define named port-forward presets once and run multiple forwards in a single command

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages