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: Mutations #720

Merged
merged 26 commits into from
Sep 18, 2024
Merged

feat: Mutations #720

merged 26 commits into from
Sep 18, 2024

Conversation

texastony
Copy link
Contributor

Issue #, if available:

Description of changes:

Squash/merge commit message, if applicable:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@texastony texastony changed the title Tony/feat mutations feat: Mutations Sep 15, 2024

This comment was marked as spam.

@seebees seebees force-pushed the seebees/add-storage-interface branch from 56e5262 to 53c9c25 Compare September 17, 2024 19:29
@texastony texastony changed the base branch from seebees/add-storage-interface to main September 18, 2024 01:10
@texastony texastony changed the base branch from main to rc-1.7.0 September 18, 2024 02:43
@texastony texastony changed the base branch from rc-1.7.0 to tony/rc-1.7.0-restore-net September 18, 2024 03:29
Comment on lines +213 to +216
Original := StateStrucs.MutableProperties(
kmsArn := activeItem.KmsArn,
customEncryptionContext := customEncryptionContext
),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TABLE_NAME is areserved word and must be invariant across items

Base automatically changed from tony/rc-1.7.0-restore-net to rc-1.7.0 September 18, 2024 21:39
@texastony texastony marked this pull request as ready for review September 18, 2024 21:41
@texastony texastony requested a review from a team as a code owner September 18, 2024 21:41
@texastony texastony merged commit 7e6b48f into rc-1.7.0 Sep 18, 2024
65 of 69 checks passed
Copy link
Contributor

@josecorella josecorella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more comments

// TODO: A mitigation to the threat model requires that we know if write requests fail due to a race.
// But, from DDB Docs: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html#API_TransactWriteItems_Errors
// > If using Java, DynamoDB lists the cancellation reasons on the CancellationReasons property.
// > This property is not set for other languages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what other languages did we check? net? python? go? rust?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python, .NET, Java.
I have not checked Rust or Go.
I actually do not even know how to do that...
I can check JavaScript.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked Go with Rishav on Thursday.
I will ask Andy for help checking Rust.

