Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6122df6

Browse files
authored
feature: gate audit log by permissions (#3464)
* pairing* restricting audit routeresolvees#3460* updated tests* fixing lint* useSelector instead of useActor
1 parent4e6645a commit6122df6

File tree

7 files changed

+164
-126
lines changed

7 files changed

+164
-126
lines changed

‎coderd/rbac/builtin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var (
8888
// Should be able to read all template details, even in orgs they
8989
// are not in.
9090
ResourceTemplate: {ActionRead},
91+
ResourceAuditLog: {ActionRead},
9192
}),
9293
}
9394
},

‎coderd/rbac/object.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ var (
2222
Type:"workspace",
2323
}
2424

25+
// ResourceAuditLog
26+
// read = access audit log
27+
ResourceAuditLog=Object{
28+
Type:"audit_log",
29+
}
30+
2531
// ResourceTemplate CRUD. Org owner only.
2632
//create/delete = Make or delete a new template
2733
//update = Update the template, make new template versions

‎site/src/AppRouter.tsx

Lines changed: 119 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import{FC,lazy,Suspense}from"react"
1+
import{useSelector}from"@xstate/react"
2+
import{FC,lazy,Suspense,useContext}from"react"
23
import{Navigate,Route,Routes}from"react-router-dom"
4+
import{selectPermissions}from"xServices/auth/authSelectors"
5+
import{XServiceContext}from"xServices/StateContext"
36
import{AuthAndFrame}from"./components/AuthAndFrame/AuthAndFrame"
47
import{RequireAuth}from"./components/RequireAuth/RequireAuth"
58
import{SettingsLayout}from"./components/SettingsLayout/SettingsLayout"
@@ -27,167 +30,172 @@ const WorkspacesPage = lazy(() => import("./pages/WorkspacesPage/WorkspacesPage"
2730
constCreateWorkspacePage=lazy(()=>import("./pages/CreateWorkspacePage/CreateWorkspacePage"))
2831
constAuditPage=lazy(()=>import("./pages/AuditPage/AuditPage"))
2932

30-
exportconstAppRouter:FC=()=>(
31-
<Suspensefallback={<></>}>
32-
<Routes>
33-
<Route
34-
index
35-
element={
36-
<RequireAuth>
37-
<IndexPage/>
38-
</RequireAuth>
39-
}
40-
/>
33+
exportconstAppRouter:FC=()=>{
34+
constxServices=useContext(XServiceContext)
35+
constpermissions=useSelector(xServices.authXService,selectPermissions)
4136

42-
<Routepath="login"element={<LoginPage/>}/>
43-
<Routepath="healthz"element={<HealthzPage/>}/>
44-
<Route
45-
path="cli-auth"
46-
element={
47-
<RequireAuth>
48-
<CliAuthenticationPage/>
49-
</RequireAuth>
50-
}
51-
/>
52-
53-
<Routepath="workspaces">
37+
return(
38+
<Suspensefallback={<></>}>
39+
<Routes>
5440
<Route
5541
index
5642
element={
57-
<AuthAndFrame>
58-
<WorkspacesPage/>
59-
</AuthAndFrame>
43+
<RequireAuth>
44+
<IndexPage/>
45+
</RequireAuth>
6046
}
6147
/>
62-
</Route>
6348

64-
<Routepath="templates">
49+
<Routepath="login"element={<LoginPage/>}/>
50+
<Routepath="healthz"element={<HealthzPage/>}/>
6551
<Route
66-
index
52+
path="cli-auth"
6753
element={
68-
<AuthAndFrame>
69-
<TemplatesPage/>
70-
</AuthAndFrame>
54+
<RequireAuth>
55+
<CliAuthenticationPage/>
56+
</RequireAuth>
7157
}
7258
/>
7359

74-
<Routepath=":template">
60+
<Routepath="workspaces">
7561
<Route
7662
index
7763
element={
7864
<AuthAndFrame>
79-
<TemplatePage/>
65+
<WorkspacesPage/>
8066
</AuthAndFrame>
8167
}
8268
/>
83-
<Route
84-
path="workspace"
85-
element={
86-
<RequireAuth>
87-
<CreateWorkspacePage/>
88-
</RequireAuth>
89-
}
90-
/>
9169
</Route>
92-
</Route>
93-
94-
<Routepath="users">
95-
<Route
96-
index
97-
element={
98-
<AuthAndFrame>
99-
<UsersPage/>
100-
</AuthAndFrame>
101-
}
102-
/>
103-
<Route
104-
path="create"
105-
element={
106-
<RequireAuth>
107-
<CreateUserPage/>
108-
</RequireAuth>
109-
}
110-
/>
111-
</Route>
11270

113-
{/* REMARK: Route under construction
114-
Eventually, we should gate this page
115-
with permissions and licensing */}
116-
<Routepath="/audit">
117-
<Route
118-
index
119-
element={
120-
process.env.NODE_ENV==="production" ?(
121-
<Navigateto="/workspaces"/>
122-
) :(
71+
<Routepath="templates">
72+
<Route
73+
index
74+
element={
12375
<AuthAndFrame>
124-
<AuditPage/>
76+
<TemplatesPage/>
12577
</AuthAndFrame>
126-
)
127-
}
128-
></Route>
129-
</Route>
78+
}
79+
/>
13080

131-
<Routepath="settings"element={<SettingsLayout/>}>
132-
<Routepath="account"element={<AccountPage/>}/>
133-
<Routepath="security"element={<SecurityPage/>}/>
134-
<Routepath="ssh-keys"element={<SSHKeysPage/>}/>
135-
</Route>
81+
<Routepath=":template">
82+
<Route
83+
index
84+
element={
85+
<AuthAndFrame>
86+
<TemplatePage/>
87+
</AuthAndFrame>
88+
}
89+
/>
90+
<Route
91+
path="workspace"
92+
element={
93+
<RequireAuth>
94+
<CreateWorkspacePage/>
95+
</RequireAuth>
96+
}
97+
/>
98+
</Route>
99+
</Route>
136100

137-
<Routepath="/@:username">
138-
<Routepath=":workspace">
101+
<Routepath="users">
139102
<Route
140103
index
141104
element={
142105
<AuthAndFrame>
143-
<WorkspacePage/>
106+
<UsersPage/>
144107
</AuthAndFrame>
145108
}
146109
/>
147110
<Route
148-
path="schedule"
111+
path="create"
149112
element={
150113
<RequireAuth>
151-
<WorkspaceSchedulePage/>
114+
<CreateUserPage/>
152115
</RequireAuth>
153116
}
154117
/>
118+
</Route>
155119

120+
{/* REMARK: Route under construction
121+
Eventually, we should gate this page
122+
with permissions and licensing */}
123+
<Routepath="/audit">
156124
<Route
157-
path="terminal"
125+
index
158126
element={
159-
<RequireAuth>
160-
<TerminalPage/>
161-
</RequireAuth>
127+
process.env.NODE_ENV==="production"||!permissions?.viewAuditLog ?(
128+
<Navigateto="/workspaces"/>
129+
) :(
130+
<AuthAndFrame>
131+
<AuditPage/>
132+
</AuthAndFrame>
133+
)
162134
}
163-
/>
135+
></Route>
136+
</Route>
137+
138+
<Routepath="settings"element={<SettingsLayout/>}>
139+
<Routepath="account"element={<AccountPage/>}/>
140+
<Routepath="security"element={<SecurityPage/>}/>
141+
<Routepath="ssh-keys"element={<SSHKeysPage/>}/>
142+
</Route>
164143

165-
<Routepath="apps">
144+
<Routepath="/@:username">
145+
<Routepath=":workspace">
166146
<Route
167-
path=":app/*"
147+
index
168148
element={
169149
<AuthAndFrame>
170-
<WorkspaceAppErrorPage/>
150+
<WorkspacePage/>
171151
</AuthAndFrame>
172152
}
173153
/>
174-
</Route>
154+
<Route
155+
path="schedule"
156+
element={
157+
<RequireAuth>
158+
<WorkspaceSchedulePage/>
159+
</RequireAuth>
160+
}
161+
/>
175162

176-
<Route
177-
path="builds/:buildNumber"
178-
element={
179-
<AuthAndFrame>
180-
<WorkspaceBuildPage/>
181-
</AuthAndFrame>
182-
}
183-
/>
163+
<Route
164+
path="terminal"
165+
element={
166+
<RequireAuth>
167+
<TerminalPage/>
168+
</RequireAuth>
169+
}
170+
/>
171+
172+
<Routepath="apps">
173+
<Route
174+
path=":app/*"
175+
element={
176+
<AuthAndFrame>
177+
<WorkspaceAppErrorPage/>
178+
</AuthAndFrame>
179+
}
180+
/>
181+
</Route>
182+
183+
<Route
184+
path="builds/:buildNumber"
185+
element={
186+
<AuthAndFrame>
187+
<WorkspaceBuildPage/>
188+
</AuthAndFrame>
189+
}
190+
/>
191+
</Route>
184192
</Route>
185-
</Route>
186193

187-
{/* Using path="*"" means "match anything", so this route
194+
{/* Using path="*"" means "match anything", so this route
188195
acts like a catch-all for URLs that we don't have explicit
189196
routes for. */}
190-
<Routepath="*"element={<NotFoundPage/>}/>
191-
</Routes>
192-
</Suspense>
193-
)
197+
<Routepath="*"element={<NotFoundPage/>}/>
198+
</Routes>
199+
</Suspense>
200+
)
201+
}

‎site/src/components/Navbar/Navbar.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ import { NavbarView } from "../NavbarView/NavbarView"
66
exportconstNavbar:React.FC=()=>{
77
constxServices=useContext(XServiceContext)
88
const[authState,authSend]=useActor(xServices.authXService)
9-
const{ me}=authState.context
9+
const{ me, permissions}=authState.context
1010
constonSignOut=()=>authSend("SIGN_OUT")
1111

12-
return<NavbarViewuser={me}onSignOut={onSignOut}/>
12+
return(
13+
<NavbarView
14+
user={me}
15+
onSignOut={onSignOut}
16+
canViewAuditLog={permissions?.viewAuditLog??false}
17+
/>
18+
)
1319
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp