Skip to content

Commit 6d22f47

Browse files
author
Noelle Daley
committed
fix: calculate expiration of all batch tokens to ensure expire warning banner is shown
1 parent 93bda36 commit 6d22f47

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

ui/app/components/token-expire-warning.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export default class TokenExpireWarning extends Component {
4646
if ('vault.cluster.oidc-provider' === currentRoute) {
4747
return false;
4848
}
49+
4950
return !!this.args.expirationDate;
5051
}
5152
}

ui/app/services/auth.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ export default Service.extend({
8181
if (!tokenName) {
8282
return;
8383
}
84+
8485
const { tokenExpirationEpoch } = this.getTokenData(tokenName);
8586
const expirationDate = new Date(0);
87+
8688
return tokenExpirationEpoch ? expirationDate.setUTCMilliseconds(tokenExpirationEpoch) : null;
8789
}),
8890

@@ -216,9 +218,17 @@ export default Service.extend({
216218
},
217219

218220
calculateExpiration(resp) {
219-
const now = this.now();
221+
let tokenExpirationEpoch;
220222
const ttl = resp.ttl || resp.lease_duration;
221-
const tokenExpirationEpoch = now + ttl * 1e3;
223+
const now = this.now();
224+
225+
if (resp.type === 'batch') {
226+
const expireTime = resp.expire_time;
227+
tokenExpirationEpoch = new Date(expireTime).getTime();
228+
} else {
229+
tokenExpirationEpoch = now + ttl * 1e3;
230+
}
231+
222232
this.set('expirationCalcTS', now);
223233
return {
224234
ttl,
@@ -296,21 +306,16 @@ export default Service.extend({
296306
resp.policies
297307
);
298308

299-
if (resp.renewable) {
300-
Object.assign(data, this.calculateExpiration(resp));
301-
} else if (resp.type === 'batch') {
302-
// if it's a batch token, it's not renewable but has an expire time
303-
// so manually set tokenExpirationEpoch and allow expiration
304-
data.tokenExpirationEpoch = new Date(resp.expire_time).getTime();
305-
this.set('allowExpiration', true);
306-
}
309+
Object.assign(data, this.calculateExpiration(resp));
307310

308311
if (!data.displayName) {
309312
data.displayName = (this.getTokenData(tokenName) || {}).displayName;
310313
}
314+
311315
this.set('tokens', addToArray(this.tokens, tokenName));
312316
this.set('allowExpiration', false);
313317
this.setTokenData(tokenName, data);
318+
314319
return resolve({
315320
namespace: currentNamespace || data.userRootNamespace,
316321
token: tokenName,

0 commit comments

Comments
 (0)