Skip to content

Commit ad00dd7

Browse files
committed
Add an exec to create the Deploy Environments RBAC Role
Prior to this commit there was a requirement for the user of this repo to create a RBAC role in order for code manager to work. After this commit an exec statement will curl the RBAC API to create the role one time and hopefully it works otherwise the exec will not run again.
1 parent ec7a8d8 commit ad00dd7

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Table of Contents
2525

2626
This control repo and the steps below are intended to be used during a new installation of PE.
2727

28-
This control repo has only been tested against PE2015.2.z, it's likely close to working on PE3.8.z but has not been tested.
28+
This control repo has only been tested against PE2015.2.z and PE2015.3.z. It is likely close to working on PE3.8.z but has not been tested.
2929

3030
If you intend to use it on an existing installation then be warned that if you've already written or downloaded modules when you start using r10k it will remove all of the existing modules and replace them with what you define in your Puppetfile. Please copy or move your existing modules to another directory to ensure you do not lose any work you've already started.
3131

@@ -144,13 +144,7 @@ So, we'll set up a deploy key in the git server that will allow a ssh-key we mak
144144
- Paste in the public key from above
145145
- `cat /etc/puppetlabs/puppetserver/code_manager.key.pub`
146146
3. Login to the PE console
147-
4. Select Access Control in the left hand panel
148-
5. On the User Roles page, add a new role called `Deploy Environments`
149-
- NOTE: Make sure to name it exactly as I have because the puppet code expects that exact name
150-
6. After creating the role click through and select the permissions tab
151-
- Add Puppet Environment type, Deploy Code permission, and All object
152-
- Add Tokens type, override default expiry permission
153-
7. Still in the PE Console, navigate to the Classification page
147+
7. Navigate to the Classification page
154148
- Click on the PE Master group
155149
- Click the Classes tab
156150
- Add the `puppet_enterprise::profile::master`

site/profile/manifests/git_webhook/code_manager.pp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,35 @@
3535
unless => "/usr/bin/test \$(stat -c %U ${::settings::codedir}/environments/production) = 'pe-puppet'",
3636
}
3737

38+
$code_manager_role_name = 'Deploy Environments'
39+
$create_role_creates_file = '/etc/puppetlabs/puppetserver/.puppetlabs/deploy_environments_created'
40+
$create_role_curl = @(EOT)
41+
/opt/puppetlabs/puppet/bin/curl -k -X POST -H 'Content-Type: application/json' \
42+
https://<%= $::trusted['certname'] %>:4433/rbac-api/v1/roles \
43+
-d '{"permissions": [{"object_type": "environment", "action": "deploy_code", "instance": "*"},
44+
{"object_type": "tokens", "action": "override_lifetime", "instance": "*"}],"user_ids": [], "group_ids": [], "display_name": "<%= $code_manager_role_name %>", "description": ""}' \
45+
--cert <%= $::settings::certdir %>/<%= $::trusted['certname'] %>.pem \
46+
--key <%= $::settings::privatekeydir %>/<%= $::trusted['certname'] %>.pem \
47+
--cacert <%= $::settings::certdir %>/ca.pem;
48+
touch <%= $create_role_creates_file %>
49+
| EOT
50+
51+
exec { 'create deploy environments role' :
52+
command => inline_epp( $create_role_curl ),
53+
creates => $create_role_creates_file,
54+
logoutput => true,
55+
path => $::path,
56+
require => File[$token_directory],
57+
}
58+
3859
rbac_user { $code_manager_service_user :
3960
ensure => 'present',
4061
name => $code_manager_service_user,
4162
email => "${code_manager_service_user}@example.com",
4263
display_name => 'Code Manager Service Account',
4364
password => $code_manager_service_user_password,
44-
roles => [ 'Deploy Environments' ],
65+
roles => [ $code_manager_role_name ],
66+
require => Exec['create deploy environments role'],
4567
}
4668

4769
file { $token_directory :

0 commit comments

Comments
 (0)