Code Monkey home page Code Monkey logo

puppet-trocla's Introduction

trocla

Build Status

This is the puppet module to manage a trocla installation on the puppet master. It also, provides the necessary function to query trocla from puppet.

To get a quick start you might be interested in using the trocla::yaml class on your master. This will install trocla and setup it using the default YAML storage backend for your master. There is no need to configure anything on the clients if you do not want to use trocla on the clients itself.

If you want to do your own very custom setup, you should look into the other classes.

Compatibility

  • Version 0.2.2 of this module is for version 0.2.2 of trocla.

Functions

trocla

Usage:

trocla(KEY, FORMAT, [optional options])

This is the main function you will use. This is similar to a

trocla create foo FORMAT

on the cli. This means, that if a password for this key and format exists, it will return this one, otherwise will create one automatically and return the generated password. So you might want to do something like:

user{'foobar':
  password => trocla('user_foobar','plain')
}

If you want to pass down encrypted passwords, you might use:

user{'foobar':
  password => trocla('user_foobar','sha512crypt')
}

As descriped further in trocla's docs.

The optional options, can be used to pass options to the format, like overriding the default length for passwords that are being created:

user{'foobar':
  password => trocla('user_foobar','sha512crypt','length: 32')
}

trocla_get

Usage:

trocla_get(KEY, FORMAT)

This will return the value of the passed key and format. If nothing is found an error will be raised. This is interesting if you want do not want to autogenerate a password and rather be sure that it's already existing in trocla's database.

trocla_set

Usage:

trocla_set(KEY, PASSWORD, FORMAT)

This will set the passed password for the key/format pair and return it as well. This is mainly interesting if you want to migrate existing manifests with plenty of passwords in it to trocla.

Note that the FORMAT, in this context, is the format of the PASSWORD itself: it will not reencode it unless you pass a second argument, for example:

trocla_set('admin', 'test', 'plain')

... will return the string "test" but this:

trocla_set('admin', 'test', 'plain', 'bcrypt')

... will return a bcrypt-hashed password.

Hiera backend

Trocla can also be integrated into Hiera.

For previous hiera versions (<= 3) you might want to use ZeroPointEnergy's hiera-backend. Simply include trocla::master::hiera to make that backend available. This backend also works with newer hiera releases, but only for a global hiera level.

For hiera >= 5, there is a custom hiera backend using a puppet lookup function shipped with this module.

It ships with the same feature set as ZeroPointEnergy's hiera-backend, but uses the modern hiera interfaces, so it can also be used in per environment.

Configuration is straight forward, by adding the following hierarchy entry:

:hierarchy:
  - name: trocla
    lookup_key: trocla_lookup_key
    options:
      trocla_hierarchy:
        - hosts/%{facts.fqdn}
        - roles/%{::role}
        - defaults
      config: /etc/puppetlabs/puppet/troclarc.yaml

Important are the options:

  • trocla_hierarchy: Defines the inner-hierarchy for the trocla hierarchy level. Usually, this might match your common hiera-hierarchy.
  • config: A path to a trocla hierarchy, defining any further options.

There are two different methods to lookup a password in trocla. trocla_lookup and trocla_hierarchy

trocla_lookup

trocla_lookup will simply lookup the password for a specified key and completely ignore the hierarchy defined in the hiera configuration. If the password does not exist it will create one.

The trocla hiera backend will resolve all the variables which start with "trocla_lookup::"

The second part of the variable is used to describe the format, the last part is the variable to lookup in trocla.

trocla_lookup::format::myvar

You can use the backend via interpolation tokens like this:

myapp::database::password: "%{hiera('trocla_lookup::plain::myapp_mysql_password')}"

mysql::server::users:
  'someuser@localhost':
      ensure: 'present'
      password_hash: "%{hiera('trocla_lookup::mysql::myapp_mysql_password')}"

trocla_hierarchy

trocla_hierarchy will lookup the key in the hierarchy defined in your hiera configuration. It will simply prefix all the variables with 'hiera/source/key' where source is one of the interpolated strings defined in the hierarchy section.

It will try to find a password on every level in your hierarchy first. After that it will create a password on the first hierarchy level by default. You can overwrite the level it should create the password with the key 'order_override' in the trocla_options hash.

This is useful if you require different key for different nodes or on any other hierarchy level you desire.

If you have a hierarchy defined like this:

:trocla_hierarchy:
  - "nodes/%{::clientcert}"
  - "roles/%{::role}"
  - defaults

And you want to create a different password on the roles level, so that nodes within the same role will get the same password you can set the 'order_override' like this:

trocla_options::my_special_key:
  order_override: "roles/%{::role}"

The format to lookup a password this way is the same as with 'trocla_lookup':

