Skip to content

Commit bc86b74

Browse files
authored
Merge pull request #289 from netmanagers/debian-family-apt-keyrings
feat(debian): use keyrings instead of key_ids
2 parents 7fcb960 + c16ecf8 commit bc86b74

File tree

6 files changed

+138
-16
lines changed

6 files changed

+138
-16
lines changed

docs/README.apt.keyrings.rst

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _readme_apt_keyrings:
2+
3+
apt repositories' keyrings
4+
==========================
5+
6+
Debian family of OSes deprecated the use of `apt-key` to manage repositories' keys
7+
in favor of using `keyring files` which contain a binary OpenPGP format of the key
8+
(also known as "GPG key public ring")
9+
10+
As nginx and passenger don't provide such key files, we created them following the
11+
official recomendations in their sites and install the resulting files.
12+
13+
Nginx
14+
-----
15+
16+
See https://nginx.org/en/linux_packages.html#Debian for details
17+
18+
.. code-block:: bash
19+
20+
$ curl -s https://nginx.org/keys/nginx_signing.key | \
21+
gpg --dearmor --output nginx-archive-keyring.gpg
22+
23+
Phusion-passenger
24+
-----------------
25+
26+
See https://www.phusionpassenger.com/docs/tutorials/deploy_to_production/installations/oss/ownserver/ruby/nginx/
27+
for more details.
28+
29+
.. code-block:: bash
30+
31+
$ gpg --keyserver keyserver.ubuntu.com \
32+
--output - \
33+
--recv-keys 561F9B9CAC40B2F7 | \
34+
gpg --export --output phusionpassenger-archive-keyring.gpg
1.04 KB
Binary file not shown.
Binary file not shown.

