Skip to content

fix(repositories): force aptkey if signed-by and allow aptkey #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apt/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
'preferences': {},
'remove_preferences': false,
'clean_preferences_d': false,
'keyrings_dir': '/etc/apt/keyrings',
'clean_keyrings_d': false,
'remove_apt_conf': false,
'clean_apt_conf_d': false,
'apt_conf_d': {},
Expand Down Expand Up @@ -52,6 +54,8 @@
'preferences': {},
'remove_preferences': false,
'clean_preferences_d': false,
'keyrings_dir': '/etc/apt/keyrings',
'clean_keyrings_d': false,
'remove_apt_conf': false,
'clean_apt_conf_d': false,
'apt_conf_d': {},
Expand Down
15 changes: 15 additions & 0 deletions apt/repositories.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{% set clean_sources_list_d = apt.get('clean_sources_list_d', apt_map.clean_sources_list_d) %}
{% set sources_list_dir = apt.get('sources_list_dir', apt_map.sources_list_dir) %}
{% set repositories = apt.get('repositories', apt_map.repositories) %}
{% set keyrings_dir = apt.get('keyrings_dir', apt_map.keyrings_dir) %}
{% set clean_keyrings_d = apt.get('clean_keyrings_d', apt_map.clean_keyrings_d) %}
{% set default_url = apt.get('default_url', apt_map.default_url) %}
{% set keyring_package = apt.get('keyring_package', apt_map.default_keyring_package) %}

Expand All @@ -30,6 +32,13 @@
- group: root
- clean: {{ clean_sources_list_d }}

{{ keyrings_dir }}:
file.directory:
- mode: '0755'
- user: root
- group: root
- clean: {{ clean_keyrings_d }}

{% for repo, args in repositories.items() %}

{% set r_opts = '' %}
Expand Down Expand Up @@ -69,6 +78,9 @@
the latter will be used. #}
{% if args.key_url is defined %}
- key_url: {{ args.key_url }}
{% if 'signed-by=' in r_opts|lower and args.aptkey is not defined %}
- aptkey: false
{% endif %}
{% elif args.key_text is defined %}
- key_text: {{ args.key_text }}
{% elif args.keyid is defined %}
Expand All @@ -78,6 +90,9 @@
- clean_file: true
- refresh: False
- refresh_db: False
{% if args.aptkey is defined %}
- aptkey: {{ args.aptkey }}
{% endif %}
- onchanges_in:
- module: apt.refresh_db

Expand Down
10 changes: 10 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ apt:
remove_preferences: true
clean_preferences_d: true

keyrings_dir: '/etc/apt/keyrings'
clean_keyrings_d: true

apt_conf_d:
30release:
'APT::Default-Release': stable
Expand Down Expand Up @@ -126,6 +129,13 @@ apt:
opts:
trusted: 'yes'
another: whatever
saltstack:
distro: stable
url: https://packages.broadcom.com/artifactory/saltproject-deb
comps: [main]
type: [binary]
key_url: https://packages.broadcom.com/artifactory/api/security/keypair/SaltProjectKey/public # yamllint disable-line rule:line-length
opts: "signed-by=/etc/apt/keyrings/salt-archive-keyring.pgp"

preferences:
00-rspamd:
Expand Down
19 changes: 19 additions & 0 deletions test/integration/repositories/controls/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,23 @@
describe file('/etc/apt/sources.list.d/raspbian-binary.list') do
it { should_not exist }
end

describe file('/etc/apt/sources.list.d/saltstack.list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its(:content) do
should match(
%r{deb \[\s?signed-by=/etc/apt/keyrings/salt-archive-keyring.pgp\s?\] https://packages.broadcom.com/artifactory/saltproject-deb stable main}
)
end
end

describe file('/etc/apt/keyrings/salt-archive-keyring.pgp') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
end
end
8 changes: 8 additions & 0 deletions test/salt/pillar/repositories.sls
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ apt:
url: http://archive.raspbian.org/raspbian
type: [source]
key_url: https://archive.raspbian.org/raspbian.public.key
saltstack:
filename: saltstack.list
distro: stable
url: https://packages.broadcom.com/artifactory/saltproject-deb
comps: [main]
type: [binary]
key_url: https://packages.broadcom.com/artifactory/api/security/keypair/SaltProjectKey/public # yamllint disable-line rule:line-length
opts: "signed-by=/etc/apt/keyrings/salt-archive-keyring.pgp"
Loading