Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Merge branch 'main' into feat/adilsitos/secret-513

adilson912ff6c215d2
diff --cc backend/src/ee/services/permission/permission-fns.test.ts
index 7d85ac1d0a,39a7821c7c..c1a525026e
--- a/backend/src/ee/services/permission/permission-fns.test.ts
+++ b/backend/src/ee/services/permission/permission-fns.test.ts
@@@ -5,7 -6,7 +6,8 @@@ import { ActorType } from "@app/service
import {
expandLegacyForbidActions,
+ handlebarsClient,
+ getProjectPermissionFingerprint,
interpolatePermissionRules,
throwIfMissingSecretReadValueOrDescribePermission
} from "./permission-fns";
@@@ -257,53 -258,36 +259,83 @@@ describe("throwIfMissingSecretReadValue
});
});
+describe("trimSuffix handlebars helper", () => {
+ const render = (template: string, value: string) =>
+ handlebarsClient.compile(template)({ identity: { auth: { kubernetes: { namespace: value } } } });
+
+ const trim = (value: string, pattern: string) =>
+ render(`{{ trimSuffix identity.auth.kubernetes.namespace '${pattern}' }}`, value);
+
+ test("trims a matching glob suffix", () => {
+ expect(trim("myapp-pr-1", "-pr-*")).toBe("myapp");
+ expect(trim("myapp-pr-42", "-pr-*")).toBe("myapp");
+ });
+
+ test("returns the value unchanged when nothing matches the pattern", () => {
+ expect(trim("myapp", "-pr-*")).toBe("myapp");
+ expect(trim("myapp-mr-1", "-pr-*")).toBe("myapp-mr-1");
+ });
+
+ test("removes the shortest matching suffix, not the longest", () => {
+ expect(trim("app-pr-1", "-*")).toBe("app-pr");
+ });
+
+ test("trims a literal suffix when the pattern has no glob syntax", () => {
+ expect(trim("myapp-prod", "-prod")).toBe("myapp");
+ expect(trim("myapp", "-prod")).toBe("myapp");
+ });
+
+ test("supports the wider glob syntax used by permission conditions", () => {
+ expect(trim("myapp-pr-1", "-{pr,mr}-*")).toBe("myapp");
+ expect(trim("myapp-pr-1", "-pr-?")).toBe("myapp");
+ });
+
+ test("leaves an unresolved attribute literal intact so the condition fails closed", () => {
+ expect(trim("{{identity.auth.kubernetes.namespace}}", "-pr-*")).toBe("{{identity.auth.kubernetes.namespace}}");
+ });
+
+ test("returns an empty string for an empty value", () => {
+ expect(trim("", "-pr-*")).toBe("");
+ });
+
+ test("returns the value unchanged for a malformed pattern instead of throwing", () => {
+ expect(trim("myapp-pr-1", "-pr-+(")).toBe("myapp-pr-1");
+ });
+
+ test("returns the value unchanged when no pattern is supplied", () => {
+ expect(render("{{ trimSuffix identity.auth.kubernetes.namespace }}", "myapp-pr-1")).toBe("myapp-pr-1");
+ });
+});
+ describe("getProjectPermissionFingerprint", () => {
+ const dto = {
+ projectId: "project-1",
+ orgId: "org-1",
+ actorId: "user-1",
+ actorType: ActorType.USER as ActorType.USER
+ };
+
+ const deps = (folderVersion?: number) =>
+ ({
+ permissionDAL: { getPermissionFingerprint: async () => "membership-hash" },
+ keyStore: { pgGetIntItem: async () => folderVersion }
+ }) as unknown as Parameters<typeof getProjectPermissionFingerprint>[1];
+
+ test("appends the project's folder permission version to the membership fingerprint", async () => {
+ expect(await getProjectPermissionFingerprint(dto, deps(7))).toBe("membership-hash:7");
+ });
+
+ test("changes when the folder permission version is bumped", async () => {
+ const [before, after] = await Promise.all([
+ getProjectPermissionFingerprint(dto, deps(7)),
+ getProjectPermissionFingerprint(dto, deps(8))
+ ]);
+ expect(before).not.toBe(after);
+ });
+
+ test("treats a missing version row as zero", async () => {
+ expect(await getProjectPermissionFingerprint(dto, deps(undefined))).toBe("membership-hash:0");
+ });
+ });
describe("interpolatePermissionRules", () => {
const templatedRule = (value: string): Rule =>
diff --cc backend/src/ee/services/permission/permission-fns.ts
index a71f86b96b,08181ede9f..ae9b4daeed
--- a/backend/src/ee/services/permission/permission-fns.ts
+++ b/backend/src/ee/services/permission/permission-fns.ts
@@@ -1,15 -1,26 +1,27 @@@
/* eslint-disable no-nested-ternary */
import { ForbiddenError, MongoAbility, PureAbility, RawRuleOf, subject } from "@casl/ability";
import handlebars from "handlebars";
+import picomatch from "picomatch";
import { z } from "zod";
- import { TOrganizations } from "@app/db/schemas";
+ import { SecretFolderRole, TOrganizations } from "@app/db/schemas";
+ import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
import { validatePermissionBoundary } from "@app/lib/casl/boundary";
- import { BadRequestError, ForbiddenRequestError, PermissionBoundaryError, UnauthorizedError } from "@app/lib/errors";
- import { ActorAuthMethod, AuthMethod } from "@app/services/auth/auth-type";
-
+ import {
+ BadRequestError,
+ ForbiddenRequestError,
+ NotFoundError,
+ PermissionBoundaryError,
+ UnauthorizedError
+ } from "@app/lib/errors";
+ import { TAdditionalPrivilegeDALFactory } from "@app/services/additional-privilege/additional-privilege-dal";
+ import { ActorAuthMethod, ActorType, AuthMethod } from "@app/services/auth/auth-type";
+ import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
+
+ import { FOLDER_SCOPED_DENY_RULES, SECRET_FOLDER_ROLE_PERMISSIONS } from "./folder-roles";
import { OrgPermissionSet } from "./org-permission";
+ import { TPermissionDALFactory } from "./permission-dal";
+ import { TCachedFolderScopedPrivileges, TProjectFolderScopedPrivilege } from "./permission-service-types";
import {
ActionAllowedConditions,
ProjectPermissionGroupActions,