mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: accept provisioner keys for provisioner auth (#13972)
This commit is contained in:
@@ -79,6 +79,9 @@ const (
|
||||
// ProvisionerDaemonPSK contains the authentication pre-shared key for an external provisioner daemon
|
||||
ProvisionerDaemonPSK = "Coder-Provisioner-Daemon-PSK"
|
||||
|
||||
// ProvisionerDaemonKey contains the authentication key for an external provisioner daemon
|
||||
ProvisionerDaemonKey = "Coder-Provisioner-Daemon-Key"
|
||||
|
||||
// BuildVersionHeader contains build information of Coder.
|
||||
BuildVersionHeader = "X-Coder-Build-Version"
|
||||
|
||||
|
||||
@@ -189,6 +189,8 @@ type ServeProvisionerDaemonRequest struct {
|
||||
Tags map[string]string `json:"tags"`
|
||||
// PreSharedKey is an authentication key to use on the API instead of the normal session token from the client.
|
||||
PreSharedKey string `json:"pre_shared_key"`
|
||||
// ProvisionerKey is an authentication key to use on the API instead of the normal session token from the client.
|
||||
ProvisionerKey string `json:"provisioner_key"`
|
||||
}
|
||||
|
||||
// ServeProvisionerDaemon returns the gRPC service for a provisioner daemon
|
||||
@@ -223,8 +225,15 @@ func (c *Client) ServeProvisionerDaemon(ctx context.Context, req ServeProvisione
|
||||
headers := http.Header{}
|
||||
|
||||
headers.Set(BuildVersionHeader, buildinfo.Version())
|
||||
if req.PreSharedKey == "" {
|
||||
// use session token if we don't have a PSK.
|
||||
|
||||
if req.ProvisionerKey != "" {
|
||||
headers.Set(ProvisionerDaemonKey, req.ProvisionerKey)
|
||||
}
|
||||
if req.PreSharedKey != "" {
|
||||
headers.Set(ProvisionerDaemonPSK, req.PreSharedKey)
|
||||
}
|
||||
if req.ProvisionerKey == "" && req.PreSharedKey == "" {
|
||||
// use session token if we don't have a PSK or provisioner key.
|
||||
jar, err := cookiejar.New(nil)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("create cookie jar: %w", err)
|
||||
@@ -234,8 +243,6 @@ func (c *Client) ServeProvisionerDaemon(ctx context.Context, req ServeProvisione
|
||||
Value: c.SessionToken(),
|
||||
}})
|
||||
httpClient.Jar = jar
|
||||
} else {
|
||||
headers.Set(ProvisionerDaemonPSK, req.PreSharedKey)
|
||||
}
|
||||
|
||||
conn, res, err := websocket.Dial(ctx, serverURL.String(), &websocket.DialOptions{
|
||||
|
||||
Reference in New Issue
Block a user