Skip to content

Commit 1214b62

Browse files
committed
move back to authorize
1 parent 1e9b79a commit 1214b62

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

coderd/httpmw/provisionerdaemon.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ 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)
3433

3534
handleOptional := func(code int, response codersdk.Response) {
3635
if opts.Optional {
@@ -103,13 +102,6 @@ func ExtractProvisionerDaemonAuthenticated(opts ExtractProvisionerAuthConfig) fu
103102
return
104103
}
105104

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

enterprise/coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
284284
r.Use(
285285
api.provisionerDaemonsEnabledMW,
286286
apiKeyMiddlewareOptional,
287-
httpmw.ExtractOrganizationParam(api.Database),
288287
httpmw.ExtractProvisionerDaemonAuthenticated(httpmw.ExtractProvisionerAuthConfig{
289288
DB: api.Database,
290289
Optional: true,
@@ -294,6 +293,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
294293
// Either a user auth or provisioner auth is required
295294
// to move forward.
296295
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ 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 pk.OrganizationID != orgID {
114+
return nil, false
115+
}
116+
}
117+
111118
// If using provisioner key / PSK auth, the daemon is, by definition, scoped to the organization.
112119
tags = provisionersdk.MutateTags(uuid.Nil, tags)
113120
return tags, true

0 commit comments

Comments
 (0)