Skip to content

Commit 58e80a9

Browse files
author
Jeff McCormick
committed
psw docs and config changes related to
1 parent 0e16dd1 commit 58e80a9

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

client/cmd/psw.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/crunchydata/postgres-operator/operator/util"
2727
//"github.com/crunchydata/postgres-operator/tpr"
2828
"github.com/spf13/cobra"
29-
//"github.com/spf13/viper"
29+
"github.com/spf13/viper"
3030
//"io/ioutil"
3131
//kerrors "k8s.io/apimachinery/pkg/api/errors"
3232
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -47,6 +47,11 @@ type PswResult struct {
4747
ConnDetails ConnInfo
4848
}
4949

50+
const DEFAULT_AGE_DAYS = 365
51+
const DEFAULT_PSW_LEN = 8
52+
53+
var PasswordAgeDays, PasswordLength int
54+
5055
var Expired string
5156
var UpdatePasswords bool
5257

@@ -71,6 +76,7 @@ func init() {
7176
pswCmd.Flags().StringVarP(&Selector, "selector", "s", "", "The selector to use for cluster filtering ")
7277
pswCmd.Flags().StringVarP(&Expired, "expired", "e", "", "--expired=7 shows passwords that will expired in 7 days")
7378
pswCmd.Flags().BoolVarP(&UpdatePasswords, "update-passwords", "u", false, "--update-passwords performs password updating on expired passwords")
79+
getDefaults()
7480

7581
}
7682

@@ -103,8 +109,8 @@ func passwordManager() {
103109
for _, v := range results {
104110
fmt.Printf("RoleName %s Role Valid Until %s\n", v.Rolname, v.Rolvaliduntil)
105111
if UpdatePasswords {
106-
newPassword := util.GeneratePassword(8)
107-
newExpireDate := GeneratePasswordExpireDate(60)
112+
newPassword := util.GeneratePassword(PasswordLength)
113+
newExpireDate := GeneratePasswordExpireDate(PasswordAgeDays)
108114
err = updatePassword(v, newPassword, newExpireDate)
109115
if err != nil {
110116
fmt.Println("error in updating password")
@@ -246,3 +252,20 @@ func GeneratePasswordExpireDate(daysFromNow int) string {
246252
return futureTime.Format("2006-01-02")
247253

248254
}
255+
256+
func getDefaults() {
257+
PasswordAgeDays = DEFAULT_AGE_DAYS
258+
PasswordLength = DEFAULT_PSW_LEN
259+
str := viper.GetString("CLUSTER.PASSWORD_AGE_DAYS")
260+
if str != "" {
261+
PasswordAgeDays, _ = strconv.Atoi(str)
262+
log.Debugf("PasswordAgeDays set to %d\n", PasswordAgeDays)
263+
264+
}
265+
str = viper.GetString("CLUSTER.PASSWORD_LENGTH")
266+
if str != "" {
267+
PasswordLength, _ = strconv.Atoi(str)
268+
log.Debugf("PasswordLength set to %d\n", PasswordLength)
269+
}
270+
271+
}

client/cmd/root.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,21 @@ func validateConfig() {
217217
os.Exit(2)
218218
}
219219
}
220+
passwordAge := viper.GetString("CLUSTER.PASSWORD_AGE_DAYS")
221+
if passwordAge != "" {
222+
_, err := resource.ParseQuantity(passwordAge)
223+
if err != nil {
224+
log.Error("CLUSTER.PASSWORD_AGE not a valid quantity")
225+
os.Exit(2)
226+
}
227+
}
228+
passwordLen := viper.GetString("CLUSTER.PASSWORD_LENGTH")
229+
if passwordLen != "" {
230+
_, err := resource.ParseQuantity(passwordLen)
231+
if err != nil {
232+
log.Error("CLUSTER.PASSWORD_LENGTH not a valid quantity")
233+
os.Exit(2)
234+
}
235+
}
220236

221237
}

docs/config.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ CLUSTER:
3838
STRATEGY: 1
3939
REPLICAS: 0
4040
POLICIES: policy1,policy2
41+
PASSWORD_AGE_DAYS: 60
42+
PASSWORD_LENGTH: 8
4143
MASTER_STORAGE:
4244
PVC_NAME: crunchy-pvc
4345
STORAGE_CLASS: standard
@@ -85,6 +87,8 @@ Values in the pgo configuration file have the following meaning:
8587
|CLUSTER.STRATEGY | sets the deployment strategy to be used for deploying a cluster, currently there is only strategy *1*
8688
|CLUSTER.REPLICAS | the number of cluster replicas to create for newly created clusters
8789
|CLUSTER.POLICIES | optional, list of policies to apply to a newly created cluster, comma separated, must be valid policies in the catalog
90+
|CLUSTER.PASSWORD_AGE_DAYS | optional, if set, will set the VALID UNTIL date on passwords to this many days in the future when creating users or setting passwords, defaults to 365 days
91+
|CLUSTER.PASSWORD_LENGTH | optional, if set, will determine the password length used when creating passwords, defaults to 8
8892
|MASTER_STORAGE.PVC_NAME |for the master postgres deployment, if set, the PVC to use for created databases, used when the storage type is *existing*
8993
|MASTER_STORAGE.STORAGE_CLASS |for the master postgres deployment, for a dynamic storage type, you can specify the storage class used for storage provisioning(e.g. standard, gold, fast)
9094
|MASTER_STORAGE.PVC_ACCESS_MODE |for the master postgres deployment, the access mode for new PVCs (e.g. ReadWriteMany, ReadWriteOnce)

examples/pgo.yaml.emptydir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CLUSTER:
99
PG_PASSWORD: password
1010
PG_DATABASE: userdb
1111
PG_ROOT_PASSWORD: password
12+
PASSWORD_AGE_DAYS: 60
13+
PASSWORD_LENGTH: 8
1214
STRATEGY: 1
1315
REPLICAS: 0
1416
MASTER_STORAGE:

examples/pgo.yaml.nfs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CLUSTER:
99
PG_PASSWORD: password
1010
PG_DATABASE: userdb
1111
PG_ROOT_PASSWORD: password
12+
PASSWORD_AGE_DAYS: 60
13+
PASSWORD_LENGTH: 8
1214
STRATEGY: 1
1315
REPLICAS: 0
1416
MASTER_STORAGE:

examples/pgo.yaml.storageclass

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CLUSTER:
99
PG_PASSWORD: password
1010
PG_DATABASE: userdb
1111
PG_ROOT_PASSWORD: password
12+
PASSWORD_AGE_DAYS: 60
13+
PASSWORD_LENGTH: 8
1214
STRATEGY: 1
1315
REPLICAS: 0
1416
MASTER_STORAGE:

0 commit comments

Comments
 (0)