Skip to content

Commit

Permalink
Merge pull request #2610 from headlamp-k8s/authvisible-verb-bug
Browse files Browse the repository at this point in the history
frontend: AuthVisible: Validate verb before auth check
  • Loading branch information
joaquimrocha authored Nov 27, 2024
2 parents ee1e62e + 98053b2 commit 877d8e1
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit 877d8e1

Please sign in to comment.