Skip to content

Commit

Permalink
Add support for proxy server (#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramanan-ravi authored Nov 12, 2024
1 parent 50e15e4 commit 097ba1c
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 48 deletions.
2 changes: 1 addition & 1 deletion deepfence_agent/plugins/SecretScanner
2 changes: 1 addition & 1 deletion deepfence_agent/plugins/YaraHunter
2 changes: 1 addition & 1 deletion deepfence_agent/plugins/cloud-scanner
6 changes: 4 additions & 2 deletions deepfence_agent/plugins/deepfence_shipper/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,17 @@ func NewPublisher(cfg PublisherConfig, maxRetries int, batchSize int) *Publisher
return rhttp.DefaultRetryPolicy(ctx, resp, err)
}

tr := http.DefaultTransport.(*http.Transport).Clone()
tr.Proxy = http.ProxyFromEnvironment

if cfg.URLSchema == "https" {
tr := http.DefaultTransport.(*http.Transport).Clone()
tr.TLSClientConfig = &tls.Config{
RootCAs: x509.NewCertPool(),
InsecureSkipVerify: true,
}
tr.DisableKeepAlives = false
rhc.HTTPClient.Transport = tr
}
rhc.HTTPClient.Transport = tr

hc = rhc.StandardClient()

Expand Down
2 changes: 1 addition & 1 deletion deepfence_agent/plugins/package-scanner
2 changes: 1 addition & 1 deletion deepfence_agent/plugins/yara-rules
Submodule yara-rules updated 1 files
+1 −1 build-timestamp
39 changes: 0 additions & 39 deletions deepfence_agent/tools/apache/deepfence/df-utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,11 @@ import (
"github.com/deepfence/ThreatMapper/deepfence_utils/log"
)

type PktDirection string
type PolicyAction string

const (
maxIdleConnsPerHost = 1024
HostMountDir = "/fenced/mnt/host/"
CheckTypeHIPAA = "hipaa"
CheckTypePCI = "pci"
CheckTypeNIST = "nist"
CheckTypeGDPR = "gdpr"
)

type ComplianceScan struct {
Code string `json:"code"`
Label string `json:"label"`
}

func RemoveLastCharacter(s string) string {
r := []rune(s)
return string(r[:len(r)-1])
}

func BuildHttpClientWithCert(certPath string) (*http.Client, error) {
// Set up our own certificate pool
tlsConfig := &tls.Config{RootCAs: x509.NewCertPool(), InsecureSkipVerify: true}
transport := &http.Transport{
MaxIdleConnsPerHost: maxIdleConnsPerHost,
TLSHandshakeTimeout: 0 * time.Second,
TLSClientConfig: tlsConfig,
}
client := &http.Client{Transport: transport}

// Load our trusted certificate path
pemData, err := os.ReadFile(certPath)
if err != nil {
return nil, err
}
ok := tlsConfig.RootCAs.AppendCertsFromPEM(pemData)
if !ok {
return nil, errors.New("unable to append certificates to PEM")
}
return client, nil
}

func GetKubernetesClusterId() string {
var kubeSystemNamespaceUid string
serviceHost := os.Getenv("KUBERNETES_SERVICE_HOST")
Expand Down
1 change: 1 addition & 0 deletions deepfence_bootstrapper/router/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func downloadFile(filepath string, url string) (err error) {

tr := http.DefaultTransport.(*http.Transport).Clone()
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
tr.Proxy = http.ProxyFromEnvironment

client := &http.Client{
Timeout: 5 * time.Minute,
Expand Down
1 change: 1 addition & 0 deletions deepfence_utils/threatintel/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func ExposeFile(ctx context.Context, fName string, consoleURL string, ttlCache *
func downloadFile(ctx context.Context, url string) (*bytes.Buffer, error) {

tr := http.DefaultTransport.(*http.Transport).Clone()
tr.Proxy = http.ProxyFromEnvironment
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}

client := http.Client{Timeout: 600 * time.Second}
Expand Down
6 changes: 5 additions & 1 deletion deepfence_utils/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ var (

func GetHTTPClient() *http.Client {
once1.Do(func() {
tr := http.DefaultTransport.(*http.Transport).Clone()
tr.Proxy = http.ProxyFromEnvironment

secureClient = &http.Client{
Timeout: time.Second * 10,
Transport: http.DefaultTransport.(*http.Transport).Clone(),
Transport: tr,
}
})

Expand All @@ -77,6 +80,7 @@ func GetInsecureHTTPClient() *http.Client {
tr := http.DefaultTransport.(*http.Transport).Clone()
tr.TLSClientConfig = tlsConfig
tr.WriteBufferSize = 10240
tr.Proxy = http.ProxyFromEnvironment

insecureClient = &http.Client{
Timeout: time.Second * 10,
Expand Down
1 change: 1 addition & 0 deletions deepfence_worker/cronjobs/rules_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func FetchThreatIntelListing(ctx context.Context, token string) (threatintel.Lis
tr.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
tr.Proxy = http.ProxyFromEnvironment
hc := http.Client{
Timeout: 10 * time.Second,
Transport: tr,
Expand Down
2 changes: 1 addition & 1 deletion golang_deepfence_sdk

0 comments on commit 097ba1c

Please sign in to comment.