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

initial commit for shield. users and roles only #464

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
# package upgrades.
# Defaults to: true
#
# [*shield_users_merge*]
# Enable Hiera's merging function for shield users
# Defaults to: false
#
#
# The default values for the parameters are set in elasticsearch::params. Have
# a look at the corresponding <tt>params.pp</tt> manifest file if you need more
# technical information about them.
Expand Down Expand Up @@ -246,7 +251,8 @@
$instances = undef,
$instances_hiera_merge = false,
$plugins = undef,
$plugins_hiera_merge = false
$plugins_hiera_merge = false,
$shield_users_merge = false,
) inherits elasticsearch::params {

anchor {'elasticsearch::begin': }
Expand Down Expand Up @@ -359,6 +365,16 @@
create_resources('elasticsearch::plugin', $x_plugins)
}

# Hiera support for esusers
validate_bool($shield_users_merge)

if $shield_users_merge == true {
$esusers = hiera_hash('elasticsearch::esusers', $::elasticsearch::esusers)
if $esusers {
validate_hash($esusers)
create_resources('elasticsearch::shield::esuser', $esusers)
}
}

if $java_install == true {
# Install java
Expand Down
31 changes: 31 additions & 0 deletions manifests/shield/esuser.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# == Class: elasticsearch::shield::esuser
#
# Class to manage creating users in elasticsearch via the shield plugin
#
# == Parameters
#
# [*username*]
# String to use for a username
#
# [*password*]
# String to use for a password
#
define elasticsearch::shield::esuser($username, $password, $roles=$title) {
if $username == undef {
fail('user must be specified')
}
validate_string($username)
if $password == undef {
fail('password must be specified')
}
validate_slength($password, 4192, 6)

# TODO: what happens if we add roles - this route we only set role on useradd
exec { "useradd shield::esuser::${username}":
user => $::elasticsearch::elasticsearch_user,
path => [ '/usr/bin', '/usr/share/elasticsearch/bin/shield' ],
command => "esusers useradd ${username} -p \"${password}\" -r ${roles} &> /dev/null",
unless => "esusers list ${username} &> /dev/null",
}
}