Preauthkey table reusable column is incorrect #627

Closed
opened 2025-12-29 02:21:19 +01:00 by adam · 4 comments
Owner

Originally created by @dustinblackman on GitHub (Feb 3, 2024).

Bug description

The preauthkeys Reusable column is incorrectly showing N/A rather than true when a key is reusable. Not quite sure what the original intention was.

I have a patch ready to go. https://github.com/juanfont/headscale/pull/1713

Environment

  • Version of headscale used: v0.23.0-alpha3

To Reproduce

headscale user create machine-1
headscale preauthkeys create -u machine-1 -e 1d --ephemeral --reusable
headscale preauthkeys list -u machine-1
# See N/A in reusable column
Originally created by @dustinblackman on GitHub (Feb 3, 2024). ## Bug description The preauthkeys Reusable column is incorrectly showing `N/A` rather than `true` when a key is reusable. Not quite sure what the original intention was. I have a patch ready to go. https://github.com/juanfont/headscale/pull/1713 ## Environment - Version of headscale used: v0.23.0-alpha3 ## To Reproduce ```bash headscale user create machine-1 headscale preauthkeys create -u machine-1 -e 1d --ephemeral --reusable headscale preauthkeys list -u machine-1 # See N/A in reusable column ```
adam added the bug label 2025-12-29 02:21:19 +01:00
adam closed this issue 2025-12-29 02:21:19 +01:00
Author
Owner

@TotoTheDragon commented on GitHub (Feb 11, 2024):

This seems to be correct with the current implementation of ephemeral keys. However the current implementation is wrong.

According to the following issue https://github.com/tailscale/tailscale/issues/5982
For a ephemeral key to be used multiple times, it needs to be reusable. But in the following code segment, we do not check if the key was used if it is reusable or ephemeral c3257e2146/hscontrol/db/preauth_keys.go (L199-L201)

@kradalby could you check my logic on this?

@TotoTheDragon commented on GitHub (Feb 11, 2024): This seems to be correct with the current implementation of ephemeral keys. However the current implementation is wrong. According to the following issue https://github.com/tailscale/tailscale/issues/5982 For a ephemeral key to be used multiple times, it needs to be reusable. But in the following code segment, we do not check if the key was used if it is reusable or ephemeral https://github.com/juanfont/headscale/blob/c3257e2146304c52e588c6de2fd28bcc0f13b1ad/hscontrol/db/preauth_keys.go#L199-L201 @kradalby could you check my logic on this?
Author
Owner

@dustinblackman commented on GitHub (Feb 12, 2024):

I'm confused. The column is just supposed to expose whether the key was created with --ephemeral or not, no? It's just listing the DB rows.

@dustinblackman commented on GitHub (Feb 12, 2024): I'm confused. The column is just supposed to expose whether the key was created with `--ephemeral` or not, no? It's just listing the DB rows.
Author
Owner

@TotoTheDragon commented on GitHub (Feb 12, 2024):

I'm confused. The column is just supposed to expose whether the key was created with --ephemeral or not, no? It's just listing the DB rows.

It does, but in the case you described it is N/A with the current implementation. If you want to change the N/A, we should also fix the logic causing it to be N/A. Currently it does not matter if a key is reusable if it already is ephemeral. This is not the same behaviour as tailscale.

@TotoTheDragon commented on GitHub (Feb 12, 2024): > I'm confused. The column is just supposed to expose whether the key was created with `--ephemeral` or not, no? It's just listing the DB rows. It does, but in the case you described it is N/A with the current implementation. If you want to change the N/A, we should also fix the logic causing it to be N/A. Currently it does not matter if a key is reusable if it already is ephemeral. This is not the same behaviour as tailscale.
Author
Owner

@kradalby commented on GitHub (Feb 15, 2024):

@TotoTheDragon I think you are right,

looks like that line hasnt changed since it was written originally and c3257e2146/hscontrol/db/preauth_keys.go (L199) is wrong, or, its too simplified.

We need to check ephemeral keys in the same way too.

@kradalby commented on GitHub (Feb 15, 2024): @TotoTheDragon I think you are right, looks like that line hasnt changed since it was written originally and https://github.com/juanfont/headscale/blob/c3257e2146304c52e588c6de2fd28bcc0f13b1ad/hscontrol/db/preauth_keys.go#L199 is wrong, or, its too simplified. We need to check ephemeral keys in the same way too.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#627