fixed migration script for signing_keys

Signed-off-by: Manuel Scurti <manuel.scurti@agilelab.it>
This commit is contained in:
Manuel Scurti
2022-05-21 12:49:39 +02:00
parent a07ced9488
commit 6dcc5f1d3e
2 changed files with 14 additions and 1 deletions
@@ -20,6 +20,13 @@
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
/**
* key field length. must be enough for the chosen JWT signing algorithm.
* the default value is set to be enough for all supported algorithms of the
* `jose` library.
*/
const SIGNING_KEY_MAX_LENGTH = 512;
return knex.schema.createTable('signing_keys', table => {
table.comment(
'Signing keys that are currently in use or have recently been used to issue tokens',
@@ -34,7 +41,10 @@ exports.up = async function up(knex) {
.notNullable()
.defaultTo(knex.fn.now())
.comment('The creation time of the key');
table.string('key').notNullable().comment('The serialized signing key');
table
.string('key', SIGNING_KEY_MAX_LENGTH)
.notNullable()
.comment('The serialized signing key');
});
};
@@ -34,6 +34,9 @@ type Options = {
keyDurationSeconds: number;
/** JWS "alg" (Algorithm) Header Parameter value. Defaults to ES256.
* Must match one of the algorithms defined for IdentityClient.
* When setting a different algorithm, check if the `key` field
* of the `signing_keys` table can fit the length of the generated keys.
* If not, modify the migration file in the migrations folder.
* More info on supported algorithms: https://github.com/panva/jose */
algorithm?: string;
};