Skip to content

Commit

Permalink
Exclude namespace when sending MR rolebindings to the backend service…
Browse files Browse the repository at this point in the history
… due to requestSecurityGuard

Signed-off-by: Mike Turley <[email protected]>
  • Loading branch information
mturley committed Sep 26, 2024
1 parent b4cc6a0 commit a8497c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ export const createModelRegistryRoleBinding = async (
rbRequest: V1RoleBinding,
mrNamespace: string,
): Promise<V1RoleBinding> => {
// Re-inject the namespace value that was omitted by the client
// (see createModelRegistryRoleBinding in frontend/src/services/modelRegistrySettingsService.ts)
// This will be unnecessary when we remove the backend service as part of https://issues.redhat.com/browse/RHOAIENG-12077
const roleBindingWithNamespace = {
...rbRequest,
metadata: { ...rbRequest.metadata, namespace: mrNamespace },
};
const response = await (fastify.kube.customObjectsApi.createNamespacedCustomObject(
MODEL_REGISTRY_ROLE_BINDING_API_GROUP,
MODEL_REGISTRY_ROLE_BINDING_API_VERSION,
mrNamespace,
MODEL_REGISTRY_ROLE_BINDING_PLURAL,
rbRequest,
roleBindingWithNamespace,
) as Promise<{ body: V1RoleBinding }>);
return response.body;
};
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/services/modelRegistrySettingsService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as _ from 'lodash-es';
import { K8sStatus } from '@openshift/dynamic-plugin-sdk-utils';
import axios from '~/utilities/axios';
import { ModelRegistryKind, RoleBindingKind } from '~/k8sTypes';
Expand Down Expand Up @@ -66,13 +67,21 @@ export const listModelRegistryRoleBindings = (): Promise<RoleBindingKind[]> =>
throw new Error(e.response.data.message);
});

export const createModelRegistryRoleBinding = (data: RoleBindingKind): Promise<RoleBindingKind> =>
axios
.post(mrRoleBindingsUrl, data)
export const createModelRegistryRoleBinding = (data: RoleBindingKind): Promise<RoleBindingKind> => {
// Don't include the namespace in the object we pass because it would get rejected by requestSecurityGuard.
// (see backend/src/utils/route-security.ts)
// Instead the namespace will be reinjected by the backend
// (see backend/src/routes/api/modelRegistries/modelRegistryUtils.ts)
// This will be unnecessary when we remove this service as part of https://issues.redhat.com/browse/RHOAIENG-12077
const roleBindingWithoutNamespace: RoleBindingKind & { metadata: { namespace?: string } } =
_.omit(data, 'metadata.namespace');
return axios
.post(mrRoleBindingsUrl, roleBindingWithoutNamespace)
.then((response) => response.data)
.catch((e) => {
throw new Error(e.response.data.message);
});
};

export const deleteModelRegistryRoleBinding = (roleBindingName: string): Promise<K8sStatus> =>
axios
Expand Down

0 comments on commit a8497c9

Please sign in to comment.