trocla_hierarchy::format::myvar

Here is how you would use that in hiera:

mysql::server::root_password: "%{hiera('trocla_hierarchy::plain::mysql_root')}"

options hash

Trocla takes a hash of options which provides information for the password creation. This options can be set directly in hiera globally or for every key. You can also specify options specifically for a password format. However, keep in mind that trocla will respect most of the options only on the initial/first lookup, when the password is created. As most of the options only apply for creating a password.

trocla_options:
  length: 16
  some_other_global_setting: bla
  mysql:
    length: 32

trocla_options::some_key:
  plain:
    length: 64
  order_override: "roles/%{::role}"

Some formats may require options to be set for creating passwords, like the postgresql format. Check the trocla documentation for available options.

Through the options mechanism it is also possible to change the lookup key used for trocla. This is especially interesting, if you want to pass 2 different options for the same key, e.g. the render option. An example for that is to have trocla use the same key for 2 different lookups, so that with the x509 format, once a certificate and once a key is returned.

var_with_x509_cert: "%{hiera('trocla_lookup::x509::my_cert')}"
trocla_options::my_cert:
  x509:
    CN: 'my-cert'
    render:
      certonly: true
var_with_x509_key: "%{hiera('trocla_lookup::x509::my_cert_only_key')}"
trocla_options::my_cert_only_key:
  x509:
    CN: 'my-cert'
    trocla_key: my_cert
    render:
      keyonly: true

This will lookup one trocla key: my_cert, but with different rendering options, so that once we only get the certificat, while on the second lookup we get the private key.

Other classes

trocla::config

This is a class that manages a trocla configuration. You might use this one if you do not use the default yaml setup.

trocla::master

This class manages the installation of trocla itself. It will not configure trocla, it will just install the necessary packages.

Moar

RTFC and for more information about trocla visit: https://github.com/duritong/trocla

puppet-trocla's People

Contributors

anarcat avatar duritong avatar fe80 avatar justicel avatar michaelweiser avatar poil avatar tilladamdmde avatar timogoebel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

puppet-trocla's Issues

Remove hiera-backend in favor of https://github.com/ZeroPointEnergy/hiera-backend-trocla

This is mainly for @michaelweiser:

So someone else implemented another hiera-backend for trocla: https://github.com/ZeroPointEnergy/hiera-backend-trocla

At first it couldn't do as much as yours, but now as the @ZeroPointEnergy iterated over it again it is feature equivalent with yours. And actually to be honest: it now not only has all the features of your backend, but also addresses a few drawbacks. Like that with your backend, you can only get a password in one specific format for one node, and you can't get both, e.g. a plain and a mysql backend.

Also that imho it makes to sense to maintain 2 backends, I'm actually in favor of removing your backend from this module and within the README of this module and trocla point to @ZeroPointEnergy's module.
Also note that for puppet-server installation we can't distribute the backend anymore using a puppet module, but should do it with a gem. Which is also something that the other module addresses and which is also one of the reasons, why I would like to keep the backend out of the module.

To make the long story short: What are you feelings about removing your code and pointing to the other backend?

I guess it should be too much work of migrating your existing hiera configuration over to the new backend, or keep your backend in an own repository, which you would maintain on your own.

Sorry for that, but I would say this is how iterating works in software development.

New release for puppetforge

Hi,

how about a new release for the puppet forge?

The current release does not support hiera 5, because the trocla_lookup_key method is missing in release 1.0.1

Cheers otterz

make a default storage file and fix its permissions

along with #4, i think we should provide a default storage file and make sure its permissions are alright, because if we follow the class declaration i have in #4, the file created is world-readable.

something like:

file { $trocla::storage: mode => 0400, owner => puppet }

should be good enough.

module doesn't deploy a proper default trocla configuration

I was expecting:

include trocla

do just "do the right thing". The readme actually made me thing that:

include trocla::master

... would also work, but then by reading the manifests, I came to understand we actually need to:

include trocla::config

... but that doesn't actually work either, because the default configuration is wrong.

I actually had to do:

class { 'trocla::config':
  adapter => 'YAML',
  adapter_options => { 'file' => '/var/lib/puppet/server_data/trocla.yml' },
}

It would be nice if those adapter options were the default!

does this support hierarchical keys?

could there be a system by which you'd have a "system-wide" password then host-specific ones?

i'm thinking of something like trocla([$fqdn, 'default'])...

Forge release

Hi

Would be great if we could get a new forge release of this module ;-)

trocla_set, don't erase if same as old password

Hi,

We want to use trocla_set to force a plain password and generate a md5crypt

On the 1st run, trocla set our password and a md5crypt.
On the 2nd run, trocla set again our password and generate a new md5crypt.

