Skip to content

Commit

Permalink
fix: use cloned krms for user impersonation (#178)
Browse files Browse the repository at this point in the history
* fix: return a cloned krm from the cache

* fix: krm must be defined

* fix: clone main razee krm for each event

* remove comments
  • Loading branch information
alewitt2 authored Apr 15, 2021
1 parent 0cc1686 commit d662e68
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/EventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lib/KubeResourceMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/kubeClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ module.exports = class KubeClass {
if (verb && krm && !krm.hasVerb(verb)) {
krm = undefined;
}
return krm;
return krm !== undefined ? krm.clone() : krm;
}

};

0 comments on commit d662e68

Please sign in to comment.