summaryrefslogtreecommitdiffstats
path: root/meta-integrity/README.md
diff options
context:
space:
mode:
authorArmin Kuster <akuster808@gmail.com>2019-05-16 15:41:49 -0700
committerArmin Kuster <akuster808@gmail.com>2019-05-28 07:38:41 -0700
commit6680225c05bb0834280307c223c3a545b088cbd3 (patch)
tree701dca648e192c492e1165020a900028adefcbb2 /meta-integrity/README.md
parent479d9cc23a741e89b2bd4884b62d8623b1cf2a19 (diff)
downloadmeta-security-6680225c05bb0834280307c223c3a545b088cbd3.tar.gz
meta-integrity: port over from meta-intel-iot-security
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'meta-integrity/README.md')
-rw-r--r--meta-integrity/README.md253
1 files changed, 253 insertions, 0 deletions
diff --git a/meta-integrity/README.md b/meta-integrity/README.md
new file mode 100644
index 0000000..ba96d8e
--- /dev/null
+++ b/meta-integrity/README.md
@@ -0,0 +1,253 @@
1This README file contains information on the contents of the
2integrity layer.
3
4Please see the corresponding sections below for details.
5
6
7Dependencies
8============
9
10This layer depends on:
11
12 URI: git://git.openembedded.org/bitbake
13 branch: master
14
15 URI: git://git.openembedded.org/openembedded-core
16 layers: meta
17 branch: master
18
19 URI: git://github.com/01org/meta-security/meta-integrate
20 layers: security-framework
21 branch: master
22
23
24Patches
25=======
26
27Please submit any patches against the integrity layer via Github
28pull requests.
29
30For discussion or patch submission via email, use the
31yocto@yoctoproject.org mailing list. When submitting patches that way,
32make sure to copy the maintainer and add a "[meta-]"
33prefix to the subject of the mails.
34
35Maintainer: Armin Kuster <akuster808@gmail.com>
36
37
38Table of Contents
39=================
40
411. Adding the integrity layer to your build
422. Usage
433. Known Issues
44
45
461. Adding the integrity layer to your build
47===========================================
48
49In order to use this layer, you need to make the build system aware of
50it.
51
52Assuming the security repository exists at the top-level of your
53yocto build tree, you can add it to the build system by adding the
54location of the integrity layer to bblayers.conf, along with any
55other layers needed. e.g.:
56
57 BBLAYERS ?= " \
58 /path/to/yocto/meta \
59 /path/to/yocto/meta-yocto \
60 /path/to/yocto/meta-yocto-bsp \
61 /path/to/yocto/meta-security/meta-integrity \
62 "
63
64It has some dependencies on a suitable BSP; in particular the kernel
65must have a recent enough IMA/EVM subsystem. The layer was tested with
66Linux 3.19 and uses some features (like loading X509 certificates
67directly from the kernel) which were added in that release. Your
68mileage may vary with older kernels.
69
70The necessary kernel configuration parameters are added to all kernel
71versions by this layer. Watch out for QA warnings about unused kernel
72configuration parameters: those indicate that the kernel used by the BSP
73does not have the necessary IMA/EVM features.
74
75Adding the layer only enables IMA (see below regarding EVM) during
76compilation of the Linux kernel. To also activate it when building
77the image, enable image signing in the local.conf like this:
78
79 INHERIT += "ima-evm-rootfs"
80 IMA_EVM_KEY_DIR = "${IMA_EVM_BASE}/data/debug-keys"
81
82This uses the default keys provided in the "data" directory of the layer.
83Because everyone has access to these private keys, such an image
84should never be used in production!
85
86For that, create your own keys first. All tools and scripts required
87for that are included in the layer. This is also how the
88``debug-keys`` were generated:
89
90 # Choose a directory for storing keys. Preserve this
91 # across builds and keep its private keys secret!
92 export IMA_EVM_KEY_DIR=/tmp/imaevm
93 mkdir -p $IMA_EVM_KEY_DIR
94 # Build the required tools.
95 bitbake openssl-native
96 # Set up shell for use of the tools.
97 bitbake -c devshell openssl-native
98 cd $IMA_EVM_KEY_DIR
99 # In that shell, create the keys. Several options exist:
100
101 # 1. Self-signed keys.
102 $IMA_EVM_BASE/scripts/ima-gen-self-signed.sh
103
104 # 2. Keys signed by a new CA.
105 # When asked for a PEM passphrase, that will be for the root CA.
106 # Signing images then will not require entering that passphrase,
107 # only creating new certificates does. Most likely the default
108 # attributes for these certificates need to be adapted; modify
109 # the scripts as needed.
110 # $IMA_EVM_BASE/scripts/ima-gen-local-ca.sh
111 # $IMA_EVM_BASE/scripts/ima-gen-CA-signed.sh
112
113 # 3. Keys signed by an existing CA.
114 # $IMA_EVM_BASE/scripts/ima-gen-CA-signed.sh <CA.pem> <CA.priv>
115 exit
116
117When using ``ima-self-signed.sh`` as described above, self-signed keys
118are created. Alternatively, one can also use keys signed by a CA. The
119``ima-gen-local-ca.sh`` and ``ima-gen.sh`` scripts create a root CA
120and sign the signing keys with it. The ``ima-evm-rootfs.bbclass`` then
121supports adding tha CA's public key to the kernel's system keyring by
122compiling it directly into the kernel. Because it is unknown whether
123that is necessary (for example, the CA might also get added to the
124system key ring via UEFI Secure Boot), one has to enable compilation
125into the kernel explicitly in a local.conf with:
126
127 IMA_EVM_ROOT_CA = "<path to .x509 file, for example the ima-local-ca.x509 created by ima-gen-local-ca.sh>"
128
129
130
131
132To use the personal keys, override the default IMA_EVM_KEY_DIR in your
133local.conf and/or override the individual variables from
134ima-evm-rootfs.bbclass:
135
136 IMA_EVM_KEY_DIR = "<full path>"
137 IMA_EVM_PRIVKEY = "<some other path/privkey_ima.pem>"
138
139By default, the entire file system gets signed. When using a policy which
140does not require that, the set of files to be labelled can be chosen
141by overriding the default "find" expression, for example like this:
142
143 IMA_EVM_ROOTFS_FILES = "usr sbin bin lib -type f"
144
145
1462. Usage
147========
148
149After creating an image with IMA/EVM enabled, one needs to enable
150the built-in policies before IMA/EVM is active at runtime. To do this,
151add one or both of these boot parameters:
152
153 ima_tcb # measures all files read as root and all files executed
154 ima_appraise_tcb # appraises all files owned by root, beware of
155 # the known issue mentioned below
156
157Instead of booting with default policies, one can also activate custom
158policies in different ways. First, boot without any IMA policy and
159then cat a policy file into
160`/sys/kernel/security/ima/policy`. This can only be done once
161after booting and is useful for debugging.
162
163In production, the long term goal is to load a verified policy
164directly from the kernel, using a patch which still needs to be
165included upstream ("ima: load policy from the kernel",
166<https://lwn.net/Articles/595759/>).
167
168Loading via systemd also works with systemd, but is considered less
169secure (policy file is not checked before activating it). Beware that
170IMA policy loading became broken in systemd 2.18. The modified systemd
1712.19 in meta-security-smack has a patch reverting the broken
172changes. To activate policy loading via systemd, place a policy file
173in `/etc/ima/ima-policy`, for example with:
174
175 IMA_EVM_POLICY_SYSTEMD = "${IMA_EVM_BASE}/data/ima_policy_simple"
176
177To check that measuring works, look at `/sys/kernel/security/ima/ascii_runtime_measurements`
178
179To check that appraisal works, try modifying executables and ensure
180that executing them fails:
181
182 echo "foobar" >>/usr/bin/rpm
183 evmctl ima_verify /usr/bin/rpm
184 rpm --version
185
186Depending on the current appraisal policy, the `echo` command may
187already fail because writing is not allowed. If the file was modified
188and the current appraisal policy allows reading, then `evmctl` will
189report (the errno value seems to be printed always and is unrelated to
190the actual verification failure here):
191
192 Verification failed: 35
193 errno: No such file or directory (2)
194
195After enabling a suitable IMA appraisal policy, reading and/or
196executing the file is no longer allowed:
197
198 # evmctl ima_verify /usr/bin/rpm
199 Failed to open: /usr/bin/rpm
200 errno: Permission denied (13)
201 # rpm --version
202 -sh: /usr/bin/rpm: Permission denied
203
204Enabling the audit kernel subsystem may help to debug appraisal
205issues. Enable it by adding the meta-security-framework layer and
206changing your local.conf:
207 SRC_URI_append_pn-linux-yocto = " file://audit.cfg"
208 CORE_IMAGE_EXTRA_INSTALL += "auditd"
209
210Then boot with "ima_appraise=log ima_appraise_tcb".
211
212Adding auditd is not strictly necessary but helps to capture a
213more complete set of events in /var/log/audit/ and search in
214them with ausearch.
215
216
2173. Known Issues
218===============
219
220EVM is not enabled, for multiple reasons:
221* Signing files in advance with a X509 certificate and then not having
222 any confidential keys on the device would be the most useful mode,
223 but is not supported by EVM [1].
224* EVM signing in advance would only work on the final file system and thus
225 will require further integration work with image creation. The content
226 of the files can be signed for IMA in the rootfs, with the extended
227 attributes remaining valid when copying the files to the final image.
228 But for EVM that copy operation changes relevant parameters (for example,
229 inode) and thus invalidates the EVM hash.
230* On device creation of EVM hashes depends on secure key handling on the
231 device (TPM) and booting at least once in a special mode (file system
232 writable, evm=fix as boot parameter, reboot after opening all files);
233 such a mode is too device specific to be implemented in a generic way.
234
235IMA appraisal with "ima_appraise_tcb" enables rules which are too strict
236for most distros. For example, systemd needs to write certain files
237as root, which is prevented by the ima_appraise_tcb appraise rules. As
238a result, the system fails to boot:
239
240 [FAILED] Failed to start Commit a transient machine-id on disk.
241 See "systemctl status systemd-machine-id-commit.service" for details.
242 ...
243 [FAILED] Failed to start Network Service.
244 See "systemctl status systemd-networkd.service" for details.
245 [FAILED] Failed to start Login Service.
246 See "systemctl status systemd-logind.service" for details.
247
248No package manager is integrated with IMA/EVM. When updating packages,
249files will end up getting installed without correct IMA/EVM attributes
250and thus will not be usable when appraisal is turned on.
251
252[1] http://permalink.gmane.org/gmane.comp.handhelds.tizen.devel/6281
253[2] http://permalink.gmane.org/gmane.comp.handhelds.tizen.devel/6275