requested changes

This commit is contained in:
Daniel Hougaard
2024-09-30 21:45:11 +04:00
parent 66485f0464
commit 7885a3b0ff
6 changed files with 24 additions and 29 deletions
@@ -9,7 +9,7 @@ import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/pe
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service"; import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
import { isAtLeastAsPrivileged } from "@app/lib/casl"; import { isAtLeastAsPrivileged } from "@app/lib/casl";
import { getConfig } from "@app/lib/config/env"; import { getConfig } from "@app/lib/config/env";
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors"; import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip"; import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
import { ActorType, AuthTokenType } from "../auth/auth-type"; import { ActorType, AuthTokenType } from "../auth/auth-type";
@@ -81,7 +81,7 @@ export const identityAwsAuthServiceFactory = ({
.some((accountId) => accountId === Account); .some((accountId) => accountId === Account);
if (!isAccountAllowed) if (!isAccountAllowed)
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: AWS account ID not allowed." message: "Access denied: AWS account ID not allowed."
}); });
} }
@@ -100,7 +100,7 @@ export const identityAwsAuthServiceFactory = ({
}); });
if (!isArnAllowed) if (!isArnAllowed)
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: AWS principal ARN not allowed." message: "Access denied: AWS principal ARN not allowed."
}); });
} }
@@ -73,7 +73,7 @@ export const identityAzureAuthServiceFactory = ({
.map((servicePrincipalId) => servicePrincipalId.trim()) .map((servicePrincipalId) => servicePrincipalId.trim())
.some((servicePrincipalId) => servicePrincipalId === azureIdentity.oid); .some((servicePrincipalId) => servicePrincipalId === azureIdentity.oid);
if (!isServicePrincipalAllowed) throw new ForbiddenRequestError({ message: "Service principal not allowed" }); if (!isServicePrincipalAllowed) throw new UnauthorizedError({ message: "Service principal not allowed" });
} }
const identityAccessToken = await identityAzureAuthDAL.transaction(async (tx) => { const identityAccessToken = await identityAzureAuthDAL.transaction(async (tx) => {
@@ -314,8 +314,7 @@ export const identityAzureAuthServiceFactory = ({
actorAuthMethod, actorAuthMethod,
actorOrgId actorOrgId
); );
const hasPriviledge = isAtLeastAsPrivileged(permission, rolePermission); if (!isAtLeastAsPrivileged(permission, rolePermission))
if (!hasPriviledge)
throw new ForbiddenRequestError({ throw new ForbiddenRequestError({
message: "Failed to revoke azure auth of identity with more privileged role" message: "Failed to revoke azure auth of identity with more privileged role"
}); });
@@ -86,7 +86,7 @@ export const identityGcpAuthServiceFactory = ({
.some((serviceAccount) => serviceAccount === gcpIdentityDetails.email); .some((serviceAccount) => serviceAccount === gcpIdentityDetails.email);
if (!isServiceAccountAllowed) if (!isServiceAccountAllowed)
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: GCP service account not allowed." message: "Access denied: GCP service account not allowed."
}); });
} }
@@ -100,7 +100,7 @@ export const identityGcpAuthServiceFactory = ({
.some((project) => project === gcpIdentityDetails.computeEngineDetails?.project_id); .some((project) => project === gcpIdentityDetails.computeEngineDetails?.project_id);
if (!isProjectAllowed) if (!isProjectAllowed)
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: GCP project not allowed." message: "Access denied: GCP project not allowed."
}); });
} }
@@ -112,7 +112,7 @@ export const identityGcpAuthServiceFactory = ({
.some((zone) => zone === gcpIdentityDetails.computeEngineDetails?.zone); .some((zone) => zone === gcpIdentityDetails.computeEngineDetails?.zone);
if (!isZoneAllowed) if (!isZoneAllowed)
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: GCP zone not allowed." message: "Access denied: GCP zone not allowed."
}); });
} }
@@ -359,8 +359,7 @@ export const identityGcpAuthServiceFactory = ({
actorAuthMethod, actorAuthMethod,
actorOrgId actorOrgId
); );
const hasPriviledge = isAtLeastAsPrivileged(permission, rolePermission); if (!isAtLeastAsPrivileged(permission, rolePermission))
if (!hasPriviledge)
throw new ForbiddenRequestError({ throw new ForbiddenRequestError({
message: "Failed to revoke gcp auth of identity with more privileged role" message: "Failed to revoke gcp auth of identity with more privileged role"
}); });
@@ -132,7 +132,7 @@ export const identityKubernetesAuthServiceFactory = ({
// check the response to determine if the token is valid // check the response to determine if the token is valid
if (!(data.status && data.status.authenticated)) if (!(data.status && data.status.authenticated))
throw new ForbiddenRequestError({ message: "Kubernetes token not authenticated" }); throw new UnauthorizedError({ message: "Kubernetes token not authenticated" });
const { namespace: targetNamespace, name: targetName } = extractK8sUsername(data.status.user.username); const { namespace: targetNamespace, name: targetName } = extractK8sUsername(data.status.user.username);
@@ -145,7 +145,7 @@ export const identityKubernetesAuthServiceFactory = ({
.some((namespace) => namespace === targetNamespace); .some((namespace) => namespace === targetNamespace);
if (!isNamespaceAllowed) if (!isNamespaceAllowed)
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: K8s namespace not allowed." message: "Access denied: K8s namespace not allowed."
}); });
} }
@@ -159,7 +159,7 @@ export const identityKubernetesAuthServiceFactory = ({
.some((name) => name === targetName); .some((name) => name === targetName);
if (!isNameAllowed) if (!isNameAllowed)
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: K8s name not allowed." message: "Access denied: K8s name not allowed."
}); });
} }
@@ -171,7 +171,7 @@ export const identityKubernetesAuthServiceFactory = ({
); );
if (!isAudienceAllowed) if (!isAudienceAllowed)
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: K8s audience not allowed." message: "Access denied: K8s audience not allowed."
}); });
} }
@@ -148,7 +148,7 @@ export const identityOidcAuthServiceFactory = ({
.split(", ") .split(", ")
.some((policyValue) => doesFieldValueMatchOidcPolicy(tokenData.aud, policyValue)) .some((policyValue) => doesFieldValueMatchOidcPolicy(tokenData.aud, policyValue))
) { ) {
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: OIDC audience not allowed." message: "Access denied: OIDC audience not allowed."
}); });
} }
@@ -161,7 +161,7 @@ export const identityOidcAuthServiceFactory = ({
if ( if (
!claimValue.split(", ").some((claimEntry) => doesFieldValueMatchOidcPolicy(tokenData[claimKey], claimEntry)) !claimValue.split(", ").some((claimEntry) => doesFieldValueMatchOidcPolicy(tokenData[claimKey], claimEntry))
) { ) {
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied: OIDC claim not allowed." message: "Access denied: OIDC claim not allowed."
}); });
} }
@@ -532,8 +532,7 @@ export const identityOidcAuthServiceFactory = ({
actorOrgId actorOrgId
); );
const hasPriviledge = isAtLeastAsPrivileged(permission, rolePermission); if (!isAtLeastAsPrivileged(permission, rolePermission)) {
if (!hasPriviledge) {
throw new ForbiddenRequestError({ throw new ForbiddenRequestError({
message: "Failed to revoke OIDC auth of identity with more privileged role" message: "Failed to revoke OIDC auth of identity with more privileged role"
}); });
@@ -88,7 +88,7 @@ export const identityUaServiceFactory = ({
isClientSecretRevoked: true isClientSecretRevoked: true
}); });
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied due to expired client secret" message: "Access denied due to expired client secret"
}); });
} }
@@ -100,7 +100,7 @@ export const identityUaServiceFactory = ({
await identityUaClientSecretDAL.updateById(validClientSecretInfo.id, { await identityUaClientSecretDAL.updateById(validClientSecretInfo.id, {
isClientSecretRevoked: true isClientSecretRevoked: true
}); });
throw new ForbiddenRequestError({ throw new UnauthorizedError({
message: "Access denied due to client secret usage limit reached" message: "Access denied due to client secret usage limit reached"
}); });
} }
@@ -368,8 +368,7 @@ export const identityUaServiceFactory = ({
actorAuthMethod, actorAuthMethod,
actorOrgId actorOrgId
); );
const hasPriviledge = isAtLeastAsPrivileged(permission, rolePermission); if (!isAtLeastAsPrivileged(permission, rolePermission))
if (!hasPriviledge)
throw new ForbiddenRequestError({ throw new ForbiddenRequestError({
message: "Failed to revoke universal auth of identity with more privileged role" message: "Failed to revoke universal auth of identity with more privileged role"
}); });
@@ -474,8 +473,8 @@ export const identityUaServiceFactory = ({
actorAuthMethod, actorAuthMethod,
actorOrgId actorOrgId
); );
const hasPriviledge = isAtLeastAsPrivileged(permission, rolePermission);
if (!hasPriviledge) if (!isAtLeastAsPrivileged(permission, rolePermission))
throw new ForbiddenRequestError({ throw new ForbiddenRequestError({
message: "Failed to add identity to project with more privileged role" message: "Failed to add identity to project with more privileged role"
}); });
@@ -521,8 +520,7 @@ export const identityUaServiceFactory = ({
actorAuthMethod, actorAuthMethod,
actorOrgId actorOrgId
); );
const hasPriviledge = isAtLeastAsPrivileged(permission, rolePermission); if (!isAtLeastAsPrivileged(permission, rolePermission))
if (!hasPriviledge)
throw new ForbiddenRequestError({ throw new ForbiddenRequestError({
message: "Failed to read identity client secret of project with more privileged role" message: "Failed to read identity client secret of project with more privileged role"
}); });
@@ -561,8 +559,8 @@ export const identityUaServiceFactory = ({
actorAuthMethod, actorAuthMethod,
actorOrgId actorOrgId
); );
const hasPriviledge = isAtLeastAsPrivileged(permission, rolePermission);
if (!hasPriviledge) if (!isAtLeastAsPrivileged(permission, rolePermission))
throw new ForbiddenRequestError({ throw new ForbiddenRequestError({
message: "Failed to revoke identity client secret with more privileged role" message: "Failed to revoke identity client secret with more privileged role"
}); });