nginx/map.jinja

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
'server_use_symlink': True,
2020
'pid_file': '/run/nginx.pid',
2121
'openssl_package': 'openssl',
22+
'package_repo_keyring': '/usr/share/keyrings/nginx-archive-keyring.gpg',
23+
'passenger_package_repo_keyring': '/usr/share/keyrings/phusionpassenger-archive-keyring.gpg',
2224
},
2325
'CentOS': {
2426
'package': 'nginx',

nginx/pkg.sls

+56-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
#
33
# Manages installation of nginx from pkg.
44

5-
{% from 'nginx/map.jinja' import nginx, sls_block with context %}
5+
{#- Get the `tplroot` from `tpldir` #}
6+
{%- set tplroot = tpldir.split('/')[0] %}
7+
{%- from tplroot ~ "/map.jinja" import nginx, sls_block with context %}
8+
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
9+
610
{%- if nginx.install_from_repo %}
711
{% set from_official = true %}
812
{% set from_ppa = false %}
@@ -33,7 +37,19 @@ nginx_install:
3337
- name: {{ nginx.lookup.package }}
3438
{% endif %}
3539
36-
{% if salt['grains.get']('os_family') == 'Debian' %}
40+
{% if grains.os_family == 'Debian' %}
41+
{%- if from_official %}
42+
nginx_official_repo_keyring:
43+
file.managed:
44+
- name: {{ nginx.lookup.package_repo_keyring }}
45+
- source: {{ files_switch(['nginx-archive-keyring.gpg'],
46+
lookup='nginx_official_repo_keyring'
47+
)
48+
}}
49+
- require_in:
50+
- pkgrepo: nginx_official_repo
51+
{%- endif %}
52+
3753
nginx_official_repo:
3854
pkgrepo:
3955
{%- if from_official %}
@@ -42,10 +58,10 @@ nginx_official_repo:
4258
- absent
4359
{%- endif %}
4460
- humanname: nginx apt repo
45-
- name: deb http://nginx.org/packages/{{ grains['os'].lower() }}/ {{ grains['oscodename'] }} nginx
46-
- file: /etc/apt/sources.list.d/nginx-official-{{ grains['oscodename'] }}.list
47-
- keyid: ABF5BD827BD9BF62
48-
- keyserver: keyserver.ubuntu.com
61+
- name: >-
62+
deb [signed-by={{ nginx.lookup.package_repo_keyring }}]
63+
http://nginx.org/packages/{{ grains.os | lower }}/ {{ grains.oscodename }} nginx
64+
- file: /etc/apt/sources.list.d/nginx-official-{{ grains.oscodename }}.list
4965
- require_in:
5066
- pkg: nginx_install
5167
- watch_in:
@@ -60,10 +76,10 @@ nginx_ppa_repo:
6076
{%- else %}
6177
- absent
6278
{%- endif %}
63-
{% if salt['grains.get']('os') == 'Ubuntu' %}
79+
{% if grains.os == 'Ubuntu' %}
6480
- ppa: nginx/{{ nginx.ppa_version }}
6581
{% else %}
66-
- name: deb http://ppa.launchpad.net/nginx/{{ nginx.ppa_version }}/ubuntu {{ grains['oscodename'] }} main
82+
- name: deb http://ppa.launchpad.net/nginx/{{ nginx.ppa_version }}/ubuntu {{ grains.oscodename }} main
6783
- keyid: C300EE8C
6884
- keyserver: keyserver.ubuntu.com
6985
{% endif %}
@@ -73,6 +89,30 @@ nginx_ppa_repo:
7389
- pkg: nginx_install
7490
{%- endif %}
7591
92+
{%- if from_phusionpassenger %}
93+
nginx_phusionpassenger_repo_keyring:
94+
file.managed:
95+
- name: /usr/share/keyrings/phusionpassenger-archive-keyring.gpg
96+
- source: {{ files_switch(['phusionpassenger-archive-keyring.gpg'],
97+
lookup='nginx_phusionpassenger_repo_keyring'
98+
)
99+
}}
100+
- require_in:
101+
- pkgrepo: nginx_phusionpassenger_repo
102+
103+
# Remove the old repo file
104+
nginx_phusionpassenger_repo_remove:
105+
pkgrepo.absent:
106+
- name: deb http://nginx.org/packages/{{ grains.os |lower }}/ {{ grains.oscodename }} nginx
107+
- keyid: 561F9B9CAC40B2F7
108+
- require_in:
109+
- pkgrepo: nginx_phusionpassenger_repo
110+
file.absent:
111+
- name: /etc/apt/sources.list.d/nginx-phusionpassenger-{{ grains.oscodename }}.list
112+
- require_in:
113+
- pkgrepo: nginx_phusionpassenger_repo
114+
{%- endif %}
115+
76116
nginx_phusionpassenger_repo:
77117
pkgrepo:
78118
{%- if from_phusionpassenger %}
@@ -81,17 +121,17 @@ nginx_phusionpassenger_repo:
81121
- absent
82122
{%- endif %}
83123
- humanname: nginx phusionpassenger repo
84-
- name: deb https://oss-binaries.phusionpassenger.com/apt/passenger {{ grains['oscodename'] }} main
85-
- file: /etc/apt/sources.list.d/nginx-phusionpassenger-{{ grains['oscodename'] }}.list
86-
- keyid: 561F9B9CAC40B2F7
87-
- keyserver: keyserver.ubuntu.com
124+
- name: >-
125+
deb [signed-by={{ nginx.lookup.passenger_package_repo_keyring }}]
126+
https://oss-binaries.phusionpassenger.com/apt/passenger {{ grains.oscodename }} main
127+
- file: /etc/apt/sources.list.d/phusionpassenger-official-{{ grains.oscodename }}.list
88128
- require_in:
89129
- pkg: nginx_install
90130
- watch_in:
91131
- pkg: nginx_install
92132
{% endif %}
93133
94-
{% if salt['grains.get']('os_family') == 'Suse' or salt['grains.get']('os') == 'SUSE' %}
134+
{% if grains.os_family == 'Suse' or grains.os == 'SUSE' %}
95135
nginx_zypp_repo:
96136
pkgrepo:
97137
{%- if from_official %}
@@ -112,8 +152,8 @@ nginx_zypp_repo:
112152
- pkg: nginx_install
113153
{% endif %}
114154
115-
{% if salt['grains.get']('os_family') == 'RedHat' %}
116-
{% if salt['grains.get']('osfinger', '') in ['Amazon Linux-2'] %}
155+
{% if grains.os_family == 'RedHat' %}
156+
{% if grains.get('osfinger', '') == 'Amazon Linux-2' %}
117157
nginx_epel_repo:
118158
pkgrepo.managed:
119159
- name: epel
@@ -138,7 +178,7 @@ nginx_yum_repo:
138178
{%- endif %}
139179
- name: nginx
140180
- humanname: nginx repo
141-
{%- if salt['grains.get']('os') == 'CentOS' %}
181+
{%- if grains.os == 'CentOS' %}
142182
- baseurl: 'http://nginx.org/packages/centos/$releasever/$basearch/'
143183
{%- else %}
144184
- baseurl: 'http://nginx.org/packages/rhel/{{ nginx.lookup.rh_os_releasever }}/$basearch/'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
case platform.family
4+
when 'redhat'
5+
repo_file = '/etc/yum.repos.d/passenger.repo'
6+
repo_url = 'https://oss-binaries.phusionpassenger.com/yum/passenger/el/$releasever/$basearch'
7+
when 'debian'
8+
# Inspec does not provide a `codename` matcher, so we add ours
9+
finger_codename = {
10+
'ubuntu-18.04' => 'bionic',
11+
'ubuntu-20.04' => 'focal',
12+
'debian-9' => 'stretch',
13+
'debian-10' => 'buster',
14+
'debian-11' => 'bullseye'
15+
}
16+
codename = finger_codename[system.platform[:finger]]
17+
18+
repo_keyring = '/usr/share/keyrings/phusionpassenger-archive-keyring.gpg'
19+
repo_file = "/etc/apt/sources.list.d/phusionpassenger-official-#{codename}.list"
20+
# rubocop:disable Metrics/LineLength
21+
repo_url = "deb [signed-by=#{repo_keyring}] https://oss-binaries.phusionpassenger.com/apt/passenger #{codename} main"
22+
# rubocop:enable Metrics/LineLength
23+
end
24+
25+
control 'Phusion-passenger repository keyring' do
26+
title 'should be installed'
27+
28+
only_if('Requirement for Debian family') do
29+
os.debian?
30+
end
31+
32+
describe file(repo_keyring) do
33+
it { should exist }
34+
it { should be_owned_by 'root' }
35+
it { should be_grouped_into 'root' }
36+
its('mode') { should cmp '0644' }
37+
end
38+
end
39+
40+
control 'Phusion-passenger repository' do
41+
impact 1
42+
title 'should be configured'
43+
describe file(repo_file) do
44+
its('content') { should include repo_url }
45+
end
46+
end

0 commit comments

Comments
 (0)