From d662e68b2a722c39f8796ac5c120311ad0096d21 Mon Sep 17 00:00:00 2001 From: Alex Lewitt <48691328+alewitt2@users.noreply.github.com> Date: Thu, 15 Apr 2021 15:59:31 -0400 Subject: [PATCH] fix: use cloned krms for user impersonation (#178) * fix: return a cloned krm from the cache * fix: krm must be defined * fix: clone main razee krm for each event * remove comments --- lib/EventHandler.js | 8 ++++---- lib/KubeResourceMeta.js | 4 ++++ lib/kubeClass.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/EventHandler.js b/lib/EventHandler.js index 69b3946..b037dd6 100644 --- a/lib/EventHandler.js +++ b/lib/EventHandler.js @@ -35,9 +35,9 @@ module.exports = class EventHandler { this._logger = params.logger || require('../bunyan-api').createLogger('EventHandler'); if (!(this._kubeResourceMeta && - this._kubeResourceMeta.constructor && - this._kubeResourceMeta.constructor.name === 'KubeResourceMeta' && - this._kubeResourceMeta.hasVerb('watch'))) { + this._kubeResourceMeta.constructor && + this._kubeResourceMeta.constructor.name === 'KubeResourceMeta' && + this._kubeResourceMeta.hasVerb('watch'))) { throw Error('Resource does not support verb "watch"'); } if (!this._kc) { @@ -68,7 +68,7 @@ module.exports = class EventHandler { // Event Handler async eventHandler(data) { let params = { - kubeResourceMeta: this._kubeResourceMeta, + kubeResourceMeta: this._kubeResourceMeta.clone(), eventData: data, kubeClass: this._kc, logger: this._logger, diff --git a/lib/KubeResourceMeta.js b/lib/KubeResourceMeta.js index 16a0c4a..63ebabf 100644 --- a/lib/KubeResourceMeta.js +++ b/lib/KubeResourceMeta.js @@ -27,6 +27,10 @@ module.exports = class KubeResourceMeta { this._logger = require('./bunyan-api').createLogger('KubeResourceMeta'); } + clone() { + return new KubeResourceMeta(this._path, this._resourceMeta, this._kubeApiConfig); + } + uri(options = {}) { let result = `${this._path}`; if (options.watch) { diff --git a/lib/kubeClass.js b/lib/kubeClass.js index 7ecebc7..fda8ca8 100644 --- a/lib/kubeClass.js +++ b/lib/kubeClass.js @@ -246,7 +246,7 @@ module.exports = class KubeClass { if (verb && krm && !krm.hasVerb(verb)) { krm = undefined; } - return krm; + return krm !== undefined ? krm.clone() : krm; } };