Skip to content

Commit f413da8

Browse files
committed
fix gosec issues
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 3f3b3d4 commit f413da8

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

cloudprovider/azure.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ func (m *CloudProviderAzure) Init(ctx context.Context, opts config.Opts) {
4747
}
4848

4949
if m.opts.CloudProvider.Config != nil {
50-
os.Setenv("AZURE_AUTH_LOCATION", *m.opts.CloudProvider.Config)
50+
if err := os.Setenv("AZURE_AUTH_LOCATION", *m.opts.CloudProvider.Config); err != nil {
51+
m.log.Panic(err)
52+
}
5153
}
5254

5355
// environment

manager/manager.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package manager
33
import (
44
"bytes"
55
"context"
6+
"crypto/rand"
67
"fmt"
78
"github.com/prometheus/client_golang/prometheus"
89
log "github.com/sirupsen/logrus"
@@ -17,7 +18,7 @@ import (
1718
"k8s.io/client-go/rest"
1819
"k8s.io/client-go/tools/clientcmd"
1920
"k8s.io/client-go/util/retry"
20-
"math/rand"
21+
"math/big"
2122
"os"
2223
"text/template"
2324
"time"
@@ -50,7 +51,6 @@ type (
5051

5152
func (m *KubeBootstrapTokenManager) Init() {
5253
m.ctx = context.Background()
53-
rand.Seed(time.Now().UnixNano())
5454
m.initK8s()
5555
m.initPrometheus()
5656
m.initCloudProvider()
@@ -332,9 +332,13 @@ func (m *KubeBootstrapTokenManager) generateTokenId() string {
332332
func (m *KubeBootstrapTokenManager) generateTokenSecret() string {
333333
b := make([]rune, m.Opts.BootstrapToken.TokenLength)
334334
runes := []rune(m.Opts.BootstrapToken.TokenRunes)
335-
runeLength := len(runes)
335+
runeLength := int64(len(runes))
336336
for i := range b {
337-
b[i] = runes[rand.Intn(runeLength)]
337+
if val, err := rand.Int(rand.Reader, big.NewInt(runeLength)); err == nil {
338+
b[i] = runes[val.Uint64()]
339+
} else {
340+
log.Panic(err)
341+
}
338342
}
339343
return string(b)
340344
}

0 commit comments

Comments
 (0)