Integrating Auth0 with AWS EventBridge and SNS

Integrating Auth0 with AWS EventBridge and SNS

A hands-on guide to integrating Auth0 with Amazon EventBridge and Amazon SNS to build an automated, event-driven security alerting system. Learn how to stream authentication logs, detect failed login attempts, configure event-based rules, and deliver real-time email notifications to administrators, improving security monitoring and operational visibility.

Cloud Architect & Product Manager | Multi-Cloud, Hybrid Solutions| master's degree

Part 1: Building an Event-Driven Alerts Workflow

Audience profile:

This article targets software engineers, DevOps professionals, and cloud architects with intermediate to advanced experience in AWS and cloud-native architectures. They are looking to enhance system reliability and automation by integrating Auth0 with AWS EventBridge and SNS to build an event-driven alert system. The audience seeks practical solutions to streamline notifications and improve cloud infrastructure efficiency using modern tools and best practices.

Introduction:

This article is the first in a series where we will integrate Auth0 with AWS native services to meet our needs. In this initial part, we’ll focus on connecting Auth0 [1] with AWS EventBridge and SNS to create an event-driven alerts workflow. The goal is to enable timely alerts and notifications based on specific events, ensuring smooth operations and enhancing overall system reliability.



Figure 1. Event-Driven Alerts Workflow- High Level Drawing

We have users who access multiple websites through the Auth0 SSO service, a SaaS solution. One day, the SSO service experienced an outage, preventing users from accessing several websites. Unfortunately, we weren’t notified of the issue promptly and lacked a contingency plan to mitigate such disruptions. Since Auth0 doesn’t offer a built-in alerts and notification system for sending logs, we decided to create a workflow to forward the logs to another platform for processing. Given that Auth0 is built on AWS infrastructure, leveraging AWS services was a natural choice as the traffic will remains within AWS backbone network.
In this article, we’ll walk through how to use AWS EventBridge to capture Auth0 logs and then configure the AWS SNS service to send email alerts and notifications based on specific rules.

How AWS EventBridge and SNS works together

Let is take a few minutes to explain how AWS EventBridge and SNS works together.
  • AWS EventBridge is a fully managed event bus service that enables integrations between AWS services, SaaS, and It is also delivers a stream of real-time data to different types of targets without writing code, in our case, the source is Auth0 logs. The publisher sends a JSON event to an event bus, and to receive events, you create a rule. If the published event matches with a rule, the event is routed to up to five targets. For more information [2].
  • AWS SNS, on the other hand, is a fully managed messaging service that delivers alerts and notifications to multiple destinations, such as email, SMS, or other AWS services. The diagram below illustrates this setup, and by leveraging this combination, we can build an event-driven architecture tailored to our use case. While the AWS SNS is a fully managed service that provides message delivery from publishers (producers) to subscribers (consumers). Publishers communicate asynchronously with subscribers by sending messages to a topic, which is a logical access point. For more information [3].
As a result, we will use AWS EventBridge as it is the only event-based service that integrates directly with 3rd SaaS partners. And AWS SNS as it gives us the ability to send messages to an external subscriber. The below diagram shows:
Note 1: Amazon EventBridge is the new version of Amazon CloudWatch Events.
Note 2: Why did I used AWS SNS instead of AWS SES service, will, SNS it’s limited in functionality and customization when compared to SES. It’s mostly used for alerts or notifications rather than transactional emails.

Solution Overview

The below is the high-level design shows our solution overview for this article, where we have Auth0 tenant that considered an Identity providers (IDP) already configured with two service providers or applications (see figure (2)):


Figure 2. Auth0 Components


First SP is a single web page portal that is a service provider that all users that have an account within Auth0 can authenticate against, and two different service providers or applications, where the users can jump after they finish their authentication process correctly.
We will connect the Auth0 tenant to our AWS account by setting up a log stream. Next, we’ll create a rule to filter incoming logs and forward them to AWS SNS, which will trigger email alerts to administrators. This solution will improve the monitoring and analysis of Auth0 tenant activity by utilizing AWS native services. Below are the configuration steps for both platforms:
0- Create a new log stream on Auth0 tenant.
1- Associate the log stream and the AWS EventBridge event bus.
2- Configure the AWS SNS topic and add email as a destination/subscriber.
3- Configure AWS EventBridge to send an email alerts and notifications to the SNS topic based on a specific rule.


Figure 3. Solution Components- HLD

To see the whole picture, lets follow the user traffic that we will be deploying and testing during this article:
1- Users are accessing the portal to authenticate against Auth0/SSO.
2 & 3- The SAML authenticate process is happening to perform the user’s verification credentials.
4- Auth0 Generate the logs internally and then send them to AWS EventBridge event bus based on the priority that we send during the stream log creating process (we only want to send the logs that are related to failed login).
5- The AWS Eventbridge rule will filter the logs based on the event bus that we will be selecting.
6- whenever there is a failed login happened by any user, the AWS will be sending a alert email.


