Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: add support for filtering by tags
adilson379e150468dd
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 1d84ecb4b2..19a2e3b3ed 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -5741,6 +5741,7 @@ interface SearchSecretsByMetadataEvent {metadata: {operator: string;filters: { key: string; value: string; operator: string }[];+ tags?: string[];numberOfSecrets: number;secretIds: string[];};diff --git a/backend/src/server/routes/v1/dashboard-router.ts b/backend/src/server/routes/v1/dashboard-router.tsindex 05019be1bb..d2afaef406 100644--- a/backend/src/server/routes/v1/dashboard-router.ts+++ b/backend/src/server/routes/v1/dashboard-router.ts@@ -102,10 +102,11 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {querystring: z.object({projectId: z.string().trim().describe(DASHBOARD.SECRET_OVERVIEW_LIST.projectId),- operator: z.nativeEnum(SecretMetadataSearchLogicalOperator).optional()+ operator: z.nativeEnum(SecretMetadataSearchLogicalOperator).optional(),+ tags: z.string().trim().transform(decodeURIComponent).optional()}).describe(- "Metadata conditions are passed as nested `filters[<n>][key|value|operator]` params (qs syntax); `operator` is the top-level and/or combinator."+ "Metadata conditions are passed as nested `filters[<n>][key|value|operator]` params (qs syntax); `operator` is the top-level and/or combinator. `tags` is an optional comma-separated list of tag slugs that further narrows results to secrets carrying at least one of them."),response: {200: z.object({@@ -131,10 +132,12 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {const rawQueryString = req.url.includes("?") ? req.url.slice(req.url.indexOf("?") + 1) : "";const { filters, operator } = SecretMetadataSearchQuerySchema.parse(qs.parse(rawQueryString));const { projectId } = req.query;+ const tagSlugs = req.query.tags?.split(",").filter((tag) => Boolean(tag.trim())) ?? [];const { secrets } = await server.services.resourceMetadata.searchSecretMetadata({filters,operator,+ tagSlugs,actor: req.permission,projectId});@@ -147,6 +150,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {metadata: {operator,filters: filters.map((filter) => ({ key: filter.key, value: filter.value, operator: filter.operator })),+ tags: tagSlugs,numberOfSecrets: secrets.length,secretIds: secrets.map((secret) => secret.secretId)}diff --git a/backend/src/services/resource-metadata/resource-metadata-dal.ts b/backend/src/services/resource-metadata/resource-metadata-dal.tsindex e79a13482c..3a96857568 100644--- a/backend/src/services/resource-metadata/resource-metadata-dal.ts+++ b/backend/src/services/resource-metadata/resource-metadata-dal.ts@@ -27,8 +27,8 @@ export const resourceMetadataDALFactory = (db: TDbClient) => {});};- const buildScopedSecretMetadataQuery = (knex: Knex, orgId: string, projectId: string) =>- knex(TableName.ResourceMetadata)+ const buildScopedSecretMetadataQuery = (knex: Knex, orgId: string, projectId: string, tagSlugs?: string[]) => {+ const query = knex(TableName.ResourceMetadata).join(TableName.SecretV2, `${TableName.SecretV2}.id`, `${TableName.ResourceMetadata}.secretId`).join(TableName.SecretFolder, `${TableName.SecretFolder}.id`, `${TableName.SecretV2}.folderId`).join(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretFolder}.envId`)@@ -40,6 +40,23 @@ export const resourceMetadataDALFactory = (db: TDbClient) => {.whereNull(`${TableName.Project}.deleteAfter`).where(`${TableName.SecretV2}.type`, SecretType.Shared);+ // optional tag filter: keep only secrets carrying at least one of the requested tag slugs. A+ // correlated existence check keeps the candidate rows 1:1 with the secret so the later+ // distinct/limit stays correct (a leftJoin would multiply rows per tag).+ if (tagSlugs && tagSlugs.length) {+ void query.whereExists((subQuery) => {+ return void subQuery+ .select(db.raw("1"))+ .from(TableName.SecretV2JnTag)+ .join(TableName.SecretTag, `${TableName.SecretV2JnTag}.${TableName.SecretTag}Id`, `${TableName.SecretTag}.id`)+ .whereRaw(`??.?? = ??.??`, [TableName.SecretV2JnTag, `${TableName.SecretV2}Id`, TableName.SecretV2, "id"])+ .whereIn(`${TableName.SecretTag}.slug`, tagSlugs);+ });+ }++ return query;+ };+// Shared step-2 hydration: for the resolved candidate secretIds, fetch the metadata rows matching// `applyMetadataMatch` plus the secret key and tags, and nest into// { secretId, secretKey, folderId, metadata: [{ key, value, encryptedValue }], tags: [{ id, slug }] }.@@ -108,14 +125,21 @@ export const resourceMetadataDALFactory = (db: TDbClient) => {// Only plaintext `value` is matched here; encrypted values are handled by// searchSecretMetadataWithEncryptedValues.const searchSecretMetadata = async (- { orgId, projectId, filters, operator, limit = MAX_SECRET_METADATA_SEARCH_SECRETS }: TSearchSecretMetadataDALDTO,+ {+ orgId,+ projectId,+ filters,+ operator,+ tagSlugs,+ limit = MAX_SECRET_METADATA_SEARCH_SECRETS+ }: TSearchSecretMetadataDALDTO,tx?: Knex) => {try {const knex = tx || db.replicaNode();- // step 1: resolve the bounded set of matching secret ids (scoping enforced by the shared builder).- const matchedSecretIdsQuery = buildScopedSecretMetadataQuery(knex, orgId, projectId);+ // step 1: resolve the bounded set of matching secret ids (scoping + tag filter enforced by the shared builder).+ const matchedSecretIdsQuery = buildScopedSecretMetadataQuery(knex, orgId, projectId, tagSlugs);if (operator === SecretMetadataSearchLogicalOperator.And) {// and: every condition must match a row of the secret. Drive the scan from the first condition@@ -167,7 +191,7 @@ export const resourceMetadataDALFactory = (db: TDbClient) => {// separate query so the common plaintext path stays untouched, and it returns early (no hydration) when// a project has no encrypted metadata for the requested keys.const searchSecretMetadataWithEncryptedValues = async (- { orgId, projectId, filters, limit = MAX_SECRET_METADATA_SEARCH_SECRETS }: TSearchSecretMetadataDALDTO,+ { orgId, projectId, filters, tagSlugs, limit = MAX_SECRET_METADATA_SEARCH_SECRETS }: TSearchSecretMetadataDALDTO,tx?: Knex) => {try {@@ -175,8 +199,8 @@ export const resourceMetadataDALFactory = (db: TDbClient) => {const keys = [...new Set(filters.map((filter) => filter.key))];// step 1: bounded set of secrets holding at least one encrypted metadata row for a requested key- // — narrowed by the (orgId, key) partial index.- const matchedSecretRows = await buildScopedSecretMetadataQuery(knex, orgId, projectId)+ // — narrowed by the (orgId, key) partial index, and by the optional tag filter.+ const matchedSecretRows = await buildScopedSecretMetadataQuery(knex, orgId, projectId, tagSlugs).whereNotNull(`${TableName.ResourceMetadata}.encryptedValue`).whereIn(`${TableName.ResourceMetadata}.key`, keys).distinct(`${TableName.ResourceMetadata}.secretId`)diff --git a/backend/src/services/resource-metadata/resource-metadata-service.ts b/backend/src/services/resource-metadata/resource-metadata-service.tsindex 02dc8bae6b..426ae14486 100644--- a/backend/src/services/resource-metadata/resource-metadata-service.ts+++ b/backend/src/services/resource-metadata/resource-metadata-service.ts@@ -42,7 +42,7 @@ export const resourceMetadataServiceFactory = ({// Project-scoped secret metadata search. The base query matches on org + project + key/value; the// results are then filtered so the requester actually has DescribeSecret permission on each returned// secret (path/tag aware). Requesting a project the actor cannot access throws (via getProjectPermission).- const searchSecretMetadata = async ({ projectId, filters, operator, actor }: TSearchSecretMetadataDTO) => {+ const searchSecretMetadata = async ({ projectId, filters, operator, tagSlugs, actor }: TSearchSecretMetadataDTO) => {if (!filters.length) {throw new BadRequestError({ message: "At least one metadata filter is required" });}@@ -61,11 +61,11 @@ export const resourceMetadataServiceFactory = ({// ciphertext), so their candidates are fetched by key and matched in-app after decryption below.const { plaintextMatched, encryptedCandidates } = await resourceMetadataDAL.transaction(async (tx) => {const plaintext = await resourceMetadataDAL.searchSecretMetadata(- { orgId: actor.orgId, projectId, filters, operator },+ { orgId: actor.orgId, projectId, filters, operator, tagSlugs },tx);const encrypted = await resourceMetadataDAL.searchSecretMetadataWithEncryptedValues(- { orgId: actor.orgId, projectId, filters, operator },+ { orgId: actor.orgId, projectId, filters, operator, tagSlugs },tx);return { plaintextMatched: plaintext, encryptedCandidates: encrypted };diff --git a/backend/src/services/resource-metadata/resource-metadata-types.ts b/backend/src/services/resource-metadata/resource-metadata-types.tsindex f4ebc950f1..fab4695317 100644--- a/backend/src/services/resource-metadata/resource-metadata-types.ts+++ b/backend/src/services/resource-metadata/resource-metadata-types.ts@@ -27,6 +27,7 @@ export type TSearchSecretMetadataDALDTO = {projectId: string;filters: TSecretMetadataSearchFilter[];operator: SecretMetadataSearchLogicalOperator;+ tagSlugs?: string[];limit?: number;};@@ -35,5 +36,6 @@ export type TSearchSecretMetadataDTO = {projectId: string;filters: TSecretMetadataSearchFilter[];operator: SecretMetadataSearchLogicalOperator;+ tagSlugs?: string[];actor: OrgServiceActor;};diff --git a/frontend/src/hooks/api/dashboard/queries.tsx b/frontend/src/hooks/api/dashboard/queries.tsxindex 9e4e73e5a9..f9a8cc2615 100644--- a/frontend/src/hooks/api/dashboard/queries.tsx+++ b/frontend/src/hooks/api/dashboard/queries.tsx@@ -527,7 +527,8 @@ export const useGetProjectSecretsQuickSearch = (export const fetchSearchSecretsByMetadata = async ({projectId,operator,- filters+ filters,+ tags}: TSearchSecretsByMetadataDTO) => {// /secrets-by-metadata parses nested `filters[<n>][key|value|operator]` params (qs syntax) from the// raw querystring, so build it explicitly rather than relying on axios' default array serialization.@@ -540,6 +541,12 @@ export const fetchSearchSecretsByMetadata = async ({params.append(`filters[${index}][operator]`, filter.operator);});+ // tags are sent as a comma-separated list of enabled slugs (same convention as the deep-search endpoint).+ const enabledTags = Object.entries(tags)+ .filter(([, enabled]) => enabled)+ .map(([slug]) => slug);+ if (enabledTags.length) params.append("tags", enabledTags.join(","));+const { data } = await apiRequest.get<TSearchSecretsByMetadataResponse>(`/api/v1/dashboard/secrets-by-metadata?${params.toString()}`);@@ -548,7 +555,7 @@ export const fetchSearchSecretsByMetadata = async ({};export const useSearchSecretsByMetadata = (- { projectId, operator, filters }: TSearchSecretsByMetadataDTO,+ { projectId, operator, filters, tags }: TSearchSecretsByMetadataDTO,options?: Omit<UseQueryOptions<TSearchSecretsByMetadataResponse,@@ -562,8 +569,8 @@ export const useSearchSecretsByMetadata = (return useQuery({...options,enabled: (options?.enabled ?? true) && filters.length > 0 && Boolean(projectId),- queryKey: dashboardKeys.searchSecretsByMetadata({ projectId, operator, filters }),- queryFn: () => fetchSearchSecretsByMetadata({ projectId, operator, filters }),+ queryKey: dashboardKeys.searchSecretsByMetadata({ projectId, operator, filters, tags }),+ queryFn: () => fetchSearchSecretsByMetadata({ projectId, operator, filters, tags }),placeholderData: (previousData) => previousData});};diff --git a/frontend/src/hooks/api/dashboard/types.ts b/frontend/src/hooks/api/dashboard/types.tsindex 553558c070..88c9413e5c 100644--- a/frontend/src/hooks/api/dashboard/types.ts+++ b/frontend/src/hooks/api/dashboard/types.ts@@ -178,6 +178,7 @@ export type TSearchSecretsByMetadataDTO = {projectId: string;operator: SecretMetadataSearchLogicalOperator;filters: TSecretMetadataSearchFilter[];+ tags: Record<string, boolean>;};export type TMetadataMatchedSecret = {diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretSearchInput/components/QuickSearchModal.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretSearchInput/components/QuickSearchModal.tsxindex d91d378ad7..a97e8ba56c 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretSearchInput/components/QuickSearchModal.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretSearchInput/components/QuickSearchModal.tsx@@ -156,7 +156,8 @@ const Content = ({metadataMatch === "all"? SecretMetadataSearchLogicalOperator.And: SecretMetadataSearchLogicalOperator.Or,- filters: metadataFilters+ filters: metadataFilters,+ tags: filterTags},{ enabled: isMetadataMode });