← Back to Pull requests

[e2e-framework] Track SSH activity on create-vm EC2 instances #57437

Closed
unknown closed this pull request without merging on Oct 15, 2026 10:51 UTC
View on GitHub
unknown unknown commented on Oct 02, 2026 13:30 UTC
Author

What does this PR do?

EC2 VMs created with dda inv aws.create-vm or agent-health-demo keep a last-activity AWS tag up to date while they are used over SSH, on Linux and Windows.

Linux (script appended to the user data, components/os/scripts/track-ssh-activity.sh):

  • on SSH session open, through a pam_exec hook (optional, runs in the background so logins are never delayed)

  • every 5 minutes while at least one SSH session (interactive or not) is open, through a systemd timer

  • at most one update per minute, since tests open many SSH connections in a row

  • the EC2 CreateTags call is signed with SigV4 using only curl and openssl, as the AWS CLI is not available on every AMI
  • Windows (components/os/scripts/track-ssh-activity.ps1):

  • copied over SSH once the VM is up, and run by a SYSTEM scheduled task:

  • - when sshd writes to its OpenSSH/Operational event log, so within seconds of an SSH connection (there is no PAM on Windows)
    - every 5 minutes, for long sessions
  • the tag is updated if an SSH connection is established, or if sshd logged a login in the last 6 minutes: most SSH commands run by tests are closed before the script starts

  • at most one update per minute, as sshd logs several events per connection

  • not added to the user data: the Windows user data (setup-ssh.ps1 + public key) already uses 9.4–10 KB of EC2's 16 KB limit, and embedding the script would go over it with RSA keys

  • the CreateTags call is signed with SigV4 in plain .NET, so it does not depend on AWS Tools for PowerShell being on the AMI
  • Every step is best effort and can't fail the user data, a login or the stack.

    It is gated by a new ddinfra:aws/trackSSHActivity setting, disabled by default and enabled by manual test scripts. Test VMs created in CI do not outlive the cleaner's threshold, so they don't need it.

    Motivation

    test-infra-cleaner uses only the creation date to decide which EC2 instances to delete. Currently it deletes any VM older than 24h. This creates friction as contributors might lose their temporary setup, and need to recreate a new instance daily. With this tag, the cleaner can keep instances that were used recently.

    Related PRs:

  • test-infra-cleaner (keeps instances with recent last-activity): https://github.com/ddoghq/test-infra-cleaner/pull/138

  • cloud-inventory (allows ec2InstanceRole to set the tag on itself only):https://github.com/DataDog/cloud-inventory/pull/72203
  • Describe how you validated your changes

    Validated with dda inv aws.create-vm:

    | Scenario | Ubuntu | Windows |
    |---|---|---|
    | Tracking installed | user data: script, pam_exec line in /etc/pam.d/sshd, systemd timer | over SSH: script in C:/ProgramData/dd-e2e/, SYSTEM scheduled task with a time trigger and an OpenSSH/Operational event trigger |
    | Tag set on SSH connect | PAM hook: login at 10:50:59Z → tag 10:50:59Z | event trigger: one-shot ssh … hostname at 13:11:29Z → tag 13:11:34Z; 20 s session at 13:12:58Z → tag 13:13:01Z |
    | Tag refreshed during a long session | timer run at 10:55:58Z with one session held open → tag 10:55:58Z | task run at 11:16:38Z with one session held open → tag 11:16:40Z |
    | No update without an SSH session | timer run at 10:50:41Z before any user session → no tag | task run at 11:21:38Z with no session (LastTaskResult 0) → tag unchanged |
    | 1 min throttle | not tested on the VM (covered by the container test) | run at 13:09:59Z, 22 s after the last update → tag unchanged |

    Additional Notes

  • macOS VMs are not covered.

  • On SELinux-enforcing distros, the PAM hook's network call may be denied; the timer still covers it, with up to 5 minutes of lag.

  • Merge order: cloud-inventory (merged), then this PR, then test-infra-cleaner.

  • Note: On Windows, aws.create-vm needs an RSA key pair: EC2 does not support ED25519 key pairs with Windows AMIs (not changed by this PR).
  • Diff: 496 lines (+372 / -124) across 6 files Reviewer: louis-cqrl Review duration: 18561m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 496 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.371
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #57437"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.5% (MEDIUM) · Higher = larger blast radius
    47.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.8% · Safe to merge
    18.8%