-
Notifications
You must be signed in to change notification settings - Fork 588
Add alert service to block tenants #7574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| */ | ||
| public JSExecutionAlert(String tenantDomain, String serviceProvider, AlertType alertType, | ||
| long resourceValue, long threshold, String threadName) { | ||
|
|
||
| this.tenantDomain = tenantDomain; | ||
| this.serviceProvider = serviceProvider; | ||
| this.alertType = alertType; | ||
| this.resourceValue = resourceValue; | ||
| this.threshold = threshold; | ||
| this.threadName = threadName; | ||
| this.timestamp = System.currentTimeMillis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 1
| */ | |
| public JSExecutionAlert(String tenantDomain, String serviceProvider, AlertType alertType, | |
| long resourceValue, long threshold, String threadName) { | |
| this.tenantDomain = tenantDomain; | |
| this.serviceProvider = serviceProvider; | |
| this.alertType = alertType; | |
| this.resourceValue = resourceValue; | |
| this.threshold = threshold; | |
| this.threadName = threadName; | |
| this.timestamp = System.currentTimeMillis(); | |
| public JSExecutionAlert(String tenantDomain, String serviceProvider, AlertType alertType, | |
| long resourceValue, long threshold, String threadName) { | |
| if (log.isDebugEnabled()) { | |
| log.debug("Creating JS execution alert for tenant: " + tenantDomain + ", SP: " + serviceProvider + | |
| ", alert type: " + alertType + ", resource value: " + resourceValue + | |
| ", threshold: " + threshold); | |
| } | |
| this.tenantDomain = tenantDomain; | |
| this.serviceProvider = serviceProvider; | |
| this.alertType = alertType; | |
| this.resourceValue = resourceValue; | |
| this.threshold = threshold; | |
| this.threadName = threadName; | |
| this.timestamp = System.currentTimeMillis(); | |
| } |
| * Create a new instance of JSExecutionEnforcer by loading configuration from the system. | ||
| * | ||
| * @return A new instance of JSExecutionEnforcer with loaded configuration. | ||
| */ | ||
| public static JSExecutionEnforcer createFromConfiguration() { | ||
|
|
||
| int maxViolationsPerTenant = loadMaxViolationsPerTenant(); | ||
| long violationWindowInMillis = loadViolationWindow(); | ||
| long blockDurationInMillis = loadBlockDuration(); | ||
| long criticalMemoryLimit = loadCriticalMemoryLimit(); | ||
|
|
||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug(String.format("Initialized JS Execution Alert Service with config: " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 2
| * Create a new instance of JSExecutionEnforcer by loading configuration from the system. | |
| * | |
| * @return A new instance of JSExecutionEnforcer with loaded configuration. | |
| */ | |
| public static JSExecutionEnforcer createFromConfiguration() { | |
| int maxViolationsPerTenant = loadMaxViolationsPerTenant(); | |
| long violationWindowInMillis = loadViolationWindow(); | |
| long blockDurationInMillis = loadBlockDuration(); | |
| long criticalMemoryLimit = loadCriticalMemoryLimit(); | |
| if (LOG.isDebugEnabled()) { | |
| LOG.debug(String.format("Initialized JS Execution Alert Service with config: " + | |
| public static JSExecutionEnforcer createFromConfiguration() { | |
| int maxViolationsPerTenant = loadMaxViolationsPerTenant(); | |
| long violationWindowInMillis = loadViolationWindow(); | |
| long blockDurationInMillis = loadBlockDuration(); | |
| long criticalMemoryLimit = loadCriticalMemoryLimit(); | |
| LOG.info(String.format("Initializing JSExecutionEnforcer with configuration: maxViolationsPerTenant=%d, " + | |
| "violationWindow=%dms, blockDuration=%dms, criticalMemoryLimit=%d bytes", | |
| maxViolationsPerTenant, violationWindowInMillis, blockDurationInMillis, criticalMemoryLimit)); |
| long expiryThreshold = currentTime - violationWindowInMillis; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 3
| long expiryThreshold = currentTime - violationWindowInMillis; | |
| private void cleanupExpiredAlerts() { | |
| if (LOG.isDebugEnabled()) { | |
| LOG.debug("Starting cleanup of expired alerts and blocks"); | |
| } |
| public void setExecutionEnforcer(JSExecutionEnforcer executionEnforcer) { | ||
|
|
||
| this.executionEnforcer = executionEnforcer; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 4
| public void setExecutionEnforcer(JSExecutionEnforcer executionEnforcer) { | |
| this.executionEnforcer = executionEnforcer; | |
| } | |
| public void setExecutionEnforcer(JSExecutionEnforcer executionEnforcer) { | |
| this.executionEnforcer = executionEnforcer; | |
| if (log.isDebugEnabled()) { | |
| log.debug("JSExecutionEnforcer has been set for monitoring script executions."); | |
| } | |
| } |
| // Push alert to the enforcer. | ||
| if (executionEnforcer != null) { | ||
| long threshold = (monitorType == MONITOR_TYPE_TIME) ? timeoutInMillis : memoryLimitInBytes; | ||
| JSExecutionAlert alert = new JSExecutionAlert(tenantDomain, serviceProvider, alertType, | ||
| consumedResourceValue, threshold, originalThread.getName()); | ||
| executionEnforcer.pushAlert(alert); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 5
| // Push alert to the enforcer. | |
| if (executionEnforcer != null) { | |
| long threshold = (monitorType == MONITOR_TYPE_TIME) ? timeoutInMillis : memoryLimitInBytes; | |
| JSExecutionAlert alert = new JSExecutionAlert(tenantDomain, serviceProvider, alertType, | |
| consumedResourceValue, threshold, originalThread.getName()); | |
| executionEnforcer.pushAlert(alert); | |
| } | |
| // Push alert to the enforcer. | |
| if (executionEnforcer != null) { | |
| long threshold = (monitorType == MONITOR_TYPE_TIME) ? timeoutInMillis : memoryLimitInBytes; | |
| JSExecutionAlert alert = new JSExecutionAlert(tenantDomain, serviceProvider, alertType, | |
| consumedResourceValue, threshold, originalThread.getName()); | |
| executionEnforcer.pushAlert(alert); | |
| if (log.isDebugEnabled()) { | |
| log.debug(String.format("Pushed %s alert for service provider: %s, tenant: %s", | |
| alertType, serviceProvider, tenantDomain)); | |
| } | |
| } |
| * @param violationCount The new violation count. | ||
| */ | ||
| public void updateViolationCount(String tenantDomain, int violationCount) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 6
| * @param violationCount The new violation count. | |
| */ | |
| public void updateViolationCount(String tenantDomain, int violationCount) { | |
| public void updateViolationCount(String tenantDomain, int violationCount) { | |
| if (LOG.isInfoEnabled()) { | |
| LOG.info(String.format("Updating violation count for tenant: %s to %d", tenantDomain, violationCount)); | |
| } | |
| try { |
| resourceAdd.setName(tenantDomain); | ||
| resourceAdd.setAttributes(attributes); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 7
| resourceAdd.setName(tenantDomain); | |
| resourceAdd.setAttributes(attributes); | |
| getConfigurationManager().replaceResource(RESOURCE_TYPE_NAME, resourceAdd); | |
| LOG.info(String.format("Successfully updated violation count for tenant %s: %d", tenantDomain, violationCount)); | |
| if (LOG.isDebugEnabled()) { |
| JSExecutionEnforcer jsExecutionEnforcer = | ||
| FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().getExecutionEnforcer(); | ||
| if (jsExecutionEnforcer.isTenantBlocked(PrivilegedCarbonContext.getThreadLocalCarbonContext() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 8
| JSExecutionEnforcer jsExecutionEnforcer = | |
| FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().getExecutionEnforcer(); | |
| if (jsExecutionEnforcer.isTenantBlocked(PrivilegedCarbonContext.getThreadLocalCarbonContext() | |
| JSExecutionEnforcer jsExecutionEnforcer = | |
| FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().getExecutionEnforcer(); | |
| if (jsExecutionEnforcer.isTenantBlocked(PrivilegedCarbonContext.getThreadLocalCarbonContext() | |
| .getTenantDomain())) { | |
| log.warn("Authentication blocked for tenant {} due to adaptive script execution violations.", | |
| PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); |
| FrameworkServiceDataHolder.getInstance() | ||
| .setJsExecutionSupervisor(new JSExecutionSupervisor(threadCount, timeOutEnabled, timeoutInMillis, | ||
| memoryLimitInBytes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 9
| FrameworkServiceDataHolder.getInstance() | |
| .setJsExecutionSupervisor(new JSExecutionSupervisor(threadCount, timeOutEnabled, timeoutInMillis, | |
| memoryLimitInBytes)); | |
| FrameworkServiceDataHolder.getInstance() | |
| .setJsExecutionSupervisor(new JSExecutionSupervisor(threadCount, timeOutEnabled, timeoutInMillis, | |
| memoryLimitInBytes)); | |
| log.info("JS execution supervisor initialized with threadCount: " + threadCount + ", timeoutEnabled: " + timeOutEnabled + ", timeout: " + timeoutInMillis + "ms"); |
| // Initialize JS execution alert service. | ||
| JSExecutionEnforcer executionEnforcer = JSExecutionEnforcer.createFromConfiguration(); | ||
| FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().setExecutionEnforcer(executionEnforcer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 10
| // Initialize JS execution alert service. | |
| JSExecutionEnforcer executionEnforcer = JSExecutionEnforcer.createFromConfiguration(); | |
| FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().setExecutionEnforcer(executionEnforcer); | |
| // Initialize JS execution alert service. | |
| JSExecutionEnforcer executionEnforcer = JSExecutionEnforcer.createFromConfiguration(); | |
| FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().setExecutionEnforcer(executionEnforcer); | |
| log.info("JS execution enforcer initialized and configured"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
| public static final boolean DEFAULT_EXECUTION_SUPERVISOR_TIMEOUT_ENABLE = true; | ||
| public static final long DEFAULT_EXECUTION_SUPERVISOR_MEMORY_LIMIT = -1; | ||
| public static final int DEFAULT_ALERT_MAX_VIOLATIONS_PER_TENANT = 5; | ||
| // Default tracking window set to 30 seconds. |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment does not start with a capital letter. Update to: "Default tracking window set to 30 seconds."
| // Default tracking window set to 30 seconds. | ||
| public static final long DEFAULT_EXECUTION_SUPERVISOR_VIOLATION_TRACKING_WINDOW_MILLIS = 30000L; | ||
| public static final long DEFAULT_EXECUTION_SUPERVISOR_BLOCK_DURATION_MILLIS = 600000L; | ||
| // Critical memory limit set to 500MB by default. |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment does not start with a capital letter. Update to: "Critical memory limit set to 500MB by default."
| .setJsExecutionSupervisor(new JSExecutionSupervisor(threadCount, timeOutEnabled, timeoutInMillis, | ||
| memoryLimitInBytes)); | ||
|
|
||
| // Initialize JS execution alert service. |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment does not start with a capital letter and does not end with a period. Update to: "Initialize JS execution alert service."
|
|
||
| private static final Log LOG = LogFactory.getLog(TenantViolationStore.class); | ||
|
|
||
| // Resource type for JS execution alerts. |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment does not start with a capital letter. Update to: "Resource type for JS execution alerts."
| // Resource type for JS execution alerts. | ||
| private static final String RESOURCE_TYPE_NAME = "JSExecutionAlerts"; | ||
|
|
||
| // Attribute keys. |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment does not start with a capital letter. Update to: "Attribute keys."
| return false; | ||
| } | ||
|
|
||
| public int getAlertCount(String tenantDomain) { |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing docstring for public method getAlertCount. Add a docstring describing the method's purpose, parameters, and return value.
| return getNonExpiredAlertCount(tenantDomain); | ||
| } | ||
|
|
||
| public void clearAlerts(String tenantDomain) { |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing docstring for public method clearAlerts. Add a docstring describing the method's purpose and parameters.
| } | ||
| } | ||
|
|
||
| public void blockTenant(String tenantDomain) { |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing docstring for public method blockTenant. Add a docstring describing the method's purpose and parameters.
...on/identity/application/authentication/framework/config/model/graph/JSExecutionEnforcer.java
Show resolved
Hide resolved
...on/identity/application/authentication/framework/config/model/graph/JSExecutionEnforcer.java
Show resolved
Hide resolved
|
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (3.27%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #7574 +/- ##
============================================
- Coverage 50.57% 50.55% -0.03%
+ Complexity 19117 18936 -181
============================================
Files 2094 2097 +3
Lines 122790 122950 +160
Branches 25559 25551 -8
============================================
+ Hits 62106 62152 +46
- Misses 52722 52815 +93
- Partials 7962 7983 +21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|



$subject