-
Notifications
You must be signed in to change notification settings - Fork 202
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
Sign k6 requests with HMAC to enable WAF bypass #4908
Conversation
The infrastructure side of things is underway in this draft PR: https://github.com/WordPress/openverse-infrastructure/pull/1048 Nothing is working yet... 🙂 but it will soon! |
28fddb7
to
0740e8f
Compare
@@ -18,7 +20,7 @@ function getConfig(testFile: string) { | |||
preserveModules: true, | |||
preserveModulesRoot: "src", | |||
}, | |||
plugins: [typescript()], | |||
plugins: [typescript(), nodeResolve(), commonjs()], |
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.
New rollup plugins used to support bundling npm dependencies, because k6 doesn't support them unless they are bundled in. In our case, we need it for core-js
to provide a sensible URL API.
I chose this as an alternative to the jslib URL implementation because (a) that still requires importing URL
and (b) there are no means to support types for it. The suggested approach for supporting types from k6 jslib libraries is to vendor the library code.
I did not try declaring the types using declare module "...jslib..."
so I'll try that for good measure (which would be nice for the other jslib function we use).
However, I've found that so far the k6 and jslib implementations of certain Web APIs have very subtle and annoying differences to the specification, which mostly just causes a bit of mental overload trying to keep track of. Which is to say, it's nice to be able to bundle in polyfills from core-js that will behave according to the specification!
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.
k6-jslib-url just exports core-js: https://github.com/grafana/k6-jslib-url/blob/main/index.src.js
For the sake of making sure bundling in node dependencies is sorted for anyone else working in these tests, I think it's best to go ahead and use core-js directly in this PR, as a means of integrating the bundling process before it's needed otherwise.
I'm fairly certain the issue with this is on the Cloudflare side with my usage of their hmac validation function (made a slight error). Excited to test later today and maybe get this in a state where we can start running these after each staging deploy starting next week 😁 cc @obulat who created the issue and I suppose will be interested to see this become available. Once this HMAC pattern is established, we can use it to run Playwright tests as well #4706 |
0740e8f
to
bba5f7c
Compare
Putting this back as draft because I realised I still had a todo comment here, and can undo the async redactor now that I've switched this back to using the k6/crypto library instead of WebCryptoAPI. K6 really isn't meant for async yet, so its okay if we stick to sync code here for now. Aside from that, if you're reading this and care to test the WAF bypass bit out, that's all working well. I also decided to leave the GitHub Workflow bits out of this PR to avoid it getting too big/complex... There are a couple of things I need to think about for those. Main thing being... We should run all test scenarios in CI/CD anytime something relevant to a test namespace changes, which is also important to avoid pushing changes to the load tests to main that haven't at least run against the local frontend in the PR CI checks. Anyway, that will be a separate PR. This one will stay scoped to only getting the HMAC signing working... Which it does! Just need to do a bit more cleanup/undo some of to unnecessary changes in this PR. Update: this is ready for review now 🙂 Check out the PR description for testing instructions. |
bba5f7c
to
fda7e48
Compare
fda7e48
to
af42e46
Compare
I'm going to review this PR tomorrow morning |
Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR: @obulat Excluding weekend1 days, this PR was ready for review 4 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2. @sarayourfriend, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings. Footnotes
|
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 whole file is great 👨🍳 💋
@@ -0,0 +1,15 @@ | |||
// Courtesy of @mbforbes via https://gist.github.com/robingustafsson/7dd6463d85efdddbb0e4bcd3ecc706e1?permalink_comment_id=4884925#gistcomment-4884925 |
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.
Random thought but it'd be kinda cool to make folks co-authors of the PR when we reuse code like this! The comment is totally sufficient, of course.
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.
Hmmm, I'd be worried about going to that extent, it might imply they were involved in the PR more broadly, because we squash commits onto main? I'd be worried about doing that without their consent.
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.
LGTM. Verified against staging and the local frontend.
Fixes
Fixes https://github.com/WordPress/openverse-infrastructure/issues/1031 by @obulat
Description
This PR adds signing requests with an HMAC to enable bypassing WAF rules, so that k6 requests do not get rate limited.
Testing Instructions
Follow the test instructions in this infrastructure PR: https://github.com/WordPress/openverse-infrastructure/pull/1048
These must be tested together.
You should also be able to run the k6 tests against your local frontend, without passing
-e signing_secret
. Run your frontend withov j p frontend prod
and then in another terminal, run the k6 tests:Checklist
Update index.md
).main
) or a parent feature branch.ov just catalog/generate-docs
for catalogPRs) or the media properties generator (
ov just catalog/generate-docs media-props
for the catalog or
ov just api/generate-docs
for the API) where applicable.Developer Certificate of Origin
Developer Certificate of Origin