diff --git a/backend/src/ee/services/event/event-sse-stream.ts b/backend/src/ee/services/event/event-sse-stream.ts index 0b7607ee5..4c5fcf779 100644 --- a/backend/src/ee/services/event/event-sse-stream.ts +++ b/backend/src/ee/services/event/event-sse-stream.ts @@ -66,19 +66,24 @@ export type EventStreamClient = { }; export function createEventStreamClient(redis: Redis, options: IEventStreamClientOpts): EventStreamClient { - const rules = options.registered.map((r) => ({ - subject: options.type, - action: "subscribe", - conditions: { - eventType: r.event, - ...(r.conditions - ? { - secretPath: r.conditions?.secretPath, - environment: r.conditions?.environmentSlug - } - : {}) - } - })); + const rules = options.registered.map((r) => { + const secretPath = r.conditions?.secretPath; + const hasConditions = r.conditions?.environmentSlug || r.conditions?.secretPath; + + return { + subject: options.type, + action: "subscribe", + conditions: { + eventType: r.event, + ...(hasConditions + ? { + environment: r.conditions?.environmentSlug ?? "", + secretPath: r.conditions?.recursive ? { $glob: `${secretPath}/**` } : secretPath + } + : {}) + } + }; + }); const id = `sse-${nanoid()}`; const control = new AbortController(); diff --git a/backend/src/ee/services/event/types.ts b/backend/src/ee/services/event/types.ts index 721e6ea13..72227c863 100644 --- a/backend/src/ee/services/event/types.ts +++ b/backend/src/ee/services/event/types.ts @@ -117,7 +117,8 @@ export const EventRegisterSchema = z.object({ conditions: z .object({ secretPath: z.string().optional().default("/"), - environmentSlug: z.string() + environmentSlug: z.string(), + recursive: z.boolean().optional().default(false) }) .optional() }); diff --git a/backend/src/server/routes/v1/event-router.ts b/backend/src/server/routes/v1/event-router.ts index dd6932c9a..c37908944 100644 --- a/backend/src/server/routes/v1/event-router.ts +++ b/backend/src/server/routes/v1/event-router.ts @@ -80,13 +80,15 @@ export const registerEventRouter = async (server: FastifyZodProvider) => { } req.body.register.forEach((r) => { + const fields = { + environment: r.conditions?.environmentSlug ?? "", + secretPath: r.conditions?.secretPath ?? "/", + eventType: r.event + }; + const allowed = info.permission.can( ProjectPermissionSecretActions.Subscribe, - subject(ProjectPermissionSub.Secrets, { - environment: r.conditions?.environmentSlug ?? "", - secretPath: r.conditions?.secretPath ?? "/", - eventType: r.event - }) + subject(ProjectPermissionSub.Secrets, fields) ); if (!allowed) { @@ -94,9 +96,9 @@ export const registerEventRouter = async (server: FastifyZodProvider) => { name: "PermissionDenied", message: `You are not allowed to subscribe on secrets`, details: { - event: r.event, - environmentSlug: r.conditions?.environmentSlug, - secretPath: r.conditions?.secretPath ?? "/" + event: fields.eventType, + environmentSlug: fields.environment, + secretPath: fields.secretPath } }); } diff --git a/docs/documentation/platform/event-subscriptions.mdx b/docs/documentation/platform/event-subscriptions.mdx index 017fd937e..cefef6824 100644 --- a/docs/documentation/platform/event-subscriptions.mdx +++ b/docs/documentation/platform/event-subscriptions.mdx @@ -5,20 +5,12 @@ description: "Subscribe to events in Infisical for real-time updates" --- - Note: Event Subscriptions is a paid feature. -
-
- On Infisical Cloud, this feature is available on the - Pro - and Enterprise tiers, with each tier providing - different event retention periods. -
- For self-hosted deployments, please contact{" "} - sales@infisical.com to purchase an + **Note:** Event Subscriptions is a paid feature. - **Infisical Cloud users:** Event Subscriptions is + available under the **Enterprise Tier**. - **Self-Hosted Infisical:** Please + contact [sales@infisical.com](mailto:sales@infisical.com) to purchase an enterprise license.
-## Introduction Event Subscriptions in Infisical allow you to receive real-time notifications when specific actions occur within your account or organization. These notifications can include changes to secrets, users, teams, and other important resources. @@ -30,9 +22,10 @@ You can currently subscribe to notifications for the following event types: - `secret:updated`: Triggered when a secret is updated. - `secret:deleted`: Triggered when a secret is deleted. + ## Permissions Setup -Proper permissions are required to configure event subscriptions. Follow these steps to set up the necessary permissions: +In order to receive events on a supported resource, the identity is required to have a Subscribe permission on that resource. Follow these steps to set up the necessary permissions: diff --git a/docs/images/platform/events/project-role.png b/docs/images/platform/events/project-role.png index 54bb62581..b6178939f 100644 Binary files a/docs/images/platform/events/project-role.png and b/docs/images/platform/events/project-role.png differ