Skip to content

Commit

Permalink
SM-1119: Rename service accounts to machine accounts (#3958)
Browse files Browse the repository at this point in the history
* SM-1119: Rename service accounts to machine accounts

* SM-1119: Undo system management portal changes
  • Loading branch information
coltonhurst committed Apr 5, 2024
1 parent 6242c25 commit b164f24
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
Expand Up @@ -85,7 +85,7 @@ public ServiceAccountPeopleAccessPolicies ToServiceAccountPeopleAccessPolicies(G

if (!policies.All(ap => ap.Read && ap.Write))
{
throw new BadRequestException("Service account access must be Can read, write");
throw new BadRequestException("Machine account access must be Can read, write");
}

return new ServiceAccountPeopleAccessPolicies
Expand Down
Expand Up @@ -2037,7 +2037,7 @@ public void ValidateSecretsManagerPlan(Models.StaticStore.Plan plan, Organizatio

if (!plan.SecretsManager.HasAdditionalServiceAccountOption && upgrade.AdditionalServiceAccounts > 0)
{
throw new BadRequestException("Plan does not allow additional Service Accounts.");
throw new BadRequestException("Plan does not allow additional Machine Accounts.");
}

if ((plan.Product == ProductType.TeamsStarter &&
Expand All @@ -2050,7 +2050,7 @@ public void ValidateSecretsManagerPlan(Models.StaticStore.Plan plan, Organizatio

if (upgrade.AdditionalServiceAccounts.GetValueOrDefault() < 0)
{
throw new BadRequestException("You can't subtract Service Accounts!");
throw new BadRequestException("You can't subtract Machine Accounts!");
}

switch (plan.SecretsManager.HasAdditionalSeatsOption)
Expand Down
Expand Up @@ -6,7 +6,7 @@
<td class="content-block"
style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 16px; color: #333; line-height: 25px; margin: 0; -webkit-font-smoothing: antialiased; padding: 0 0 10px; -webkit-text-size-adjust: none;"
valign="top">
Your organization has reached the Secrets Manager service accounts limit of {{MaxServiceAccountsCount}}. New service accounts cannot be created
Your organization has reached the Secrets Manager machine accounts limit of {{MaxServiceAccountsCount}}. New machine accounts cannot be created
</td>
</tr>
<tr
Expand Down
@@ -1,5 +1,5 @@
{{#>BasicTextLayout}}
Your organization has reached the Secrets Manager service accounts limit of {{MaxServiceAccountsCount}}. New service accounts cannot be created
Your organization has reached the Secrets Manager machine accounts limit of {{MaxServiceAccountsCount}}. New machine accounts cannot be created

For more information, please refer to the following help article: https://bitwarden.com/help/managing-users
{{/BasicTextLayout}}
Expand Up @@ -118,7 +118,7 @@ private async Task SendServiceAccountLimitEmailAsync(Organization organization)
}
catch (Exception e)
{
_logger.LogError(e, $"Error encountered notifying organization owners of service accounts limit reached.");
_logger.LogError(e, $"Error encountered notifying organization owners of machine accounts limit reached.");
}

}
Expand Down Expand Up @@ -253,12 +253,12 @@ private async Task ValidateSmServiceAccountsUpdateAsync(SecretsManagerSubscripti
// Check if the organization has unlimited service accounts
if (organization.SmServiceAccounts == null)
{
throw new BadRequestException("Organization has no service accounts limit, no need to adjust service accounts");
throw new BadRequestException("Organization has no machine accounts limit, no need to adjust machine accounts");
}

if (update.Autoscaling && update.SmServiceAccounts.Value < organization.SmServiceAccounts.Value)
{
throw new BadRequestException("Cannot use autoscaling to subtract service accounts.");
throw new BadRequestException("Cannot use autoscaling to subtract machine accounts.");
}

// Check plan maximum service accounts
Expand All @@ -267,29 +267,29 @@ private async Task ValidateSmServiceAccountsUpdateAsync(SecretsManagerSubscripti
{
var planMaxServiceAccounts = plan.SecretsManager.BaseServiceAccount +
plan.SecretsManager.MaxAdditionalServiceAccount.GetValueOrDefault();
throw new BadRequestException($"You have reached the maximum number of service accounts ({planMaxServiceAccounts}) for this plan.");
throw new BadRequestException($"You have reached the maximum number of machine accounts ({planMaxServiceAccounts}) for this plan.");
}

// Check autoscale maximum service accounts
if (update.MaxAutoscaleSmServiceAccounts.HasValue &&
update.SmServiceAccounts.Value > update.MaxAutoscaleSmServiceAccounts.Value)
{
var message = update.Autoscaling
? "Secrets Manager service account limit has been reached."
: "Cannot set max service accounts autoscaling below service account amount.";
? "Secrets Manager machine account limit has been reached."
: "Cannot set max machine accounts autoscaling below machine account amount.";
throw new BadRequestException(message);
}

// Check minimum service accounts included with plan
if (plan.SecretsManager.BaseServiceAccount > update.SmServiceAccounts.Value)
{
throw new BadRequestException($"Plan has a minimum of {plan.SecretsManager.BaseServiceAccount} service accounts.");
throw new BadRequestException($"Plan has a minimum of {plan.SecretsManager.BaseServiceAccount} machine accounts.");
}

// Check minimum service accounts required by business logic
if (update.SmServiceAccounts.Value <= 0)
{
throw new BadRequestException("You must have at least 1 service account.");
throw new BadRequestException("You must have at least 1 machine account.");
}

// Check minimum service accounts currently in use by the organization
Expand All @@ -298,8 +298,8 @@ private async Task ValidateSmServiceAccountsUpdateAsync(SecretsManagerSubscripti
var currentServiceAccounts = await _serviceAccountRepository.GetServiceAccountCountByOrganizationIdAsync(organization.Id);
if (currentServiceAccounts > update.SmServiceAccounts)
{
throw new BadRequestException($"Your organization currently has {currentServiceAccounts} service accounts. " +
$"You cannot decrease your subscription below your current service account usage.");
throw new BadRequestException($"Your organization currently has {currentServiceAccounts} machine accounts. " +
$"You cannot decrease your subscription below your current machine account usage.");
}
}
}
Expand Down Expand Up @@ -346,18 +346,18 @@ private void ValidateMaxAutoscaleSmServiceAccountUpdate(SecretsManagerSubscripti
if (update.SmServiceAccounts.HasValue && update.MaxAutoscaleSmServiceAccounts.Value < update.SmServiceAccounts.Value)
{
throw new BadRequestException(
$"Cannot set max service accounts autoscaling below current service accounts count.");
$"Cannot set max machine accounts autoscaling below current machine accounts count.");
}

if (!plan.SecretsManager.AllowServiceAccountsAutoscale)
{
throw new BadRequestException("Your plan does not allow service accounts autoscaling.");
throw new BadRequestException("Your plan does not allow machine accounts autoscaling.");
}

if (plan.SecretsManager.MaxServiceAccounts.HasValue && update.MaxAutoscaleSmServiceAccounts.Value > plan.SecretsManager.MaxServiceAccounts)
{
throw new BadRequestException(string.Concat(
$"Your plan has a service account limit of {plan.SecretsManager.MaxServiceAccounts}, ",
$"Your plan has a machine account limit of {plan.SecretsManager.MaxServiceAccounts}, ",
$"but you have specified a max autoscale count of {update.MaxAutoscaleSmServiceAccounts}.",
"Reduce your max autoscale count."));
}
Expand Down
Expand Up @@ -330,9 +330,9 @@ public class UpgradeOrganizationPlanCommand : IUpgradeOrganizationPlanCommand
if (currentServiceAccounts > newPlanServiceAccounts)
{
throw new BadRequestException(
$"Your organization currently has {currentServiceAccounts} service accounts. " +
$"Your new plan only allows {newSecretsManagerPlan.SecretsManager.MaxServiceAccounts} service accounts. " +
"Remove some service accounts or increase your subscription.");
$"Your organization currently has {currentServiceAccounts} machine accounts. " +
$"Your new plan only allows {newSecretsManagerPlan.SecretsManager.MaxServiceAccounts} machine accounts. " +
"Remove some machine accounts or increase your subscription.");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Services/Implementations/HandlebarsMailService.cs
Expand Up @@ -951,7 +951,7 @@ public async Task SendUnverifiedOrganizationDomainEmailAsync(IEnumerable<string>
public async Task SendSecretsManagerMaxServiceAccountLimitReachedEmailAsync(Organization organization, int maxSeatCount,
IEnumerable<string> ownerEmails)
{
var message = CreateDefaultMessage($"{organization.DisplayName()} Secrets Manager Service Accounts Limit Reached", ownerEmails);
var message = CreateDefaultMessage($"{organization.DisplayName()} Secrets Manager Machine Accounts Limit Reached", ownerEmails);
var model = new OrganizationServiceAccountsMaxReachedViewModel
{
OrganizationId = organization.Id,
Expand Down
Expand Up @@ -410,7 +410,7 @@ public async Task SignUpAsync_SecretManager_AdditionalServiceAccounts_NotAllowed

var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.SignUpAsync(signup));
Assert.Contains("Plan does not allow additional Service Accounts.", exception.Message);
Assert.Contains("Plan does not allow additional Machine Accounts.", exception.Message);
}

[Theory]
Expand Down Expand Up @@ -444,7 +444,7 @@ public async Task SignUpAsync_InvalidateServiceAccount_ShouldThrowException(Orga

var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.SignUpAsync(signup));
Assert.Contains("You can't subtract Service Accounts!", exception.Message);
Assert.Contains("You can't subtract Machine Accounts!", exception.Message);
}

[Theory]
Expand Down Expand Up @@ -2208,7 +2208,7 @@ public void ValidateSecretsManagerPlan_ThrowsException_WhenSubtractingSeats(Plan
AdditionalSeats = 3
};
var exception = Assert.Throws<BadRequestException>(() => sutProvider.Sut.ValidateSecretsManagerPlan(plan, signup));
Assert.Contains("Plan does not allow additional Service Accounts.", exception.Message);
Assert.Contains("Plan does not allow additional Machine Accounts.", exception.Message);
}

[Theory]
Expand Down Expand Up @@ -2249,7 +2249,7 @@ public void ValidateSecretsManagerPlan_ThrowsException_WhenMoreSeatsThanPassword
AdditionalSeats = 5
};
var exception = Assert.Throws<BadRequestException>(() => sutProvider.Sut.ValidateSecretsManagerPlan(plan, signup));
Assert.Contains("You can't subtract Service Accounts!", exception.Message);
Assert.Contains("You can't subtract Machine Accounts!", exception.Message);
}

[Theory]
Expand Down
Expand Up @@ -447,7 +447,7 @@ await sutProvider.GetDependency<IPaymentService>().Received(1)
var update = new SecretsManagerSubscriptionUpdate(organization, false).AdjustServiceAccounts(1);

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.UpdateSubscriptionAsync(update));
Assert.Contains("Organization has no service accounts limit, no need to adjust service accounts", exception.Message);
Assert.Contains("Organization has no machine accounts limit, no need to adjust machine accounts", exception.Message);
await VerifyDependencyNotCalledAsync(sutProvider);
}

Expand All @@ -460,7 +460,7 @@ await sutProvider.GetDependency<IPaymentService>().Received(1)
var update = new SecretsManagerSubscriptionUpdate(organization, true).AdjustServiceAccounts(-2);

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.UpdateSubscriptionAsync(update));
Assert.Contains("Cannot use autoscaling to subtract service accounts.", exception.Message);
Assert.Contains("Cannot use autoscaling to subtract machine accounts.", exception.Message);
await VerifyDependencyNotCalledAsync(sutProvider);
}

Expand All @@ -475,7 +475,7 @@ await sutProvider.GetDependency<IPaymentService>().Received(1)
var update = new SecretsManagerSubscriptionUpdate(organization, false).AdjustServiceAccounts(1);

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.UpdateSubscriptionAsync(update));
Assert.Contains("You have reached the maximum number of service accounts (3) for this plan",
Assert.Contains("You have reached the maximum number of machine accounts (3) for this plan",
exception.Message, StringComparison.InvariantCultureIgnoreCase);
await VerifyDependencyNotCalledAsync(sutProvider);
}
Expand All @@ -492,7 +492,7 @@ await sutProvider.GetDependency<IPaymentService>().Received(1)
var update = new SecretsManagerSubscriptionUpdate(organization, true).AdjustServiceAccounts(2);

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.UpdateSubscriptionAsync(update));
Assert.Contains("Secrets Manager service account limit has been reached.", exception.Message);
Assert.Contains("Secrets Manager machine account limit has been reached.", exception.Message);
await VerifyDependencyNotCalledAsync(sutProvider);
}

Expand All @@ -516,7 +516,7 @@ await sutProvider.GetDependency<IPaymentService>().Received(1)

var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.UpdateSubscriptionAsync(update));
Assert.Contains("Cannot set max service accounts autoscaling below service account amount", exception.Message);
Assert.Contains("Cannot set max machine accounts autoscaling below machine account amount", exception.Message);
await VerifyDependencyNotCalledAsync(sutProvider);
}

