Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: T4919: Add support for encrypted config with TPM #1740

Merged
merged 3 commits into from
Mar 7, 2024

Conversation

sarthurdev
Copy link
Member

@sarthurdev sarthurdev commented Jan 6, 2023

Change Summary

PR to implement how a TPM could be used to provide hardware backed encryption of the /config data.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Component(s) name

config

Proposed changes

  • Add module vyos.tpm for interacting with TPM device.
  • Add encryption op-mode commands:
    • encryption enable generates an LUKS encrypted volume and stores one key in the TPM and also provides a recovery key to the user. /config contents is migrated to the volume and is mounted over /config.
    • encryption disable takes either the TPM key, or prompts for a recovery key to load the volume (if volume not already mounted), migrates config data to /config on rootfs and clears the TPM and removes volume.
    • encryption load allows for loading the encrypted config volume if VyOS failed to decrypt the volume on-boot.

Related PRs:

How to test

Success boot message:

[   27.987068] vyos-router[1114]: Waiting for NICs to settle down: settled in 0sec..
[   31.555678] vyos-router[1114]: Mounting VyOS Config...done.
[   34.480597] vyos-router[1114]: Mounted encrypted config volume
[   39.571402] vyos-router[1114]: Starting VyOS router: migrate configure.
[   40.017721] vyos-config[1124]: Configuration success

Failed boot message:

[   19.619459] vyos-router[1008]: Waiting for NICs to settle down: settled in 0sec..
[   23.399971] vyos-router[1008]: Mounting VyOS Config...done.
[   23.797441] vyos-router[1008]: ERROR: Failed to fetch encryption key from TPM. Encrypted config volume has not been mounted
[   23.799499] vyos-router[1008]: Use 'encryption load' to load volume with recovery key
[   23.800669] vyos-router[1008]: or 'encryption disable' to decrypt volume with recovery key
[   35.614991] vyos-router[1008]: Starting VyOS router: migrate configure.
[   36.577641] vyos-config[1017]: Configuration success

(Note: configuration success because VyOS default config.boot is created and loaded)

Installing from ISO over an existing install with an encrypted config:

Install the image on? [sda]:

This will destroy all data on /dev/sda.
Continue? (Yes/No) [No]: yes

Looking for pre-existing RAID groups...none found.
Looking for config files from previous installations on sda1...
Looking for config files from previous installations on sda2...
Looking for config files from previous installations on sda3...
I found the following encrypted config volumes on sda3:
  1: 1.4-rolling-202301032140
Would you like to save config volume from it? (Yes/No) [Yes]
Saving config volume from image 1.4-rolling-202301032140.
Done.
How big of a root partition should I create? (2000MB - 4294MB) [4294]MB:

Op-mode commands:

vyos@vyos:~$ encryption enable
Automatically generate a recovery key? [Y/n]
Enter size of encrypted config partition (MB):  (Default: 512)
Encrypted config volume has been enabled
Backup the recovery key in a safe place!
Recovery key: eJIlCbNm_nptQ_joEEMCqtc4vtoIQyaRLlG5G3lRTVQ=

vyos@vyos:~$ encryption disable
Moving existing /config folder to /config.old
Encrypted config volume has been disabled
Contents have been migrated to /config on rootfs

(Below was run after clearing TPM and rebooting with failed boot decryption)
vyos@vyos:~$ encryption load
Failed to read key from TPM, recovery key required
Enter recovery key: eJIlCbNm_nptQ_joEEMCqtc4vtoIQyaRLlG5G3lRTVQ=
Encrypted config volume has been mounted
Use "load /config/config.boot" to load configuration

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@sarthurdev sarthurdev changed the title config: T4919: Add support for encrypted config file with TPM config: T4919: Add support for encrypted config with TPM Jan 6, 2023
@c-po c-po requested review from a team, dmbaturin, zdc, jestabro, sever-sever and c-po and removed request for a team January 6, 2023 20:08
@c-po
Copy link
Member

c-po commented Jan 7, 2023

Can we somehow test this using a simulated TPM like smoketesting in QEmu?

Can we also extend it like on Debian by simply using a passphrase to encrypt?

@sarthurdev
Copy link
Member Author

Can we somehow test this using a simulated TPM like smoketesting in QEmu?

Should be possible, will investigate and add smoketest if possible.

Can we also extend it like on Debian by simply using a passphrase to encrypt?

Do you mean allowing a passphrase to encrypt without using the TPM? If so, I'm not sure how we could implement the passphrase prompt on boot, using a TPM to store a key and have no boot interruption seems the best approach imo.

