Skip to content
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

frontend: AuthVisible: Validate verb before auth check #2610

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
18 changes: 18 additions & 0 deletions frontend/src/components/common/Resource/AuthVisible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import React, { useEffect } from 'react';
import { KubeObject } from '../../../lib/k8s/KubeObject';
import { KubeObjectClass } from '../../../lib/k8s/KubeObject';

/** List of valid request verbs. See https://kubernetes.io/docs/reference/access-authn-authz/authorization/#determine-the-request-verb. */
const VALID_AUTH_VERBS = [
'create',
'get',
'list',
'watch',
'update',
'patch',
'delete',
'deletecollection',
];

export interface AuthVisibleProps extends React.PropsWithChildren<{}> {
/** The item for which auth will be checked or a resource class (e.g. Job). */
item: KubeObject | KubeObjectClass | null;
Expand All @@ -27,6 +39,12 @@ export interface AuthVisibleProps extends React.PropsWithChildren<{}> {
*/
export default function AuthVisible(props: AuthVisibleProps) {
const { item, authVerb, subresource, namespace, onError, onAuthResult, children } = props;

if (!VALID_AUTH_VERBS.includes(authVerb)) {
console.warn(`Invalid authVerb provided: "${authVerb}". Skipping authorization check.`);
return null;
}

const { data } = useQuery<any>({
enabled: !!item,
queryKey: ['authVisible', item, authVerb, subresource, namespace],
Expand Down
Loading