-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enable auth migration based on config refresh. #3786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,7 +245,6 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token) | |
// Decrypt the message body if the session is using encryption | ||
message = DecryptMessage(message); | ||
|
||
|
||
if (message != null && message.MessageType == BrokerMigrationMessage.MessageType) | ||
{ | ||
var migrationMessage = JsonUtility.FromString<BrokerMigrationMessage>(message.Body); | ||
|
@@ -306,6 +305,10 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token) | |
Trace.Error("Catch exception during get next message."); | ||
Trace.Error(ex); | ||
|
||
// clear out potential message for broker migration, | ||
// in case the exception is thrown from get message from broker-listener. | ||
message = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in case we got migration message from pipelines, but fail to get message broker-listener. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good find |
||
|
||
// don't retry if SkipSessionRecover = true, DT service will delete agent session to stop agent from taking more jobs. | ||
if (ex is TaskAgentSessionExpiredException && !_settings.SkipSessionRecover && (await CreateSessionAsync(token) == CreateSessionResult.Success)) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ public sealed class Runner : RunnerService, IRunner | |
private ITerminal _term; | ||
private bool _inConfigStage; | ||
private ManualResetEvent _completedCommand = new(false); | ||
private IRunnerServer _runnerServer; | ||
|
||
// <summary> | ||
// Helps avoid excessive calls to Run Service when encountering non-retriable errors from /acquirejob. | ||
|
@@ -51,6 +52,7 @@ public override void Initialize(IHostContext hostContext) | |
base.Initialize(hostContext); | ||
_term = HostContext.GetService<ITerminal>(); | ||
_acquireJobThrottler = HostContext.CreateService<IErrorThrottler>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should always use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was originally intended not to be a singleton. Why switch to singleton? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i didn't find any place we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i changed it back for now. |
||
_runnerServer = HostContext.GetService<IRunnerServer>(); | ||
} | ||
|
||
public async Task<int> ExecuteCommand(CommandSettings command) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,7 +211,17 @@ private async Task UpdateRunnerCredentialsAsync(string serviceType, string confi | |
|
||
// save the refreshed runner credentials as a separate file | ||
_store.SaveMigratedCredential(refreshedCredConfig); | ||
await ReportTelemetryAsync("Runner credentials updated successfully."); | ||
|
||
if (refreshedCredConfig.Data.ContainsKey("authorizationUrlV2")) | ||
{ | ||
HostContext.EnableAuthMigration("Credential file updated"); | ||
await ReportTelemetryAsync("Runner credentials updated successfully. Auth migration is enabled."); | ||
} | ||
else | ||
{ | ||
HostContext.DeferAuthMigration(TimeSpan.FromDays(365), "Credential file does not contain authorizationUrlV2"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is acting as disable the migration via FF from the service. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fuzzy on this detail. This PR seems fine for now. I will catch up on this detail on the next PR. |
||
await ReportTelemetryAsync("Runner credentials updated successfully. Auth migration is disabled."); | ||
} | ||
} | ||
|
||
private async Task<bool> VerifyRunnerQualifiedId(string runnerQualifiedId) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,24 +18,21 @@ public sealed class BrokerMessageListenerL0 | |
private readonly Mock<IBrokerServer> _brokerServer; | ||
private readonly Mock<IRunnerServer> _runnerServer; | ||
private readonly Mock<ICredentialManager> _credMgr; | ||
private Mock<IConfigurationStore> _store; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't use this any more. |
||
|
||
|
||
public BrokerMessageListenerL0() | ||
{ | ||
_settings = new RunnerSettings { AgentId = 1, AgentName = "myagent", PoolId = 123, PoolName = "default", ServerUrl = "http://myserver", WorkFolder = "_work", ServerUrlV2 = "http://myserverv2" }; | ||
_config = new Mock<IConfigurationManager>(); | ||
_config.Setup(x => x.LoadSettings()).Returns(_settings); | ||
_credMgr = new Mock<ICredentialManager>(); | ||
_store = new Mock<IConfigurationStore>(); | ||
_brokerServer = new Mock<IBrokerServer>(); | ||
_runnerServer = new Mock<IRunnerServer>(); | ||
} | ||
|
||
[Fact] | ||
[Trait("Level", "L0")] | ||
[Trait("Category", "Runner")] | ||
public async void CreatesSession() | ||
public async Task CreatesSession() | ||
{ | ||
using (TestHostContext tc = CreateTestContext()) | ||
using (var tokenSource = new CancellationTokenSource()) | ||
|
@@ -51,8 +48,6 @@ public async void CreatesSession() | |
.Returns(Task.FromResult(expectedSession)); | ||
|
||
_credMgr.Setup(x => x.LoadCredentials(It.IsAny<bool>())).Returns(new VssCredentials()); | ||
_store.Setup(x => x.GetCredentials()).Returns(new CredentialData() { Scheme = Constants.Configuration.OAuthAccessToken }); | ||
_store.Setup(x => x.GetMigratedCredentials()).Returns(default(CredentialData)); | ||
|
||
// Act. | ||
BrokerMessageListener listener = new(); | ||
|
@@ -75,7 +70,6 @@ private TestHostContext CreateTestContext([CallerMemberName] String testName = " | |
TestHostContext tc = new(this, testName); | ||
tc.SetSingleton<IConfigurationManager>(_config.Object); | ||
tc.SetSingleton<ICredentialManager>(_credMgr.Object); | ||
tc.SetSingleton<IConfigurationStore>(_store.Object); | ||
tc.SetSingleton<IBrokerServer>(_brokerServer.Object); | ||
tc.SetSingleton<IRunnerServer>(_runnerServer.Object); | ||
return tc; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,8 +103,8 @@ public async Task Delay(TimeSpan delay, CancellationToken token) | |
handler(this, new DelayEventArgs(delay, token)); | ||
} | ||
|
||
// Delay zero | ||
await Task.Delay(TimeSpan.Zero); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// Delay 10ms | ||
await Task.Delay(TimeSpan.FromMilliseconds(10)); | ||
} | ||
|
||
public T CreateService<T>() where T : class, IRunnerService | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add verbose trace.