Skip to content

Conversation

Foxboron
Copy link
Owner

@Foxboron Foxboron commented Mar 2, 2025

  • Write man pages
  • More testing?
    Should be able to filter away some key types later

@Foxboron Foxboron force-pushed the morten/hierarchy-keys branch 2 times, most recently from 4ccd6b9 to e58a89b Compare March 2, 2025 22:29
@Foxboron Foxboron force-pushed the morten/hierarchy-keys branch 3 times, most recently from b05a05a to e048eec Compare March 10, 2025 22:56
Copy link

@behrmann behrmann left a comment

Choose a reason for hiding this comment

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

Looking forward to this!

@Foxboron
Copy link
Owner Author

@behrmann Do consider the UX you want on this. Currently you can only get a hold of the public keys with ssh-tpm-keygen -A --hierarchy owner. But maybe a bare --hierarchy owner should be permitted as well?

@behrmann
Copy link

Do consider the UX you want on this. Currently you can only get a hold of the public keys with ssh-tpm-keygen -A --hierarchy owner. But maybe a bare --hierarchy owner should be permitted as well?

I'm not sure I understand what the difference would mean.

I gather there wouldn't be a semantic difference, when keys for a given hierarchy already exist, since -A would be a noop then, right? But if they don't exist yet, it probably shouldn't create them (imply -A) and error out instead?

I haven't built this yet, but I'll testdrive it tomorrow.

@Foxboron Foxboron force-pushed the morten/hierarchy-keys branch 2 times, most recently from 2a9e18c to 49b3c36 Compare March 11, 2025 21:29
@Foxboron
Copy link
Owner Author

I gather there wouldn't be a semantic difference, when keys for a given hierarchy already exist, since -A would be a noop then, right? But if they don't exist yet, it probably shouldn't create them (imply -A) and error out instead?

Well, -A --hierarchy would only really be useable when you are setting up host keys. But if you are a user that want to pre-seed your agent you probably want to have a way to produce the public key files.

@behrmann
Copy link

Maybe I'm still misunderstanding, but wouldn't that be something for a -l option?

Copy link

@behrmann behrmann left a comment

Choose a reason for hiding this comment

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

Playing with this I ran into some mild usability problems:

While the ssh-tpm-agent understands PREFIX and DESTDIR and can be used to generate the unit files when packaging (I packaged it to get it on my test system), this doesn't work for ssh-tpm-hostkeys --install-sshd-config, I'll open a separate issue for that, since I think that's an issue already.

Speaking of the unit files, though, with the introduced hierarchy setting, they should maybe become template units with DefaultInstance=owner.

Related, I'm not sure whether it makes sense to have hostkeys from different hierarchies at the same time, but if so, it might make sense to encode the name of the hierarchy in the filename, since otherwise the condition in the keygen service would not be able to tell apart different hierarchies.

The most important thing: I can't say whether this so far survives a reboot with my testing, I've been holding it wrong for a bit and waiting for my machine to reinstall.

@Foxboron
Copy link
Owner Author

While the ssh-tpm-agent understands PREFIX and DESTDIR and can be used to generate the unit files when packaging (I packaged it to get it on my test system), this doesn't work for ssh-tpm-hostkeys --install-sshd-config, I'll open a separate issue for that, since I think that's an issue already.

Fwiw, I regret implementing that entire thing. I thought it would be neat but it's clear to me it's just way too complicated.

Related, I'm not sure whether it makes sense to have hostkeys from different hierarchies at the same time, but if so, it might make sense to encode the name of the hierarchy in the filename, since otherwise the condition in the keygen service would not be able to tell apart different hierarchies.

I don't see a use-case for this yet so I reckon this is a "WONT FIX" until someone gives me a better idea.

@Foxboron
Copy link
Owner Author

Speaking of the unit files, though, with the introduced hierarchy setting, they should maybe become template units with DefaultInstance=owner.

I actually can't quite tell what this setting does?

@behrmann
Copy link

Fwiw, I regret implementing that entire thing. I thought it would be neat but it's clear to me it's just way too complicated.

Maybe a good point to drop it then? You're still below 1.0. I have to agree that the UX there is problematic.

