Skip to content
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

feat: Storm cache supports millisecond resolution #1011

Merged
merged 29 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4de0595
feat: Storm cache supports millisecond resolution
seebees Nov 15, 2024
e3f5194
simplify caling structure
seebees Nov 15, 2024
6797d7f
const in Dafny are not const :(
seebees Nov 15, 2024
be35ad7
Update tests
seebees Nov 15, 2024
8aa4d17
Poly CS
seebees Nov 15, 2024
891300d
Units need to propigate to the H-Keyring
seebees Nov 15, 2024
ace6959
python
lucasmcdonald3 Nov 16, 2024
2774604
repoly python
lucasmcdonald3 Nov 16, 2024
f249e22
Units between CMCs
seebees Nov 16, 2024
44c650b
Merge branch 'main' into seebees/storm-of-failures
seebees Nov 16, 2024
415e67a
Grade Period is in ms and expiryTime is in seconds
seebees Nov 16, 2024
813debe
Units test
seebees Nov 16, 2024
f4847c4
format
seebees Nov 16, 2024
40c2615
polymorph test vectors
seebees Nov 16, 2024
fef9e6b
update verification
seebees Nov 18, 2024
56d7e4b
dafny format
seebees Nov 18, 2024
7c3cf6d
add another test
seebees Nov 18, 2024
d67f8db
Merge branch 'main' into seebees/storm-of-failures
seebees Nov 18, 2024
cc2ae78
update to have both
seebees Nov 18, 2024
3e6879f
First cut on MaxWait
seebees Nov 18, 2024
d62c2ce
Merge branch 'main' into seebees/storm-of-failures
seebees Nov 18, 2024
794d909
Revert "First cut on MaxWait"
seebees Nov 19, 2024
190eb22
use inFlightTTL as maxInFlight
seebees Nov 19, 2024
d13613f
inFlight ==> maxWait
seebees Nov 19, 2024
3b97c63
leave interval < inFlight
seebees Nov 19, 2024
f416f56
Java format
seebees Nov 19, 2024
71e121d
Update Python
seebees Nov 19, 2024
f80cbd7
cs poly
seebees Nov 19, 2024
2b0ccff
Merge branch 'main' into seebees/storm-of-failures
seebees Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1623,12 +1623,16 @@ module {:extern "software.amazon.cryptography.materialproviders.internaldafny.ty
nameonly graceInterval: CountingNumber ,
nameonly fanOut: CountingNumber ,
nameonly inFlightTTL: CountingNumber ,
nameonly sleepMilli: CountingNumber
nameonly sleepMilli: CountingNumber ,
nameonly timeUnits: Option<TimeUnits> := Option.None
)
datatype SymmetricSignatureAlgorithm =
| HMAC(HMAC: AwsCryptographyPrimitivesTypes.DigestAlgorithm)
| None(None: None)
type SymmetricSigningKeyList = seq<Secret>
datatype TimeUnits =
| Seconds
| Milliseconds
datatype UpdateUsageMetadataInput = | UpdateUsageMetadataInput (
nameonly identifier: seq<uint8> ,
nameonly bytesUsed: PositiveInteger
Expand Down Expand Up @@ -1661,6 +1665,9 @@ module {:extern "software.amazon.cryptography.materialproviders.internaldafny.ty
| EntryDoesNotExist (
nameonly message: string
)
| InFlightTTLExceeded (
nameonly message: string
)
| InvalidAlgorithmSuiteInfo (
nameonly message: string
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ structure EntryAlreadyExists {
message: String,
}

@error("client")
structure InFlightTTLExceeded {
@required
message: String,
}

// Materials Cache Constructors

@positional
Expand Down Expand Up @@ -190,26 +196,43 @@ structure StormTrackingCache {
entryPruningTailSize: CountingNumber,

@required
@javadoc("How many seconds before expiration should an attempt be made to refresh the materials.
@javadoc("How much time before expiration should an attempt be made to refresh the materials.
If zero, use a simple cache with no storm tracking.")
gracePeriod: CountingNumber,

@required
@javadoc("How many seconds between attempts to refresh the materials.")
@javadoc("How much time between attempts to refresh the materials.")
graceInterval: CountingNumber,

@required
@javadoc("How many simultaneous attempts to refresh the materials.")
fanOut: CountingNumber,

@required
@javadoc("How many seconds until an attempt to refresh the materials should be forgotten.")
@javadoc("How much time until an attempt to refresh the materials should be forgotten.")
inFlightTTL: CountingNumber,

@required
@javadoc("How many milliseconds should a thread sleep if fanOut is exceeded.")
sleepMilli: CountingNumber,
}

@javadoc("The time unit for gracePeriod, graceInterval, and inFlightTTL.
The default is seconds.
If this is set to milliseconds, then these values will be treated as milliseconds.")
timeUnits: TimeUnits
}

@enum([
{
name: "Seconds",
value: "Seconds",
},
{
name: "Milliseconds",
value: "Milliseconds",
},
])
string TimeUnits

union CacheType {
Default : DefaultCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,15 @@ module AwsCryptographyMaterialProvidersOperations refines AbstractAwsCryptograph
method CheckCache(cache : CacheType, ttlSeconds: PositiveLong) returns (output : Outcome<Error>)
{
if cache.StormTracking? {
var gracePeriod := if cache.StormTracking.timeUnits.UnwrapOr(Types.Seconds).Seconds? then
cache.StormTracking.gracePeriod as PositiveLong
else
cache.StormTracking.gracePeriod as PositiveLong / 1000;
var storm := cache.StormTracking;
if ttlSeconds <= storm.gracePeriod as PositiveLong {
if ttlSeconds <= gracePeriod {
var msg := "When creating an AwsKmsHierarchicalKeyring with a StormCache, " +
"the ttlSeconds of the KeyRing must be greater than the gracePeriod of the StormCache " +
"yet the ttlSeconds is " + N(ttlSeconds) + " and the gracePeriod is " + N(storm.gracePeriod as PositiveLong) + ".";
"yet the ttlSeconds is " + N(ttlSeconds) + " and the gracePeriod is " + N(gracePeriod) + ".";
return Fail(Types.AwsCryptographicMaterialProvidersException(message := msg));
}
return Pass;
Expand Down Expand Up @@ -819,6 +823,8 @@ module AwsCryptographyMaterialProvidersOperations refines AbstractAwsCryptograph
case StormTracking(c) =>
var cache := c.( entryPruningTailSize := OptionalCountingNumber(c.entryPruningTailSize));
:- StormTracker.CheckSettings(cache);


var cmc := new StormTracker.StormTracker(cache);
var synCmc := new StormTrackingCMC.StormTrackingCMC(cmc);
return Success(synCmc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ module {:options "/functionSyntax:4" } LocalCMC {
ensures GetCacheEntryEnsuresPublicly(input, output)
ensures unchanged(History)
ensures InternalModifies <= old(InternalModifies)
ensures output.Success? ==> now <= output.value.expiryTime
{
if cache.HasKey(input.identifier) {
var entry := cache.Select(input.identifier);
Expand Down
Loading
Loading