Skip to content

Conversation

@jmayclin
Copy link
Contributor

@jmayclin jmayclin commented Dec 16, 2024

Description of changes:

This example demonstrate the pkey offload feature in combination with KMS APIs.

Call-outs:

I structured this example as a test, because it was the only way to keep my sanity while I was writing it. Furthermore, I think this is an excellent item to add to our CI.

While there might be a slight readability hit by structuring it as a "test", I actually think that keeping everything in the same process is a bit of a readability win. There isn't an CLI parsing, etc. So very happy to make the tradeoff.

Testing:

Verified that the test passes locally.

I also opened #4979 to track this.

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

Copy link
Contributor

@maddeleine maddeleine left a comment

Choose a reason for hiding this comment

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

I really just have nits. I don't know if we can make the example better without fixing our underlying issues.

Comment on lines 103 to 107
// > The public key that AWS KMS returns is a DER-encoded X.509 public key,
// > also known as SubjectPublicKeyInfo (SPKI), as defined in RFC 5280.
// > When you use the HTTP API or the AWS CLI, the value is Base64-encoded.
// > Otherwise, it is not Base64-encoded.
// https://docs.aws.amazon.com/kms/latest/developerguide/download-public-key.html
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 prefer the link first so that I know what I'm reading

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I feel like that's a bit non-standard w.r.t block quotes, e.g. apa.

@jmayclin jmayclin requested a review from lrstewart January 15, 2025 18:29
* make error message parameterized
@jmayclin
Copy link
Contributor Author

Offline discussion: what this PR is missing is an explanation of where the tricky things come from.

Everyone feels like this feature should be easier to use, but it's difficult to explain why or why not. I need to explain why it can't be any simpler.


The solution is to wrap the anonymous future in some other type, something like the following:
```rust
pub struct SimplePrivateKeyFuture<F> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you instead spawn the task in handle_operation and then store the outputted JoinHandle in SimplePrivateKeyFuture? JoinHandle is Sync, so it would clean up the Future a little.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm 🤔 . So we could do that, but it's not really the way we want customers to use this? Like generally they shouldn't be tokio::spawning tasks just to get a join handle. They are only having to do that as a workaround for our send/sync stuff.

Copy link
Contributor

Choose a reason for hiding this comment

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

I took a whack at implementing it this way. I still think it's cleaner, but I did run into all of the same things you ran into. I'm interested if you think this is better, worse, or exactly equivalent to your implementation:
maddeleine@5ae2652
It does compile, although I haven't actually run the test for this diff.

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 do expect that it would pass tests, but I do not think it's nicer.

Customers are used to using the AWS-SDK, and hate working with manual futures. The AWS-SDK provides convenient async functions, which allows them to easily use the async functionality.

For a customers starting from the mental model, I think the current example structure is the clearest/most accurate. Bascially "lots of business logic lives in the async method, and that all sort of works".

While your implementation does minimize the amount of code in the async block, I don't think that's actually cleaner, and it relies on an "accident" of implementation w.r.t. the the tokio JoinHandle, which in an ideal world wouldn't exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah then I don't really have any ideas for how to improve this example 🤷‍♀️

- clarify where "block_on" is used
* reference the KMS developer guide
* update diagram
@jmayclin jmayclin requested a review from maddeleine August 7, 2025 22:11
* fix name leftover from development explanation

// We need multiple threads, because the block_on (used in cert generation) can
// only be used in multi-threaded runtimes.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
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 am planning to talk a crack at getting these tests actually running in CI. If I can't do that simply, how do people feel about just mocking out the KMS dependency and using a "fake" client?

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no problem with a "fake" client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants