项目作者: coreycothrum

项目描述 :
mender with LUKS encrypted partitions
高级语言: Shell
项目地址: git://github.com/coreycothrum/meta-mender-luks.git
创建时间: 2020-05-26T12:13:28Z
项目社区:https://github.com/coreycothrum/meta-mender-luks

开源协议:MIT License

下载


meta-mender-luks

LUKS encrypted rootfs and /data partitions for meta-mender. TPM2 integration for unattended boot.

Requires meta-mender-kernel for separate A/B kernel partitions.

Overview

  • The /boot and A/B kernel partitions are left unencrypted.
  • The rootfs and /data partitions are encrypted with detached LUKS headers. The detached headers are stored on the /boot partition.
  • The LUKS passphrase is stored in plain text on the (encrypted) /data partition.
  • An ArtifactInstall state-script mounts the rootfs LUKS partition for mender-client access during an update.
  • Optional TPM2 integration for unattended boot.

#FIXME - flesh this out more, bootflow, etc

#FIXME - coming soon

TPM2 Integration

Requires meta-secure-core. See this kas file for more setup details.

For unattended boot, the LUKS passphrase is loaded/sealed on the TPM2 device. This should be transparent to the user.

  • mender-luks-password-agent reads key and provides to cryptsetup at boot
  • mender-luks-tpm-key-watcher.service updates TPM2 when/if the LUKS key (file, on the filesystem) changes
  • mender updates:
    • mender-luks-state-scripts-tpm unlocks/reseals to MENDER/LUKS_TPM_PCR_UPDATE_UNLOCK after a mender artifact is installed/written.
    • After a reboot, mender-luks-tpm-seal-on-boot.service reseals to MENDER/LUKS_TPM_PCR_SET_MAX if no systemd services have failed after MENDER/LUKS_SEAL_DELAY_SECS (i.e. a successful boot).
      Additional systemd dependencies can by added with MENDER/LUKS_SEAL_SYSTEMD_AFTER.

Utilities and Services

luks-util

#FIXME - coming soon

tpm2-util

#FIXME - coming soon

Dependencies

This layer depends on:

  1. URI: git://git.openembedded.org/bitbake
  2. URI: git://git.openembedded.org/openembedded-core
  3. layers: meta
  4. branch: master
  5. URI: https://github.com/mendersoftware/meta-mender.git
  6. layers: meta-mender-core
  7. branch: master
  8. URI: https://github.com/coreycothrum/meta-mender-kernel.git
  9. layers: meta-mender-kernel
  10. branch: master
  11. URI: https://github.com/coreycothrum/meta-bitbake-variable-substitution.git
  12. layers: meta-bitbake-variable-substitution
  13. branch: master

Installation

Add Layer to Build

In order to use this layer, the build system must be aware of it.

Assuming this layer exists at the top-level of the yocto build tree; add the location of this layer to bblayers.conf, along with any additional layers needed:

  1. BBLAYERS ?= " \
  2. /path/to/yocto/meta \
  3. /path/to/yocto/meta-poky \
  4. /path/to/yocto/meta-yocto-bsp \
  5. /path/to/yocto/meta-mender/meta-mender-core \
  6. /path/to/yocto/meta-bitbake-variable-substitution \
  7. /path/to/yocto/meta-mender-kernel \
  8. /path/to/yocto/meta-mender-luks \
  9. "

Alternatively, run bitbake-layers to add:

  1. $ bitbake-layers add-layer /path/to/yocto/meta-mender-luks

Configure Layer

The following definitions should be added to local.conf or custom_machine.conf

  1. require conf/include/mender-luks.inc
  2. MENDER/LUKS_PASSWORD = "n3w_p@ssw0rd"
  3. # 0 = @ system boot: randomize LUKS password if weak or still set to default value
  4. # 1 = @ system boot: do not check LUKS password
  5. # MENDER/LUKS_BYPASS_RANDOM_KEY = "1"
  6. # 0 = @ system boot: reencrypt LUKS master key(s) if password is still set to default value
  7. # 1 = @ system boot: do no reencrypt LUKS partitions
  8. # MENDER/LUKS_BYPASS_REENCRYPT = "1"
  9. # PCRs levels to seal TPM2
  10. # unlock options: none | min | max | N,N,N
  11. # MENDER/LUKS_TPM_PCR_SET_NONE = "0"
  12. # MENDER/LUKS_TPM_PCR_SET_MIN = "0,1"
  13. # MENDER/LUKS_TPM_PCR_SET_MAX = "0,1,2,3,4,5"
  14. # MENDER/LUKS_TPM_PCR_UPDATE_UNLOCK = "min"

kas

Alternatively, a kas file has been provided to help with setup/config. Include kas/kas.yml from this layer in the top level kas file. E.g.:

  1. header:
  2. version : 1
  3. includes:
  4. - repo: meta-mender-luks
  5. file: kas/kas.yml
  6. local_conf_header:
  7. 01_meta-mender-luks: |
  8. # define here, or in a custom layer
  9. MENDER/LUKS_PASSWORD = "n3w_p@ssw0rd"
  10. MENDER/LUKS_BYPASS_RANDOM_KEY = "1"
  11. MENDER/LUKS_BYPASS_REENCRYPT = "1"

Additional files in kas/ have been provided to selectively turn on some features, such as TPM2 integration.

Building

A standalone reference build kas file has been provided.

Docker

All testing has been done with the Dockerfile located in this repo.

Example/Reference Build

Commands executed from docker image:

  1. # clone repo
  2. cd $YOCTO_WORKDIR && git clone https://github.com/coreycothrum/meta-mender-luks.git
  3. # build TARGET image
  4. cd $YOCTO_WORKDIR && kas build $YOCTO_WORKDIR/meta-mender-luks/kas/reference_builds/kas.min.x86-64.yml
  5. # build QEMU image
  6. cd $YOCTO_WORKDIR && kas build $YOCTO_WORKDIR/meta-mender-luks/kas/reference_builds/kas.min.x86-64.yml:$YOCTO_WORKDIR/meta-mender-luks/kas/reference_builds/kas.qemu.yml

Encrypting

Encryption is not an automated part of the build process. This native script is provided as an optional post-build action.

This is only needed when provisioning a new device from the full disk image. The mender artifacts work as-is w/o this encryption step.

To execute the encryption script:

  1. bitbake mender-luks-encrypt-image-native -caddto_recipe_sysroot && \
  2. oe-run-native mender-luks-encrypt-image-native mender-luks-encrypt-image.sh <path_to_deploy_image>

This will take awhile. If it fails, it may not cleanup gracefully. Check /dev/mapper and /dev/loop* and cleanup as needed
(hint(s): sudo dmsetup remove --force <NAME> and sudo losetup && sudo losetup -D).

Use Notes

  • The mender update artifact (*.mender) is UNENCRYPTED.
  • MENDER_BOOT_PART_SIZE_MB needs to have capacity for detached LUKS headers.
  • Enabling efi-secure-boot is recommended, especially when using unattended boot (requires meta-secure-core).

Contributing

Please submit any patches against this layer via pull request.

Commits must be signed off.

Use conventional commits.

Release Schedule and Roadmap

This layer will remain compatible with the latest YOCTO LTS. This mirrors what meta-mender does.