More Info:
Ensure Event Rules track Network Security Group edits. Immediate event triggers on NSGs prevent attackers from silently opening SSH or RDP ports to compute instances.Risk Level
MediumAddress
Compliance, SecurityCompliance Standards
- APRA CPS 234 (Australia)
- AWS Well Architected Framework
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS AWS
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- Cloudanix Best Practice
- DPDPA
- Digital Operational Resilience Act (EU)
- HIPAA
- HITRUST CSF
- ISO 27001
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST
- NIST CSF
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- SOC2
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are step‑by‑step instructions to configure an OCI Event Rule for NSG changes and integrate it with OCI Alerting (Notifications) using the OCI Console.
(Use the UI dropdowns rather than typing JSON if available.)
1. Prerequisites
- You must have permissions (policies) to:
- Use
events-rulesin the compartment - Use
notifications-topicsandsubscriptions
- Use
- Identify the compartment where your Network Security Groups (NSGs) reside.
2. Create (or Reuse) a Notifications Topic
- In the OCI Console, open the navigation menu and go to
Developer Services → Notifications. - Make sure the correct Compartment is selected.
- Click Create Topic.
- Enter:
- Name: e.g.
nsg-change-alerts - Description: e.g.
Alerts for NSG configuration changes
- Name: e.g.
- Click Create.
Add a Subscription (Email / Pager / etc.)
- Open the topic you just created (e.g.
nsg-change-alerts). - Under Subscriptions, click Create Subscription.
- Choose Protocol: e.g.
Email. - Enter your Email address.
- Click Create.
- Confirm the subscription from your email (click the confirmation link).
3. Create the Event Rule for NSG Changes
- Open the navigation menu and go to
Observability & Management → Events Service → Rules. - Make sure the Compartment is set to where you want the rule stored (often same as NSGs, or a central logging/ops compartment).
- Click Create Rule.
3.1. Basic Rule Details
- Name: e.g.
Detect-NSG-Changes - Description: e.g.
Triggers when NSG configuration is modified or deleted - Rule State: ensure it is Enabled.
3.2. Define the Event Pattern
- In Rule Conditions, choose:
- Rule Type:
Event Type
- Rule Type:
- Configure:
- Service:
Virtual Cloud Network (VCN)orNetworking(name may vary slightly). - Resource Type:
NetworkSecurityGroup.
- Service:
- For Event Type, select the operations you care about (at minimum):
Update Network Security GroupChange Security Rules(if separately available)Delete Network Security Group- Optionally also:
Create Network Security Group(to track creation)
- If needed, restrict by Compartment of the NSGs (often you choose the same application compartment).
4. Attach an Action to Send Alerts
- In the Actions section of the rule, click + Add Action.
- Choose Action Type:
Notifications. - Select the Notifications Topic you created earlier
(e.g.nsg-change-alerts). - Optionally, add a Message Format or specify custom payload if offered; otherwise, leave defaults.
- Click Create (or Create Rule) to save the rule.
5. (Optional) Centralize or Enhance Monitoring
If you want more advanced workflows (e.g. send events to Logging or custom processors):- Use Service Connector Hub:
- Source: Events Service
- Target: Logging or Function for richer analysis.
6. Test the Configuration
- Go to Networking → Virtual Cloud Networks → Network Security Groups.
- Pick an NSG in the monitored compartment.
- Perform one of the actions you configured:
- Modify a security rule (e.g., change port or CIDR).
- Add or remove a rule.
- Within a short time, verify you receive an email (or other protocol) from the Notifications topic indicating an NSG change event.
Using CLI
Using CLI
Below is a simple, CLI‑only way to get alerts when any Network Security Group (NSG) is changed, using OCI Events + Notifications (which is what OCI “alerting/monitoring” for config changes is built on).Replace all
Capture the
Confirm the email subscription when you receive the confirmation email.
Notes:
<PLACEHOLDER> values with your own OCIDs / data.1. Prereqs
- OCI CLI installed and configured (
oci setup config) - You know:
- Tenancy OCID:
<TENANCY_OCID> - Target compartment OCID where NSGs live:
<COMPARTMENT_OCID> - Region is set in your CLI config
- Tenancy OCID:
2. Create a Notifications topic
id from the output as <TOPIC_OCID>.3. Create a subscription on the topic (e.g., email)
4. Create the Events rule for NSG changes
Event types for NSGs include:com.oraclecloud.virtualnetwork.createnetworksecuritygroupcom.oraclecloud.virtualnetwork.updatenetworksecuritygroupcom.oraclecloud.virtualnetwork.deletenetworksecuritygroup
- Use
<TENANCY_OCID>for the rule compartment (best practice), and filter to<COMPARTMENT_OCID>in thecondition. - If you want this to fire for all compartments, drop the
data.compartmentIdfilter.
5. Test
- Modify an NSG (e.g., add a rule) in
<COMPARTMENT_OCID>. - Verify that you receive an email from the Notifications topic.
Using Python
Using Python
Below is a practical way to enforce “OCI Monitoring Should Have Event Rule For NSG Changes” and wire it into alerting using OCI Events + Notifications in Python.
Condition (rule) expression:
Notes:
If you want, I can adapt this to:
1. What you will create
In one Python run you will:- Create an ONS Topic (Notifications).
- Create an Email Subscription to that topic.
- Create an Events Rule that listens for NSG create / update / delete events.
- Route matching events to the ONS topic (so you get alerts).
2. Prerequisites
- OCI Python SDK installed:
- OCI config file (
~/.oci/config) with a profile, e.g.DEFAULT. - Your:
compartment_ocidregion- An email address for alerts.
3. Event Types for NSG Changes
Use these event types for Network Security Groups (NSGs):4. Full Python Example
- Ensure your SDK version supports
CreateNotificationServiceActionDetails. If not, update: - After running the script, confirm the email subscription from your inbox.
- From then on, any NSG create/update/delete in the compartment will trigger an email alert.
If you want, I can adapt this to:
- Use a specific dynamic group/policy setup,
- Target a different protocol (Slack via HTTPS, PagerDuty, etc.),
- Or wire an OCI Function instead of direct email.
Using Terraform
Using Terraform
oci_events_rule (no forced replacement unless you change compartment_id to a different compartment or switch to a new rule resource entirely).Verification: terraform plan should show either a new oci_events_rule.nsg_change_events being created or the existing rule updated so that:is_enabledistrueconditionmatches the NSG event typesactions[0].action_typeisONSwith the desiredtopic_id.

