Skip to content

fix: show an error banner if the user does not have permission to view the audit page #16637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,25 @@ func New(options *Options) *API {
r.Route("/audit", func(r chi.Router) {
r.Use(
apiKeyMiddleware,
// This middleware only checks the site and orgs for the audit_log read
// permission.
// In the future if it makes sense to have this permission on the user as
// well we will need to update this middleware to include that check.
func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
if api.Authorize(r, policy.ActionRead, rbac.ResourceAuditLog) {
next.ServeHTTP(rw, r)
return
}

if api.Authorize(r, policy.ActionRead, rbac.ResourceAuditLog.AnyOrganization()) {
next.ServeHTTP(rw, r)
return
}

httpapi.Forbidden(rw)
})
},
)

r.Get("/", api.auditLogs)
Expand Down
9 changes: 9 additions & 0 deletions site/src/pages/AuditPage/AuditPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { paginatedAudits } from "api/queries/audits";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { useFilter } from "components/Filter/Filter";
import { useUserFilterMenu } from "components/Filter/UserFilter";
import { isNonInitialPage } from "components/PaginationWidget/utils";
Expand Down Expand Up @@ -67,6 +68,14 @@ const AuditPage: FC = () => {
}),
});

if (auditsQuery.error) {
return (
<div className="p-6">
<ErrorAlert error={auditsQuery.error} />
</div>
);
}

return (
<>
<Helmet>
Expand Down
Loading