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

adilson156918395569
diff --cc backend/src/ee/services/permission/permission-fns.test.ts
index 88bec8fa22,d5ccae6ed5..7d85ac1d0a
--- a/backend/src/ee/services/permission/permission-fns.test.ts
+++ b/backend/src/ee/services/permission/permission-fns.test.ts
@@@ -5,7 -5,7 +5,8 @@@ import { conditionsMatcher } from "@app
import {
expandLegacyForbidActions,
+ handlebarsClient,
+ interpolatePermissionRules,
throwIfMissingSecretReadValueOrDescribePermission
} from "./permission-fns";
import {
@@@ -256,50 -256,36 +257,84 @@@ 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("interpolatePermissionRules", () => {
+ const templatedRule = (value: string): Rule =>
+ ({
+ action: [ProjectPermissionSecretActions.DescribeSecret],
+ subject: ProjectPermissionSub.Secrets,
+ conditions: { environment: value }
+ }) as Rule;
+
+ test("interpolates identity context when the rules carry a template", () => {
+ const [rule] = interpolatePermissionRules([templatedRule("{{ identity.metadata.env }}")], {
+ identity: { metadata: { env: "prod" } }
+ });
+
+ expect(rule.conditions).toEqual({ environment: "prod" });
+ });
+
+ // Untemplated rules are returned as-is rather than copied, so callers share the module-level built-in
+ // rule sets. This is what makes mutating a rule in place unsafe.
+ test("returns untemplated rules as-is, without copying", () => {
+ const rules = [templatedRule("prod"), templatedRule("staging")];
+
+ expect(interpolatePermissionRules(rules, { identity: { metadata: {} } })).toBe(rules);
+ });
+
+ test("still templates block helpers and comments, which are not bare expressions", () => {
+ const [rule] = interpolatePermissionRules(
+ [templatedRule("{{#if identity.metadata.env}}{{ identity.metadata.env }}{{else}}dev{{/if}}")],
+ { identity: { metadata: {} } }
+ );
+
+ expect(rule.conditions).toEqual({ environment: "dev" });
+ });
+ });