]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apt/recipes/repository.rb
Give up on allowing shared access to APT repository
[chef.git] / cookbooks / apt / recipes / repository.rb
1 #
2 # Cookbook:: apt
3 # Recipe:: repository
4 #
5 # Copyright:: 2024, Tom Hughes
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 node.default[:accounts][:users][:apt][:status] = :role
21
22 include_recipe "accounts"
23 include_recipe "apache"
24
25 package "aptly"
26
27 repository_keys = data_bag_item("apt", "repository")
28
29 gpg_passphrase = repository_keys["gpg_passphrase"]
30
31 template "/etc/aptly.conf" do
32   source "aptly.conf.erb"
33   owner "root"
34   group "root"
35   mode "644"
36 end
37
38 directory "/srv/apt.openstreetmap.org" do
39   owner "apt"
40   group "apt"
41   mode "755"
42 end
43
44 execute "apt-generate-key" do
45   command "gpg --no-tty --batch --passphrase=#{gpg_passphrase} --generate-key"
46   cwd "/srv/apt.openstreetmap.org"
47   user "apt"
48   group "apt"
49   environment "HOME" => "/srv/apt.openstreetmap.org"
50   input <<~EOS
51     Key-Type: RSA
52     Key-Length: 4096
53     Key-Usage: sign
54     Subkey-Type: RSA
55     Subkey-Length: 4096
56     Subkey-Usage: sign
57     Name-Real: OpenStreetMap Admins
58     Name-Email: admins@openstreetmap.org
59     Expire-Date: 0
60     Passphrase: #{gpg_passphrase}
61   EOS
62   not_if { ::Dir.exist?("/srv/apt.openstreetmap.org/.gnupg") }
63 end
64
65 %w[focal jammy bookworm].each do |distribution|
66   repository = "openstreetmap-#{distribution}"
67
68   execute "aptly-repo-create-#{distribution}" do
69     command "aptly repo create -comment='Packages used on OpenStreetMap Servers' -distribution=#{distribution} #{repository}"
70     cwd "/srv/apt.openstreetmap.org"
71     user "apt"
72     group "apt"
73     environment "HOME" => "/srv/apt.openstreetmap.org"
74     not_if "aptly repo show #{repository}"
75   end
76
77   execute "aptly-publish-repo-#{distribution}" do
78     action :nothing
79     command "aptly publish repo -batch -passphrase=#{gpg_passphrase} #{repository}"
80     cwd "/srv/apt.openstreetmap.org"
81     user "apt"
82     group "apt"
83     environment "HOME" => "/srv/apt.openstreetmap.org"
84     subscribes :run, "execute[aptly-repo-create-#{distribution}]", :immediately
85   end
86
87   execute "aptly-publish-update-#{distribution}" do
88     command "aptly publish update -batch -passphrase=#{gpg_passphrase} #{distribution}"
89     cwd "/srv/apt.openstreetmap.org"
90     user "apt"
91     group "apt"
92     environment "HOME" => "/srv/apt.openstreetmap.org"
93   end
94 end
95
96 execute "gpg-export-key" do
97   command "gpg --no-tty --batch --passphrase=#{gpg_passphrase} --armor --output=/srv/apt.openstreetmap.org/public/gpg.key --export admins@openstreetmap.org"
98   cwd "/srv/apt.openstreetmap.org"
99   user "apt"
100   group "apt"
101   environment "HOME" => "/srv/apt.openstreetmap.org"
102   not_if { ::File.exist?("/srv/apt.openstreetmap.org/public/gpg.key") }
103 end
104
105 ssl_certificate "apt.openstreetmap.org" do
106   domains ["apt.openstreetmap.org", "apt.osm.org"]
107   notifies :reload, "service[apache2]"
108 end
109
110 apache_site "apt.openstreetmap.org" do
111   template "apache.erb"
112   directory "/srv/apt.openstreetmap.org"
113   variables :aliases => ["apt.osm.org"]
114 end