diff options
author | Armin Kuster <akuster808@gmail.com> | 2019-05-16 15:41:49 -0700 |
---|---|---|
committer | Armin Kuster <akuster808@gmail.com> | 2019-05-28 07:38:41 -0700 |
commit | 6680225c05bb0834280307c223c3a545b088cbd3 (patch) | |
tree | 701dca648e192c492e1165020a900028adefcbb2 /meta-integrity/README.md | |
parent | 479d9cc23a741e89b2bd4884b62d8623b1cf2a19 (diff) | |
download | meta-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.md | 253 |
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 @@ | |||
1 | This README file contains information on the contents of the | ||
2 | integrity layer. | ||
3 | |||
4 | Please see the corresponding sections below for details. | ||
5 | |||
6 | |||
7 | Dependencies | ||
8 | ============ | ||
9 | |||
10 | This 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 | |||
24 | Patches | ||
25 | ======= | ||
26 | |||
27 | Please submit any patches against the integrity layer via Github | ||
28 | pull requests. | ||
29 | |||
30 | For discussion or patch submission via email, use the | ||
31 | yocto@yoctoproject.org mailing list. When submitting patches that way, | ||
32 | make sure to copy the maintainer and add a "[meta-]" | ||
33 | prefix to the subject of the mails. | ||
34 | |||
35 | Maintainer: Armin Kuster <akuster808@gmail.com> | ||
36 | |||
37 | |||
38 | Table of Contents | ||
39 | ================= | ||
40 | |||
41 | 1. Adding the integrity layer to your build | ||
42 | 2. Usage | ||
43 | 3. Known Issues | ||
44 | |||
45 | |||
46 | 1. Adding the integrity layer to your build | ||
47 | =========================================== | ||
48 | |||
49 | In order to use this layer, you need to make the build system aware of | ||
50 | it. | ||
51 | |||
52 | Assuming the security repository exists at the top-level of your | ||
53 | yocto build tree, you can add it to the build system by adding the | ||
54 | location of the integrity layer to bblayers.conf, along with any | ||
55 | other 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 | |||
64 | It has some dependencies on a suitable BSP; in particular the kernel | ||
65 | must have a recent enough IMA/EVM subsystem. The layer was tested with | ||
66 | Linux 3.19 and uses some features (like loading X509 certificates | ||
67 | directly from the kernel) which were added in that release. Your | ||
68 | mileage may vary with older kernels. | ||
69 | |||
70 | The necessary kernel configuration parameters are added to all kernel | ||
71 | versions by this layer. Watch out for QA warnings about unused kernel | ||
72 | configuration parameters: those indicate that the kernel used by the BSP | ||
73 | does not have the necessary IMA/EVM features. | ||
74 | |||
75 | Adding the layer only enables IMA (see below regarding EVM) during | ||
76 | compilation of the Linux kernel. To also activate it when building | ||
77 | the 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 | |||
82 | This uses the default keys provided in the "data" directory of the layer. | ||
83 | Because everyone has access to these private keys, such an image | ||
84 | should never be used in production! | ||
85 | |||
86 | For that, create your own keys first. All tools and scripts required | ||
87 | for 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 | |||
117 | When using ``ima-self-signed.sh`` as described above, self-signed keys | ||
118 | are 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 | ||
120 | and sign the signing keys with it. The ``ima-evm-rootfs.bbclass`` then | ||
121 | supports adding tha CA's public key to the kernel's system keyring by | ||
122 | compiling it directly into the kernel. Because it is unknown whether | ||
123 | that is necessary (for example, the CA might also get added to the | ||
124 | system key ring via UEFI Secure Boot), one has to enable compilation | ||
125 | into 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 | |||
132 | To use the personal keys, override the default IMA_EVM_KEY_DIR in your | ||
133 | local.conf and/or override the individual variables from | ||
134 | ima-evm-rootfs.bbclass: | ||
135 | |||
136 | IMA_EVM_KEY_DIR = "<full path>" | ||
137 | IMA_EVM_PRIVKEY = "<some other path/privkey_ima.pem>" | ||
138 | |||
139 | By default, the entire file system gets signed. When using a policy which | ||
140 | does not require that, the set of files to be labelled can be chosen | ||
141 | by overriding the default "find" expression, for example like this: | ||
142 | |||
143 | IMA_EVM_ROOTFS_FILES = "usr sbin bin lib -type f" | ||
144 | |||
145 | |||
146 | 2. Usage | ||
147 | ======== | ||
148 | |||
149 | After creating an image with IMA/EVM enabled, one needs to enable | ||
150 | the built-in policies before IMA/EVM is active at runtime. To do this, | ||
151 | add 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 | |||
157 | Instead of booting with default policies, one can also activate custom | ||
158 | policies in different ways. First, boot without any IMA policy and | ||
159 | then cat a policy file into | ||
160 | `/sys/kernel/security/ima/policy`. This can only be done once | ||
161 | after booting and is useful for debugging. | ||
162 | |||
163 | In production, the long term goal is to load a verified policy | ||
164 | directly from the kernel, using a patch which still needs to be | ||
165 | included upstream ("ima: load policy from the kernel", | ||
166 | <https://lwn.net/Articles/595759/>). | ||
167 | |||
168 | Loading via systemd also works with systemd, but is considered less | ||
169 | secure (policy file is not checked before activating it). Beware that | ||
170 | IMA policy loading became broken in systemd 2.18. The modified systemd | ||
171 | 2.19 in meta-security-smack has a patch reverting the broken | ||
172 | changes. To activate policy loading via systemd, place a policy file | ||
173 | in `/etc/ima/ima-policy`, for example with: | ||
174 | |||
175 | IMA_EVM_POLICY_SYSTEMD = "${IMA_EVM_BASE}/data/ima_policy_simple" | ||
176 | |||
177 | To check that measuring works, look at `/sys/kernel/security/ima/ascii_runtime_measurements` | ||
178 | |||
179 | To check that appraisal works, try modifying executables and ensure | ||
180 | that executing them fails: | ||
181 | |||
182 | echo "foobar" >>/usr/bin/rpm | ||
183 | evmctl ima_verify /usr/bin/rpm | ||
184 | rpm --version | ||
185 | |||
186 | Depending on the current appraisal policy, the `echo` command may | ||
187 | already fail because writing is not allowed. If the file was modified | ||
188 | and the current appraisal policy allows reading, then `evmctl` will | ||
189 | report (the errno value seems to be printed always and is unrelated to | ||
190 | the actual verification failure here): | ||
191 | |||
192 | Verification failed: 35 | ||
193 | errno: No such file or directory (2) | ||
194 | |||
195 | After enabling a suitable IMA appraisal policy, reading and/or | ||
196 | executing 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 | |||
204 | Enabling the audit kernel subsystem may help to debug appraisal | ||
205 | issues. Enable it by adding the meta-security-framework layer and | ||
206 | changing your local.conf: | ||
207 | SRC_URI_append_pn-linux-yocto = " file://audit.cfg" | ||
208 | CORE_IMAGE_EXTRA_INSTALL += "auditd" | ||
209 | |||
210 | Then boot with "ima_appraise=log ima_appraise_tcb". | ||
211 | |||
212 | Adding auditd is not strictly necessary but helps to capture a | ||
213 | more complete set of events in /var/log/audit/ and search in | ||
214 | them with ausearch. | ||
215 | |||
216 | |||
217 | 3. Known Issues | ||
218 | =============== | ||
219 | |||
220 | EVM 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 | |||
235 | IMA appraisal with "ima_appraise_tcb" enables rules which are too strict | ||
236 | for most distros. For example, systemd needs to write certain files | ||
237 | as root, which is prevented by the ima_appraise_tcb appraise rules. As | ||
238 | a 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 | |||
248 | No package manager is integrated with IMA/EVM. When updating packages, | ||
249 | files will end up getting installed without correct IMA/EVM attributes | ||
250 | and 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 | ||