Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap config fails with type mismatch #50

Open
khdevel opened this issue Aug 14, 2015 · 7 comments
Open

ldap config fails with type mismatch #50

khdevel opened this issue Aug 14, 2015 · 7 comments

Comments

@khdevel
Copy link

khdevel commented Aug 14, 2015

Hi,
When trying to deploy the ldap authentication for grafana I'm experiencing an issue with port variable being treated as string and not an integer.
This is a part of the config file:

ldap_cfg => {
servers => [
{ host => 'blabla.host',
ssl_skip_verify => true,
use_ssl => true,
search_filter => '(uid=%s)',
search_base_dns => [ 'cn=bla,cn=bla,dc=bla' ],
bind_dn => 'uid=%s,cn=bla,cn=bla,dc=bla',
port => '636',
},

And the output ldap.toml file looks like:

[[servers]]
bind_dn = "uid=%s,cn=bla,cn=bla,dc=bla"
host = "bla.host"
port = "636"
search_base_dns = ["cn=bla,cn=bla,dc=bla"]
search_filter = "(uid=%s)"
ssl_skip_verify = true
use_ssl = true"

It doesn't matter whether I change port to:
port => 636,
In the ldap.toml file I still get this value as string. Also trying not to specify any port results in an error where it uses 0 as port. Anyone seen something like this?

@Ev1l
Copy link

Ev1l commented Sep 10, 2015

Yes, seeing this myself as well.

2015/09/09 21:53:24 [log.go:75 Fatal()] [E] Failed to load ldap config file: Type mismatch for 'login.LdapConfig.servers': Type mismatch for 'login.LdapServerConf.port': Expected integer but found 'string'.

Also for some reason puppet writes the config to the ldap.toml in random order, and causes another error.

2015/09/09 21:51:59 [log.go:75 Fatal()] [E] Failed to load ldap config file: Near line 17 (last key parsed ''): Key '' was already created and cannot be used as an array.

This will happen if the field [[servers]] ends up under any other field like [[servers.group_mappings]]. Very frustrating because you never know what order you will get. But the string/integer error is very annoying since it will get double quoted no matter what you do.

@slick666
Copy link

I think these are two separate issues. The quotes around the 636 port being one but the issue @Ev1l is talking about seems to be an ordering issue. For me when I saw that Key '' was already created error it was because the [[server]] appears after the [server.attributes] header. Rearranging them in the file fixed it for me.
To get this in puppet I had to do

servers => [
        { ...
          'servers.attributes' => {
            ...
          },
        }
      ],

Still stuck on the string quote issue though.

@slick666
Copy link

@khdevel My solution to your problem was to template out the TOML file separately. It's a little hacky but it seems to work.

@Ev1l
Copy link

Ev1l commented Oct 30, 2015

@slick666 do you have an example of the templating you can share? Seems that will be the only way that this can work or else it might break after each puppet run.

@jaredledvina
Copy link

I'm experiencing the exact issue described here. I took a look at the TOML ruby gem but don't see anything obvious as to why this is happening. Looks like I'll need to go the template-ing route until this is resolved.

@adamcstephens - I see that you created the PR in #43. Have you run into this?

@bfraser
Copy link
Owner

bfraser commented Oct 31, 2015

@jaredledvina I agree, it doesn't appear to be the TOML gem that is causing this. As you can see here, the string returned by TOML::Generator.new(@ldap_cfg).body does not have the port number in quotes.

$ irb
2.2.1 :001 > require 'toml'
 => true 
2.2.1 :002 > ldap_cfg = {
2.2.1 :003 >     'servers' => [
2.2.1 :004 >           { 'host' => 'blabla.host',
2.2.1 :005 >               'ssl_skip_verify' => true,
2.2.1 :006 >               'use_ssl' => true,
2.2.1 :007 >               'search_filter' => '(uid=%s)',
2.2.1 :008 >               'search_base_dns' => [ 'cn=bla,cn=bla,dc=bla' ],
2.2.1 :009 >               'bind_dn' => 'uid=%s,cn=bla,cn=bla,dc=bla',
2.2.1 :010 >               'port' => 636,
2.2.1 :011 >             },
2.2.1 :012 >         ]
2.2.1 :013?>   }
 => {"servers"=>[{"host"=>"blabla.host", "ssl_skip_verify"=>true, "use_ssl"=>true, "search_filter"=>"(uid=%s)", "search_base_dns"=>["cn=bla,cn=bla,dc=bla"], "bind_dn"=>"uid=%s,cn=bla,cn=bla,dc=bla", "port"=>636}]} 
2.2.1 :014 > puts TOML::Generator.new(ldap_cfg).body

[[servers]]
bind_dn = "uid=%s,cn=bla,cn=bla,dc=bla"
host = "blabla.host"
port = 636
search_base_dns = ["cn=bla,cn=bla,dc=bla"]
search_filter = "(uid=%s)"
ssl_skip_verify = true
use_ssl = true
 => nil 
2.2.1 :015 > 

However, I don't understand at this point where the quotes are being added. Maybe it's got something to do with how the variable is referenced, or there's some manipulation being done by the inline_template function when it returns the string to the content parameter. Either way, this is not something I've seen before and I'm open to suggestions.

@adamcstephens
Copy link
Contributor

Finally had time to look at this, and it appears I worked around the issue. Puppet is converting it into a string, not the toml gem. My workaround was to force puppet to cast it as an Integer by adding zero:

$base_ldap_cfg = {
  servers => [
    { host => $ldap_server,
      port => 636+0,
      use_ssl => true,

Its a hack. Sorry, I should have added this to the README section when I set this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants