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 ¶
- Variables
- func ID(token string) (string, bool)
- type KV
- type Store
- func (s Store) Check(ctx context.Context, token string) (Token, error)
- func (s Store) Consume(ctx context.Context, token string) (Token, error)
- func (s Store) Create(ctx context.Context, expires time.Duration, uses int, labels map[string]string) (string, Token, error)
- func (s Store) List(ctx context.Context) ([]Token, error)
- func (s Store) Revoke(ctx context.Context, id string) error
- type Token
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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.
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.