# cmchenr/secure-workload-aws-workspaces architecture

> Architecture diagram of the GitHub repository cmchenr/secure-workload-aws-workspaces, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cmchenr/secure-workload-aws-workspaces
- Repository: https://github.com/cmchenr/secure-workload-aws-workspaces

## Overview

##### Main Components
- AWS Lambda Functions:
- labels_lambda (handler.py): Synchronizes AWS WorkSpace tags and additional attributes (e.g., UserName) to Cisco Secure Workload.
- cleanup_lambda (handler.py): Cleans up Cisco Secure Workload records when a WorkSpace is terminated.
- Scheduled Task Component (workspace_scheduled_task):
- XML file (RestartTetrationOnResume.xml): Defines a scheduled task that triggers on the system event when a WorkSpace resumes from hibernation.
- PowerShell script (start_enforcement_agent.ps1): Contains the logic to verify connectivity and restart the enforcement services on the WorkSpace.
- External Systems/Services:
- Amazon WorkSpaces: The virtual desktops whose context and security events are being managed.
- Cisco Secure Workload: The endpoint security system that ingests labels and sensor data, and enforces policies.
- AWS CloudWatch Events: Although not explicit in the file tree, the README indicates that CloudWatch events are used to schedule the Lambda functions (e.g., every 2 minutes for labels updates and every 10 minutes for cleanup).
- Environment Variables:
- These serve as configuration points for both lambdas, controlling behavior such as tag synchronization, deletion of sensor records, and connecting to Cisco Secure Workload with its API credentials.

##### Relationships and Interactions
- Data Flow:
- For the labels_lambda:
1. Triggered by a recurring CloudWatch event.
2. Reads current AWS WorkSpaces and their associated tags and attributes.
3. If configured (via ADD_TAGS and ATTRIBUTES_LIST), synchronizes this data with Cisco Secure Workload via its API.
- For the cleanup_lambda:
1. Also triggered by a recurring CloudWatch event.
2. Monitors WorkSpace terminations and issues cleanup commands to Cisco Secure Workload (possibly deleting stale sensor records if DELETE_SENSORS is true).
- For the Scheduled Task:
1. On a WorkSpace (or a golden image) coming out of hibernation, the scheduled task (defined by the XML template) is automatically triggered.
2. It launches the PowerShell script, which checks connectivity (e.g., to www.tetrationcloud.com or a Cisco-specific IP) and then restarts key Cisco Secure Workload agent services.
- Architectural Patterns:
- Serverless design for the automation components (lambda functions).
- Scheduled tasks on a Windows-based WorkSpace image to manage service state upon hibernation.
- Loose coupling between AWS and Cisco systems via REST API calls, with configuration via environment variables for flexibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Services
    CloudWatch["CloudWatch Events"] 
    awsWorkspaces["Amazon WorkSpaces"]
    cisco["Cisco Secure Workload API"]
    envConfig["Environment Variables<br/>(API credentials, options)"]

    %% Serverless Automation Subgraph
    subgraph "Serverless Automation"
        tagSync["Lambda: Tag Synchronization"]
        cleanup["Lambda: Cleanup Function"]
    end

    %% Windows Golden Image Subgraph
    subgraph "Windows Golden Image"
        taskXML["Scheduled Task Definition (XML)"]
        psScript["PowerShell Script"]
    end

    %% Data Flow Connections
    CloudWatch -->|"triggers"| tagSync
    CloudWatch -->|"triggers"| cleanup
    awsWorkspaces -->|"provides_tags"| tagSync
    tagSync -->|"syncs_tags"| cisco
    cleanup -->|"cleans_records"| cisco
    psScript -->|"restarts_agent_services"| cisco
    envConfig -.-> tagSync
    envConfig -.-> cleanup

    %% Click Events
    click tagSync "https://github.com/cmchenr/secure-workload-aws-workspaces/blob/master/labels_lambda/handler.py"
    click cleanup "https://github.com/cmchenr/secure-workload-aws-workspaces/blob/master/cleanup_lambda/handler.py"
    click taskXML "https://github.com/cmchenr/secure-workload-aws-workspaces/blob/master/workspace_scheduled_task/RestartTetrationOnResume.xml"
    click psScript "https://github.com/cmchenr/secure-workload-aws-workspaces/blob/master/workspace_scheduled_task/start_enforcement_agent.ps1"

    %% Styles
    classDef cloudwatch fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef lambda fill:#fce4ec,stroke:#c2185b,stroke-width:2px;
    classDef scheduled fill:#e1bee7,stroke:#6a1b9a,stroke-width:2px;
    classDef external fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px;
    classDef config fill:#fff9c4,stroke:#f9a825,stroke-width:2px;

    class CloudWatch cloudwatch;
    class awsWorkspaces external;
    class cisco external;
    class tagSync,cleanup lambda;
    class taskXML,psScript scheduled;
    class envConfig config;
```
