Skip to content

Commit e405ead

Browse files
committed
groups->ldapgroups
1 parent 92259c6 commit e405ead

File tree

3 files changed

+99
-12
lines changed

3 files changed

+99
-12
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ so, let's say you built the 'sqlite' plugin, you would now specify its library:
3535
### SQLite, MySQL, Postgres
3636

3737
Tables:
38-
- users, groups are self-explanatory
38+
- users, ldapgroups are self-explanatory
3939
- includegroups store the 'includegroups' relationships
4040
- othergroups, on the other hand, are a comma-separated list found in the users table (performance)
4141

4242
Here is how to insert example data using your database's REPL (more detailed information can be found in pkg/plugins/sample-database.cfg)
4343

4444
```sql
45-
INSERT INTO groups(name, gidnumber) VALUES('superheros', 5501);
46-
INSERT INTO groups(name, gidnumber) VALUES('svcaccts', 5502);
47-
INSERT INTO groups(name, gidnumber) VALUES('civilians', 5503);
48-
INSERT INTO groups(name, gidnumber) VALUES('caped', 5504);
49-
INSERT INTO groups(name, gidnumber) VALUES('lovesailing', 5505);
50-
INSERT INTO groups(name, gidnumber) VALUES('smoker', 5506);
45+
INSERT INTO ldapgroups(name, gidnumber) VALUES('superheros', 5501);
46+
INSERT INTO ldapgroups(name, gidnumber) VALUES('svcaccts', 5502);
47+
INSERT INTO ldapgroups(name, gidnumber) VALUES('civilians', 5503);
48+
INSERT INTO ldapgroups(name, gidnumber) VALUES('caped', 5504);
49+
INSERT INTO ldapgroups(name, gidnumber) VALUES('lovesailing', 5505);
50+
INSERT INTO ldapgroups(name, gidnumber) VALUES('smoker', 5506);
5151
INSERT INTO includegroups(parentgroupid, includegroupid) VALUES(5503, 5501);
5252
INSERT INTO includegroups(parentgroupid, includegroupid) VALUES(5504, 5502);
5353
INSERT INTO includegroups(parentgroupid, includegroupid) VALUES(5504, 5501);

postgres.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

66
_ "github.com/lib/pq"
77

8-
"github.com/glauth/glauth/v2/pkg/plugins"
98
"github.com/glauth/glauth/v2/pkg/handler"
9+
"github.com/glauth/glauth/v2/pkg/plugins"
1010
)
1111

1212
type PostgresBackend struct {
@@ -50,9 +50,9 @@ CREATE TABLE IF NOT EXISTS users (
5050
statement.Exec()
5151
statement, _ = db.Prepare("CREATE UNIQUE INDEX IF NOT EXISTS idx_user_name on users(name)")
5252
statement.Exec()
53-
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS groups (id SERIAL PRIMARY KEY, name TEXT NOT NULL, gidnumber INTEGER NOT NULL)")
53+
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS ldapgroups (id SERIAL PRIMARY KEY, name TEXT NOT NULL, gidnumber INTEGER NOT NULL)")
5454
statement.Exec()
55-
statement, _ = db.Prepare("CREATE UNIQUE INDEX IF NOT EXISTS idx_group_name on groups(name)")
55+
statement, _ = db.Prepare("CREATE UNIQUE INDEX IF NOT EXISTS idx_group_name on ldapgroups(name)")
5656
statement.Exec()
5757
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS includegroups (id SERIAL PRIMARY KEY, parentgroupid INTEGER NOT NULL, includegroupid INTEGER NOT NULL)")
5858
statement.Exec()
@@ -61,9 +61,15 @@ CREATE TABLE IF NOT EXISTS users (
6161
}
6262

6363
// Migrate schema if necessary
64-
func (b PostgresBackend) MigrateSchema(db *sql.DB, checker func(*sql.DB, string) bool) {
65-
if !checker(db, "sshkeys") {
64+
func (b PostgresBackend) MigrateSchema(db *sql.DB, checker func(*sql.DB, string, string) bool) {
65+
if !checker(db, "users", "sshkeys") {
6666
statement, _ := db.Prepare("ALTER TABLE users ADD COLUMN sshkeys TEXT DEFAULT ''")
6767
statement.Exec()
6868
}
69+
if checker(db, "groups", "name") {
70+
statement, _ := db.Prepare("DROP TABLE ldapgroups")
71+
statement.Exec()
72+
statement, _ = db.Prepare("ALTER TABLE groups RENAME TO ldapgroups")
73+
statement.Exec()
74+
}
6975
}

sample-psql.cfg

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#################
2+
# glauth.conf
3+
4+
#################
5+
# General configuration.
6+
debug = true
7+
# syslog = true
8+
# structuredlog = true
9+
#
10+
# Enable hot-reload of configuration on changes
11+
# - does NOT work [ldap], [ldaps], [backend] or [api] sections
12+
# watchconfig = true
13+
14+
#################
15+
# yubikeyclientid = "yubi-api-clientid"
16+
# yubikeysecret = "yubi-api-secret"
17+
18+
#################
19+
# Server configuration.
20+
[ldap]
21+
enabled = true
22+
# run on a non privileged port
23+
listen = "0.0.0.0:3893"
24+
25+
[ldaps]
26+
# to enable ldaps generate a certificate, eg. with:
27+
# openssl req -x509 -newkey rsa:4096 -keyout glauth.key -out glauth.crt -days 365 -nodes -subj '/CN=`hostname`'
28+
enabled = false
29+
listen = "0.0.0.0:3894"
30+
cert = "glauth.crt"
31+
key = "glauth.key"
32+
33+
#################
34+
# The backend section controls the data store.
35+
[backend]
36+
datastore = "plugin"
37+
plugin = "bin/postgres-linux-amd64.so"
38+
pluginHandler = "NewPostgresHandler"
39+
database = "host=127.0.0.1 port=5432 dbname=glauth user=glauthtest password=glauth sslmode=disable"
40+
baseDN = "dc=glauth,dc=com"
41+
nameformat = "cn"
42+
groupformat = "ou"
43+
44+
# If you are using a client that requires reading the root DSE first
45+
# such as SSSD
46+
# anonymousdse = true
47+
48+
## Configure dn format to use structures like
49+
## "uid=serviceuser,cn=svcaccts,$BASEDN" instead of "cn=serviceuser,ou=svcaccts,$BASEDN"
50+
## to help ease migrations from other LDAP systems
51+
# nameformat = "uid"
52+
# groupformat = "cn"
53+
54+
## Configure ssh-key attribute name, default is 'sshPublicKey'
55+
# sshkeyattr = "ipaSshPubKey"
56+
57+
[behaviors]
58+
# Ignore all capabilities restrictions, for instance allowing every user to perform a search
59+
IgnoreCapabilities = false
60+
# Enable a "fail2ban" type backoff mechanism temporarily banning repeated failed login attempts
61+
LimitFailedBinds = true
62+
# How many failed login attempts are allowed before a ban is imposed
63+
NumberOfFailedBinds = 3
64+
# How long (in seconds) is the window for failed login attempts
65+
PeriodOfFailedBinds = 10
66+
# How long (in seconds) is the ban duration
67+
BlockFailedBindsFor = 60
68+
# Clean learnt IP addresses every N seconds
69+
PruneSourceTableEvery = 600
70+
# Clean learnt IP addresses not seen in N seconds
71+
PruneSourcesOlderThan = 600
72+
73+
#################
74+
# Enable and configure the optional REST API here.
75+
[api]
76+
enabled = true
77+
internals = true # debug application performance
78+
tls = false # enable TLS for production!!
79+
listen = "0.0.0.0:5555"
80+
cert = "cert.pem"
81+
key = "key.pem"

0 commit comments

Comments
 (0)