nix(loadtest): remove genKeyMaterials

Merge the same code into genTargets, which removes the need to save the
private key to disk and read it again.
This commit is contained in:
Wolfgang Walther
2026-06-26 19:33:51 +00:00
parent 32706284f0
commit e83a25a698
3 changed files with 17 additions and 78 deletions
-51
View File
@@ -1,51 +0,0 @@
# Generate HS & RSA JWK/public material for loadtests.
import argparse
import sys
from pathlib import Path
import jwcrypto.jwk as jwk
def main():
parser = argparse.ArgumentParser(
description="Generate RSA JWK/private key pair for loadtests"
)
parser.add_argument(
"--jwks",
dest="jwks_path",
metavar="JWKS_PATH",
type=Path,
required=True,
help="Path to write the JWKS file",
)
parser.add_argument(
"--private-key",
dest="private_key_path",
metavar="PRIVATE_KEY_PATH",
type=Path,
required=True,
help="Path to write the RSA private key file",
)
args = parser.parse_args()
hs = jwk.JWK.from_password("reallyreallyreallyreallyverysafe")
rsa = jwk.JWK.generate(kty="RSA", size=4096)
jwks = jwk.JWKSet()
jwks.add(hs)
jwks.add(rsa)
# Technically, this exports the private keys, because HS does not have the concept
# of a public key. This is not a problem for tests, though, PostgREST can verify
# tokens with the private key just as well.
args.jwks_path.write_text(jwks.export())
print(f"Created JWKSet on {args.jwks_path}")
args.private_key_path.write_text(rsa.export_private())
print(f"Created private key on {args.private_key_path}")
if __name__ == "__main__":
main()
+14 -12
View File
@@ -62,13 +62,6 @@ def main():
help="Path to write the generated files",
type=Path,
)
parser.add_argument(
"--private-key",
dest="private_key_path",
metavar="PRIVATE_KEY_PATH",
type=Path,
help="Path to the RSA private key file",
)
parser.add_argument(
"--worst",
dest="worst",
@@ -81,15 +74,24 @@ def main():
targets_path = args.generated_path / "gen_targets.http"
rsa_private_key: Optional[jwt.JWK] = None
hs = jwt.JWK.from_password(secret_key)
rsa = jwt.JWK.generate(kty="RSA", size=4096)
jwks = jwt.JWKSet()
jwks.add(hs)
jwks.add(rsa)
jwks_path = args.generated_path / "gen_jwks.json"
# Technically, this exports the private keys, because HS does not have the concept
# of a public key. This is not a problem for tests, though, PostgREST can verify
# tokens with the private key just as well.
jwks_path.write_text(jwks.export())
print(f"Created JWKSet on {jwks_path}")
nsamples = 500 # per algorithm
ntargets = 100000
hs = jwt.JWK.from_password(secret_key)
private_key_data = args.private_key_path.read_text()
rsa = jwt.JWK.from_json(private_key_data)
print(f"Generating {ntargets} targets...")
now = int(time.time())
+3 -15
View File
@@ -66,11 +66,9 @@ let
case "$_arg_kind" in
jwt)
export PGRST_JWT_CACHE_MAX_ENTRIES="0"
${genKeyMaterials} --jwks="$_arg_testdir"/gen_jwks.json --private-key="$_arg_testdir"/gen_private.json
export PGRST_JWT_SECRET="@$_arg_testdir/gen_jwks.json"
${genTargets} --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir"
${genTargets} "$_arg_testdir"
# shellcheck disable=SC2145
${withTools.withPg} -f "$_arg_testdir"/fixtures.sql \
@@ -80,10 +78,9 @@ let
;;
jwt-cache)
${genKeyMaterials} --jwks="$_arg_testdir"/gen_jwks.json --private-key="$_arg_testdir"/gen_private.json
export PGRST_JWT_SECRET="@$_arg_testdir/gen_jwks.json"
${genTargets} --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir"
${genTargets} "$_arg_testdir"
# shellcheck disable=SC2145
${withTools.withPg} -f "$_arg_testdir"/fixtures.sql \
@@ -93,10 +90,9 @@ let
;;
jwt-cache-worst)
${genKeyMaterials} --jwks="$_arg_testdir"/gen_jwks.json --private-key="$_arg_testdir"/gen_private.json
export PGRST_JWT_SECRET="@$_arg_testdir/gen_jwks.json"
${libfaketime}/bin/faketime '2000-01-01 00:00:00' ${genTargets} --worst --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir"
${libfaketime}/bin/faketime '2000-01-01 00:00:00' ${genTargets} --worst "$_arg_testdir"
# shellcheck disable=SC2145
${withTools.withPg} -f "$_arg_testdir"/fixtures.sql \
@@ -317,14 +313,6 @@ let
}
(builtins.readFile ./generate_targets.py);
genKeyMaterials =
writers.writePython3 "postgrest-gen-key-materials"
{
libraries = [ python3Packages.jwcrypto ];
doCheck = false; # postgrest-style conflicts with this
}
(builtins.readFile ./gen_key_materials.py);
mergeMonitorResults =
writers.writePython3 "postgrest-merge-monitor-results"
{