This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
3,645 additions
and
3,436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
Patch manifests | ||
*/ | ||
module.exports = (manifests) => { | ||
for (const manifest of manifests) { | ||
const { kind } = manifest; | ||
if (kind === "Deployment" && manifest.metadata.name === "app") { | ||
manifest.spec.template.spec = { | ||
...manifest.spec.template.spec, | ||
serviceAccountName: "vault" | ||
}; | ||
} | ||
} | ||
return manifests; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as fs from 'fs'; | ||
|
||
const vault = require("node-vault"); | ||
|
||
|
||
class VaultModule { | ||
private vaultClient: any; | ||
private readonly vaultRole: string | ||
private isKubelogged: boolean | ||
|
||
constructor(vaultRole: string) { | ||
this.vaultClient = vault({ | ||
apiVersion: 'v1', | ||
endpoint: "http://vault.vault-dev.svc:8200", | ||
}); | ||
this.vaultRole = vaultRole | ||
this.isKubelogged = false | ||
} | ||
|
||
async readSecret(path: string): Promise<any> { | ||
const JWT_TOKEN_FILE="/var/run/secrets/kubernetes.io/serviceaccount/token"; | ||
const jwt = fs.readFileSync(JWT_TOKEN_FILE); | ||
|
||
if (!this.isKubelogged) { | ||
try { | ||
const result = await this.vaultClient.kubernetesLogin({ | ||
"role": this.vaultRole, | ||
"jwt": jwt.toString() | ||
}); | ||
this.vaultClient.token = result.auth.client_token; | ||
} catch (error) { | ||
console.error('Error authenticating to vault instance:', error); | ||
throw error; | ||
} | ||
this.isKubelogged = true | ||
} | ||
try { | ||
const res = await this.vaultClient.read(path); | ||
let obj = Object.keys(res.data.data) | ||
return res.data.data[obj[0]] | ||
} catch (error) { | ||
console.error('Error reading secret:', error); | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
export default VaultModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "vault-integrated", | ||
"version": "1.0.0", | ||
"description": "Vault integrated for template application", | ||
"main": "app.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"start": "node index.ts" | ||
}, | ||
"dependencies": { | ||
"node-vault": "^0.10.2" | ||
}, | ||
"devDependencies": { | ||
"typescript": "5.1.6" | ||
}, | ||
"engines": { | ||
"node": "18.11.17" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2018", | ||
"module": "commonjs", | ||
"outDir": ".", | ||
"rootDir": ".", | ||
"strict": true, | ||
"esModuleInterop": true | ||
}, | ||
"include": [ | ||
"*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
Oops, something went wrong.