mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add cache abstraction for fetching signing keys (#14777)
- Adds the database implementation for fetching and caching keys used for JWT signing. It's been merged into the `keyrotate` pkg and renamed to `cryptokeys` since they're coupled concepts.
This commit is contained in:
@@ -3101,3 +3101,32 @@ func (c *Client) SSHConfiguration(ctx context.Context) (SSHConfigResponse, error
|
||||
var sshConfig SSHConfigResponse
|
||||
return sshConfig, json.NewDecoder(res.Body).Decode(&sshConfig)
|
||||
}
|
||||
|
||||
type CryptoKeyFeature string
|
||||
|
||||
const (
|
||||
CryptoKeyFeatureWorkspaceApp CryptoKeyFeature = "workspace_apps"
|
||||
CryptoKeyFeatureOIDCConvert CryptoKeyFeature = "oidc_convert"
|
||||
CryptoKeyFeatureTailnetResume CryptoKeyFeature = "tailnet_resume"
|
||||
)
|
||||
|
||||
type CryptoKey struct {
|
||||
Feature CryptoKeyFeature `json:"feature"`
|
||||
Secret string `json:"secret"`
|
||||
DeletesAt time.Time `json:"deletes_at" format:"date-time"`
|
||||
Sequence int32 `json:"sequence"`
|
||||
StartsAt time.Time `json:"starts_at" format:"date-time"`
|
||||
}
|
||||
|
||||
func (c CryptoKey) CanSign(now time.Time) bool {
|
||||
now = now.UTC()
|
||||
isAfterStartsAt := !c.StartsAt.IsZero() && !now.Before(c.StartsAt)
|
||||
return isAfterStartsAt && c.CanVerify(now)
|
||||
}
|
||||
|
||||
func (c CryptoKey) CanVerify(now time.Time) bool {
|
||||
now = now.UTC()
|
||||
hasSecret := c.Secret != ""
|
||||
beforeDelete := c.DeletesAt.IsZero() || now.Before(c.DeletesAt)
|
||||
return hasSecret && beforeDelete
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user