Skip to content

Commit 037c13a

Browse files
committed
feat(debian): use keyrings instead of key_ids
1 parent 3402374 commit 037c13a

File tree

5 files changed

+127
-8
lines changed

5 files changed

+127
-8
lines changed

docs/README.apt.keyrings.rst

Lines changed: 34 additions & 0 deletions
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+
Ngninx
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.
188 KB
Binary file not shown.

nginx/pkg.sls

Lines changed: 44 additions & 8 deletions
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 %}
@@ -34,6 +38,18 @@ nginx_install:
3438
{% endif %}
3539
3640
{% if salt['grains.get']('os_family') == 'Debian' %}
41+
{%- if from_official %}
42+
nginx_official_repo_keyring:
43+
file.managed:
44+
- name: /usr/share/keyrings/nginx-archive-keyring.gpg
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,8 @@ 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
61+
- name: deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/{{ grains['os'].lower() }}/ {{ grains['oscodename'] }} nginx
4662
- file: /etc/apt/sources.list.d/nginx-official-{{ grains['oscodename'] }}.list
47-
- keyid: ABF5BD827BD9BF62
48-
- keyserver: keyserver.ubuntu.com
4963
- require_in:
5064
- pkg: nginx_install
5165
- watch_in:
@@ -73,6 +87,30 @@ nginx_ppa_repo:
7387
- pkg: nginx_install
7488
{%- endif %}
7589
90+
{%- if from_phusionpassenger %}
91+
nginx_phusionpassenger_repo_keyring:
92+
file.managed:
93+
- name: /usr/share/keyrings/phusionpassenger-archive-keyring.gpg
94+
- source: {{ files_switch(['phusionpassenger-archive-keyring.gpg'],
95+
lookup='nginx_phusionpassenger_repo_keyring'
96+
)
97+
}}
98+
- require_in:
99+
- pkgrepo: nginx_phusionpassenger_repo
100+
101+
# Remove the old repo file
102+
nginx_phusionpassenger_repo_remove:
103+
pkgrepo.absent:
104+
- name: deb http://nginx.org/packages/{{ grains['os'].lower() }}/ {{ grains['oscodename'] }} nginx
105+
- keyid: 561F9B9CAC40B2F7
106+
- require_in:
107+
- pkgrepo: nginx_phusionpassenger_repo
108+
file.absent:
109+
- name: /etc/apt/sources.list.d/nginx-phusionpassenger-{{ grains['oscodename'] }}.list
110+
- require_in:
111+
- pkgrepo: nginx_phusionpassenger_repo
112+
{%- endif %}
113+
76114
nginx_phusionpassenger_repo:
77115
pkgrepo:
78116
{%- if from_phusionpassenger %}
@@ -81,10 +119,8 @@ nginx_phusionpassenger_repo:
81119
- absent
82120
{%- endif %}
83121
- 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
122+
- name: deb [signed-by=/usr/share/keyrings/phusionpassenger-archive-keyring.gpg] https://oss-binaries.phusionpassenger.com/apt/passenger {{ grains['oscodename'] }} main
123+
- file: /etc/apt/sources.list.d/phusionpassenger-official-{{ grains['oscodename'] }}.list
88124
- require_in:
89125
- pkg: nginx_install
90126
- watch_in:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# frozen_string_literal: true
2+
3+
case os[:name]
4+
when 'centos'
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', 'ubuntu'
8+
# Inspec does not provide a `codename` matcher, so we add ours
9+
case platform[:release].to_f.truncate
10+
# ubuntu
11+
when 18
12+
codename = 'bionic'
13+
when 20
14+
codename = 'focal'
15+
# debian
16+
when 10
17+
codename = 'buster'
18+
when 11
19+
codename = 'bullseye'
20+
end
21+
repo_keyring = '/usr/share/keyrings/phusionpassenger-archive-keyring.gpg'
22+
repo_file = "/etc/apt/sources.list.d/phusionpassenger-official-#{codename}.list"
23+
# rubocop:disable Metrics/LineLength
24+
repo_url = "deb [signed-by=#{repo_keyring}] https://oss-binaries.phusionpassenger.com/apt/passenger #{codename} main"
25+
# rubocop:enable Metrics/LineLength
26+
end
27+
28+
control 'Phusion-passenger repository keyring' do
29+
title 'should be installed'
30+
31+
only_if('Requirement for Debian family') do
32+
os.debian?
33+
end
34+
35+
describe file(repo_keyring) do
36+
it { should exist }
37+
it { should be_owned_by 'root' }
38+
it { should be_grouped_into 'root' }
39+
its('mode') { should cmp '0644' }
40+
end
41+
end
42+
43+
control 'Phusion-passenger repository' do
44+
impact 1
45+
title 'should be configured'
46+
describe file(repo_file) do
47+
its('content') { should include repo_url }
48+
end
49+
end

0 commit comments

Comments
 (0)