I had asked a question about the master key and migration earlier which you guys helped me with - thank you for that!
I thought id create a new discussion in regards to changing from Domain authentication to username pass.
I know we can switch between the two, but my question is, could we convert those existing users in octopus that were created by authenticating against the domain to standalone octopus users? and keep everything intact i.e. api keys etc?
In Octopus Deploy you can have more than one identity provider associated with Octopus user accounts. There is no need to convert or create new accounts, rather you can just enable the username/password authentication provider and everything will remain intact.
However you will need to set passwords for all the Octopus user accounts (that require interactive login) before attempting to login using username/passwords. The password can be set by the users themselves (once logged in using the current Domain authentication) or by an Octopus administrator.
Once you have verified all users have set a password and can login using that password, you can then disable the Domain authentication if no longer needed.
Here is a C# script using Octopus.Client to get you started. Just modify to suit your environment, and execute with performUpdate set to false to verify the changes first. Once you are happy with the changes set performUpdate to true to actually perform the username updates via the API.
var octopusServer = "http://localhost";
var apiKey = "API-xxxxxxxxxxxxxxxxxxxxxxxxxx";
var client = new Octopus.Client.OctopusClient(new Octopus.Client.OctopusServerEndpoint(octopusServer, apiKey));
var repo = new Octopus.Client.OctopusRepository(client);
var n = 0;
var performUpdate = false; // change to true to actually save the username changes
var users = repo.Users.FindAll();
foreach (var user in users)
{
if (user.Username.Contains('@'))
{
// Changing username from first.last@domain.local to first.last
var usernameParts = user.Username.Split('@');
var newUsername = usernameParts[0]; // ignore the @domain.local part
Console.WriteLine($"Changing user {user.Username} to {newUsername}");
if (performUpdate)
{
user.Username = newUsername;
repo.Users.Modify(user);
}
n++;
}
else
{
Console.WriteLine($"Skipping user {user.Username}");
}
}
Console.WriteLine($"Updated {n} users");
I’m sorry this is causing issues. I suggest running the code in a .NET console app. Create a new project in Visual Studio and select Console App (.NET Framework) as the project type.
Add the nuget package Octopus.Client either via the Nuget Package Manager UI or via Package Manager Console using Install-Package Octopus.Client
Insert the code from above into the Main function in Program.cs