Skip to content

Commit 3ec666d

Browse files
feat(ldap): add option to load ldap from file
Signed-off-by: Laurentiu Niculae <[email protected]>
1 parent 2db6e86 commit 3ec666d

File tree

10 files changed

+759
-40
lines changed

10 files changed

+759
-40
lines changed

examples/config-ldap-credentials.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"bindDN":"cn=ldap-searcher,ou=Users,dc=example,dc=org",
3+
"bindPassword":"ldap-searcher-password"
4+
}

examples/config-ldap.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"auth": {
1515
"ldap": {
16+
"credentialsFile": "",
1617
"address": "ldap.example.org",
1718
"port": 389,
1819
"startTLS": false,

pkg/api/authn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ func (amw *AuthnMiddleware) tryAuthnHandlers(ctlr *Controller) mux.MiddlewareFun
266266
UseSSL: !ldapConfig.Insecure,
267267
SkipTLS: !ldapConfig.StartTLS,
268268
Base: ldapConfig.BaseDN,
269-
BindDN: ldapConfig.BindDN,
269+
BindDN: ldapConfig.BindDN(),
270+
BindPassword: ldapConfig.BindPassword(),
270271
UserGroupAttribute: ldapConfig.UserGroupAttribute, // from config
271-
BindPassword: ldapConfig.BindPassword,
272272
UserFilter: fmt.Sprintf("(%s=%%s)", ldapConfig.UserAttribute),
273273
InsecureSkipVerify: ldapConfig.SkipVerify,
274274
ServerName: ldapConfig.Address,

pkg/api/config/config.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,48 @@ type SchedulerConfig struct {
121121
NumWorkers int
122122
}
123123

124+
type LDAPCredentials struct {
125+
BindDN string
126+
BindPassword string
127+
}
128+
124129
type LDAPConfig struct {
130+
CredentialsFile string
131+
Unauthenticated bool
125132
Port int
126133
Insecure bool
127134
StartTLS bool // if !Insecure, then StartTLS or LDAPs
128135
SkipVerify bool
129136
SubtreeSearch bool
130137
Address string
131-
BindDN string
138+
bindDN string `json:"-"`
139+
bindPassword string `json:"-"`
132140
UserGroupAttribute string
133-
BindPassword string
134141
BaseDN string
135142
UserAttribute string
136143
CACert string
137144
}
138145

146+
func (ldapConf *LDAPConfig) BindDN() string {
147+
return ldapConf.bindDN
148+
}
149+
150+
func (ldapConf *LDAPConfig) SetBindDN(bindDN string) *LDAPConfig {
151+
ldapConf.bindDN = bindDN
152+
153+
return ldapConf
154+
}
155+
156+
func (ldapConf *LDAPConfig) BindPassword() string {
157+
return ldapConf.bindPassword
158+
}
159+
160+
func (ldapConf *LDAPConfig) SetBindPassword(bindPassword string) *LDAPConfig {
161+
ldapConf.bindPassword = bindPassword
162+
163+
return ldapConf
164+
}
165+
139166
type LogConfig struct {
140167
Level string
141168
Output string
@@ -266,14 +293,14 @@ func (c *Config) Sanitize() *Config {
266293
panic(err)
267294
}
268295

269-
if c.HTTP.Auth != nil && c.HTTP.Auth.LDAP != nil && c.HTTP.Auth.LDAP.BindPassword != "" {
296+
if c.HTTP.Auth != nil && c.HTTP.Auth.LDAP != nil && c.HTTP.Auth.LDAP.bindPassword != "" {
270297
sanitizedConfig.HTTP.Auth.LDAP = &LDAPConfig{}
271298

272299
if err := DeepCopy(c.HTTP.Auth.LDAP, sanitizedConfig.HTTP.Auth.LDAP); err != nil {
273300
panic(err)
274301
}
275302

276-
sanitizedConfig.HTTP.Auth.LDAP.BindPassword = "******"
303+
sanitizedConfig.HTTP.Auth.LDAP.bindPassword = "******"
277304
}
278305

279306
return sanitizedConfig

pkg/api/config/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ func TestConfig(t *testing.T) {
6969
Convey("Test DeepCopy() & Sanitize()", t, func() {
7070
conf := config.New()
7171
So(conf, ShouldNotBeNil)
72-
authConfig := &config.AuthConfig{LDAP: &config.LDAPConfig{BindPassword: "oina"}}
72+
authConfig := &config.AuthConfig{LDAP: (&config.LDAPConfig{}).SetBindPassword("oina")}
7373
conf.HTTP.Auth = authConfig
7474
So(func() { conf.Sanitize() }, ShouldNotPanic)
7575
conf = conf.Sanitize()
76-
So(conf.HTTP.Auth.LDAP.BindPassword, ShouldEqual, "******")
76+
So(conf.HTTP.Auth.LDAP.BindPassword(), ShouldEqual, "******")
7777

7878
// negative
7979
obj := make(chan int)

0 commit comments

Comments
 (0)