Expand All @@ -537,7 +537,7 @@ await sutProvider.GetDependency<IPaymentService>().Received(1)

var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.UpdateSubscriptionAsync(update));
Assert.Contains("Plan has a minimum of 200 service accounts", exception.Message);
Assert.Contains("Plan has a minimum of 200 machine accounts", exception.Message);
await VerifyDependencyNotCalledAsync(sutProvider);
}

Expand Down Expand Up @@ -570,7 +570,7 @@ await sutProvider.GetDependency<IPaymentService>().Received(1)
.Returns(currentServiceAccounts);

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.UpdateSubscriptionAsync(update));
Assert.Contains("Your organization currently has 301 service accounts. You cannot decrease your subscription below your current service account usage", exception.Message);
Assert.Contains("Your organization currently has 301 machine accounts. You cannot decrease your subscription below your current machine account usage", exception.Message);
await VerifyDependencyNotCalledAsync(sutProvider);
}

Expand Down Expand Up @@ -648,7 +648,7 @@ await sutProvider.GetDependency<IPaymentService>().Received(1)
var update = new SecretsManagerSubscriptionUpdate(organization, false) { MaxAutoscaleSmServiceAccounts = 3 };

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.UpdateSubscriptionAsync(update));
Assert.Contains("Your plan does not allow service accounts autoscaling.", exception.Message);
Assert.Contains("Your plan does not allow machine accounts autoscaling.", exception.Message);
await VerifyDependencyNotCalledAsync(sutProvider);
}

Expand Down
Expand Up @@ -192,7 +192,7 @@ public class UpgradeOrganizationPlanCommandTests
.GetServiceAccountCountByOrganizationIdAsync(organization.Id).Returns(currentServiceAccounts);

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.UpgradePlanAsync(organization.Id, upgrade));
Assert.Contains($"Your organization currently has {currentServiceAccounts} service accounts. Your new plan only allows", exception.Message);
Assert.Contains($"Your organization currently has {currentServiceAccounts} machine accounts. Your new plan only allows", exception.Message);

sutProvider.GetDependency<IOrganizationService>().DidNotReceiveWithAnyArgs().ReplaceAndUpdateCacheAsync(default);
}
Expand Down

0 comments on commit b164f24

Please sign in to comment.