Skip to content

Commit 6f99100

Browse files
committed
feat: add audit_log read permission check to audit route
1 parent 9f5ad23 commit 6f99100

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

coderd/coderd.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,25 @@ func New(options *Options) *API {
930930
r.Route("/audit", func(r chi.Router) {
931931
r.Use(
932932
apiKeyMiddleware,
933+
// This middleware only checks the site and orgs for the audit_log read
934+
// permission.
935+
// In the future if it makes sense to have this permission on the user as
936+
// well we will need to update this middleware to include that check.
937+
func(next http.Handler) http.Handler {
938+
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
939+
if api.Authorize(r, policy.ActionRead, rbac.ResourceAuditLog) {
940+
next.ServeHTTP(rw, r)
941+
return
942+
}
943+
944+
if api.Authorize(r, policy.ActionRead, rbac.ResourceAuditLog.AnyOrganization()) {
945+
next.ServeHTTP(rw, r)
946+
return
947+
}
948+
949+
httpapi.Forbidden(rw)
950+
})
951+
},
933952
)
934953

935954
r.Get("/", api.auditLogs)

0 commit comments

Comments
 (0)