hashicorp / hashicorp/nomad

use codegen for `jwt.NumericDate` serialization

Open
#16,129 0 comments 0 reactions 0 assignees View on GitHub
type/enhancement type/tech-debt
Dominant language
Go
Stars
17k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
105

Description

Currently we exclude `structs.IdentityClaims` from msgpack code generate (ref [`generate.sh#L11`](https://github.com/hashicorp/nomad/blob/v1.5.0-beta.1/nomad/structs/generate.sh#L11)) because it blows up when the code generator passes over `jwt.NumericDate`, which is a thin wrapper around `time.Time`.

Basically the problem here is that we have `TimeNotBuiltIn` set in our msgpack configuration for backwards compatibility with the original version of the library -- we serialize to the raft logs and snapshots so we're largely stuck with the on-disk structure of any existing serialized types. In theory we could write our own `Ext` that implements the [timestamp extension type](https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type) just for `jwt.NumericDate`. That would let us use the fast-path codegen'd encoder from `go-msgpack` rather than the slower reflection-based one.

But this is a bit of a lift and currently only the `ACL.WhoAmI` endpoint passes around `structs.IdentityClaims`. It's never persisted to disk. Taking the slow path on a little used endpoint isn't a big deal, so this is a nice-to-have for some other time.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with nomad/structs/generate.sh at the exclusion for structs.IdentityClaims, then trace the msgpack configuration and jwt.NumericDate handling. Review the ACL.WhoAmI path and go-msgpack behavior; done means IdentityClaims uses generated serialization without changing existing raft log or snapshot formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.