Skip to content

Commit

Permalink
Fix security issues
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Nov 25, 2024
1 parent eca1436 commit 3c3c100
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 5 additions & 2 deletions pkg/imagepuller/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ package imagepuller
import (
//"k8s.io/apimachinery/pkg/watch"
"context"
"crypto/rand"
"fmt"
"log"
"math/rand"
"math/big"
"os"
"sync"
"time"
Expand Down Expand Up @@ -191,7 +192,9 @@ func setWorkingNodes(kubeClientset kubernetes.Interface) error {
func generatePodGroupName() string {
b := make([]byte, lengthStr)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
max := big.NewInt(int64(len(letterBytes)))
randomNumber, _ := rand.Int(rand.Reader, max)
b[i] = letterBytes[randomNumber.Int64()]
}
return "pod-group-" + string(b)
}
15 changes: 9 additions & 6 deletions pkg/resourcemanager/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package resourcemanager

import (
"bytes"
"crypto/rand"
"crypto/tls"
"encoding/json"
"fmt"
"log"
"math/rand"
"math/big"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -131,7 +132,7 @@ func DelegateJob(service *types.Service, event string, logger *log.Logger) error
// Make HTTP client
var transport http.RoundTripper = &http.Transport{
// Enable/disable SSL verification
TLSClientConfig: &tls.Config{InsecureSkipVerify: !cluster.SSLVerify},
TLSClientConfig: &tls.Config{InsecureSkipVerify: !cluster.SSLVerify}, // #nosec
}
client := &http.Client{
Transport: transport,
Expand Down Expand Up @@ -193,7 +194,7 @@ func DelegateJob(service *types.Service, event string, logger *log.Logger) error
// Make HTTP client
var transport http.RoundTripper = &http.Transport{
// Enable/disable SSL verification
TLSClientConfig: &tls.Config{InsecureSkipVerify: !replica.SSLVerify},
TLSClientConfig: &tls.Config{InsecureSkipVerify: !replica.SSLVerify}, // #nosec
}
client := &http.Client{
Transport: transport,
Expand Down Expand Up @@ -269,7 +270,7 @@ func updateServiceToken(replica types.Replica, cluster types.Cluster) (string, e
// Make HTTP client
var transport http.RoundTripper = &http.Transport{
// Enable/disable SSL verification
TLSClientConfig: &tls.Config{InsecureSkipVerify: !cluster.SSLVerify},
TLSClientConfig: &tls.Config{InsecureSkipVerify: !cluster.SSLVerify}, // #nosec
}
client := &http.Client{
Transport: transport,
Expand Down Expand Up @@ -344,7 +345,7 @@ func getClusterStatus(service *types.Service) {
// Make HTTP client
var transport http.RoundTripper = &http.Transport{
// Enable/disable SSL verification
TLSClientConfig: &tls.Config{InsecureSkipVerify: !cluster.SSLVerify},
TLSClientConfig: &tls.Config{InsecureSkipVerify: !cluster.SSLVerify}, // #nosec
}
client := &http.Client{
Transport: transport,
Expand Down Expand Up @@ -395,7 +396,9 @@ func getClusterStatus(service *types.Service) {
if dist >= 0 {
fmt.Println("Resources available in ClusterID", replica.ClusterID)
if service.Delegation == "random" {
randPriority := rand.Intn(noDelegateCode)
max := big.NewInt(int64(noDelegateCode))
randomNumber, _ := rand.Int(rand.Reader, max)
randPriority := randomNumber.Int64()
replica.Priority = uint(randPriority)
fmt.Println("Priority ", replica.Priority, " with ", service.Delegation, " delegation")
} else if service.Delegation == "load-based" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (minIOProvider MinIOProvider) GetS3Client() *s3.S3 {
// Disable tls verification in client transport if Verify == false
if !minIOProvider.Verify {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // #nosec
}
s3MinIOConfig.HTTPClient = &http.Client{Transport: tr}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func MakeMinIOAdminClient(cfg *types.Config) (*MinIOAdminClient, error) {
// Disable tls verification in client transport if verify == false
if !cfg.MinIOProvider.Verify {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // #nosec
}
adminClient.SetCustomTransport(tr)
}
Expand Down

0 comments on commit 3c3c100

Please sign in to comment.