jointoken

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jointoken is the store of join tokens: a token that admits an agent at its join (osapi-io/osapi#1313). The controller keeps a hash of each token in its enrollment bucket, never the token, with its expiry, the number of uses that it has left and the labels that an agent that uses it gets. Consume, which the join calls, takes one use.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid is a token that the controller does not have: unknown,
	// revoked, or malformed.
	ErrInvalid = errors.New("join token is not valid")
	// ErrExpired is a token past its expiry.
	ErrExpired = errors.New("join token has expired")
	// ErrUsed is a token with no use left.
	ErrUsed = errors.New("join token has no use left")
)

The causes of a token that does not admit.

Functions

func ID

func ID(
	token string,
) (string, bool)

ID is the ID of token, which is not secret, and whether token has the form of a join token.

Types

type KV

type KV interface {
	KVGet(ctx context.Context, bucket string, key string) (jetstream.KeyValueEntry, error)
	KVCreate(ctx context.Context, bucket string, key string, value []byte) (uint64, error)
	KVUpdate(
		ctx context.Context,
		bucket string,
		key string,
		value []byte,
		revision uint64,
	) (uint64, error)
	KVDelete(ctx context.Context, bucket string, key string) error
	KVKeys(ctx context.Context, bucket string, filters ...string) ([]string, error)
}

KV is what the store needs of the enrollment bucket.

type Store

type Store struct {
	KV     KV
	Bucket string
	// Now is the time, for a test to replace.
	Now func() time.Time
}

Store keeps the join tokens in bucket.

func (Store) Check

func (s Store) Check(
	ctx context.Context,
	token string,
) (Token, error)

Check is token when it admits now, in a jointoken.check span that names the token's ID, never the token. It takes no use: the auth callout checks a token at each connection of its join.

func (Store) Consume

func (s Store) Consume(
	ctx context.Context,
	token string,
) (Token, error)

Consume takes a use of token, in a jointoken.consume span that names the token's ID, never the token.

func (Store) Create

func (s Store) Create(
	ctx context.Context,
	expires time.Duration,
	uses int,
	labels map[string]string,
) (string, Token, error)

Create makes a token, in a jointoken.create span that names its ID. The span never holds the token.

func (Store) List

func (s Store) List(
	ctx context.Context,
) ([]Token, error)

List is each token, in a jointoken.list span.

func (Store) Revoke

func (s Store) Revoke(
	ctx context.Context,
	id string,
) error

Revoke removes the token with id, in a jointoken.revoke span.

type Token

type Token struct {
	// ID names the token in list and revoke. It is not secret.
	ID string `json:"id"`
	// Hash is the SHA-256 of the secret part of the token, in hex.
	Hash string `json:"hash"`
	// CreatedAt is when it was made.
	CreatedAt time.Time `json:"created_at"`
	// ExpiresAt is when it stops admitting.
	ExpiresAt time.Time `json:"expires_at"`
	// UsesLeft is how many more agents it admits.
	UsesLeft int `json:"uses_left"`
	// Labels are the labels that an agent that joins with it gets.
	Labels map[string]string `json:"labels,omitempty"`
}

Token is what the controller keeps of a join token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL