in src/Amazon.AspNetCore.DataProtection.SSM/SSMXmlRepository.cs [182:221]
private ParameterTier GetParameterTier(string elementValue)
{
var elementValueLength = elementValue.Length;
var storageMode = _options.TierStorageMode;
_logger.LogDebug($"Using tier storage mode {storageMode} to decide which SSM parameter tier to use for DataProtection element.");
// Check if the value is too large for the advanced tier (8192 characters/ 8KB), in this case the key generation is not suitable for keys that should be stored as SSM parameter.
const int advancedTierMaxSize = 8192;
if (elementValueLength > advancedTierMaxSize)
{
throw new SSMParameterToLongException($"Could not save DataProtection element to SSM parameter. " +
$"DataProtection element has a length of {elementValueLength} which exceeds the maximum SSM parameter size of {advancedTierMaxSize}. " +
$"Please consider using another key provider or key store.");
}
// Check if advanced tier has to be used anyway due to tier storage mode
if (storageMode == TierStorageMode.AdvancedOnly)
return ParameterTier.Advanced;
// Check if the value is too big for the standard tier and try to use the advanced tier if the storage mode allows it.
// 4096 characters (4KB) is the maximum size for the standard tier.
const int standardTierMaxSize = 4096;
if (elementValueLength > standardTierMaxSize)
{
_logger.LogDebug($"DataProtection element has a length of {elementValueLength} which exceeds the maximum standard tier SSM parameter size of {standardTierMaxSize} (4KB), checking if advanced tier usage is allowed.");
// tier is too large for standard tier, check if advanced tier is allowed
if (_options == null || _options.TierStorageMode == TierStorageMode.StandardOnly)
{
throw new SSMParameterToLongException($"Could not save DataProtection element to SSM parameter. " +
$"Element has {elementValueLength} characters which exceeds the limit of {standardTierMaxSize} characters of the standard parameter tier and usage of advanced tier is not configured." +
$"You can resolve this issue by changing the TierStorageMode to {nameof(TierStorageMode.AdvancedUpgradeable)} or {nameof(TierStorageMode.AdvancedOnly)} in the configuration.");
}
return ParameterTier.Advanced;
}
return ParameterTier.Standard;
}