Comment on lines +791 to +802
var mLockKey: DDB.Key := map[
Structure.BRANCH_KEY_IDENTIFIER_FIELD := DDB.AttributeValue.S(input.Identifier),
Structure.TYPE_FIELD := DDB.AttributeValue.S(Structure.MUTATION_LOCK_TYPE)
];
var activeKey: DDB.Key := map[
Structure.BRANCH_KEY_IDENTIFIER_FIELD := DDB.AttributeValue.S(input.Identifier),
Structure.TYPE_FIELD := DDB.AttributeValue.S(Structure.BRANCH_KEY_ACTIVE_TYPE)
];
var beaconKey: DDB.Key := map[
Structure.BRANCH_KEY_IDENTIFIER_FIELD := DDB.AttributeValue.S(input.Identifier),
Structure.TYPE_FIELD := DDB.AttributeValue.S(Structure.BEACON_KEY_TYPE_VALUE)
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these could be made into quick functions that return the map. imo, cleaner and easier to read since this method is long

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ryan and I have agreed to replace Batch Get Item with Transact Get Item.
Ryan has advocated for an option that uses Query;
such an option is a very low priority,
and will probably not be in scope for even GA.

i.e: It will not be implemented unless a customer asks for it.

Comment on lines +892 to +919
:- Need(
activeItem.Some?,
Types.KeyStorageException(
message:=
"Could not find the ACTIVE Item. TableName: " + ddbTableName + "\tBranch Key ID: " + input.Identifier
));
:- Need(
&& Structure.ActiveHierarchicalSymmetricKey?(activeItem.value)
&& activeItem.value.Identifier == input.Identifier
&& activeItem.value.EncryptionContext[Structure.TABLE_FIELD] == logicalKeyStoreName,
Types.KeyStorageException(
message:=
"Item returned for the ACTIVE is malformed. TableName: " + ddbTableName + "\tBranch Key ID: " + input.Identifier
));

:- Need(beaconItem.Some?,
Types.KeyStorageException(
message:=
"Could not find the Beacon Key. TableName: " + ddbTableName + "\tBranch Key ID: " + input.Identifier
));
:- Need(
&& Structure.ActiveHierarchicalSymmetricBeaconKey?(beaconItem.value)
&& beaconItem.value.Identifier == input.Identifier
&& beaconItem.value.EncryptionContext[Structure.TABLE_FIELD] == logicalKeyStoreName,
Types.KeyStorageException(
message:=
"Item returned for Beacon Key is malformed. TableName: " + ddbTableName + "\tBranch Key ID: " + input.Identifier
));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move all these checks to one method, makes it easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring this method to use Transact Get Item MAY simplify this.
But yes, I will break this into smaller pieces.

Comment on lines +1159 to +1163
.MapFailure(
eString
=>
Types.KeyStorageException(
message:="Could not UTF8 Decode Exclusive Start Key. " + eString));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im pretty sure this is not correct dafny syntax looking at the other elephant operator operations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry... I do not get a Dafny Syntax error;
this appears to be correct Dafny code.

Are you saying this not correctly format?
i.e: It is stylistically weird?

In which case,
I wholly agree with you.

But the Dafny formatter wants it this way.

It, in my opinion, in correctly over indents if logical symbols are on the same line.
Hence, .MapFailure starts 2 spaces over from where the logical end of UTF8.Decode.

If I had put versionStr, :-, and UTF8.Decode each on their own line,
each would get two additional spaces intended in.

But because I put them all on the same line,
.MapFailure starts two spaces from the start of UTF8.Decode.

Which... is... the Dafny formatter just wants a lot of vertical space,
and if you do not give it to it,
it will cost you 10 fold in horizontal space.

I am not a fan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I have another way of formatting this.

Comment on lines +1165 to +1166
// I elected to require len > 15, rather than len == 51, in case we or someone else ever uses not-UUIDv4 for version.
&& 15 < |versionStr| && versionStr[0 .. 15] == "branch:version:",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would much rather have a complete check for both "branch:version:" and for the expected length of the uuid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... one day... we might switch to UUID v7...
or at least support UUID v7...

It solves some problems.
I made Ryan be strict about UUID v4 strings over in the Hierarchical Keyring's
EDK logic.

I did that so Storage would not care.

To a certain degree,
it would be wonderful is Storage did not care about the Hierarchical Keyring Version.

i.e: This storage layer works with MOST changes we can envision to Branch Keys.

Comment on lines +1194 to +1200
.MapFailure(
eString
=>
Types.KeyStorageException(
message
:=
"Could not UTF8 Encode Last Evaluated Key. " + eString));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odd formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my earlier point on the Dafny Formatter.

Comment on lines +1232 to +1251
var items?: seq<DDB.TransactWriteItem> :- Seq.MapWithResult(
(key: Types.EncryptedHierarchicalKey)
=>
:- Need(
&& (forall k <- key.EncryptionContext.Keys :: DDB.IsValid_AttributeName(k)),
Types.KeyStorageException( message := ErrorMessages.ENCRYPTION_CONTEXT_EXCEEDS_DDB_LIMIT)
);
:- Need(
key.Type.HierarchicalSymmetricVersion?,
Types.KeyStorageException(
message :=
"WriteMutatedVersions of DynamoDB Encrypted Key Storage ONLY writes Decrypt Only Items to Storage. "
+ "Encountered a non-Decrypt Only Item."
));
var item := CreateTransactWritePutItem(
key,
ddbTableName,
BRANCH_KEY_EXISTS);
Success(item),
input.items);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some extra commens here would be helpful :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments.

@seebees seebees deleted the tony/feat-mutations branch September 19, 2024 02:45
@seebees seebees restored the tony/feat-mutations branch September 19, 2024 02:47
texastony added a commit that referenced this pull request Sep 22, 2024
texastony added a commit that referenced this pull request Sep 22, 2024
texastony added a commit that referenced this pull request Sep 26, 2024
texastony added a commit that referenced this pull request Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants