File tree 2 files changed +21
-1
lines changed 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,11 @@ func (r *ReconcilePostgresUser) Reconcile(request reconcile.Request) (reconcile.
162
162
163
163
// Creation logic
164
164
var role , login string
165
- password := utils .GetRandomString (15 )
165
+ password , err := utils .GetSecureRandomString (15 )
166
+
167
+ if err != nil {
168
+ return r .requeue (instance , err )
169
+ }
166
170
167
171
if instance .Status .PostgresRole == "" {
168
172
// We need to get the Postgres CR to get the group role name
Original file line number Diff line number Diff line change 1
1
package utils
2
2
3
+ import cryptorand "crypto/rand"
3
4
import "math/rand"
5
+ import "math/big"
4
6
5
7
var letterRunes = []rune ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" )
6
8
@@ -11,3 +13,17 @@ func GetRandomString(length int) string {
11
13
}
12
14
return string (b )
13
15
}
16
+
17
+ // If the secure random number generator malfunctions it will return an error
18
+ func GetSecureRandomString (length int ) (string , error ) {
19
+ b := make ([]rune , length )
20
+ for i := 0 ; i < length ; i ++ {
21
+ num , err := cryptorand .Int (cryptorand .Reader , big .NewInt (int64 (len (letterRunes ))))
22
+ if err != nil {
23
+ return "" , err
24
+ }
25
+ b [i ] = letterRunes [num .Int64 ()]
26
+ }
27
+
28
+ return string (b ), nil
29
+ }
You can’t perform that action at this time.
0 commit comments