Skip to content

Commit d3dc97a

Browse files
author
freisenhauer
authored
Merge pull request #27 from mittwald/fix/k8s-token-reload
Kubernetes Auth: Always load jwt from file, cached jwt could be expired
2 parents f27a046 + b0cf5eb commit d3dc97a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/auth/kubernetes.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ export class VaultKubernetesAuthClient extends AbstractVaultClient implements IV
2525
if (!this.config) {
2626
throw new Error("Kubernetes Auth Client not configured");
2727
}
28-
if (!this.config.jwt) {
29-
this.initConfig(this.config);
30-
}
31-
return this.rawWrite(["/login"], this.config, {
32-
retryWithTokenRenew: false,
33-
}).then((res) => {
28+
return this.rawWrite(
29+
["/login"],
30+
{
31+
role: this.config.role,
32+
jwt: this.config.jwt ?? this.loadJwtFromPath(),
33+
},
34+
{
35+
retryWithTokenRenew: false,
36+
},
37+
).then((res) => {
3438
tiChecker.IVaultTokenAuthResponse.check(res);
3539
return res;
3640
});
@@ -42,16 +46,16 @@ export class VaultKubernetesAuthClient extends AbstractVaultClient implements IV
4246
*/
4347
public async login(config?: IVaultKubernetesAuthLoginConfig): Promise<IVaultKubernetesAuthLoginResponse> {
4448
if (config) {
45-
this.initConfig(config);
49+
this.config = config;
4650
}
4751
return this.auth();
4852
}
4953

50-
private initConfig(config: IVaultKubernetesAuthLoginConfig): void {
51-
if (!config.jwt) {
52-
config.jwt = fs.readFileSync(config.jwt_path ?? "/run/secrets/kubernetes.io/serviceaccount/token", "utf8");
53-
delete config.jwt_path;
54+
private loadJwtFromPath(): string {
55+
if (!this.config) {
56+
throw new Error("Kubernetes Auth Client not configured");
5457
}
55-
this.config = config;
58+
const jwt = fs.readFileSync(this.config.jwt_path ?? "/run/secrets/kubernetes.io/serviceaccount/token", "utf8");
59+
return jwt;
5660
}
5761
}

0 commit comments

Comments
 (0)