@andamasov
Copy link
Member

virtual tpm available on VMware, not sure about quemu

@c-po
Copy link
Member

c-po commented Jan 7, 2023

Do you mean allowing a passphrase to encrypt without using the TPM?

Exactly

My requirement is like you get in Debian with an encrypted rootfs where you are prompted for a password on bootup from the serial/KVM console. I know this sounds stupid as it does not make the router reboot-safe but imagine a random cloud provider which only supports KVM access and no TPM - you still could encrypt your stuff.

One might ask what happens if the router crashes as it would reboot automatically - the answer is simple - it should not crash at all ;)

What you think?

@sarthurdev
Copy link
Member Author

My requirement is like you get in Debian with an encrypted rootfs where you are prompted for a password on bootup from the serial/KVM console. I know this sounds stupid as it does not make the router reboot-safe but imagine a random cloud provider which only supports KVM access and no TPM - you still could encrypt your stuff.

I think best solution for that is to allow the encryption enable command to work without a TPM - just a recovery key, on boot it'll boot into VyOS with a default config, and you can then KVM/Serial in with default vyos/vyos login, use encryption load to load the encrypted volume and load the now decrypted proper config.boot

What do you think to that?

@sarthurdev sarthurdev force-pushed the tpm_luks branch 4 times, most recently from a462c50 to d90cc5c Compare January 23, 2023 12:16
@zdc
Copy link
Contributor

zdc commented Mar 7, 2023

@c-po @sarthurdev is there anything that we can do to move this further? The feature is interesting.

@sarthurdev
Copy link
Member Author

@zdc Haven't tested it for a while, Bookworm upgrade took priority recently.

I think we need to discuss some design choices for TPM support: how to handle image upgrades, default (and user-specified) criteria for verifying integrity, handling decryption failure (or is it up to the end user to ensure devices are reachable in event of failed config load).

I am also curious if #1768 is close to merge as it would make the install/upgrade aspect of this PR much easier to deal with.

@giga1699
Copy link
Contributor

I am in agreement with @c-po on being able to manually enter encryption key, especially in virtual environments. There have been some documented instances of virtual hard drives containing data from a previous tenant. A malicious cloud employee could also steal the virtual drive if they thought the data on it was valuable.

While a memory capture could lead to encryption key exposure, it's a higher bar to attain than just pulling the virtual disk off the storage network. Would it maybe be prudent to have some kind of message about encryption passphrase use versus TPM use?

Things like crypto keys could potentially be stolen if the config were not encrypted at rest. While keys can be rotated, any previous encrypted traffic that may have been captured could then be decrypted with the old key.

It may be an annoying extra step for some to have to login to the console with the cloud provider, but it could be very beneficial for some threat models.

This would also set VyOS apart from many other networking platforms that generally don't do any configuration encryption at rest.

@c-po c-po added the current label Aug 25, 2023
@dmbaturin
Copy link
Member

Let's merge when 1.4 is branched off.

@github-actions
Copy link

github-actions bot commented Oct 9, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link

github-actions bot commented Oct 9, 2023

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link

github-actions bot commented Nov 9, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link

Conflicts have been resolved. A maintainer will review the pull request shortly.

@sever-sever
Copy link
Member

@sarthurdev Let us know if the task still in progress

@sarthurdev
Copy link
Member Author

Will pick this back up after Kea implementation has most issues resolved.

@sarthurdev sarthurdev force-pushed the tpm_luks branch 3 times, most recently from 41bf6ce to 159b7a9 Compare February 20, 2024 11:39
@sarthurdev sarthurdev marked this pull request as ready for review February 20, 2024 11:49
@vyosbot vyosbot requested a review from a team February 20, 2024 11:49
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<interfaceDefinition>
<node name="encryption">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put it under set, together with set system image default-boot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, do you agree with set system encryption ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only issue with using the set node, is then encryption load would need to move to a separate node. set system encryption load wouldn't really make sense.

<interfaceDefinition>
<node name="encryption">
<properties>
<help>Manage config encryption</help>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention the TPM part explicitly? Manage configuration encryption using TPM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't going to mention TPM explicitly as @c-po has requested that perhaps we can also accept encryption without a TPM, requiring a password instead on boot.

src/helpers/vyos-config-encrypt.py Outdated Show resolved Hide resolved
@dmbaturin dmbaturin merged commit 6e7e784 into vyos:current Mar 7, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

7 participants