Add controller-led worker auth flow (#2413)
This adds an action to the API that allows pulling out an activation token that can be given to a worker in its config (directly or via env or file). The worker can pass this along with its normal request in place of its normal nonce and the server will automatically accept it. Co-authored-by: Irena Rindos <irenarindos@users.noreply.github.com>
This commit is contained in:
1 parent
a1be125f5b
commit
01fb949d0b
55 files changed
+2728
-625
No files matched your search
@@ -212,6 +212,11 @@ type Worker struct {
|
||||
|
||||
// AuthStoragePath represents the location a worker stores its node credentials, if set
|
||||
AuthStoragePath string `hcl:"auth_storage_path"`
|
||||
|
||||
// ControllerGeneratedActivationToken is a controller-generated activation
|
||||
// token used to register this worker to the cluster. It can be a path, env
|
||||
// var, or direct value.
|
||||
ControllerGeneratedActivationToken string `hcl:"controller_generated_activation_token"`
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
@@ -454,6 +459,11 @@ func Parse(d string) (*Config, error) {
|
||||
return nil, errors.New("Worker description contains non-printable characters")
|
||||
}
|
||||
|
||||
result.Worker.ControllerGeneratedActivationToken, err = parseutil.ParsePath(result.Worker.ControllerGeneratedActivationToken)
|
||||
if err != nil && !errors.Is(err, parseutil.ErrNotAUrl) {
|
||||
return nil, fmt.Errorf("Error parsing worker activation token: %w", err)
|
||||
}
|
||||
|
||||
if result.Worker.TagsRaw != nil {
|
||||
switch t := result.Worker.TagsRaw.(type) {
|
||||
// We allow `tags` to be a simple string containing a URL with schema.
|
||||
|
||||
@@ -301,6 +301,24 @@ func TestDevWorker(t *testing.T) {
|
||||
|
||||
_, err = Parse(devConfig + devWorkerKeyValueConfig)
|
||||
assert.Error(t, err)
|
||||
|
||||
// Check activation token parsing
|
||||
devWorkerActivationTokenConfig := `
|
||||
listener "tcp" {
|
||||
purpose = "proxy"
|
||||
}
|
||||
|
||||
worker {
|
||||
name = "dev-worker"
|
||||
description = "A default worker created in dev mode"
|
||||
initial_upstreams = ["127.0.0.1"]
|
||||
controller_generated_activation_token = "foobar"
|
||||
}
|
||||
`
|
||||
|
||||
actual, err = Parse(devConfig + devWorkerActivationTokenConfig)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "foobar", actual.Worker.ControllerGeneratedActivationToken)
|
||||
}
|
||||
|
||||
func TestDevCombined(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user