Skip to content

Commit

Permalink
loading files
Browse files Browse the repository at this point in the history
  • Loading branch information
david-wunderlich committed Mar 4, 2022
1 parent a4861d4 commit 4307319
Show file tree
Hide file tree
Showing 7 changed files with 1,249 additions and 23 deletions.
45 changes: 22 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
# Local .terraform directories
**/.terraform/*
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# .tfstate files
*.tfstate
*.tfstate.*
# Test binary, built with `go test -c`
*.test

# Crash log files
crash.log
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars
# Dependency directories (remove the comment below to include it)
# vendor/

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json
# Go workspace file
go.work

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf
# additons for this project
.DS_Store
.idea
.vscode

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
/bin
90 changes: 90 additions & 0 deletions README2.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# scalesecSecretStore: Example Plugin

Example custom Hashicorp custom secret engine plugin. It helps illustrate what happens in the lifecycle calls of vault. It provides a starting point to build out your own custom plugin.

**Setup:**
* Installation of Go Lang
* Installation of Hashicorp Vault: Recommend the ScaleSec Vault Assistant project: xxxxxx
* VSCode is recommended for an IDE
* Checkout code from GitHub

`make-scalesec-secret-store-plugin.sh`: command script to help you build and deploy the plugin code. It takes in the following arguments in sequence you wish executed:
* debug - Set the debug flags for the a build
* build - Build the plugin
* deploy - Deploy and Register the plugin to vault. Handles removing prior installs
* test - Run all the test functions listed below
* test_list - Test/Run just the vault list function
* test_read - Test/Run just the vault read function
* test_write - Test/Run just the vault write function
* test_delete - Test/Run just the vault delete function

_Example Usage:_
`make-scalesec-secret-store-plugin.sh build deploy`


## Debugging

There are two options using the interactive debugger in VSCode.
* Command Line
* VSCode Debugger GUI

**Setup:**
* Install of "Delve" is required. The most common way to install is running the command: `go install github.com/go-delve/delve/cmd/dlv@latest`

For more detailed install information visit the Delve web site: https://github.com/go-delve/delve

* Compile for debugging. Compile with the flags: -gcflags "all=-N -l". Run: `make-scalesec-secret-store-plugin.sh debug build`

**_Command Line_**
1. Install and register your plugin. `make-scalesec-secret-store-plugin.sh deploy`
2. Run a vault command to start the plugin backend. `vault list scalesecsecrets/test`
3. Locate the process that above step created. `ps -ef | grep scalesecSecretStorePlugin` or `pgrep scalesecSecretStorePlugin`
4. Run dlv to attach to the process `$HOME/go/bin/dlv attach 56135` You should now have a (dlv) command line.
5. Set some breakpoins and now your ready to invoke your plugin to debug
- [ ] `export VAULT_CLIENT_TIMEOUT=300` To extend the CLI timeout to give you time to debug
- [ ] `vault list scalesecsecrets/test` Run the command you want to debug

_Delve Commands:_ Enter help to learn the commands to use dlv. Hear are some to help

* b = set break point
* n = next line
* c = continue to next break point
* args = show values of arguments passed to current function
* locals = show values of local function variables
* exit = exit

**_VSCode Debugger GUI_**

1. Install and register your plugin. `make-scalesec-secret-store-plugin.sh deploy`
2. Run a vault command to start the plugin backend. `vault list scalesecsecrets/test`
3. Locate the process that above step created. `ps -ef | grep scalesecSecretStorePlugin` or `pgrep scalesecSecretStorePlugin`
4. Create a debug "launch.json" file: https://code.visualstudio.com/docs/editor/debugging
5. Your launch.json should contain the following block of code. #### should be replaced with the process number you located in step 3
```
{
"name": "Attach to local process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": ####
}
```
6. Run this launch config from the debugger.
7. Set some breakpoints and now your ready to invoke your plugin to debug
- [ ] `export VAULT_CLIENT_TIMEOUT=300` To extend the CLI timeout to give you time to debug
- [ ] `vault list scalesecsecrets/test` Run the command you want to debug




https://learn.hashicorp.com/tutorials/vault/getting-started-secrets-engines

https://learn.hashicorp.com/tutorials/vault/plugin-backends

https://discuss.hashicorp.com/t/debug-vault-plugin-with-vs-code/14806/2

https://groups.google.com/g/vault-tool/c/oV5bi1ls76s

https://github.com/golang/vscode-go/blob/master/docs/debugging.md

https://github.com/golang/vscode-go/blob/master/docs/debugging-legacy.md#selecting-legacy-debug-adapter
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module scalesec.com/scalesec-secret-store

go 1.16

require (
github.com/fatih/color v1.7.0 // indirect
github.com/hashicorp/errwrap v1.1.0
github.com/hashicorp/go-hclog v1.1.0 // indirect
github.com/hashicorp/vault/api v1.3.1
github.com/hashicorp/vault/sdk v0.3.0
github.com/mitchellh/gox v1.0.1 // indirect
)
Loading

0 comments on commit 4307319

Please sign in to comment.