I don't see a use-case for this yet so I reckon this is a "WONT FIX" until someone gives me a better idea.

Fine by me.

I actually can't quite tell what this setting does?

I'm currently running these unit files

# ssh-tpm-agent@.service
[Unit]
ConditionEnvironment=!SSH_AGENT_PID
Description=ssh-tpm-agent service
Documentation=man:ssh-agent(1) man:ssh-add(1) man:ssh(1)
Wants=ssh-tpm-genkeys@%i.service
After=ssh-tpm-genkeys@%i.service
After=network.target
After=sshd.target
Requires=ssh-tpm-agent@%i.socket

[Service]
ExecStart=/usr/bin/ssh-tpm-agent --key-dir /etc/ssh --hierarchy %i
PassEnvironment=SSH_AGENT_PID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target
DefaultInstance=endorsement
[Unit]
Description=SSH TPM agent socket
Documentation=man:ssh-agent(1) man:ssh-add(1) man:ssh(1)

[Socket]
ListenStream=/var/tmp/ssh-tpm-agent.sock
SocketMode=0600
Service=ssh-tpm-agent@%i.service

[Install]
WantedBy=sockets.target
DefaultInstance=endorsement

and

[Unit]
Description=SSH TPM Key Generation
ConditionPathExists=|!/etc/ssh/ssh_tpm_host_ecdsa_key.tpm
ConditionPathExists=|!/etc/ssh/ssh_tpm_host_ecdsa_key.pub
ConditionPathExists=|!/etc/ssh/ssh_tpm_host_rsa_key.tpm
ConditionPathExists=|!/etc/ssh/ssh_tpm_host_rsa_key.pub

[Service]
ExecStart=/usr/bin/ssh-tpm-keygen -A --hierarchy %i
Type=oneshot
RemainAfterExit=yes

The DefaultInstance makes that when doing systemctl enable ssh-tpm-agent@.socket what actually gets enabled is ssh-tpm-agent@endorsement.socket, i.e.

# systemctl enable ssh-tpm-agent@.socket
Created symlink /etc/systemd/system/sockets.target.wants/ssh-tpm-agent@endorsement.socket → /lib/systemd/system/ssh-tpm-agent@.socket

I'm not entirely sure whether this is actually worthwhile. In light of the above "WONT FIX", it's probably better to just ship a dropin that changes the ExecStart=—I usually don't want to do that, but the ones here are plain enough and probably won't change much.

@behrmann
Copy link

The most important thing: I can't say whether this so far survives a reboot with my testing, I've been holding it wrong for a bit and waiting for my machine to reinstall.

I can report back now, it's working fine. The endorsement hierarchy key survives fine.

Copy link

@behrmann behrmann left a comment

Choose a reason for hiding this comment

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

That should be all endorments

@Foxboron
Copy link
Owner Author

@behrmann ah, the service files are clever. I'll need to think a little bit on how this could be packaged up in the project though.

@Foxboron
Copy link
Owner Author

Added service files here https://github.com/Foxboron/ssh-tpm-agent/tree/morten/hierarchy-keys/contrib/services/hierarchy_keys

Not sure how I'll distribute it yet, but now it's somewhere :)

Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
@Foxboron Foxboron force-pushed the morten/hierarchy-keys branch from 22ba9f1 to 20b067a Compare March 16, 2025 21:11
Foxboron added 10 commits March 16, 2025 22:14
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
@Foxboron Foxboron force-pushed the morten/hierarchy-keys branch from 20b067a to c8b4adc Compare March 16, 2025 21:14
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Morten Linderud <morten@linderud.pw>
@Foxboron Foxboron force-pushed the morten/hierarchy-keys branch from 46ffa0b to 9cb1645 Compare March 16, 2025 21:38
@Foxboron Foxboron merged commit 9cb1645 into master Mar 16, 2025
10 checks passed

[Install]
WantedBy=multi-user.target
DefaultInstance=endorsement

Choose a reason for hiding this comment

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

While I'm running it this way, the thing that's shipped (even only as contrib), should probably be

DefaultInstance=owner

@Foxboron Foxboron deleted the morten/hierarchy-keys branch March 27, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants