Skip to content

Commit

Permalink
introduce output format render
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Morelly committed Apr 27, 2022
1 parent 1e93616 commit e29b696
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 341 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ vkv
vendor/
coverage.out
/dist
.envrc
format.yaml
.envrc
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,4 @@ vault:

.PHONY: kill
kill:
@kill -9 $(shell pgrep -x vault) 2> /dev/null || true

.PHONY: gif
gif:
terminalizer record demo -k -c assets/config.yml
terminalizer render demo -o assets/demo.gif
@kill -9 $(shell pgrep -x vault) 2> /dev/null || true
278 changes: 19 additions & 259 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# vkv
<div align="center">
<h1> vkv </h1>
<img src="assets/base.svg" alt="drawing" height="400" width="550">

[![Test](https://github.com/FalcoSuessgott/vkv/actions/workflows/test.yml/badge.svg)](https://github.com/FalcoSuessgott/vkv/actions/workflows/test.yml) [![golangci-lint](https://github.com/FalcoSuessgott/vkv/actions/workflows/lint.yml/badge.svg)](https://github.com/FalcoSuessgott/vkv/actions/workflows/lint.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/FalcoSuessgott/vkv)](https://goreportcard.com/report/github.com/FalcoSuessgott/vkv) [![codecov](https://codecov.io/gh/FalcoSuessgott/vkv/branch/master/graph/badge.svg?token=UYVZ8LTA45)](https://codecov.io/gh/FalcoSuessgott/vkv)
[![Test](https://github.com/FalcoSuessgott/vkv/actions/workflows/test.yml/badge.svg)](https://github.com/FalcoSuessgott/vkv/actions/workflows/test.yml) [![golangci-lint](https://github.com/FalcoSuessgott/vkv/actions/workflows/lint.yml/badge.svg)](https://github.com/FalcoSuessgott/vkv/actions/workflows/lint.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/FalcoSuessgott/vkv)](https://goreportcard.com/report/github.com/FalcoSuessgott/vkv) [![codecov](https://codecov.io/gh/FalcoSuessgott/vkv/branch/master/graph/badge.svg?token=UYVZ8LTA45)](https://codecov.io/gh/FalcoSuessgott/vkv)
[![Github all releases](https://img.shields.io/github/downloads/FalcoSuessgott/vkv/total.svg)](https://GitHub.com/FalcoSuessgott/vkv/releases/)
</div>

![img](assets/demo.gif)

# Description
`vkv` recursively list you all key-value entries from Vaults KV2 secret engine in various formats. `vkv` flags can be devided into input, modifying and output format flags.
Expand All @@ -16,22 +18,23 @@ So far `vkv` offers:
### Modifying flags
* `--only-keys`: show only keys (env: `VKV_ONLY_KEYS`, default: `false`)
* `--only-paths`: show only paths (env: `VKV_ONLY_PATHS`, default: `false`)
* `-show-values`: dont mask values (env: `VKV_SHOW_VALUES`, default: `false`)
* `--show-values`: dont mask values (env: `VKV_SHOW_VALUES`, default: `false`)
* `--max-value-length`: maximum char length of values (set to `-1` for disabling) (env: `VKV_MAX_VALUE_LENGTH`, default: `12`)
* `--template-file`: path to a file containing Go-template syntax to render the KV entries (env: `VKV_TEMPLATE_FILE`)
* `--template-string`: string containting Go-template syntax to render KV entries (env: `VKV_TEMPLATE_STRING`)

### Output Flags
* `-f | --format`: output format (options: `base`, `yaml`, `json`, `export`, `markdown`) (env: `"VKV_FORMAT"`, default: `"base"`)
### Output Flags (see [Supported Formats](https://github.com/FalcoSuessgott/vkv/tree/template#supported-formats))
* `-f | --format`: output format (options: `base`, `yaml`, `json`, `export`, `markdown`, `template`) (env: `"VKV_FORMAT"`, default: `"base"`)

⚠️ **A flag always preceed its environment variable**

You can combine most of those flags in order to receive the desired output.
For examples see the [Examples](https://github.com/FalcoSuessgott/vkv#examples)

# Installation
Find the corresponding binaries, `.rpm` and `.deb` packages in the [release](https://github.com/FalcoSuessgott/vkv/releases) section.

# Supported OS and Vault Versions
`vkv` is being tested on `Windows`, `MacOS` and `Linux` and also against Vault Version < `v1.8.0` (but it also may work with lower versions).
`vkv` is being tested on `Windows`, `MacOS` and `Linux` and also against Vault Version >= `v1.8.0` (but it also may work with lower versions).

# Authentication
`vkv` supports token based authentication. It is clear that you can only see the secrets that are allowed by your token policy.
Expand All @@ -48,257 +51,14 @@ SET VAULT_TOKEN=s.XXX
vkv.exe -p <kv-path>
```

# Examples
Imagine you have the following KV2 structure mounted at path `secret/`:
# Supported Formats
| | |
|:-------------:|:-------------------------------:|
| `base`<br> ![](assets/base.svg)| `markdown`<br> ![](assets/markdown.svg) |
| `json`<br> ![](assets/json.svg)| `yaml`<br> ![](assets/yaml.svg) |

```
secret/
demo
foo=bar
sub
sub=passw0rd
sub/demo
demo="hello world"
password=s3cre5
user=admin
sub/sub2/demo
value=nevermind
password=secret2
user=database
```

## Input
### list secrets (`--path` | `-p` | `VKV_PATHS="kv1:kv2"`)
You can list all secrets recursively by running:

```bash
$> vkv --path secret
secret/
├── demo
│ └── foo=***
├── sub
│ └── sub=********
├── sub/
│ └── demo
│ ├── demo=***********
│ ├── password=******
│ └── user=*****
└── sub/
└── sub2/
└── demo
├── user=************
└── value=*********
```

You can also specifiy a specific subpaths:

```bash
$> vkv --path secret/sub/sub2
secret/sub/sub2/
└── sub/
└── sub2/
└── demo
├── user=************
└── value=*********
```

and list as much paths as you want:

```bash
# or as comma separated with no spaces!
$> vkv -p secret -p secret2
secret/
├── demo
│ └── foo=***
├── sub
│ └── sub=********
├── sub/
│ └── demo
│ ├── demo=***********
│ ├── password=******
│ └── user=*****
└── sub/
└── sub2/
└── demo
├── user=************
└── value=*********
secret_2/
├── demo
│ └── foo=***
├── sub
│ └── sub=********
├── sub/
│ └── demo
│ ├── foo=***
│ ├── password=********
│ └── user=****
└── sub/
└── sub2/
└── demo
├── foo=***
├── password=********
└── user=****
```

## Modifying
### list only paths (`--only-paths` | `VKV_ONLY_PATHS=true`)
We can receive only the paths by running

```bash
$> vkv -p secret --only-paths
secret/
├── demo
├── sub
├── sub/
│ └── demo
└── sub/
└── sub2/
└── demo
```

### list only secret keys (`--only-keys` | `VKV_ONLY_KEYS=true`)
If we want to know just the keys in every directory we can run

```bash
$> vkv -p secret --only-keys
secret/
├── demo
│ └── foo
├── sub
│ └── sub
├── sub/
│ └── demo
│ ├── demo
│ ├── password
│ └── user
└── sub/
└── sub2/
└── demo
├── user
└── value
```

### show values (`--show-values` | `VKV_SHOW_VALUES=true`)
Per default values are masked. Using `--show-values` shows the values. **Use with Caution**

```bash
$> vkv -p secret --show-values
secret/
├── demo
│ └── foo=bar
├── sub
│ └── sub=password
├── sub/
│ └── demo
│ ├── demo=hello world
│ ├── password=s3cre5
│ └── user=admin
└── sub/
└── sub2/
└── demo
├── user=databasepassword=secret2
└── value=nevermind
```

## Output Format
### export format (`--format=export` | `VKV_FORMAT=export`)
You can print out the entries in `export key=value` format for further processing:

```bash
$> vkv --path secret/sub/sub2 --format=export
export demo="hello world"
export password="s3cre5"
export user="admin"
export user="databasepassword=secret2"
export value="nevermind"
export foo="bar"
export sub="password
```
You can then use `eval` to source those env vars:
```bash
echo $foo # not defined
eval $(vkv -f=export --path secret/sub/sub2)
echo $foo
"bar" # value under the specific key exported
```
## markdown (`--format=markdown` | `VKV_FORMAT=markdown`)
```bash
vkv -p secret --format=markdown
```
returns:
| MOUNT | PATHS | KEYS | VALUES |
|--------|----------------------|----------|--------------|
| secret | secret/demo | foo | *** |
| | secret/sub | sub | ******** |
| | secret/sub/demo | demo | *********** |
| | | password | ****** |
| | | user | ***** |
| | secret/sub/sub2/demo | user | ************ |
| | | value | ********* |
### json (`--format=json` | `VKV_FORMAT=json`)
You can combine all flags and export the result to json by running:
```bash
vkv -p secret --show-values --format=json
```
```json
{
"secret": {
"secret/demo": {
"foo": "***"
},
"secret/sub": {
"sub": "********"
},
"secret/sub/demo": {
"demo": "***********",
"password": "******",
"user": "*****"
},
"secret/sub/sub2/demo": {
"user": "************",
"value": "*********"
}
}
}%
```
### yaml (`--format=yaml` | `VKV_FORMAT=yaml`)
Same applies for yaml:
```bash
vkv --path secret --show-values --format=yaml
```
```yaml
secret:
secret/demo:
foo: '***'
secret/sub:
sub: '********'
secret/sub/demo:
demo: '***********'
password: '******'
user: '*****'
secret/sub/sub2/demo:
user: '************'
value: '*********'
```
| |
|:---:|
| `template`<br> <img src="assets/template.svg" width="600" /> |

# Acknowledgements / Similar tools
`vkv` is inspired by:
* https://github.com/jonasvinther/medusa

Similar tools are:
* https://github.com/kir4h/rvault
17 changes: 17 additions & 0 deletions assets/base.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 0 additions & 54 deletions assets/config.yml

This file was deleted.

Binary file removed assets/demo.gif
Binary file not shown.
8 changes: 0 additions & 8 deletions assets/demo_cmds.txt

This file was deleted.

17 changes: 17 additions & 0 deletions assets/json.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions assets/markdown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions assets/template.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions assets/yaml.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e29b696

Please sign in to comment.