Skip to content

Conversation

TingluoHuang
Copy link
Member

@TingluoHuang TingluoHuang commented May 7, 2025

@Copilot Copilot AI review requested due to automatic review settings May 7, 2025 19:19
@TingluoHuang TingluoHuang requested a review from a team as a code owner May 7, 2025 19:19
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Ensures OAuth token claims match expected values during authentication migrations.

  • Introduces a background task (CheckOAuthTokenClaimsAsync) to periodically validate new OAuth v2 token claims against baseline tokens.
  • Adds synchronization primitives (locks, token sources) and cancellation of the claims check task alongside telemetry.
  • Logs mismatches and defers migration when claim values diverge.
Comments suppressed due to low confidence (1)

src/Runner.Listener/Runner.cs:776

  • Consider adding unit or integration tests to cover CheckOAuthTokenClaimsAsync, including scenarios for matching and mismatched claims.
private async Task CheckOAuthTokenClaimsAsync(CancellationToken token)

@TingluoHuang TingluoHuang force-pushed the users/tihuang/node branch from 0bb0bef to 8054699 Compare May 7, 2025 19:25
TingluoHuang and others added 3 commits May 7, 2025 15:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@TingluoHuang TingluoHuang reopened this May 7, 2025
if (v2Claim?.Value != baselineClaim.Value)
{
Trace.Info($"Token Claim mismatch between two issuers. Expected: {baselineClaim.Type}:{baselineClaim.Value}. Actual: {v2Claim?.Type ?? "Empty"}:{v2Claim?.Value ?? "Empty"}");
HostContext.DeferAuthMigration(TimeSpan.FromMinutes(60), $"Expected claim {baselineClaim.Type}:{baselineClaim.Value} does not match {v2Claim?.Type ?? "Empty"}:{v2Claim?.Value ?? "Empty"}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this trigger any telemetry? Wondering how we know whether this is happening.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed the while loop sleeps for 100m yet this for loop defers 60m. Is that discrepancy OK?

Copy link
Member Author

Choose a reason for hiding this comment

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

Any DeferAuthMigration() should publish telemetry back to service.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's on purposely to not lines up so different things won't trigger at the same time.

{
try
{
await HostContext.Delay(TimeSpan.FromMinutes(100), token);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this only delay after the first iteration? Or first successful iteration? Or does it matter?

Copy link
Member Author

Choose a reason for hiding this comment

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

i don't want the runner to get multiple tokens during start up, try to avoid too much load on the service.

{
try
{
await HostContext.Delay(TimeSpan.FromMinutes(100), token);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it matter than an intermittent network IO error may cause the logic further below not be skipped for more than multiple 100m delays?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should not see any claim diff from the token.
We will use Ring 0 to fully test this out and make sure we never see any failure.

@TingluoHuang TingluoHuang merged commit 505fa60 into main May 7, 2025
9 checks passed
@TingluoHuang TingluoHuang deleted the users/tihuang/node branch May 7, 2025 21:35
marko-k0 pushed a commit to dfinity/runner that referenced this pull request May 13, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
sirredbeard pushed a commit to sirredbeard/runner that referenced this pull request Jun 11, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
sirredbeard pushed a commit to sirredbeard/runner that referenced this pull request Jun 11, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants