Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion internal/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
Expand All @@ -16,6 +17,7 @@ import (
"runtime"
"sort"
"strings"
"syscall"
"time"

"github.com/himattm/prism/internal/fsutil"
Expand Down Expand Up @@ -468,7 +470,32 @@ func (m *Manager) addFromDirectURL(rawURL string) error {
return fmt.Errorf("unsupported URL scheme: %s", parsedURL.Scheme)
}

resp, err := http.Get(parsedURL.String())
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.DisableKeepAlives = true
dialer := &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
Control: func(network, address string, c syscall.RawConn) error {
host, _, err := net.SplitHostPort(address)
if err != nil {
return err
}
if idx := strings.IndexByte(host, '%'); idx != -1 {
host = host[:idx]
}
ip := net.ParseIP(host)
if ip != nil && ip.String() == "169.254.169.254" {
return fmt.Errorf("access to cloud metadata IP is forbidden")
}
return nil
},
}
transport.DialContext = dialer.DialContext
client := &http.Client{
Timeout: 10 * time.Second,
Transport: transport,
}
resp, err := client.Get(parsedURL.String())
if err != nil {
return fmt.Errorf("failed to fetch plugin: %w", err)
}
Expand Down
Loading