|
26 | 26 |
|
27 | 27 | agent_major_version = Chef::Datadog.agent_major_version(node)
|
28 | 28 |
|
| 29 | +# A2923DFF56EDA6E76E55E492D3A80E30382E94DE expires in 2022 |
| 30 | +# D75CEA17048B9ACBF186794B32637D44F14F620E expires in 2032 |
| 31 | +apt_gpg_keys = ['A2923DFF56EDA6E76E55E492D3A80E30382E94DE', 'D75CEA17048B9ACBF186794B32637D44F14F620E'] |
| 32 | + |
| 33 | +# DATADOG_RPM_KEY_E09422B3.public expires in 2022 |
| 34 | +# DATADOG_RPM_KEY_20200908.public expires in 2024 |
| 35 | +rpm_gpg_keys = [['DATADOG_RPM_KEY_E09422B3.public', 'e09422b3', 'A4C0 B90D 7443 CF6E 4E8A A341 F106 8E14 E094 22B3'], |
| 36 | + ['DATADOG_RPM_KEY_20200908.public', 'fd4bf915', 'C655 9B69 0CA8 82F0 23BD F3F6 3F4D 1729 FD4B F915']] |
| 37 | + |
| 38 | +# Local file name of the key |
| 39 | +rpm_gpg_keys_name = 0 |
| 40 | +# Short fingerprint for rpm commands, used in "rpm -q gpg-pubkey-*" and node['datadog']["yumrepo_gpgkey_new_*"] |
| 41 | +rpm_gpg_keys_short_fingerprint = 1 |
| 42 | +# Space delimited full fingerprint |
| 43 | +rpm_gpg_keys_full_fingerprint = 2 |
| 44 | + |
29 | 45 | case node['platform_family']
|
30 | 46 | when 'debian'
|
31 | 47 | apt_update 'update'
|
|
48 | 64 |
|
49 | 65 | retries = node['datadog']['aptrepo_retries']
|
50 | 66 | keyserver = node['datadog']['aptrepo_use_backup_keyserver'] ? node['datadog']['aptrepo_backup_keyserver'] : node['datadog']['aptrepo_keyserver']
|
51 |
| - # Add APT repository |
52 |
| - apt_repository 'datadog' do |
53 |
| - keyserver keyserver |
54 |
| - key 'A2923DFF56EDA6E76E55E492D3A80E30382E94DE' |
55 |
| - uri node['datadog']['aptrepo'] |
56 |
| - distribution node['datadog']['aptrepo_dist'] |
57 |
| - components components |
58 |
| - action :add |
59 |
| - retries retries |
| 67 | + # Add APT repositories |
| 68 | + apt_gpg_keys.each do |apt_gpg_key| |
| 69 | + apt_repository "datadog_apt_#{apt_gpg_key}" do |
| 70 | + keyserver keyserver |
| 71 | + key apt_gpg_key |
| 72 | + uri node['datadog']['aptrepo'] |
| 73 | + distribution node['datadog']['aptrepo_dist'] |
| 74 | + components components |
| 75 | + action :add |
| 76 | + retries retries |
| 77 | + end |
60 | 78 | end
|
61 | 79 |
|
62 | 80 | # Previous versions of the cookbook could create this repo file, make sure we remove it now
|
|
65 | 83 | end
|
66 | 84 | when 'rhel', 'fedora', 'amazon'
|
67 | 85 | # Import new RPM key
|
68 |
| - if node['datadog']['yumrepo_gpgkey_new'] |
| 86 | + rpm_gpg_keys.each do |rpm_gpg_key| |
| 87 | + next unless node['datadog']["yumrepo_gpgkey_new_#{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}"] |
| 88 | + |
69 | 89 | # gnupg is required to check the downloaded key's fingerprint
|
70 | 90 | package 'gnupg' do
|
71 | 91 | action :install
|
72 | 92 | only_if { node['packages']['gnupg2'].nil? }
|
73 | 93 | end
|
74 | 94 |
|
75 | 95 | # Download new RPM key
|
76 |
| - key_local_path = ::File.join(Chef::Config[:file_cache_path], 'DATADOG_RPM_KEY_E09422B3.public') |
77 |
| - remote_file 'DATADOG_RPM_KEY_E09422B3.public' do |
| 96 | + key_local_path = ::File.join(Chef::Config[:file_cache_path], rpm_gpg_key[rpm_gpg_keys_name]) |
| 97 | + remote_file "remote_file_#{rpm_gpg_key[rpm_gpg_keys_name]}" do |
78 | 98 | path key_local_path
|
79 |
| - source node['datadog']['yumrepo_gpgkey_new'] |
80 |
| - not_if 'rpm -q gpg-pubkey-e09422b3' # (key already imported) |
81 |
| - notifies :run, 'execute[rpm-import datadog key e09422b3]', :immediately |
| 99 | + source node['datadog']["yumrepo_gpgkey_new_#{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}"] |
| 100 | + not_if "rpm -q gpg-pubkey-#{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}" # (key already imported) |
| 101 | + notifies :run, "execute[rpm-import datadog key #{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}]", :immediately |
82 | 102 | end
|
83 | 103 |
|
| 104 | + # The fingerprint string has spaces in it, calculate one without space here |
| 105 | + gpg_key_fingerprint_without_space = rpm_gpg_key[rpm_gpg_keys_full_fingerprint].delete(' ') |
| 106 | + |
84 | 107 | # Import key if fingerprint matches
|
85 |
| - execute 'rpm-import datadog key e09422b3' do |
| 108 | + execute "rpm-import datadog key #{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}" do |
86 | 109 | command "rpm --import #{key_local_path}"
|
87 |
| - only_if "gpg --dry-run --quiet --with-fingerprint #{key_local_path} | grep 'A4C0 B90D 7443 CF6E 4E8A A341 F106 8E14 E094 22B3' || gpg --dry-run --import --import-options import-show #{key_local_path} | grep 'A4C0B90D7443CF6E4E8AA341F1068E14E09422B3'" |
| 110 | + only_if "gpg --dry-run --quiet --with-fingerprint #{key_local_path} | grep '#{rpm_gpg_key[rpm_gpg_keys_full_fingerprint]}' || gpg --dry-run --import --import-options import-show #{key_local_path} | grep '#{gpg_key_fingerprint_without_space}'" |
88 | 111 | action :nothing
|
89 | 112 | end
|
90 | 113 | end
|
|
105 | 128 | end
|
106 | 129 |
|
107 | 130 | # Add YUM repository
|
| 131 | + yumrepo_gpgkeys = [] |
| 132 | + if agent_major_version < 7 |
| 133 | + yumrepo_gpgkeys.push(node['datadog']['yumrepo_gpgkey']) |
| 134 | + else |
| 135 | + rpm_gpg_keys.each do |rpm_gpg_key| |
| 136 | + yumrepo_gpgkeys.push(node['datadog']["yumrepo_gpgkey_new_#{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}"]) |
| 137 | + end |
| 138 | + end |
| 139 | + |
108 | 140 | yum_repository 'datadog' do
|
109 | 141 | description 'datadog'
|
110 | 142 | baseurl baseurl
|
111 | 143 | proxy node['datadog']['yumrepo_proxy']
|
112 | 144 | proxy_username node['datadog']['yumrepo_proxy_username']
|
113 | 145 | proxy_password node['datadog']['yumrepo_proxy_password']
|
114 |
| - gpgkey agent_major_version < 7 ? node['datadog']['yumrepo_gpgkey'] : node['datadog']['yumrepo_gpgkey_new'] |
| 146 | + gpgkey yumrepo_gpgkeys |
115 | 147 | gpgcheck true
|
116 | 148 | action :create
|
117 | 149 | end
|
118 | 150 | when 'suse'
|
119 | 151 | # Import new RPM key
|
120 |
| - if node['datadog']['yumrepo_gpgkey_new'] |
| 152 | + rpm_gpg_keys.each do |rpm_gpg_key| |
| 153 | + next unless node['datadog']["yumrepo_gpgkey_new_#{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}"] |
| 154 | + |
121 | 155 | # Download new RPM key
|
122 |
| - new_key_local_path = ::File.join(Chef::Config[:file_cache_path], 'DATADOG_RPM_KEY_E09422B3.public') |
123 |
| - remote_file 'DATADOG_RPM_KEY_E09422B3.public' do |
| 156 | + new_key_local_path = ::File.join(Chef::Config[:file_cache_path], rpm_gpg_key[rpm_gpg_keys_name]) |
| 157 | + remote_file "remote_file_#{rpm_gpg_key[rpm_gpg_keys_name]}" do |
124 | 158 | path new_key_local_path
|
125 |
| - source node['datadog']['yumrepo_gpgkey_new'] |
126 |
| - not_if 'rpm -q gpg-pubkey-e09422b3' # (key already imported) |
127 |
| - notifies :run, 'execute[rpm-import datadog key e09422b3]', :immediately |
| 159 | + source node['datadog']["yumrepo_gpgkey_new_#{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}"] |
| 160 | + not_if "rpm -q gpg-pubkey-#{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}" # (key already imported) |
| 161 | + notifies :run, "execute[rpm-import datadog key #{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}]", :immediately |
128 | 162 | end
|
129 | 163 |
|
| 164 | + # The fingerprint string has spaces in it, calculate one without space here |
| 165 | + gpg_key_fingerprint_without_space = rpm_gpg_key[rpm_gpg_keys_full_fingerprint].delete(' ') |
| 166 | + |
130 | 167 | # Import key if fingerprint matches
|
131 |
| - execute 'rpm-import datadog key e09422b3' do |
| 168 | + execute "rpm-import datadog key #{rpm_gpg_key[rpm_gpg_keys_short_fingerprint]}" do |
132 | 169 | command "rpm --import #{new_key_local_path}"
|
133 |
| - only_if "gpg --dry-run --quiet --with-fingerprint #{new_key_local_path} | grep 'A4C0 B90D 7443 CF6E 4E8A A341 F106 8E14 E094 22B3' || gpg --dry-run --import --import-options import-show #{new_key_local_path} | grep 'A4C0B90D7443CF6E4E8AA341F1068E14E09422B3'" |
| 170 | + only_if "gpg --dry-run --quiet --with-fingerprint #{new_key_local_path} | grep '#{rpm_gpg_key[rpm_gpg_keys_full_fingerprint]}' || gpg --dry-run --import --import-options import-show #{new_key_local_path} | grep '#{gpg_key_fingerprint_without_space}'" |
134 | 171 | action :nothing
|
135 | 172 | end
|
136 | 173 | end
|
137 | 174 |
|
| 175 | + # Now the old key is mostly hard-coded |
138 | 176 | old_key_local_path = ::File.join(Chef::Config[:file_cache_path], 'DATADOG_RPM_KEY.public')
|
139 | 177 | remote_file 'DATADOG_RPM_KEY.public' do
|
140 | 178 | path old_key_local_path
|
|
167 | 205 | zypper_repository 'datadog' do
|
168 | 206 | description 'datadog'
|
169 | 207 | baseurl baseurl
|
170 |
| - gpgkey agent_major_version < 7 ? node['datadog']['yumrepo_gpgkey'] : node['datadog']['yumrepo_gpgkey_new'] |
| 208 | + gpgkey agent_major_version < 7 ? node['datadog']['yumrepo_gpgkey'] : node['datadog']["yumrepo_gpgkey_new_#{rpm_gpg_keys[0][rpm_gpg_keys_short_fingerprint]}"] |
171 | 209 | gpgautoimportkeys false
|
172 | 210 | gpgcheck false
|
173 | 211 | action :create
|
|
0 commit comments