From 416014b7b810f5d58f3bf7a111efec4a2b9662ef Mon Sep 17 00:00:00 2001 From: Manuel Scurti Date: Sun, 22 May 2022 19:30:40 +0200 Subject: [PATCH] added migration file Signed-off-by: Manuel Scurti --- .../migrations/20200619125845_init.js | 12 +---- .../20220522100910_key_field_size.js | 49 +++++++++++++++++++ .../auth-backend/src/identity/TokenFactory.ts | 2 +- 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 plugins/auth-backend/migrations/20220522100910_key_field_size.js diff --git a/plugins/auth-backend/migrations/20200619125845_init.js b/plugins/auth-backend/migrations/20200619125845_init.js index 6697d168c0..d5fc08ce48 100644 --- a/plugins/auth-backend/migrations/20200619125845_init.js +++ b/plugins/auth-backend/migrations/20200619125845_init.js @@ -20,13 +20,6 @@ * @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', @@ -41,10 +34,7 @@ exports.up = async function up(knex) { .notNullable() .defaultTo(knex.fn.now()) .comment('The creation time of the key'); - table - .string('key', SIGNING_KEY_MAX_LENGTH) - .notNullable() - .comment('The serialized signing key'); + table.string('key').notNullable().comment('The serialized signing key'); }); }; diff --git a/plugins/auth-backend/migrations/20220522100910_key_field_size.js b/plugins/auth-backend/migrations/20220522100910_key_field_size.js new file mode 100644 index 0000000000..c6637525f3 --- /dev/null +++ b/plugins/auth-backend/migrations/20220522100910_key_field_size.js @@ -0,0 +1,49 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// @ts-check + +/** + * @param {import('knex').Knex} knex + */ +exports.up = async function up(knex) { + // Sqlite does not support alter column. + if (!knex.client.config.client.includes('sqlite3')) { + await knex.schema.alterTable('signing_keys', table => { + table + .text('key') + .notNullable() + .comment('The serialized signing key') + .alter({ alterType: true }); + }); + } +}; + +/** + * @param {import('knex').Knex} knex + */ +exports.down = async function down(knex) { + // Sqlite does not support alter column. + if (!knex.client.config.client.includes('sqlite3')) { + await knex.schema.alterTable('signing_keys', table => { + table + .string('key') + .notNullable() + .comment('The serialized signing key') + .alter({ alterType: true }); + }); + } +}; diff --git a/plugins/auth-backend/src/identity/TokenFactory.ts b/plugins/auth-backend/src/identity/TokenFactory.ts index fdc7210650..44cfebfb71 100644 --- a/plugins/auth-backend/src/identity/TokenFactory.ts +++ b/plugins/auth-backend/src/identity/TokenFactory.ts @@ -36,7 +36,7 @@ type Options = { * 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. + * If not, add a knex migration file in the migrations folder. * More info on supported algorithms: https://github.com/panva/jose */ algorithm?: string; };