Skip to content

fix(cloud-tests): add OAuth token auto-refresh to Azure remediation#2564

Merged
tofikwest merged 2 commits intomainfrom
fix/azure-oauth-token-refresh
Apr 16, 2026
Merged

fix(cloud-tests): add OAuth token auto-refresh to Azure remediation#2564
tofikwest merged 2 commits intomainfrom
fix/azure-oauth-token-refresh

Conversation

@tofikwest
Copy link
Copy Markdown
Contributor

@tofikwest tofikwest commented Apr 15, 2026

Summary

Azure remediation was using getDecryptedCredentials() which returns raw stored tokens without checking expiry or refreshing. This caused "OAuth token expired" errors and connections getting marked as error during remediation.

  • Added getValidAzureToken() method that auto-refreshes expired OAuth tokens (mirrors GCP's existing getValidGcpToken() pattern)
  • Applied to resolveContext (preview + execute) and rollbackRemediation
  • Falls back to legacy service principal flow when OAuth is not configured
Provider Scan Remediation (before) Remediation (after)
AWS N/A (IAM role) N/A N/A
GCP Auto-refresh Auto-refresh Auto-refresh (unchanged)
Azure Auto-refresh No refresh — raw token Auto-refresh

Test plan

  • Run Azure remediation with a connection that's been idle for >1 hour (token expired) — should auto-refresh and succeed
  • Azure rollback should also use refreshed token
  • Legacy service principal connections still work (fallback path)
  • GCP remediation unchanged — still works

🤖 Generated with Claude Code


Summary by cubic

Fixes Azure remediation failures by auto-refreshing expired OAuth tokens in preview, execute, and rollback, and ensures the connection is a valid, active Azure link. Also makes the OAuth refresh flow more robust across all integrations.

  • Bug Fixes
    • Added getValidAzureToken with a 5‑minute buffer and legacy SP fallback; used in preview, execute, and rollback.
    • Replaced raw credential reads with refreshed tokens and clearer rollback errors; validates the connection is an active Azure connection.
    • Hardened OAuth refresh for all providers: prefer activeCredentialVersionId, retry once after 2s, log provider error body, and mark connection as error on 400/401/403.
    • GCP behavior unchanged; AWS unaffected.

Written for commit 3f17765. Summary will update on new commits.

Azure remediation was using getDecryptedCredentials() which returns
raw stored tokens without checking expiry or refreshing. This caused
"OAuth token expired" errors and connection status changes to 'error'.

Now uses getValidAzureToken() (mirrors GCP's getValidGcpToken() pattern):
- Checks token expiry with 5-minute buffer
- Auto-refreshes via OAuth refresh_token if expired
- Falls back to legacy service principal flow
- Applied to resolveContext (preview/execute) and rollback

GCP already had this pattern. AWS uses IAM roles (no expiry issue).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comp-framework-editor Ready Ready Preview, Comment Apr 16, 2026 0:22am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
app Skipped Skipped Apr 16, 2026 0:22am
portal Skipped Skipped Apr 16, 2026 0:22am

Request Review

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Requires human review: Modifies authentication logic and token management for cloud remediation, which is a sensitive core business path that requires human verification.

…ging

Three issues fixed in the credential vault:

1. No retry on refresh failure — a single transient 400/401 from
   Google/Microsoft would permanently kill the connection. Now retries
   once after 2s before marking as error.

2. Error response body was discarded — logged "HTTP 400" but threw away
   the actual error from the provider (e.g., "invalid_grant"). Now logs
   the full response body for debugging.

3. getDecryptedCredentials ignored activeCredentialVersionId — always
   fetched by highest version number instead of the explicitly marked
   active version. Now prefers activeCredentialVersionId with fallback.

These affect ALL OAuth integrations (GCP, Azure, Slack, Google
Workspace, etc.), not just cloud tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Requires human review: Modifies core credential management and OAuth refresh logic in CredentialVaultService, which affects multiple cloud providers and critical remediation paths.

@tofikwest tofikwest merged commit 348f5da into main Apr 16, 2026
11 checks passed
@tofikwest tofikwest deleted the fix/azure-oauth-token-refresh branch April 16, 2026 02:30
@claudfuen
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.22.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants