Skip to content

Commit cb45891

Browse files
authored
Merge pull request #242 from DataDog/jaime/keys
[keys][rpm+deb] rotate repo keys.
2 parents bcc0204 + 3a3763c commit cb45891

8 files changed

Lines changed: 69 additions & 11 deletions

File tree

.fixtures.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
fixtures:
22
repositories:
3-
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
3+
stdlib:
4+
repo: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
5+
ref: "4.12.0"
46
ruby: "git://github.com/puppetlabs/puppetlabs-ruby.git"
7+
remote_file: "git://github.com/lwf/puppet-remote_file.git"
58
symlinks:
69
datadog_agent: "#{source_dir}"

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ group :test do
99
gem "puppet-syntax"
1010
gem "puppetlabs_spec_helper"
1111
gem "rake"
12-
gem "rspec-puppet", '2.2.0'
12+
gem "rspec-puppet", '2.3.2'
1313
end
1414

1515
group :development do
16-
gem "beaker"
16+
gem "beaker", '2.51.0'
1717
gem "beaker-rspec"
1818
gem "puppet-blacksmith"
1919
gem "guard-rake"

manifests/redhat.pp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,48 @@
1313
#
1414
# Sample Usage:
1515
#
16+
#
1617
class datadog_agent::redhat(
1718
$baseurl = "https://yum.datadoghq.com/rpm/${::architecture}/",
18-
$gpgkey = 'https://yum.datadoghq.com/DATADOG_RPM_KEY.public',
19+
$gpgkey = 'https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public',
1920
$manage_repo = true,
2021
$agent_version = 'latest'
2122
) {
2223

2324
validate_bool($manage_repo)
2425
if $manage_repo {
26+
$public_key_local = '/tmp/DATADOG_RPM_KEY.public'
27+
2528
validate_string($baseurl)
2629

30+
remote_file { 'DATADOG_RPM_KEY.public':
31+
owner => root,
32+
group => root,
33+
mode => '600',
34+
path => $public_key_local,
35+
source => $gpgkey
36+
}
37+
38+
exec { 'install-gpg-key':
39+
command => "/bin/rpm --import ${public_key_local}",
40+
onlyif => "/bin/gpg --quiet --with-fingerprint -n ${public_key_local} | grep \'A4C0 B90D 7443 CF6E 4E8A A341 F106 8E14 E094 22B3\'",
41+
unless => '/bin/rpm -q gpg-pubkey-e09422b3',
42+
require => Remote_file['DATADOG_RPM_KEY.public'],
43+
notify => Exec['cleanup-gpg-key'],
44+
}
45+
46+
exec { 'cleanup-gpg-key':
47+
command => "/bin/rm ${public_key_local}",
48+
onlyif => "/bin/test -f ${public_key_local}",
49+
}
50+
2751
yumrepo {'datadog':
2852
enabled => 1,
2953
gpgcheck => 1,
3054
gpgkey => $gpgkey,
3155
descr => 'Datadog, Inc.',
3256
baseurl => $baseurl,
57+
require => Exec['install-gpg-key'],
3358
}
3459

3560
Package { require => Yumrepo['datadog']}

manifests/ubuntu.pp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@
1010
#
1111
# Sample Usage:
1212
#
13+
#
14+
1315
class datadog_agent::ubuntu(
14-
$apt_key = 'C7A7DA52',
15-
$agent_version = 'latest'
16+
$apt_key = '382E94DE',
17+
$agent_version = 'latest',
18+
$other_keys = ['C7A7DA52']
1619
) {
1720

1821
ensure_packages(['apt-transport-https'])
22+
validate_array($other_keys)
1923

2024
if !$::datadog_agent::skip_apt_key_trusting {
21-
exec { 'datadog_key':
22-
command => "/usr/bin/apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys ${apt_key}",
23-
unless => "/usr/bin/apt-key list | grep ${apt_key} | grep expires",
25+
$mykeys = concat($other_keys, [$apt_key])
26+
27+
::datadog_agent::ubuntu::install_key { $mykeys:
2428
before => File['/etc/apt/sources.list.d/datadog.list'],
2529
}
30+
2631
}
2732

2833
file { '/etc/apt/sources.list.d/datadog.list':

manifests/ubuntu/install_key.pp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Resource type: datadog_agent::ubuntu::install_key
2+
#
3+
# This resource type install repository keys in Ubuntu
4+
#
5+
# Parameters:
6+
#
7+
# Actions:
8+
#
9+
# Requires:
10+
#
11+
# Sample Usage:
12+
#
13+
#
14+
#
15+
define datadog_agent::ubuntu::install_key() {
16+
exec { "key ${name}":
17+
command => "/usr/bin/apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys ${name}",
18+
unless => "/usr/bin/apt-key list | grep ${name} | grep expires",
19+
}
20+
}

metadata.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
{
7272
"name": "puppetlabs/ruby",
7373
"version_requirement": ">=0.2.0 <1.0.0"
74+
},
75+
{
76+
"name": "lwf/remote_file",
77+
"version_requirement": ">=1.1.3"
7478
}
7579
]
7680
}

spec/classes/datadog_agent_redhat_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
should contain_yumrepo('datadog')
1717
.with_enabled(1)\
1818
.with_gpgcheck(1)\
19-
.with_gpgkey('https://yum.datadoghq.com/DATADOG_RPM_KEY.public')\
19+
.with_gpgkey('https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public')\
2020
.with_baseurl('https://yum.datadoghq.com/rpm/x86_64/')
2121
end
2222
end

spec/classes/datadog_agent_ubuntu_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
end
1515

1616
# it should install the mirror
17-
it { should contain_exec('datadog_key') }
17+
it { should contain_datadog_agent__ubuntu__install_key('C7A7DA52') }
18+
it { should contain_datadog_agent__ubuntu__install_key('382E94DE') }
1819
it do
1920
should contain_file('/etc/apt/sources.list.d/datadog.list')\
2021
.that_notifies('Exec[datadog_apt-get_update]')

0 commit comments

Comments
 (0)