/
system_packages_doc.go
188 lines (175 loc) · 7.75 KB
/
system_packages_doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2020 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package builtin
import (
"github.com/snapcore/snapd/interfaces"
"github.com/snapcore/snapd/interfaces/apparmor"
"github.com/snapcore/snapd/interfaces/mount"
"github.com/snapcore/snapd/osutil"
)
const systemPackagesDocSummary = `allows access to documentation of system packages`
const systemPackagesDocBaseDeclarationSlots = `
system-packages-doc:
allow-installation:
slot-snap-type:
- core
deny-auto-connection: true
`
const systemPackagesDocConnectedPlugAppArmor = `
# Description: can access documentation of system packages.
/usr/{,local/}share/doc/{,**} r,
/usr/share/cups/doc-root/{,**} r,
/usr/share/gimp/2.0/help/{,**} r,
/usr/share/gtk-doc/{,**} r,
/usr/share/javascript/{jquery,sphinxdoc}/{,**} r,
/usr/share/libreoffice/help/{,**} r,
/usr/share/sphinx_rtd_theme/{,**} r,
/usr/share/xubuntu-docs/{,**} r,
`
type systemPackagesDocInterface struct {
commonInterface
}
func (iface *systemPackagesDocInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
spec.AddSnippet(systemPackagesDocConnectedPlugAppArmor)
emit := spec.AddUpdateNSf
emit(" # Mount documentation of system packages\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/doc/ -> /usr/share/doc/,\n")
emit(" remount options=(bind, ro) /usr/share/doc/,\n")
emit(" umount /usr/share/doc/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/local/share/doc/ -> /usr/local/share/doc/,\n")
emit(" remount options=(bind, ro) /usr/local/share/doc/,\n")
emit(" umount /usr/local/share/doc/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/cups/doc-root/ -> /usr/share/cups/doc-root/,\n")
emit(" remount options=(bind, ro) /usr/share/cups/doc-root/,\n")
emit(" umount /usr/share/cups/doc-root/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/gimp/2.0/help/ -> /usr/share/gimp/2.0/help/,\n")
emit(" remount options=(bind, ro) /usr/share/gimp/2.0/help/,\n")
emit(" umount /usr/share/gimp/2.0/help/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/gtk-doc/ -> /usr/share/gtk-doc/,\n")
emit(" remount options=(bind, ro) /usr/share/gtk-doc/,\n")
emit(" umount /usr/share/gtk-doc/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/javascript/jquery/ -> /usr/share/javascript/jquery/,\n")
emit(" remount options=(bind, ro) /usr/share/javascript/jquery/,\n")
emit(" umount /usr/share/javascript/jquery/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/javascript/sphinxdoc/ -> /usr/share/javascript/sphinxdoc/,\n")
emit(" remount options=(bind, ro) /usr/share/javascript/sphinxdoc/,\n")
emit(" umount /usr/share/javascript/sphinxdoc/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/libreoffice/help/ -> /usr/share/libreoffice/help/,\n")
emit(" remount options=(bind, ro) /usr/share/libreoffice/help/,\n")
emit(" umount /usr/share/libreoffice/help/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/sphinx_rtd_theme/ -> /usr/share/sphinx_rtd_theme/,\n")
emit(" remount options=(bind, ro) /usr/share/sphinx_rtd_theme/,\n")
emit(" umount /usr/share/sphinx_rtd_theme/,\n")
emit(" mount options=(bind) /var/lib/snapd/hostfs/usr/share/xubuntu-docs/ -> /usr/share/xubuntu-docs/,\n")
emit(" remount options=(bind, ro) /usr/share/xubuntu-docs/,\n")
emit(" umount /usr/share/xubuntu-docs/,\n")
// The mount targets under /usr/share/ do not necessarily exist in the
// base image, in which case, we need to create a writable mimic.
apparmor.GenWritableProfile(emit, "/usr/share/cups/", 3)
apparmor.GenWritableProfile(emit, "/usr/share/gimp/2.0/", 3)
apparmor.GenWritableProfile(emit, "/usr/share/javascript/jquery/", 3)
apparmor.GenWritableProfile(emit, "/usr/share/javascript/sphinxdoc/", 3)
apparmor.GenWritableProfile(emit, "/usr/share/libreoffice/", 3)
apparmor.GenWritableProfile(emit, "/usr/share/sphinx_rtd_theme/", 3)
if base := plug.Snap().Base; base == "bare" || base == "test-snapd-base-bare" {
// The bare snap does not have enough mount points, causing us to create a mimic over /
// which only works when snap-update-ns is invoked without the sandbox by snapd. When invoked
// from starting snap via the snap-run -> snap-confine -> snap-update-ns chain, the permissions
// are not sufficient.
//
// In essence, constructing this sort of mimic requires nearly arbitrary writes/mounts at root:
// See bug comments for details LP:#2044335
emit(`
# Writable mimic over / - extra permissions generalized
"/**" rw,
mount options=(rbind, rw) "/**" -> "/tmp/.snap/**",
mount fstype=tmpfs options=(rw) tmpfs -> "/**",
mount options=(rbind, rw) "/tmp/.snap/**" -> "/**",
mount options=(bind, rw) "/tmp/.snap/**" -> "/**",
mount options=(rprivate) -> "/tmp/.snap/**",
mount options=(rprivate) -> "/**",
umount "/**",
`)
}
return nil
}
func (iface *systemPackagesDocInterface) MountConnectedPlug(spec *mount.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/doc",
Dir: "/usr/share/doc",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/local/share/doc",
Dir: "/usr/local/share/doc",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/cups/doc-root",
Dir: "/usr/share/cups/doc-root",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/gimp/2.0/help",
Dir: "/usr/share/gimp/2.0/help",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/gtk-doc",
Dir: "/usr/share/gtk-doc",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/javascript/jquery",
Dir: "/usr/share/javascript/jquery",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/javascript/sphinxdoc",
Dir: "/usr/share/javascript/sphinxdoc",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/libreoffice/help",
Dir: "/usr/share/libreoffice/help",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/sphinx_rtd_theme",
Dir: "/usr/share/sphinx_rtd_theme",
Options: []string{"bind", "ro"},
})
spec.AddMountEntry(osutil.MountEntry{
Name: "/var/lib/snapd/hostfs/usr/share/xubuntu-docs",
Dir: "/usr/share/xubuntu-docs",
Options: []string{"bind", "ro"},
})
return nil
}
func init() {
registerIface(&systemPackagesDocInterface{
commonInterface: commonInterface{
name: "system-packages-doc",
summary: systemPackagesDocSummary,
implicitOnClassic: true,
baseDeclarationSlots: systemPackagesDocBaseDeclarationSlots,
// affects the plug snap because of mount backend
affectsPlugOnRefresh: true,
},
})
}