Skip to content

Commit 1e9b79a

Browse files
committed
move to mw
1 parent c9376a0 commit 1e9b79a

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

coderd/httpmw/provisionerdaemon.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func ExtractProvisionerDaemonAuthenticated(opts ExtractProvisionerAuthConfig) fu
3030
return func(next http.Handler) http.Handler {
3131
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3232
ctx := r.Context()
33+
org := OrganizationParam(r)
3334

3435
handleOptional := func(code int, response codersdk.Response) {
3536
if opts.Optional {
@@ -102,6 +103,13 @@ func ExtractProvisionerDaemonAuthenticated(opts ExtractProvisionerAuthConfig) fu
102103
return
103104
}
104105

106+
if pk.OrganizationID != org.ID {
107+
handleOptional(http.StatusUnauthorized, codersdk.Response{
108+
Message: "provisioner daemon key invalid",
109+
})
110+
return
111+
}
112+
105113
// The provisioner key does not indicate a specific provisioner daemon. So just
106114
// store a boolean so the caller can check if the request is from an
107115
// authenticated provisioner daemon.

enterprise/coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
284284
r.Use(
285285
api.provisionerDaemonsEnabledMW,
286286
apiKeyMiddlewareOptional,
287+
httpmw.ExtractOrganizationParam(api.Database),
287288
httpmw.ExtractProvisionerDaemonAuthenticated(httpmw.ExtractProvisionerAuthConfig{
288289
DB: api.Database,
289290
Optional: true,
@@ -293,7 +294,6 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
293294
// Either a user auth or provisioner auth is required
294295
// to move forward.
295296
httpmw.RequireAPIKeyOrProvisionerDaemonAuth(),
296-
httpmw.ExtractOrganizationParam(api.Database),
297297
)
298298
r.With(apiKeyMiddleware).Get("/", api.provisionerDaemons)
299299
r.With(apiKeyMiddlewareOptional).Get("/serve", api.provisionerDaemonServe)

enterprise/coderd/provisionerdaemons.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ func (p *provisionerDaemonAuth) authorize(r *http.Request, orgID uuid.UUID, tags
108108
return nil, false
109109
}
110110

111-
pk, ok := httpmw.ProvisionerKeyAuthOptional(r)
112-
if ok {
113-
if orgID != pk.OrganizationID {
114-
return nil, false
115-
}
116-
}
117-
118111
// If using provisioner key / PSK auth, the daemon is, by definition, scoped to the organization.
119112
tags = provisionersdk.MutateTags(uuid.Nil, tags)
120113
return tags, true

0 commit comments

Comments
 (0)