Skip to content

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

add to missing routes

Thiago Araujo da Silva9013b36076c5
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index f5e0ea98e4..0d49baef42 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -492,7 +492,7 @@ Built-in roles: `Admin`, `Member`, `Viewer`, `NoAccess`. Custom roles use unpack
**Privilege boundaries mean different things on the two privilege systems.** `organizations.shouldUseNewPrivilegeSystem` (default `true`, backfilled `false` for orgs predating March 2025) picks which. `validatePrivilegeChangeOperation` / `assertRoleSetBoundary` (`permission-fns.ts`) are the shim: on the new system they collapse to `actorPermission.can(action, subject)`, on the legacy one they run `validatePermissionBoundary`, requiring the actor to out-rank every role the target holds. So a boundary at a call site that already gated on the same action is a no-op for new-system orgs and the only protection for legacy ones. Two consequences: "the route checks the action" is not a substitute for a boundary, and adding one is not a behavior change for most tenants. Prefer `getOrgPermissionByRoles` / `getProjectPermissionByRoles` + `assertRoleSetBoundary` over fetching the target's merged ability. It bounds each role separately, and it avoids `getProjectPermission`, which stamps whichever actor it was called for onto the request context the audit log reads.
-**Identity auth-method mutations go through `assertIdentityAuthMutationAllowed`** (`src/services/identity/identity-auth-permission-fns.ts`), because repointing an identity's auth trust lets the caller authenticate as that identity. All 13 auth services call it once per attach/update/revoke, after the `throwUnlessCan` gate and outside the `identity.projectId` branch so both scopes are covered. A new auth method calls it too. Credential issuance (`createTokenAuthToken`, `createUniversalAuthClientSecret`) goes through it as well, under `create-token`, since minting a credential is the same escalation as repointing the trust. The remaining token read/rename/revoke paths still carry their own inline boundary, org branch only. The target's grants come from `permissionService.getActorGrantAbilities`, not from a membership lookup, and it returns one ability per grant rather than per role. Two things a role-slug resolver misses: a group-derived membership carries a NULL `actorIdentityId`, so `membershipIdentityDAL.getIdentityById` never sees it, and an additional privilege carries a raw permission blob with no slug at all, so no `*PermissionByRoles` path can express it. Either omission clears an actor that out-ranks the target's direct roles but not its effective access. `getActorGrantAbilities` reads the same `permissionDAL.getPermission` query the ability itself is built from, so the bounded set cannot drift from the effective one.
+**Identity auth-method access goes through `assertIdentityAuthAccessAllowed`** (`src/services/identity/identity-auth-permission-fns.ts`), because repointing an identity's auth trust lets the caller authenticate as that identity. All 13 auth services call it once per attach/update/revoke, after the `throwUnlessCan` gate and outside the `identity.projectId` branch so both scopes are covered. A new auth method calls it too. Credential issuance (`createTokenAuthToken`, `createUniversalAuthClientSecret`) goes through it under `create-token`, since minting a credential is the same escalation as repointing the trust, and so do the per-credential paths: `updateTokenAuthToken` under `create-token`, `getUniversalAuthClientSecrets` / `getUniversalAuthClientSecretById` under `get-token`, and `revokeUniversalAuthClientSecret` under `delete-token`. **`PROJECT_ACTION_BY_ORG_ACTION` must map the org action to the same project action the route's own `throwUnlessCan` already checks** — that identity is what keeps the helper a no-op for new-system orgs, so a new entry is only safe once you have confirmed the pair matches. `revokeTokenAuthToken` and `clearUniversalAuthLockouts` are still unbounded in both scopes (and the former gates on `edit` where its UA counterpart gates on `delete-token`); that predates the helper and is a deliberate gap, not an oversight to copy. The target's grants come from `permissionService.getActorGrantAbilities`, not from a membership lookup, and it returns one ability per grant rather than per role. Two things a role-slug resolver misses: a group-derived membership carries a NULL `actorIdentityId`, so `membershipIdentityDAL.getIdentityById` never sees it, and an additional privilege carries a raw permission blob with no slug at all, so no `*PermissionByRoles` path can express it. Either omission clears an actor that out-ranks the target's direct roles but not its effective access. `getActorGrantAbilities` reads the same `permissionDAL.getPermission` query the ability itself is built from, so the bounded set cannot drift from the effective one.
**Project permission caching** uses a fingerprint-based two-tier cache (`withCacheFingerprint` in `src/lib/cache/with-cache.ts`):
- **Short-lived marker** (10s TTL) in Redis — while present, cached data is served with 0 DB reads.
diff --git a/backend/e2e-test/routes/v1/identity-auth-boundary.spec.ts b/backend/e2e-test/routes/v1/identity-auth-boundary.spec.ts
new file mode 100644
index 0000000000..b488a97c72
--- /dev/null
+++ b/backend/e2e-test/routes/v1/identity-auth-boundary.spec.ts
@@ -0,0 +1,531 @@
+/**
+ * The gap these cover: repointing an identity's auth trust (attach/update), revoking it, or minting
+ * a token for it all let the caller authenticate *as* that identity. The action check alone was
+ * enough, so an actor holding only `identity:edit-auth` could take over an Admin-role identity.
+ *
+ * The boundary added for this only bites on the legacy privilege system. Under the new system
+ * holding the action IS the authorization, so every operation below must still pass — that half is
+ * a regression guard, not an aspiration.
+ *
+ * Every test drives the reach as a machine identity rather than the seeded admin user, so the
+ * actor's role is exactly what the assertion is about.
+ */
+
+import { packRules } from "@casl/ability/extra";
+
+import { AccessScope, OrgMembershipRole, ProjectMembershipRole, TableName } from "@app/db/schemas";
+import { seedData1 } from "@app/db/seed-data";
+
+const ORG_ID = seedData1.organization.id;
+
+const adminHeaders = () => ({ authorization: `Bearer ${jwtAuthToken}` });
+const asIdentity = (token: string) => ({ authorization: `Bearer ${token}` });
+
+/**
+ * Picks the boundary semantics: false => the actor must dominate the target's privileges, true =>
+ * holding the action is enough. Defaults to true, so both branches need exercising explicitly.
+ */
+const setNewPrivilegeSystem = async (enabled: boolean) => {
+ await testDb(TableName.Organization).where({ id: ORG_ID }).update({ shouldUseNewPrivilegeSystem: enabled });
+};
+
+/**
+ * Written straight to the table because the e2e license mock reports `rbac: false` and the
+ * custom-role routes refuse to create one. The boundary reads these same columns either way.
+ */
+const insertRole = async (slug: string, permissions: object[], scope: { orgId: string } | { projectId: string }) => {
+ const [role] = await testDb(TableName.Role)
+ .insert({ name: slug, slug, permissions: JSON.stringify(packRules(permissions as never)), ...scope })
+ .returning("id");
+
+ return (role as { id: string }).id;
+};
+
+const findMembership = async (actorIdentityId: string, scope: { scopeProjectId?: string }) => {
+ const membership = await testDb(TableName.Membership)
+ .where({
+ scope: scope.scopeProjectId ? AccessScope.Project : AccessScope.Organization,
+ scopeOrgId: ORG_ID,
+ actorIdentityId,
+ ...(scope.scopeProjectId ? { scopeProjectId: scope.scopeProjectId } : {})
+ })
+ .first();
+ expect(membership).toBeDefined();
+ return (membership as { id: string }).id;
+};
+
+/** Repoint an existing membership at a custom role, replacing the built-in role it was created with. */
+const useCustomRole = async (membershipId: string, customRoleId: string) => {
+ await testDb(TableName.MembershipRole).where({ membershipId }).delete();
+ await testDb(TableName.MembershipRole).insert({ membershipId, role: "custom", customRoleId });
+};
+
+const createOrgIdentity = async (name: string, role: OrgMembershipRole) => {
+ const res = await testServer.inject({
+ method: "POST",
+ url: "/api/v1/identities",
+ headers: adminHeaders(),
+ body: { name, role, organizationId: ORG_ID }
+ });
+ expect(res.statusCode).toBe(200);
+ return res.json().identity.id as string;
+};
+
+const deleteIdentity = (identityId: string) =>
+ testServer.inject({ method: "DELETE", url: `/api/v1/identities/${identityId}`, headers: adminHeaders() });
+
+/** Attaches Universal Auth and logs in, so the identity can act as the caller. */
+const loginAsIdentity = async (identityId: string) => {
+ const attachRes = await testServer.inject({
+ method: "POST",
+ url: `/api/v1/auth/universal-auth/identities/${identityId}`,
+ headers: adminHeaders(),
+ body: { accessTokenTTL: 2592000, accessTokenMaxTTL: 2592000, accessTokenNumUsesLimit: 0 }
+ });
+ expect(attachRes.statusCode).toBe(200);
+ const clientId = attachRes.json().identityUniversalAuth.clientId as string;
+
+ const csRes = await testServer.inject({
+ method: "POST",
+ url: `/api/v1/auth/universal-auth/identities/${identityId}/client-secrets`,
+ headers: adminHeaders(),
+ body: {}
+ });
+ expect(csRes.statusCode).toBe(200);
+
+ const loginRes = await testServer.inject({
+ method: "POST",
+ url: "/api/v1/auth/universal-auth/login",
+ body: { clientId, clientSecret: csRes.json().clientSecret }
+ });
+ expect(loginRes.statusCode).toBe(200);
+ return loginRes.json().accessToken as string;
+};
+
+// The four guarded operations. Each is the *first* thing the route does after the plain action
+// check, so a 403 here is the boundary and anything else means it let the actor through.
+const attachTokenAuth = (identityId: string, headers: Record<string, string>) =>
+ testServer.inject({
+ method: "POST",
+ url: `/api/v1/auth/token-auth/identities/${identityId}`,
+ headers,
+ body: { accessTokenTTL: 2592000, accessTokenMaxTTL: 2592000, accessTokenNumUsesLimit: 0 }
+ });
+
+const updateTokenAuth = (identityId: string, headers: Record<string, string>) =>
+ testServer.inject({
+ method: "PATCH",
+ url: `/api/v1/auth/token-auth/identities/${identityId}`,
+ headers,
+ body: { accessTokenTTL: 1800 }
+ });
+
+const createTokenAuthToken = (identityId: string, headers: Record<string, string>) =>
+ testServer.inject({
+ method: "POST",
+ url: `/api/v1/auth/token-auth/identities/${identityId}/tokens`,
+ headers,
+ body: { name: "e2e-token" }
+ });
+
+const revokeTokenAuth = (identityId: string, headers: Record<string, string>) =>
+ testServer.inject({
+ method: "DELETE",
+ url: `/api/v1/auth/token-auth/identities/${identityId}`,
+ headers
+ });
+
+/** Detach token auth so the same target can be re-attached by the next test. */
+const resetTokenAuth = async (identityId: string) => {
+ await revokeTokenAuth(identityId, adminHeaders());
+};
+
+const AUTH_EDITOR_PERMISSIONS = [
+ { subject: "identity", action: ["read", "create", "edit", "edit-auth", "revoke-auth", "create-token"] }
+];
+
+describe("Privilege boundary on organization-scoped identity auth", () => {
+ let actor: { identityId: string; token: string };
+ let peerTarget: string;
+ let adminTarget: string;
+ let groupTarget: string;
+ let privilegeTarget: string;
+ let groupId: string;
+
+ beforeAll(async () => {
+ const actorIdentityId = await createOrgIdentity("e2e-iab-actor", OrgMembershipRole.Member);
+ const token = await loginAsIdentity(actorIdentityId);
+ actor = { identityId: actorIdentityId, token };
+
+ // The actor legitimately holds every guarded action, and nothing else. That is the shape the
+ // boundary is about: real reach, yet weaker than the targets below.
+ const authEditorRoleId = await insertRole("e2e-iab-auth-editor", AUTH_EDITOR_PERMISSIONS, { orgId: ORG_ID });
+ await useCustomRole(await findMembership(actorIdentityId, {}), authEditorRoleId);
+
+ peerTarget = await createOrgIdentity("e2e-iab-peer-target", OrgMembershipRole.Member);
+ adminTarget = await createOrgIdentity("e2e-iab-admin-target", OrgMembershipRole.Admin);
+
+ // Member role directly, Admin only by group inheritance. The boundary has to resolve the
+ // group-derived membership or this target looks like a peer.
+ groupTarget = await createOrgIdentity("e2e-iab-group-target", OrgMembershipRole.Member);
+ const [group] = await testDb(TableName.Groups)
+ .insert({ orgId: ORG_ID, name: "e2e-iab-admin-group", slug: "e2e-iab-admin-group" })
+ .returning("id");
+ groupId = (group as { id: string }).id;
+ await testDb(TableName.IdentityGroupMembership).insert({ identityId: groupTarget, groupId });
+ const [groupMembership] = await testDb(TableName.Membership)
+ .insert({ scope: AccessScope.Organization, scopeOrgId: ORG_ID, actorGroupId: groupId })
+ .returning("id");
+ await testDb(TableName.MembershipRole).insert({
+ membershipId: (groupMembership as { id: string }).id,
+ role: OrgMembershipRole.Admin
+ });
+
+ // Member role plus a standalone additional privilege. Roles alone do not dominate this target.
+ privilegeTarget = await createOrgIdentity("e2e-iab-privilege-target", OrgMembershipRole.Member);
+ await testDb(TableName.AdditionalPrivilege).insert({
+ name: "e2e-iab-broad-privilege",
+ actorIdentityId: privilegeTarget,
+ orgId: ORG_ID,
+ permissions: JSON.stringify(
+ packRules([{ subject: "sso", action: ["read", "create", "edit", "delete"] }] as never)
+ )
+ });
+ });
+
+ afterAll(async () => {
+ await testDb(TableName.Groups).where({ id: groupId }).delete();
+ await Promise.all(
+ [actor.identityId, peerTarget, adminTarget, groupTarget, privilegeTarget].map((id) => deleteIdentity(id))
+ );
+ await testDb(TableName.Role).where({ slug: "e2e-iab-auth-editor", orgId: ORG_ID }).delete();
+ });
+
+ test("the actor does hold the guarded actions, so the reach is real", async () => {
+ // Attaching to an equal-privilege target succeeds, which is what makes the assertions below
+ // boundary checks rather than plain missing-permission rejections.
+ const attachRes = await attachTokenAuth(peerTarget, asIdentity(actor.token));
+ expect(attachRes.statusCode).toBe(200);
+
+ const updateRes = await updateTokenAuth(peerTarget, asIdentity(actor.token));
+ expect(updateRes.statusCode).toBe(200);
+
+ const tokenRes = await createTokenAuthToken(peerTarget, asIdentity(actor.token));
+ expect(tokenRes.statusCode).toBe(200);
+
+ const revokeRes = await revokeTokenAuth(peerTarget, asIdentity(actor.token));
+ expect(revokeRes.statusCode).toBe(200);
+ });
+
+ describe("on the legacy privilege system", () => {
+ beforeAll(() => setNewPrivilegeSystem(false));
+ afterAll(() => setNewPrivilegeSystem(true));
+
+ test("the actor cannot attach token auth to an Admin-role identity", async () => {
+ const res = await attachTokenAuth(adminTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+ });
+
+ test("the actor cannot update token auth of an Admin-role identity", async () => {
+ await attachTokenAuth(adminTarget, adminHeaders());
+
+ const res = await updateTokenAuth(adminTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+ });
+
+ test("the actor cannot mint a token for an Admin-role identity", async () => {
+ const res = await createTokenAuthToken(adminTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+ });
+
+ test("the actor cannot revoke token auth of an Admin-role identity", async () => {
+ const res = await revokeTokenAuth(adminTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+
+ await resetTokenAuth(adminTarget);
+ });
+
+ test("a target that is Admin only through a group is still out of reach", async () => {
+ const res = await attachTokenAuth(groupTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+ });
+
+ test("a target whose extra reach comes from an additional privilege is still out of reach", async () => {
+ const res = await attachTokenAuth(privilegeTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+ });
+
+ test("an admin can still drive every guarded operation", async () => {
+ expect((await attachTokenAuth(adminTarget, adminHeaders())).statusCode).toBe(200);
+ expect((await updateTokenAuth(adminTarget, adminHeaders())).statusCode).toBe(200);
+ expect((await createTokenAuthToken(adminTarget, adminHeaders())).statusCode).toBe(200);
+ expect((await revokeTokenAuth(adminTarget, adminHeaders())).statusCode).toBe(200);
+ });
+ });
+
+ describe("on the new privilege system", () => {
+ // Deliberate, not an oversight: under the new system holding the action IS the authorization, so
+ // these pass regardless of the target's roles. You narrow it with conditions on the action, not
+ // with a privilege comparison. This is the default, so most orgs get an inert boundary here.
+ afterAll(() => resetTokenAuth(adminTarget));
+
+ test("the actor can attach and update token auth on an Admin-role identity", async () => {
+ expect((await attachTokenAuth(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ expect((await updateTokenAuth(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ });
+
+ test("the actor can mint a token for an Admin-role identity", async () => {
+ expect((await createTokenAuthToken(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ });
+
+ test("the actor can revoke token auth of an Admin-role identity", async () => {
+ expect((await revokeTokenAuth(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ });
+
+ test("group inheritance and additional privileges on the target change nothing", async () => {
+ expect((await attachTokenAuth(groupTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ expect((await attachTokenAuth(privilegeTarget, asIdentity(actor.token))).statusCode).toBe(200);
+
+ await resetTokenAuth(groupTarget);
+ await resetTokenAuth(privilegeTarget);
+ });
+ });
+});
+
+describe("Privilege boundary on project-scoped identity auth", () => {
+ // Project-level identities (identities.projectId set) take the project branch of the guard, which
+ // had no boundary at all before this change — the org branch was the only one that checked.
+ let project: { id: string };
+ let actor: { identityId: string; token: string };
+ let peerTarget: string;
+ let adminTarget: string;
+
+ const createProjectIdentity = async (name: string, role: ProjectMembershipRole) => {
+ const res = await testServer.inject({
+ method: "POST",
+ url: `/api/v1/projects/${project.id}/identities`,
+ headers: adminHeaders(),
+ body: { name, roles: [{ role }] }
+ });
+ expect(res.statusCode).toBe(200);
+ return res.json().identity.id as string;
+ };
+
+ beforeAll(async () => {
+ const createProjectRes = await testServer.inject({
+ method: "POST",
+ url: "/api/v1/projects",
+ headers: adminHeaders(),
+ body: { projectName: "e2e-identity-auth-boundary" }
+ });
+ expect(createProjectRes.statusCode).toBe(200);
+ project = createProjectRes.json().project;
+
+ const actorIdentityId = await createProjectIdentity("e2e-iab-proj-actor", ProjectMembershipRole.Member);
+ const token = await loginAsIdentity(actorIdentityId);
+ actor = { identityId: actorIdentityId, token };
+
+ const authEditorRoleId = await insertRole("e2e-iab-proj-auth-editor", AUTH_EDITOR_PERMISSIONS, {
+ projectId: project.id
+ });
+ await useCustomRole(await findMembership(actorIdentityId, { scopeProjectId: project.id }), authEditorRoleId);
+
+ peerTarget = await createProjectIdentity("e2e-iab-proj-peer", ProjectMembershipRole.Member);
+ adminTarget = await createProjectIdentity("e2e-iab-proj-admin", ProjectMembershipRole.Admin);
+ });
+
+ afterAll(async () => {
+ await Promise.all([actor.identityId, peerTarget, adminTarget].map((id) => deleteIdentity(id)));
+ await testServer.inject({
+ method: "DELETE",
+ url: `/api/v1/projects/${project.id}`,
+ headers: adminHeaders()
+ });
+ });
+
+ test("the actor does hold the guarded actions, so the reach is real", async () => {
+ expect((await attachTokenAuth(peerTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ expect((await createTokenAuthToken(peerTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ expect((await revokeTokenAuth(peerTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ });
+
+ describe("on the legacy privilege system", () => {
+ beforeAll(() => setNewPrivilegeSystem(false));
+ afterAll(() => setNewPrivilegeSystem(true));
+
+ test("the actor cannot attach token auth to a project Admin identity", async () => {
+ const res = await attachTokenAuth(adminTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+ });
+
+ test("the actor cannot mint a token for a project Admin identity", async () => {
+ await attachTokenAuth(adminTarget, adminHeaders());
+
+ const res = await createTokenAuthToken(adminTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+ });
+
+ test("the actor cannot revoke token auth of a project Admin identity", async () => {
+ const res = await revokeTokenAuth(adminTarget, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+
+ await resetTokenAuth(adminTarget);
+ });
+ });
+
+ describe("on the new privilege system", () => {
+ test("the actor can drive every guarded operation on a project Admin identity", async () => {
+ expect((await attachTokenAuth(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ expect((await updateTokenAuth(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ expect((await createTokenAuthToken(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ expect((await revokeTokenAuth(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+ });
+ });
+});
+
+/**
+ * The client-secret paths were the half of the auth surface the first pass missed: bounded in the
+ * org branch, unbounded in the project branch. That asymmetry let an actor holding only
+ * `identity:delete-token` on one project identity revoke an Admin identity's credentials, while
+ * being refused when it tried to create one — a boundary that fires on create and not on revoke.
+ */
+describe("Privilege boundary on project-scoped Universal Auth client secrets", () => {
+ let project: { id: string };
+ let actor: { identityId: string; token: string };
+ let adminTarget: string;
+
+ const createProjectIdentity = async (name: string, role: ProjectMembershipRole) => {
+ const res = await testServer.inject({
+ method: "POST",
+ url: `/api/v1/projects/${project.id}/identities`,
+ headers: adminHeaders(),
+ body: { name, roles: [{ role }] }
+ });
+ expect(res.statusCode).toBe(200);
+ return res.json().identity.id as string;
+ };
+
+ const attachUniversalAuth = (identityId: string) =>
+ testServer.inject({
+ method: "POST",
+ url: `/api/v1/auth/universal-auth/identities/${identityId}`,
+ headers: adminHeaders(),
+ body: { accessTokenTTL: 2592000, accessTokenMaxTTL: 2592000, accessTokenNumUsesLimit: 0 }
+ });
+
+ const createClientSecret = (identityId: string, headers: Record<string, string>) =>
+ testServer.inject({
+ method: "POST",
+ url: `/api/v1/auth/universal-auth/identities/${identityId}/client-secrets`,
+ headers,
+ body: {}
+ });
+
+ const listClientSecrets = (identityId: string, headers: Record<string, string>) =>
+ testServer.inject({
+ method: "GET",
+ url: `/api/v1/auth/universal-auth/identities/${identityId}/client-secrets`,
+ headers
+ });
+
+ const revokeClientSecret = (identityId: string, clientSecretId: string, headers: Record<string, string>) =>
+ testServer.inject({
+ method: "POST",
+ url: `/api/v1/auth/universal-auth/identities/${identityId}/client-secrets/${clientSecretId}/revoke`,
+ headers,
+ body: {}
+ });
+
+ beforeAll(async () => {
+ const createProjectRes = await testServer.inject({
+ method: "POST",
+ url: "/api/v1/projects",
+ headers: adminHeaders(),
+ body: { projectName: "e2e-identity-auth-boundary-ua" }
+ });
+ expect(createProjectRes.statusCode).toBe(200);
+ project = createProjectRes.json().project;
+
+ const actorIdentityId = await createProjectIdentity("e2e-iab-ua-actor", ProjectMembershipRole.Member);
+ const token = await loginAsIdentity(actorIdentityId);
+ actor = { identityId: actorIdentityId, token };
+
+ // Holds every client-secret action, so a refusal below is the boundary and not a missing action.
+ const roleId = await insertRole(
+ "e2e-iab-ua-secret-manager",
+ [{ subject: "identity", action: ["read", "create", "edit", "create-token", "get-token", "delete-token"] }],
+ { projectId: project.id }
+ );
+ await useCustomRole(await findMembership(actorIdentityId, { scopeProjectId: project.id }), roleId);
+
+ adminTarget = await createProjectIdentity("e2e-iab-ua-admin", ProjectMembershipRole.Admin);
+ expect((await attachUniversalAuth(adminTarget)).statusCode).toBe(200);
+ });
+
+ afterAll(async () => {
+ await Promise.all([actor.identityId, adminTarget].map((id) => deleteIdentity(id)));
+ // Deleting the project cascades the custom role; deleting the role directly races the
+ // membership_roles rows that still reference it.
+ await testServer.inject({
+ method: "DELETE",
+ url: `/api/v1/projects/${project.id}`,
+ headers: adminHeaders()
+ });
+ });
+
+ describe("on the legacy privilege system", () => {
+ beforeAll(() => setNewPrivilegeSystem(false));
+ afterAll(() => setNewPrivilegeSystem(true));
+
+ test("the actor cannot revoke a client secret of a project Admin identity", async () => {
+ // Minted as an admin, because the actor is refused on create under this same boundary.
+ const created = await createClientSecret(adminTarget, adminHeaders());
+ expect(created.statusCode).toBe(200);
+ const clientSecretId = created.json().clientSecretData.id as string;
+
+ const res = await revokeClientSecret(adminTarget, clientSecretId, asIdentity(actor.token));
+ expect(res.statusCode).toBe(403);
+ expect(res.json().message).toContain("more privileged role");
+
+ // The refusal has to be a no-op, not just a non-200.
+ const row = await testDb(TableName.IdentityUaClientSecret).where({ id: clientSecretId }).first();
+ expect((row as { isClientSecretRevoked: boolean }).isClientSecretRevoked).toBe(false);
+ });
+
+ test("the actor cannot list or create client secrets of a project Admin identity", async () => {
+ const listed = await listClientSecrets(adminTarget, asIdentity(actor.token));
+ expect(listed.statusCode).toBe(403);
+ expect(listed.json().message).toContain("more privileged role");
+
+ const created = await createClientSecret(adminTarget, asIdentity(actor.token));
+ expect(created.statusCode).toBe(403);
+ expect(created.json().message).toContain("more privileged role");
+ });
+ });
+
+ describe("on the new privilege system", () => {
+ // Holding the action is the authorization here, so all three pass regardless of the target's roles.
+ test("the actor can create, list and revoke client secrets of a project Admin identity", async () => {
+ const created = await createClientSecret(adminTarget, asIdentity(actor.token));
+ expect(created.statusCode).toBe(200);
+
+ expect((await listClientSecrets(adminTarget, asIdentity(actor.token))).statusCode).toBe(200);
+
+ const revoked = await revokeClientSecret(
+ adminTarget,
+ created.json().clientSecretData.id as string,
+ asIdentity(actor.token)
+ );
+ expect(revoked.statusCode).toBe(200);
+ });
+ });
+});
diff --git a/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts b/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts
index 7acc129d2d..fbcf70759f 100644
--- a/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts
+++ b/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts
@@ -25,7 +25,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -306,7 +306,7 @@ export const identityAliCloudAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -429,7 +429,7 @@ export const identityAliCloudAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -577,7 +577,7 @@ export const identityAliCloudAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
index 880e0f9040..ba4ab9c4ff 100644
--- a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
@@ -26,7 +26,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -404,7 +404,7 @@ export const identityAwsAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -530,7 +530,7 @@ export const identityAwsAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -680,7 +680,7 @@ export const identityAwsAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts b/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts
index f1c9b28278..53bee09961 100644
--- a/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts
+++ b/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts
@@ -21,7 +21,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -305,7 +305,7 @@ export const identityAzureAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -431,7 +431,7 @@ export const identityAzureAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -583,7 +583,7 @@ export const identityAzureAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts
index a3252d2396..5fd4d2fa5f 100644
--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts
+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts
@@ -21,7 +21,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -350,7 +350,7 @@ export const identityGcpAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -477,7 +477,7 @@ export const identityGcpAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -631,7 +631,7 @@ export const identityGcpAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
index 55ff84d3df..7a43902c18 100644
--- a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
+++ b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
@@ -33,7 +33,7 @@ import { getValueByDot } from "@app/lib/template/dot-access";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -471,7 +471,7 @@ export const identityJwtAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -626,7 +626,7 @@ export const identityJwtAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -836,7 +836,7 @@ export const identityJwtAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
index 4fd508026a..f6fb7fa050 100644
--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
@@ -54,7 +54,7 @@ import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { getSharedHttpsAgent, safeRequest } from "@app/lib/validator/safe-request";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -881,7 +881,7 @@ export const identityKubernetesAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -1239,7 +1239,7 @@ export const identityKubernetesAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -1786,7 +1786,7 @@ export const identityKubernetesAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
index 17a45297a7..8cfe32b605 100644
--- a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
+++ b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
@@ -37,7 +37,7 @@ import {
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import {
clearIdentityLockoutsForAuthMethod,
@@ -392,7 +392,7 @@ export const identityLdapAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -625,7 +625,7 @@ export const identityLdapAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -896,7 +896,7 @@ export const identityLdapAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts b/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts
index f1ec64634e..cb3ef4c583 100644
--- a/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts
+++ b/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts
@@ -26,7 +26,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -318,7 +318,7 @@ export const identityOciAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -443,7 +443,7 @@ export const identityOciAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -594,7 +594,7 @@ export const identityOciAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
index 4a6b47c330..617d7b9290 100644
--- a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
+++ b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
@@ -43,7 +43,7 @@ import { getValueByDot } from "@app/lib/template/dot-access";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -657,7 +657,7 @@ export const identityOidcAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -862,7 +862,7 @@ export const identityOidcAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -1131,7 +1131,7 @@ export const identityOidcAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts b/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts
index 62878bd33f..ef9dcf2ad7 100644
--- a/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts
+++ b/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts
@@ -31,7 +31,7 @@ import {
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -545,7 +545,7 @@ export const identitySpiffeAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -708,7 +708,7 @@ export const identitySpiffeAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -924,7 +924,7 @@ export const identitySpiffeAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts
index a91dfdc485..81f626a845 100644
--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts
+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts
@@ -24,7 +24,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -535,7 +535,7 @@ export const identityTlsCertAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -671,7 +671,7 @@ export const identityTlsCertAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -853,7 +853,7 @@ export const identityTlsCertAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
diff --git a/backend/src/services/identity-token-auth/identity-token-auth-service.ts b/backend/src/services/identity-token-auth/identity-token-auth-service.ts
index e7b3b2695c..4ac809ea2d 100644
--- a/backend/src/services/identity-token-auth/identity-token-auth-service.ts
+++ b/backend/src/services/identity-token-auth/identity-token-auth-service.ts
@@ -9,26 +9,16 @@ import {
} from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { computeTokenAuthRevokeMarkerExpiry } from "../identity-access-token/identity-access-token-fns";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -150,7 +140,7 @@ export const identityTokenAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -271,7 +261,7 @@ export const identityTokenAuthServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -424,7 +414,7 @@ export const identityTokenAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -518,7 +508,7 @@ export const identityTokenAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -801,37 +791,22 @@ export const identityTokenAuthServiceFactory = ({
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
+ }
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ await assertIdentityAuthAccessAllowed(
+ { permissionService, orgDAL },
+ {
+ identityId: identityMembershipOrg.identity.id,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.CreateToken,
+ baseMessage: "Failed to update token for identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
- actorOrgId,
- scope: OrganizationActionScope.Any
- });
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.CreateToken,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to update token for identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.CreateToken,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(foundToken.identityId, isActorSuperAdmin);
diff --git a/backend/src/services/identity-ua/identity-ua-service.ts b/backend/src/services/identity-ua/identity-ua-service.ts
index 755a0b01e6..24c9a723dd 100644
--- a/backend/src/services/identity-ua/identity-ua-service.ts
+++ b/backend/src/services/identity-ua/identity-ua-service.ts
@@ -4,10 +4,6 @@ import { requestContext } from "@fastify/request-context";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
@@ -17,7 +13,6 @@ import {
BadRequestError,
ForbiddenRequestError,
NotFoundError,
- PermissionBoundaryError,
RateLimitError,
UnauthorizedError
} from "@app/lib/errors";
@@ -34,7 +29,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import {
clearIdentityLockoutsForAuthMethod,
@@ -495,7 +490,7 @@ export const identityUaServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -651,7 +646,7 @@ export const identityUaServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -826,7 +821,7 @@ export const identityUaServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -917,7 +912,7 @@ export const identityUaServiceFactory = ({
);
}
- await assertIdentityAuthMutationAllowed(
+ await assertIdentityAuthAccessAllowed(
{ permissionService, orgDAL },
{
identityId,
@@ -1007,37 +1002,22 @@ export const identityUaServiceFactory = ({
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Read, OrgPermissionSubjects.Identity);
+ }
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ await assertIdentityAuthAccessAllowed(
+ { permissionService, orgDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.GetToken,
+ baseMessage: "Failed to get identity client secret with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
- actorOrgId,
- scope: OrganizationActionScope.Any
- });
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.GetToken,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to get identity client secret with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.GetToken,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
const identityUniversalAuth = await identityUaDAL.findOne({
identityId
@@ -1106,36 +1086,23 @@ export const identityUaServiceFactory = ({
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Read, OrgPermissionSubjects.Identity);
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ }
+
+ await assertIdentityAuthAccessAllowed(
+ { permissionService, orgDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.GetToken,
+ baseMessage: "Failed to read identity client secret of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
- actorOrgId,
- scope: OrganizationActionScope.Any
- });
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.GetToken,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to read identity client secret of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.GetToken,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
+
return { ...clientSecret, identityId, orgId: identityMembershipOrg.scopeOrgId };
};
@@ -1199,39 +1166,22 @@ export const identityUaServiceFactory = ({
OrgPermissionIdentityActions.Delete,
OrgPermissionSubjects.Identity
);
+ }
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ await assertIdentityAuthAccessAllowed(
+ { permissionService, orgDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.DeleteToken,
+ baseMessage: "Failed to revoke identity client secret with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
- actorOrgId,
- scope: OrganizationActionScope.Any
- });
-
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.DeleteToken,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid) {
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke identity client secret with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.DeleteToken,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
+ actorOrgId
}
- }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
diff --git a/backend/src/services/identity/identity-auth-permission-fns.test.ts b/backend/src/services/identity/identity-auth-permission-fns.test.ts
index c4c399c094..d61e57cce8 100644
--- a/backend/src/services/identity/identity-auth-permission-fns.test.ts
+++ b/backend/src/services/identity/identity-auth-permission-fns.test.ts
@@ -17,7 +17,7 @@ import {
import { PermissionBoundaryError } from "@app/lib/errors";
import { ActorType } from "@app/services/auth/auth-type";
-import { assertIdentityAuthMutationAllowed } from "./identity-auth-permission-fns";
+import { assertIdentityAuthAccessAllowed } from "./identity-auth-permission-fns";
// Regression guard for the privilege boundary on identity auth-method mutations. Attach and update
// carried none, and revoke carried one only on its org branch, so on the legacy privilege system a
@@ -80,9 +80,9 @@ const runBoundary = async ({
}
},
orgDAL: { findById: () => Promise.resolve({ shouldUseNewPrivilegeSystem }) }
- } as unknown as Parameters<typeof assertIdentityAuthMutationAllowed>[0];
+ } as unknown as Parameters<typeof assertIdentityAuthAccessAllowed>[0];
- await assertIdentityAuthMutationAllowed(deps, {
+ await assertIdentityAuthAccessAllowed(deps, {
identityId: "identity-1",
orgId: "org-1",
projectId,
@@ -95,7 +95,7 @@ const runBoundary = async ({
});
};
-describe("assertIdentityAuthMutationAllowed", () => {
+describe("assertIdentityAuthAccessAllowed", () => {
describe("organization-level identity", () => {
test("an admin actor may configure a member identity's auth", async () => {
await expect(runBoundary({ actorPermission: orgAdmin, targetPermissions: [orgMember] })).resolves.toBeUndefined();
diff --git a/backend/src/services/identity/identity-auth-permission-fns.ts b/backend/src/services/identity/identity-auth-permission-fns.ts
index 93dd44b353..6116cdef92 100644
--- a/backend/src/services/identity/identity-auth-permission-fns.ts
+++ b/backend/src/services/identity/identity-auth-permission-fns.ts
@@ -11,7 +11,9 @@ import { TOrgDALFactory } from "@app/services/org/org-dal";
const PROJECT_ACTION_BY_ORG_ACTION = {
[OrgPermissionIdentityActions.EditAuth]: ProjectPermissionIdentityActions.EditAuth,
[OrgPermissionIdentityActions.RevokeAuth]: ProjectPermissionIdentityActions.RevokeAuth,
- [OrgPermissionIdentityActions.CreateToken]: ProjectPermissionIdentityActions.CreateToken
+ [OrgPermissionIdentityActions.CreateToken]: ProjectPermissionIdentityActions.CreateToken,
+ [OrgPermissionIdentityActions.GetToken]: ProjectPermissionIdentityActions.GetToken,
+ [OrgPermissionIdentityActions.DeleteToken]: ProjectPermissionIdentityActions.DeleteToken
} as const;
type TIdentityAuthPermissionDeps = {
@@ -22,7 +24,7 @@ type TIdentityAuthPermissionDeps = {
orgDAL: Pick<TOrgDALFactory, "findById">;
};
-type TAssertIdentityAuthMutationAllowedDTO = {
+type TAssertIdentityAuthAccessAllowedDTO = {
identityId: string;
orgId: string;
projectId?: string | null;
@@ -34,10 +36,11 @@ type TAssertIdentityAuthMutationAllowedDTO = {
actorOrgId: string;
};
-// Repointing an identity's auth trust, or minting a credential for it, lets you authenticate as that
-// identity, so the actor has to out-rank every role the target holds. Only bites on the legacy privilege system: on the new one
+// Repointing an identity's auth trust or minting a credential for it lets you authenticate as that
+// identity, and enumerating its credential records tells you what to attack, so the actor has to
+// out-rank every role the target holds. Only bites on the legacy privilege system: on the new one
// `assertRoleSetBoundary` reduces to the action check the caller already ran.
-export const assertIdentityAuthMutationAllowed = async (
+export const assertIdentityAuthAccessAllowed = async (
{ permissionService, orgDAL }: TIdentityAuthPermissionDeps,
{
identityId,
@@ -49,7 +52,7 @@ export const assertIdentityAuthMutationAllowed = async (
actorId,
actorAuthMethod,
actorOrgId
- }: TAssertIdentityAuthMutationAllowedDTO
+ }: TAssertIdentityAuthAccessAllowedDTO
) => {
const { shouldUseNewPrivilegeSystem } = await requestMemoize(requestMemoKeys.orgFindById(orgId), () =>
orgDAL.findById(orgId)