-
Notifications
You must be signed in to change notification settings - Fork 63
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
1 parent
b90fccf
commit 8566ffe
Showing
16 changed files
with
375 additions
and
41 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,37 @@ | ||
# Vault(KV Engines only) | ||
InfraBox can fetch values as environment from vault service, so if your variable rotation regularly, you can configure it with vault in your projects. You just need to update the variable in Vault rather than update in your Infrabox project when the variable rotation. Login to the InfraBox Dashboard, select your project and go to the Settings tab. There you can create a vault with a name, a url, a namespace, a version, a token and a ca certificate. | ||
|
||
## Parameters explanation | ||
|
||
name: a DIY name (e.g. myvault) | ||
|
||
url: the url of vault service (e.g. https://vault-service.com:1234) | ||
|
||
namespace: the Vault's namespace, only enterprise edition enable namespace. | ||
|
||
version:Vault provide version 1 or 2 for KV engine. just set it with 1 or 2. | ||
|
||
token: a token to access Vault. | ||
|
||
ca: provide ca certificate if using https. | ||
|
||
|
||
|
||
## Using secrets as environment variable | ||
If you have created a [vault](#vault) you can make it available as a environment variable. | ||
|
||
```json | ||
{ | ||
"version": 1, | ||
"jobs": [{ | ||
... | ||
"environment": { | ||
"SOME_VALUE": { | ||
"$vault": " the name of the vault", | ||
"$vault_secret_path": "the secret path in vault's kv engine", | ||
"$vault_secret_key": "the key of the vault secret" | ||
}, | ||
} | ||
}] | ||
} | ||
``` |
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
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,56 @@ | ||
from flask import request, g, abort | ||
from flask_restx import Resource, fields | ||
|
||
from pyinfraboxutils.ibflask import OK | ||
from pyinfraboxutils.ibrestplus import api, response_model | ||
|
||
ns = api.namespace('Vault', | ||
path='/api/v1/projects/<project_id>/vault', | ||
description='Vault service related operations') | ||
|
||
project_vault_model = api.model('VaultService', { | ||
'name': fields.String(required=True), | ||
'url': fields.String(required=True), | ||
'namespace': fields.String(required=False), | ||
'version': fields.String(required=True), | ||
'token': fields.String(required=True), | ||
'ca': fields.String(required=False), | ||
'id': fields.String(required=False) | ||
}) | ||
|
||
@ns.route('/') | ||
@api.doc(responses={403: 'Not Authorized'}) | ||
class Tokens(Resource): | ||
|
||
@api.marshal_with(project_vault_model) | ||
def get(self, project_id): | ||
'''one | ||
Returns project's vault service | ||
''' | ||
v = g.db.execute_many_dict(''' | ||
SELECT id, name, url, namespace, version, token, ca | ||
FROM vault | ||
WHERE project_id = %s | ||
''', [project_id]) | ||
return v | ||
|
||
@api.expect(project_vault_model) | ||
def post(self, project_id): | ||
b = request.get_json() | ||
g.db.execute(''' | ||
INSERT INTO vault (project_id, name, url, namespace, version, token, ca) VALUES(%s, %s, %s, %s, %s, %s, %s) | ||
''', [project_id, b['name'], b['url'], b['namespace'], b['version'], b['token'], b['ca']]) | ||
g.db.commit() | ||
return OK('Successfully added vault.') | ||
|
||
|
||
@ns.route('/<vault_id>') | ||
@api.doc(responses={403: 'Not Authorized'}) | ||
class Secret(Resource): | ||
@api.response(200, 'Success', response_model) | ||
def delete(self, project_id, vault_id): | ||
g.db.execute(''' | ||
DELETE FROM vault WHERE project_id = %s and id = %s | ||
''', [project_id, vault_id]) | ||
g.db.commit() | ||
return OK('Successfully deleted vault.') |
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,108 @@ | ||
<template> | ||
<div class="m-sm full-height"> | ||
<md-card md-theme="white" class="full-height clean-card"> | ||
<md-card-header> | ||
<md-card-header-text class="setting-list"> | ||
<md-icon>security</md-icon> | ||
<span>Vault</span> | ||
</md-card-header-text> | ||
</md-card-header> | ||
<md-card-area> | ||
<md-list class="m-t-md m-b-md"> | ||
<md-list-item> | ||
<md-input-container class="m-l-sm"> | ||
<label>Name</label> | ||
<md-textarea v-model="name" required></md-textarea> | ||
</md-input-container> | ||
<md-input-container class="m-l-sm"> | ||
<label>Url</label> | ||
<md-textarea v-model="url" required></md-textarea> | ||
</md-input-container> | ||
<md-input-container class="m-l-sm"> | ||
<label>Namespace</label> | ||
<md-textarea v-model="namespace"></md-textarea> | ||
</md-input-container> | ||
<md-input-container> | ||
<label>Version</label> | ||
<md-select name="version" id="version" v-model="version" required> | ||
<md-option value="v1" class="bg-white">1</md-option> | ||
<md-option value="v2" class="bg-white">2</md-option> | ||
</md-select> | ||
</md-input-container> | ||
<md-input-container class="m-l-sm"> | ||
<label>Token</label> | ||
<md-textarea v-model="token" required></md-textarea> | ||
</md-input-container> | ||
<md-input-container class="m-l-sm"> | ||
<label>CA</label> | ||
<md-textarea v-model="ca"></md-textarea> | ||
</md-input-container> | ||
<md-button class="md-icon-button md-list-action" @click="addVault()"> | ||
<md-icon md-theme="running" class="md-primary">add_circle</md-icon> | ||
<md-tooltip>Add new Vault record</md-tooltip> | ||
</md-button> | ||
</md-list-item> | ||
<md-list-item v-for="v in project.vault" :key="v.id"> | ||
<div class="md-input-container m-r-xl md-theme-white"> | ||
{{ v.name }} | ||
</div> | ||
<md-button type="submit" class="md-icon-button md-list-action" @click="deleteVault(v.id)"> | ||
<md-icon class="md-primary">delete</md-icon> | ||
<md-tooltip>Delete secret permanently</md-tooltip> | ||
</md-button> | ||
</md-list-item> | ||
</md-list> | ||
</md-card-area> | ||
</md-card> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import NewAPIService from '../../services/NewAPIService' | ||
import NotificationService from '../../services/NotificationService' | ||
import Notification from '../../models/Notification' | ||
export default { | ||
props: ['project'], | ||
data: () => ({ | ||
name: '', | ||
url: '', | ||
namespace: '', | ||
version: '', | ||
token: '', | ||
ca: '' | ||
}), | ||
created () { | ||
this.project._loadVault() | ||
}, | ||
methods: { | ||
deleteVault (id) { | ||
NewAPIService.delete(`projects/${this.project.id}/vault/${id}`) | ||
.then((response) => { | ||
NotificationService.$emit('NOTIFICATION', new Notification(response)) | ||
this.project._reloadVault() | ||
}) | ||
.catch((err) => { | ||
NotificationService.$emit('NOTIFICATION', new Notification(err)) | ||
}) | ||
}, | ||
addVault () { | ||
const d = { name: this.name, url: this.url, namespace: this.namespace, version: this.version, token: this.token, ca: this.ca } | ||
NewAPIService.post(`projects/${this.project.id}/vault`, d) | ||
.then((response) => { | ||
NotificationService.$emit('NOTIFICATION', new Notification(response)) | ||
this.name = '' | ||
this.url = '' | ||
this.namespace = '' | ||
this.version = '' | ||
this.token = '' | ||
this.ca = '' | ||
this.project._reloadVault() | ||
}) | ||
.catch((err) => { | ||
NotificationService.$emit('NOTIFICATION', new Notification(err)) | ||
}) | ||
} | ||
} | ||
} | ||
</script> |
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
Oops, something went wrong.