Unable to set expiration time for preauth key in days #119

Closed
opened 2025-12-29 01:23:30 +01:00 by adam · 3 comments
Owner

Originally created by @kazauwa on GitHub (Feb 15, 2022).

Bug description

Unable to set expiration time when creating preauth key in days, operation fails with the following message:

invalid argument "365d" for "-e, --expiration" flag: time: unknown unit "d" in duration "365d"

To Reproduce

headscale preauthkeys create -e 365d -n example-ns or any other number

Context info
Version of headscale used: v0.12.4

Originally created by @kazauwa on GitHub (Feb 15, 2022). **Bug description** Unable to set expiration time when creating preauth key in days, operation fails with the following message: `invalid argument "365d" for "-e, --expiration" flag: time: unknown unit "d" in duration "365d"` **To Reproduce** `headscale preauthkeys create -e 365d -n example-ns` or any other number **Context info** Version of headscale used: v0.12.4
adam added the bug label 2025-12-29 01:23:30 +01:00
adam closed this issue 2025-12-29 01:23:31 +01:00
Author
Owner

@huskyii commented on GitHub (Mar 14, 2022):

RCA

headscale use time.ParseDuration to parse Duration underneath, the valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

Solutions

We have 2 options to fix it:

  1. correct help message
  2. write custom parse routine to handle d-suffix, have not use cobra before, don't know if it's possible

@kradalby @juanfont Which solution do you prefer? I can help implement the fix.

@huskyii commented on GitHub (Mar 14, 2022): ### RCA headscale use `time.ParseDuration` to parse Duration underneath, the valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". ### Solutions We have 2 options to fix it: 1. correct help message 2. write custom parse routine to handle d-suffix, have not use cobra before, don't know if it's possible @kradalby @juanfont Which solution do you prefer? I can help implement the fix.
Author
Owner

@kradalby commented on GitHub (Mar 19, 2022):

@huskyii I am a bit conflicted, because it would actually be nice to stick to the built in Go one, so we don't need to handle tests for this particular thing.

On the other hand, days is a somewhat sensible unit for the problem at hand.

Let's see what Prometheus or alertmanager does, I think they support day and week, maybe we can just import their function

@kradalby commented on GitHub (Mar 19, 2022): @huskyii I am a bit conflicted, because it would actually be nice to stick to the built in Go one, so we don't need to handle tests for this particular thing. On the other hand, days is a somewhat sensible unit for the problem at hand. Let's see what Prometheus or alertmanager does, I _think_ they support day and week, maybe we can just import their function
Author
Owner

@jcollie commented on GitHub (Apr 19, 2022):

In addition to days & weeks, it would be nice to have months, years, and "never".

@jcollie commented on GitHub (Apr 19, 2022): In addition to days & weeks, it would be nice to have months, years, and "never".
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#119