Skip to content

Commit 5d4cbc0

Browse files
committed
feat: add --key flag to provisionerd start
1 parent 38b5738 commit 5d4cbc0

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

enterprise/cli/provisionerdaemonstart.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
4646
pollInterval time.Duration
4747
pollJitter time.Duration
4848
preSharedKey string
49+
provisionerKey string
4950
verbose bool
5051

5152
prometheusEnable bool
@@ -113,6 +114,19 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
113114
return err
114115
}
115116

117+
if provisionerKey != "" {
118+
if preSharedKey != "" {
119+
return xerrors.New("cannot provide both provisioner key --key and pre-shared key --psk")
120+
}
121+
if len(rawTags) > 0 {
122+
return xerrors.New("cannot provide tags when using provisioner key")
123+
}
124+
// _, err := provisionerkey.Parse(provisionerKey)
125+
// if err != nil {
126+
// return xerrors.Errorf("parse provisioner key: %w", err)
127+
// }
128+
}
129+
116130
logOpts := []clilog.Option{
117131
clilog.WithFilter(logFilter...),
118132
clilog.WithHuman(logHuman),
@@ -136,10 +150,10 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
136150
logger.Info(ctx, "note: untagged provisioners can only pick up jobs from untagged templates")
137151
}
138152

139-
// When authorizing with a PSK, we automatically scope the provisionerd
140-
// to organization. Scoping to user with PSK auth is not a valid configuration.
141-
if preSharedKey != "" {
142-
logger.Info(ctx, "psk auth automatically sets tag "+provisionersdk.TagScope+"="+provisionersdk.ScopeOrganization)
153+
// When authorizing with a PSK / provisioner key, we automatically scope the provisionerd
154+
// to organization. Scoping to user with PSK / provisioner key auth is not a valid configuration.
155+
if preSharedKey != "" || provisionerKey != "" {
156+
logger.Info(ctx, "psk or provisioner key auth automatically sets tag "+provisionersdk.TagScope+"="+provisionersdk.ScopeOrganization)
143157
tags[provisionersdk.TagScope] = provisionersdk.ScopeOrganization
144158
}
145159

@@ -213,6 +227,7 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
213227
Tags: tags,
214228
PreSharedKey: preSharedKey,
215229
Organization: org.ID,
230+
// ProvisionerKey: provisionerKey,
216231
})
217232
}, &provisionerd.Options{
218233
Logger: logger,
@@ -296,6 +311,13 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
296311
Description: "Pre-shared key to authenticate with Coder server.",
297312
Value: serpent.StringOf(&preSharedKey),
298313
},
314+
{
315+
Flag: "key",
316+
Env: "CODER_PROVISIONER_DAEMON_KEY",
317+
Description: "Provisioner key to authenticate with Coder server.",
318+
Value: serpent.StringOf(&provisionerKey),
319+
Hidden: true,
320+
},
299321
{
300322
Flag: "name",
301323
Env: "CODER_PROVISIONER_DAEMON_NAME",

enterprise/cli/provisionerdaemonstart_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
301301
})
302302
}
303303

304+
func TestProvisionerDaemon_ProvisionerKey(t *testing.T) {
305+
t.Parallel()
306+
307+
t.Run("OK", func(t *testing.T) {
308+
t.Parallel()
309+
310+
})
311+
}
312+
304313
//nolint:paralleltest,tparallel // Test uses a static port.
305314
func TestProvisionerDaemon_PrometheusEnabled(t *testing.T) {
306315
// Ephemeral ports have a tendency to conflict and fail with `bind: address already in use` error.

0 commit comments

Comments
 (0)