Change to using group roles and dbowner roles

This commit is contained in:
Alex D. 2024-10-17 19:41:18 +00:00
parent 8fea0e21fb
commit 86abbc1fb3
Signed by: caskd
GPG Key ID: F92BA85F61F4C173

15
main.go
View File

@ -45,8 +45,11 @@ func main() {
v []string
)
v, _ = pairs[user]
pairs[user] = append(v, db)
// Groups
if user != db {
v, _ = pairs[user]
pairs[user] = append(v, db)
}
databases[db] = nil
}
@ -54,13 +57,15 @@ func main() {
hbabuf.WriteString("local\tall\tpostgres\ttrust\n")
for d := range databases {
initbuf.WriteString(fmt.Sprintf("CREATE DATABASE %s;\n", d))
initbuf.WriteString(fmt.Sprintf("CREATE ROLE %s LOGIN;\n", d))
initbuf.WriteString(fmt.Sprintf("CREATE DATABASE %s OWNER %s;\n", d, d))
hbabuf.WriteString(fmt.Sprintf("hostssl\t%s\t%s\tall\tcert\tclientcert=verify-full\n", d, d))
}
for u, v := range pairs {
initbuf.WriteString(fmt.Sprintf("CREATE USER %s LOGIN;\n", u))
initbuf.WriteString(fmt.Sprintf("CREATE ROLE %s LOGIN;\n", u))
for _, d := range v {
initbuf.WriteString(fmt.Sprintf("GRANT ALL PRIVILEGES ON DATABASE %s TO %s;\n", d, u))
initbuf.WriteString(fmt.Sprintf("GRANT %s TO %s;\n", d, u))
hbabuf.WriteString(fmt.Sprintf("hostssl\t%s\t%s\tall\tcert\tclientcert=verify-full\n", u, d))
}
}