# sidharathbansal/nsg-security-check architecture

> Architecture diagram of the GitHub repository sidharathbansal/nsg-security-check, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sidharathbansal/nsg-security-check
- Repository: https://github.com/sidharathbansal/nsg-security-check

## Overview

##### Project Type & Purpose
- This is a utility project built with Bash scripts that leverage the Azure CLI to audit and clean up Azure Network Security Groups (NSGs).
- Its main functions are scanning NSGs for security risks (e.g., open ports like 22, 3389, 27017 and rules allowing access from anywhere) and cleaning up unused NSGs.

##### Analyzing the File Structure
- The project is very lightweight and consists of three files:
- README.md: Contains the project overview and instructions.
- nsg_audit.sh: A script to scan for risky NSG configurations.
- nsg_cleanup.sh: A script to remove unassigned NSGs.
- The absence of complex directories indicates that the architecture is script-based and not layered as in full-stack or microservices designs.

##### Main Components
a. Azure CLI and Authentication:
- A component representing the Azure CLI tool, including prerequisites like being logged in and necessary permissions.
b. NSG Audit Script:
- Nsg_audit.sh as a component that orchestrates scanning of NSGs.
c. NSG Cleanup Script:
- Nsg_cleanup.sh as a component that automates deletion.
- Similarly, show its interaction with the Azure API to remove unassigned NSGs.
d. Azure NSG Resources:
- Azure NSGs as external resources that are queried and/or manipulated by the scripts.
e. Data Flow & Feedback:
- That after scanning, feedback is provided to the user (e.g., listing vulnerable NSGs), and then cleanup actions are performed.

##### Relationships and Interactions
- How each script invokes the Azure CLI.
- Data retrieval from Azure NSG resources.
- The decision or conditional flows (e.g., identifying rules with open ports and unassigned NSGs).

##### Architectural Patterns & Design Principles
- Separation of concerns: One script focuses on auditing while the other performs cleanup.
- Direct interaction with external systems (Azure).
- The use of automation to maintain security hygiene.
- Even though it’s simple, it emphasizes modularity by keeping audit and cleanup functionality separated.

##### Relevant Technologies & Tools
- Azure CLI: Mention that it is central to executing commands against the Azure environment.
- Bash Scripting: The underlying technology of both scripts.
- Azure Network Security Groups (NSGs): The target resources being managed.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Nodes
    A["Project Overview & Instructions (README.md)"]:::info
    B["NSG Audit Script (nsg_audit.sh)"]:::script
    C["NSG Cleanup Script (nsg_cleanup.sh)"]:::script
    D["Azure CLI"]:::cli
    E["Azure NSG Resources"]:::azure

    %% Flow connections for audit process
    A -->|"startAudit"| B
    B -->|"invokeAudit"| D
    D -->|"fetchData"| E
    E -->|"returnData"| D
    D -->|"outputAudit"| B

    %% Flow connection for cleanup process
    B -->|"triggerCleanup"| C
    C -->|"invokeCleanup"| D
    D -->|"deleteNSG"| E
    E -->|"deletionFeedback"| D
    D -->|"outputCleanup"| C

    %% Click Events
    click A "https://github.com/sidharathbansal/nsg-security-check/blob/main/README.md"
    click B "https://github.com/sidharathbansal/nsg-security-check/blob/main/nsg_audit.sh"
    click C "https://github.com/sidharathbansal/nsg-security-check/blob/main/nsg_cleanup.sh"

    %% Styles
    classDef script fill:#cce5ff,stroke:#1a75ff,stroke-width:2px;
    classDef cli fill:#fff2cc,stroke:#e69500,stroke-width:2px;
    classDef azure fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef info fill:#f9cb9c,stroke:#e69138,stroke-width:2px;
```
