Skip to content

DRIVERS-3723: Restore the instance profile in auth_aws teardown - #926

Merged
blink1073 merged 1 commit into
masterfrom
DRIVERS-3723
Nov 6, 2026
Merged

blink1073 merged 1 commit into
masterfrom
DRIVERS-3723

Conversation

@adelinowona

@adelinowona adelinowona commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

DRIVERS-3723

Summary

After the web identity test detaches the host's EC2 instance profile, auth_aws/teardown.sh runs aws_assign_instance_profile.py to put it back. The call fails with InvalidInstanceID.NotFound and prints a traceback, but the command ends in || true, so the task still passes and the profile is never restored.

The cause is that the task's secrets-role credentials are still in the environment. They belong to a different AWS account than the host, so EC2 calls made with them cannot see the instance. aws_assign_instance_profile.py only applies the instance account's credentials with os.environ.setdefault, so the ambient keys take precedence. aws_setup.sh already unsets the AWS_* variables before running, but teardown.sh does not.

Changes in this PR

teardown.sh unsets AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN before sourcing the secrets file, mirroring aws_setup.sh.

Test Plan

Evergreen patch running test-auth-aws on the Ubuntu 22.04, Ubuntu 24.04 and both Windows variants, with the EKS subtest skipped as in #920 so that the Linux runs reach teardown. All four pass. With temporary diagnostics around the assign call (not part of this PR), the instance's profile association list was empty before the call and contained the host's profile afterwards on every host, and the InvalidInstanceID.NotFound traceback no longer appears.

I did not run this against the unfixed script on Linux, so the failure itself was only observed on the Windows variants.

Checklist

Checklist for Author

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@adelinowona
adelinowona requested a review from a team as a code owner November 6, 2026 01:28
@adelinowona
adelinowona requested review from PavelSafronov and blink1073 and a balanced review from Copilot and removed request for PavelSafronov November 6, 2026 01:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the AWS authentication teardown change.

No open issues 🎉

What changed in this PR

Fixes AWS authentication teardown so ambient credentials from another account do not prevent restoration of the host’s EC2 instance profile.

Changes:

  • Clears the three AWS credential environment variables before sourcing secrets, matching aws_setup.sh.
  • Adds a comment explaining why ambient credentials must be cleared.
File Description
.evergreen/​auth_aws/​teardown.sh Clears ambient AWS credentials so profile restoration can use the instance account’s credentials.

Review effort: Balanced

@blink1073 blink1073 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM

@blink1073
blink1073 merged commit 5abaf9d into master Nov 6, 2026
82 of 85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants