Skip to content

Commit 24ef0c4

Browse files
authored
Fix/Windows Hosts Path Auto-Detection (#359)
* Sign release artifacts with Cosign in GoReleaser configuration - Updated `.goreleaser.yml` to sign both archive and checksum artifacts using Cosign (keyless OIDC). - Added specific arguments and signature templates for artifact signing. * Update .gitignore to exclude /kubefwd.* files * Use OS-specific hosts file path detection in `--hosts-path` flag. * Use explicit ids for cosign signs in .goreleaser.yml * Set global timeout for fuzz tests in CI workflow - Added a `-timeout=60s` flag to fuzz tests to ensure a total timeout for each test’s setup and teardown process.
1 parent 1351ad1 commit 24ef0c4

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ jobs:
8989

9090
- name: Run fuzz tests
9191
run: |
92-
# Run each fuzz test for 30 seconds
92+
# Run each fuzz test for 30 seconds with 60s total timeout for setup/teardown
9393
echo "Running FuzzIpFromString..."
94-
go test -fuzz=FuzzIpFromString -fuzztime=30s ./pkg/fwdip/...
94+
go test -fuzz=FuzzIpFromString -fuzztime=30s -timeout=60s ./pkg/fwdip/...
9595
echo "Running FuzzServiceConfigurationFromReservation..."
96-
go test -fuzz=FuzzServiceConfigurationFromReservation -fuzztime=30s ./pkg/fwdip/...
96+
go test -fuzz=FuzzServiceConfigurationFromReservation -fuzztime=30s -timeout=60s ./pkg/fwdip/...
9797
9898
build:
9999
name: Build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dist
77
vendor
88
dist/
99
/kubefwd
10+
/kubefwd.*
1011
RELEASE_*
1112
NOTES_*
1213
site/

.goreleaser.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,19 @@ archives:
5454
checksum:
5555
name_template: '{{ .ProjectName }}_checksums.txt'
5656

57-
# Sign checksums with Cosign (keyless - uses OIDC identity)
57+
# Sign release artifacts with Cosign (keyless - uses OIDC identity)
5858
signs:
59-
- cmd: cosign
59+
- id: archives
60+
cmd: cosign
61+
artifacts: archive
62+
signature: "${artifact}.sigstore.json"
63+
args:
64+
- "sign-blob"
65+
- "--yes"
66+
- "--bundle=${signature}"
67+
- "${artifact}"
68+
- id: checksums
69+
cmd: cosign
6070
artifacts: checksum
6171
signature: "${artifact}.sigstore.json"
6272
args:

cmd/kubefwd/services/services.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"os"
88
"os/signal"
9+
"runtime"
910
"sync"
1011
"syscall"
1112
"time"
@@ -56,6 +57,14 @@ var autoReconnect bool
5657
// Version is set by the main package
5758
var Version string
5859

60+
// defaultHostsPath returns the OS-appropriate hosts file path
61+
func defaultHostsPath() string {
62+
if runtime.GOOS == "windows" {
63+
return `C:\Windows\System32\drivers\etc\hosts`
64+
}
65+
return "/etc/hosts"
66+
}
67+
5968
func init() {
6069
// override error output from k8s.io/apimachinery/pkg/util/runtime
6170
utilRuntime.ErrorHandlers[0] = func(_ context.Context, err error, _ string, _ ...interface{}) {
@@ -75,7 +84,7 @@ func init() {
7584
Cmd.Flags().StringSliceVarP(&fwdReservations, "reserve", "r", []string{}, "Specify an IP reservation. Specify multiple reservations by duplicating this argument.")
7685
Cmd.Flags().StringVarP(&fwdConfigurationPath, "fwd-conf", "z", "", "Define an IP reservation configuration")
7786
Cmd.Flags().IntVarP(&timeout, "timeout", "t", 300, "Specify a timeout seconds for the port forwarding.")
78-
Cmd.Flags().StringVar(&hostsPath, "hosts-path", "/etc/hosts", "Hosts Path default /etc/hosts.")
87+
Cmd.Flags().StringVar(&hostsPath, "hosts-path", defaultHostsPath(), "Hosts file path.")
7988
Cmd.Flags().BoolVarP(&refreshHostsBackup, "refresh-backup", "b", false, "Create a fresh hosts backup, replacing any existing backup.")
8089
Cmd.Flags().BoolVarP(&purgeStaleIps, "purge-stale-ips", "p", false, "Remove stale kubefwd host entries (IPs in 127.1.27.1 - 127.255.255.255 range) before starting.")
8190
Cmd.Flags().DurationVar(&resyncInterval, "resync-interval", 5*time.Minute, "Interval for forced service resync (e.g., 1m, 5m, 30s)")

0 commit comments

Comments
 (0)