Skip to content

Commit 48a01c3

Browse files
authored
fix(frontend): require podnamespace for pod logs when authz is enabled (#12778)
Signed-off-by: Jeff Spahr <[email protected]>
1 parent 9972245 commit 48a01c3

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

frontend/server/app.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,13 @@ describe('UIServer apis', () => {
495495
.get('/k8s/pod/logs?podname=test-pod&podnamespace=test-ns')
496496
.expect(403, 'Access denied to namespace');
497497
});
498+
499+
it('asks for podnamespace if not provided when authorization is enabled', async () => {
500+
const authRequest = requests(app.app);
501+
await authRequest
502+
.get('/k8s/pod/logs?podname=test-pod')
503+
.expect(422, 'podnamespace argument is required');
504+
});
498505
});
499506

500507
describe('/apis/v1beta1/', () => {

frontend/server/app.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ function createUIServer(options: UIConfigs) {
202202
registerHandler(
203203
app.get,
204204
'/k8s/pod/logs',
205-
getPodLogsHandler(options.argo, options.artifacts, options.pod.logContainerName, authorizeFn),
205+
getPodLogsHandler(
206+
options.argo,
207+
options.artifacts,
208+
options.pod.logContainerName,
209+
authorizeFn,
210+
options.auth.enabled,
211+
),
206212
);
207213
}
208214

@@ -228,7 +234,13 @@ function createUIServer(options: UIConfigs) {
228234
registerHandler(
229235
app.get,
230236
'/k8s/pod/logs',
231-
getPodLogsHandler(options.argo, options.artifacts, options.pod.logContainerName, authorizeFn),
237+
getPodLogsHandler(
238+
options.argo,
239+
options.artifacts,
240+
options.pod.logContainerName,
241+
authorizeFn,
242+
options.auth.enabled,
243+
),
232244
);
233245
}
234246

frontend/server/handlers/pod-logs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { AuthorizeFn } from '../helpers/auth.js';
3636
* @param argoOptions fallback options to retrieve log archive
3737
* @param artifactsOptions configs and credentials for the different artifact backend
3838
* @param authorizeFn function to authorize namespace access
39+
* @param authEnabled whether namespace authorization checks are enabled
3940
*/
4041
export function getPodLogsHandler(
4142
argoOptions: ArgoConfigs,
@@ -45,6 +46,7 @@ export function getPodLogsHandler(
4546
},
4647
podLogContainerName: string,
4748
authorizeFn: AuthorizeFn,
49+
authEnabled: boolean,
4850
): Handler {
4951
const {
5052
archiveLogs,
@@ -89,6 +91,12 @@ export function getPodLogsHandler(
8991
// Note decodeURIComponent(undefined) === 'undefined', so I cannot pass the argument directly.
9092
const podNamespace = decodeURIComponent((req.query.podnamespace as string) || '') || undefined;
9193

94+
// In multi-user mode, namespace must be explicit so authz cannot be bypassed.
95+
if (authEnabled && !podNamespace) {
96+
res.status(422).send('podnamespace argument is required');
97+
return;
98+
}
99+
92100
// Check access to namespace if podNamespace is provided
93101
if (podNamespace) {
94102
try {

0 commit comments

Comments
 (0)