-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Batch hmac - (#5850) #5875
Batch hmac - (#5850) #5875
Conversation
The transit/path_config_test is failing because path_hmac now returns an error if request "input" field is missing: (This mimics the behaviour of transit/encrypt when no plaintext is supplied.) Unfortunately, path_config_test reuses a transit/encrypt request when first calling pathHMAC - and so this carries a I can either revert path_hmac to its old behaviour - quietly returning the hmac of an empty input if input is not supplied - or I can keep the new, arguably more correct behaviour of rejecting requests with no input (or batch_input) fields and fix the path_config_test so that the input field is present. What should I do ? |
For the time being, I have reverted to the existing behaviour of accepting requests without an input field and returning the HMAC of a blank field. I guess there would be no harm in fixing up the path_config_test case by copying the In the batch_response, hmac fields are uppercase HMAC rather than lowercase for non-batch. I will fix that later. I was expecting it to be converted to lowercase given the definition:
I expected the json markup to be honoured in generating the message from the batch_response. |
I have fixed up the transit/path_config_test so that I have reverted transit/path_hmac pathHMACWrite to return an error if no input is supplied. When batch_input is supplied, any item in the data array without an
Now returns:
|
Hi @martinwaite, thanks for contributing this change! We'd like to get this merged in soon, so we were wondering if you could add API docs for the new API? |
Hi @briankassouf - I have added some api docs. |
@martinwaite After thinking about it some more it would be really nice to also offer a batch verify and a batch sign API at the same time as this change. Is that something you'd be willing to add to this PR? I imagine the changeset for verify/sign would look very similar to what you did for hmac. |
@briankassouf - I will extend the PR to cover sign and verify. I should get it done over the weekend. |
@briankassouf - I have added a first draft of the code for supporting batch_input for sign and verify. I still need to test the HMAC verification path, and I expect to have broken the acceptance tests. I will complete this next weekend. |
Refined the error-handling so that when batch mode simulates simple 'input' case, errors are reported in same way as before batch was added. This is working for the Sign path, but needs to be extended to the verify and hmac cases. |
@briankassouf - |
a409b8d
to
c7d84b4
Compare
@briankassouf - I need help with the failing tests. 5 of the tests are something to do with the documentation. The logs show a ruby stack trace - I have no idea how to deal with that. One of the CI builds tripped over a JWT issue - I can't tell if that is something I did. |
website fix
99c94b8
to
1d645bf
Compare
@briankassouf - all tests are passing now. This is ready for review. |
@@ -747,13 +747,26 @@ be used. | |||
|
|||
- `input` `(string: <required>)` – Specifies the **base64 encoded** input data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer a required parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed "<required>" to nil - and added a sentence about either input or batch_input being needed. I'm not sure about "nil" being correct .
@@ -806,6 +870,28 @@ supports signing. | |||
|
|||
- `input` `(string: <required>)` – Specifies the **base64 encoded** input data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer a required parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed "<required>" to nil - and added a sentence about either input or batch_input being needed. I'm not sure about "nil" being correct .
@martinwaite This looks really good! I left a few minor comments but overall I think it's close. @briankassouf Any thoughts on having a limit (possible pretty high) on the max batch size? I'm wondering if having no limit might lure users into dumping all items into a batch, and then as their batch size grows they might start hitting request timeout errors, or Vault has issues, etc. Enforcing some level of batching on the caller's side now might avoid those issues. |
@kalafut we already have a per-listener maximum request size (with a default of about 32 MB). I guess the question would be, in a normal request timeout period, what does this translate to in terms of max batched operations. But that request timeout is also driven by the client, so if the client is hitting errors it can change it... |
@kalafut - I have implemented all of your code suggestions. I'm not sure about the changes I made to the website doc - please check. Ugh - build fails. I'll see if rebase fixes it. Lots of build errors concerning caching - for example TestLeaseCache_SendCacheable. I don't think it is anything to do with my changes. Maybe I should have merged rather than rebased: your review comments no longer refer to valid commits. Sorry. |
} | ||
return "" | ||
t.Fatalf("bad: expected response, got: %#v", *resp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Fatalf("bad: expected response, got: %#v", *resp) | |
t.Fatalf("bad: expected error response, got: %#v", *resp) |
@@ -745,15 +745,29 @@ be used. | |||
- `sha2-384` | |||
- `sha2-512` | |||
|
|||
- `input` `(string: <required>)` – Specifies the **base64 encoded** input data. | |||
- `input` `(string: nil)` – Specifies the **base64 encoded** input data. One of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `input` `(string: nil)` – Specifies the **base64 encoded** input data. One of | |
- `input` `(string: "")` – Specifies the **base64 encoded** input data. One of |
@@ -805,7 +870,30 @@ supports signing. | |||
- `sha2-384` | |||
- `sha2-512` | |||
|
|||
- `input` `(string: <required>)` – Specifies the **base64 encoded** input data. | |||
- `input` `(string: nil)` – Specifies the **base64 encoded** input data. One of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `input` `(string: nil)` – Specifies the **base64 encoded** input data. One of | |
- `input` `(string: "")` – Specifies the **base64 encoded** input data. One of |
@@ -894,6 +1023,31 @@ data. | |||
`/transit/hmac` function. Either this must be supplied or `signature` must be | |||
supplied. | |||
|
|||
- `batch_input` `(array<object>: nil)` – Specifies a list of items for processing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(GH won't let me add this comment outside the diff range). Please update the input
docs here as you did the others.
@@ -116,70 +136,105 @@ func (b *backend) pathHMACWrite(ctx context.Context, req *logical.Request, d *fr | |||
return nil, fmt.Errorf("HMAC key value could not be computed") | |||
} | |||
|
|||
var hf hash.Hash | |||
var hashAlg func() hash.Hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably use the keysutil.HashTypeMap stuff we are using elsewhere in transit
} | ||
|
||
var hf hash.Hash | ||
var hashAlg func() hash.Hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment
type batchResponseSignItem struct { | ||
// signature for the input present in the corresponding batch | ||
// request item | ||
Signature string `json:"signature,omitempty" structs:"signature" mapstructure:"signature"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and elsewhere, if you are not using the structs
package in your tests for this functionality, please don't decorate it. We are generally trying to get rid of usage of that package.
@martinwaite Thanks for addressing the comments and the contribution as a whole. There a few additional comments that have been left, but at this point I'm going to merge your PR and make those changes. |
Guidance is needed on some points:
Most of the changes are copied from batch_input in path_encrypt. I was surprised that the framework.Path structure did not mention batch_input. Why is it not there ?