Figure 4. UserTraffic Workflow


The workflow Steps:

Let is divide the whole workflow into two different workflows:

A. User Authentication Workflow:

This is the SSO authentication workflow that happened between the end users every time they want to access different platforms from a single portal using SSO. The following sequential diagram explaining how we used the SSO approach to let the users authenticate against one Idf and then gain the access to multiple service providers. Here we proposed that the portal will be the first service provider that the user the access and then will be re-directed to Idp or Auth0 to authenticate and receive the and save it in the user’s browser to access the rest of the service providers or applications.

Figure 5. Sequential Diagram Authentication


B. Routing Auth0 Events with Amazon EventBridge.

This workflow shows how the events/logs will be routed to AWS native services, starting from AWS Eventbridge that will capture the events and filter them based the configured rules and then send them to AWS SNS topic.
1. Events are emitted from Auth0 when a user interacts with the login service on the front-end application.
2. These events are streamed into a custom SaaS event bus in EventBridge.
3. Event rules match events and send them downstream to AWS SNS topic.

Overview of the tasks:

During this section we will document all implementation and testing steps:

1- Access your Auth0 dashboard, create a new log stream: Here you need to put your AWS account/tenant ID and the region where you will send the logs and where AWS EventBridge service. And as a result of that, Auth0 will generate a event source name for you which will be used to associate to an event bus in your AWS EventBridge as shown in the below screenshot:

Figure 6 . Create Auth0 Log Stream

At this step as shown in the below screenshot, you can filter or prioritized the logs that Auth0 will send to AWS EventBridge. For example, you might be only interesting to be notified for the failed login logs, and do not care about how type the password incorrectly, so here we can do this.



Figure 7. Prioritized Logs


After you finish, click on save, and you will see that there is a active stream created as shown in the below screenshot.


Figure 8. Auth0 Log Streams

  1. In background, Auth0 will send a request to AWS EventBridge service in your account. Go to your AWS account and select the correct region, and navigate to AWS EventBridge, then go to partner event sources, and you will see a pending partner event bus request as the below screenshot, click on it and click on “associate with event bus” button as shown in the below screenshot, and then the event bus will be active. To make sure, return back to Auth0 and see the health of the log stream that we created in step 1, and you will see that it is active, and the logs is started to be send to AWS.


Figure 9 . AWS Evenbridge Event Source

Click on “associate with event bus”, as the below screenshot shows:

Figure 10 . Associate AWS Eventbridge With Event Bus

And as you see below, the connectivity is not working, and Auth0 started delivering logs to EventBridge event bus over AWS backbone network:


Figure 11. Auth0- AWS Eventbridge Health Status

And if you go again to AWS Eventbridge service, you will that the event source is now active as shown in below screenshot:

Figure 12. AWS Eventbridge Event Bus Status

At this step, we made sure that the connectivity between Auth0 tenant (log stream) and AWS account/tenant (AWS EventBridge event bus) is working.

Figure 13. Auth0 tenant- AWS Eventbridge Connectivity

3. let is go to AWS SNS service and configure our SNS topic that will be used as a target to AWS EventBridge as our goal is to send emails notification and when configuring AWS EventBridge it is going to ask us where is your SNS topic, so let is finish from it before :)-> Go to AWS SNS and follow the below steps:
3–1- Create a new topic: Give it a name, in our case will be “Auth0_Topic”, and it the type in our case will be standard which is for most use cases.


Figure 14 . Create AWS SNS Topic

Once the topic is created, you will see the topic ARN (Amazon Resource Name) on the topic’s details page, this ARN uniquely identifies the SNS topic as shown in the below screenshot:


Figure 15 . AWS SNS Topic Details


3–2- Create a subscription: Navigate to your SNS topic, and click create subscription, then select the protocol for the subscription, in our case, we want to send email notifications, so will select email as shown in the below screenshot:


Figure 16. Create AWS SNS Subscription


3–3- Enter endpoint: Depending on the protocol chosen you will need to provide an endpoint, in our case, will provide a email address where the email notifications will be send, and this email ID will be a subscriber to the subscription in step 2.
4- Confirm subscription: After creating the subscription, the status for it will be pending, as we choose email as the protocol, so we should receive a confirmation email, then the recipient must click the confirmation link to activate the subscription:


Figure 17. AWS SNS Subscription Confirmation Email (1)


4–1- After clicking on confirm subscription, you will be re-directed to the below web page:


FIgure 18. AWS SNS Subscription Confirmation Email (2)


4–2- Then go back to AWS console, and refresh the page, and you will see that the subscription status is active. same as the topic, the subscription also will have subscription ARN.

Figure 19. AWS SNS Subscription Status

5- Publish a message (optional): To test your topic, you can publish a message to your SNS topic from AWS console. Let is test it, below is the result of this result:


Figure 20. Publish Message Active- AWS SNS topic

At this step, we made sure that the connectivity between AWS SNS topic and the target email address is working, so let is go again to AWS EventBridge and finish the job we started.


Figure 21 . AWS SNS- Destination Email Connectivity


  1. Now, it is time to go back and configure EventBridge rules: The event source will be AWS events or EventBridge partner events, and the target will be AWS SNS topic that we create in step 3, and AWS will create an execution role for us (or you can created yourself).
Go to rules from EventBridge page and follow the below steps:
6–1- Create a rule after selecting the correct event bus that is related to Auth0 that we created (Figure (22)), give it a name:

Figure 22 . Create AWS EventBridge- Rule 1

and select the event bus, and select AWS events or EventBridge partner events as an event source as the below screenshot shows:

Figure 23. Create AWS EventBridge- Rule 2

We will select a template provided by EventBridge to create an event pattern:

Figure 24 . Create AWS EventBridge- Rule 3

For the target, we are are going to use AWS SNS service as a target, and will select the AWS SNS topic that we created before:


Figure 25. Create AWS EventBridge- Rule 4
7- Amazon EventBridge input transformation (optional) [4]: It is possible to customize a notification. You can customize the text from an event before EventBridge passes the information to the target of a rule. Using the input transformer in the console or the API, you define variables that use JSON path to reference values in the original event source. Reference link [4], below drawing shows the steps to for the process:

Figure 26. AWS EventBridge Input Transformation

EventBridge uses input transformers at runtime to create valid JSON output. Here’s how you can use them to customize your JSON messages:
  • Using Quotes - Add quotes around variables that refer to JSON path parameters. - Do not add quotes around variables that refer to JSON objects or arrays.
  • Strings Handling: - Quotes are optional for string variables. EventBridge automatically adds quotes to string values during transformation.
  • No Quotes for Objects/Arrays: - EventBridge does not add quotes to JSON objects or arrays. Therefore, you shouldn’t add them either.
To transform a JSON file using Amazon EventBridge input transformation, you can use the Input Transformer feature. This allows you to modify the structure of your event before it’s sent to the target. Here’s a step-by-step guide on how to do this:
7–1- Understand your input JSON: First, you need to know the structure of your input JSON. This is because you will be need to reference variables on the JSON.
7–2- Create a custom Input path. I created the below input path based on the json event you shared:
{"version": "$.detail.data.type","timestamp": "$.detail.data.date","description": "$.detail.data.description","error_message": "$.detail.data.details.error.message","error_type": "$.detail.data.details.error.type","ip": "$.detail.data.ip","user_agent": "$.detail.data.user_agent","log_id": "$.detail.data.log_id"}
And in the “Input Path” box, enter your Input Path JSON or the below example.
The Input Path defined as key-value pairs is used to define variables. You use JSON path to reference items in your event and store those values in variables. For instance, you could create an Input Path to reference values in the event.
7–3- Create a custom template, I have created the below template based on the Json event you shared. As seen below the template references the variables created in the Input path, and in the “Template” box, enter your Input Template JSON or the below example:
Template: The Input Template is a template for the information you want to pass to your target. You can create a template that passes either a string or JSON to the target.
{"timestamp": <timestamp>,"log_type": <version>,"log_id": <log_id>,"error_details": {"message": <error_message>,"type": <error_type>},"user_info": {"ip": <ip>,"user_agent": <user_agent>},"description": <description>}
7–4- Click on confirm 7–5- Click on next until it allows you to update the rule
Finally, you can make edits to the both the Input path and template to create a custom message output that contains all your required values and format.Conclusion
In this article, we discussed a solution to the challenge faced when a SaaS tenant lacks a built-in alerts or notification system for service issues. To address this, we integrated Auth0 with AWS EventBridge and SNS to send email alerts to administrators whenever a failed login attempt is logged. This enables quick action to be taken in response to potential security threats or service disruptions.

Next Steps

The next step in addressing this issue is to integrate AWS EventBridge with DynamoDB and Lambda to create more intelligent alerting. Specifically, we can configure the system to send email alerts only after a threshold, such as three failed login attempts, is reached. Additionally, we can send the logs to AWS CloudWatch Logs to enable better monitoring and troubleshooting. This approach will address one of the limitations of EventBridge, which is the challenge of debugging or visually tracking the events fired on the event bus, thereby improving both visibility and control over the alerting process. Finally**,** we can enhance the monitoring and analysis by sending all types of events and logs generated from the Auth0 tenant to AWS QuickSight. This will allow us to visualize Auth0 user events through interactive dashboards, providing administrators with a clear, real-time overview of authentication activities and any potential issues.

References:

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article