It doesn't seem possible to check if a password is already defined and equal to the password we wanted.

Ideally I would wrote somethings like this :

if trocla_get('mykey_user', 'plain') != $my_password_from_hiera {
   $md5pass = trocla_set('mykey_user', $my_password_from_hiera, 'plain', 'md5crypt')
} else {
  $md5pass = trocla('mykey_user', 'md5crypt') # or trocla_get
}

Is it possible to do something like this, or have you an idea how to do this ?
Perhaps we can patch trocla or trocla_get to do not raise a fatal error if the password does not exist in the trocla database ?

Best regards

Error when using module.

Error: /File[/var/lib/puppet/lib]: Failed to generate additional resources using 'eval_generate': Error 400 on SERVER: Permission denied - /etc/puppet/modules/trocla/lib/puppet/parser/functions/trocla_get.rb

how to use this module?

Hi,

how to use this module? I download it but I don't know where to start. Can you give an example?

Thanks.

Investigate connection leaks in trocla-hiera-backend

As reported on puppet-users, it seems that the hiera-backend is leaking stores:

https://groups.google.com/forum/#!topic/puppet-users/JDfXiA1xnCg

The workaround proposed on the list goes into the same direction as what we discussed in #18 and hence is introducing the same inefficiency (re-opening database connection), that I tried to avoid in the patches that followed to that PR.

Although, I explicitly tried to not run into the same problem as in the original puppet function with the hiera-backend, it looks like we are creating objects over and over again and hence keeping tons of connections open. Though that is my current guess and the little info we have on the report on the list, but it's the only explanation I have so far for the growing connection count.

What might interfere is the way how puppet is setting up the caches for hiera backends and eventually we might need to try to do that differently than storing the trocla object in the hash. But that's a pure guess atm, that needs more verification and analysis.

This is mainly a brain dump at the moment, to not loose track on what came up so far.

no such file to load -- trocla

Hello

I have problems using this module. I installed it to the puppet master with the trocla::yaml class. But when I try to use the trocla function I get a error:

Could not retrieve catalog from remote server: Error 500 on SERVER: Internal Server Error: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- trocla

This is the code I use on the client

`$passkey = "${::hostname}_root"

user { $passkey:
name => 'root',
ensure => present,
password => trocla($passkey,'sha512crypt'),
}`

Normally client and puppet master are in different environment but the module is installed in booth environment. And for testing purposes I also tested with a client in the same environment as the puppet master. The result was the same.

trocla_get render

Hi,

We can't get cert or key only with x509 format, as like duritong/trocla#42

I fix with:

diff --git a/lib/puppet/parser/functions/trocla_get.rb b/lib/puppet/parser/functions/trocla_get.rb
index fb5cd5a..c7596bf 100644
--- a/lib/puppet/parser/functions/trocla_get.rb
+++ b/lib/puppet/parser/functions/trocla_get.rb
@@ -29,8 +29,9 @@ the return value will be undef if the key & format pair is not found.
     end
     require File.dirname(__FILE__) + '/../../util/trocla_helper'
     args[1] ||= 'plain'
-    raise_error = args[2].nil? ? true : args[2]
-    if (answer=Puppet::Util::TroclaHelper.trocla(:get_password,false,[args[0],args[1]])).nil? && raise_error
+    options = args[2] || {}
+    raise_error = args[3].nil? ? true : args[3]
+    if (answer=Puppet::Util::TroclaHelper.trocla(:get_password,true,[args[0],args[1],options])).nil? && raise_error
       raise(Puppet::ParseError, "No password for key,format #{args[0..1].flatten.inspect} found!")
     end
     answer.nil? ? :undef : answer

Options order have change with this fix (raise_error is on args[3])

Do you want I fork and create a merge request ?

Could not find class rubygems::moneta for

Hi,

I'm trying to install trocla

I've installed trocla via gem install trocla
I've added to my puppetmaster node "include trocla::mastertrocla::config"

gem list give

  • moneta (0.7.20)
  • highline (1.6.20)

But when I run puppet agent -t I've " Could not find class rubygems::moneta for myhost"

When I remove the include on my puppetmaster node and I run puppet agent on a client which have an user resource, password managed with troca I've "Error: Could not retrieve catalog from remote server: Error 400 on SERVER: no such file to load -- trocla"

I've create an empty file puppet owned in /etc/puppet/troclarc.yaml
And I don't have "server_data/trocla_data.yaml" on my master node

I'm on Centos 6.5, ruby 1.8.7 / puppet 3.2.4

Any help ?

Best regards,

Puppet 8 compatibility

Hi,
Is this module compatible with Puppet 8x ?
Do you have tested it ? Do you have any feedback ?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.