Skip to content

Commit

Permalink
feat(customconfig): support for custom vault interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jalpp committed Oct 27, 2024
1 parent 819753f commit 68cb930
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 29 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Because managing tokens, pins used in various dummy/dev apps require them to be
- Automatically config password/token lengths and other settings
- Hashicorp Vault integration to connect to secure vault and store generated secrets on cloud
- 1Password integration to connect to secure vault and store generated secrets on cloud
- Custom vaults support via extend package in passdiy to allow you to connect to your own cloud vaults via passDiy UI

## Hashicorp Vault Commands
- hcpvaultconnect automatically connect to hcp vault via service principle
Expand All @@ -34,6 +35,8 @@ Because managing tokens, pins used in various dummy/dev apps require them to be
- 1passstore store secrets into the vault via name|password|url format
- 1passwordlist list secret names for connected vault

## Custom Vault
Don't see a vault you use, but not supported by PassDIY? No worries! write your own vaults driver code in `/extend` within provided functions and set `export USE_PASDIY_CUSTOM_VAULT=true`to connect PassDIY to your vault provider. Read `/extend/README.md`

## Demo

Expand All @@ -55,9 +58,37 @@ To allow PassDIY to connect to your 1Password Vault you would need to set [servi

`export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>`

## Config
## Config custom vault to use PassDIY TUI

you can config PassDIY's password/token/pin char lengths additional confiurations by running config command
to config custom vaults that are not currently supported by Passdiy all you have to do is edit the interface.go file and define your custom implementation of the functions, then you set `export USE_PASDIY_CUSTOM_VAULT=true` and PassDIY will automatically interface the custom vault

```go
package extend

var (
VAULT_PREFIX = "pref"
VAULT_MAIN_DESC = "Manage token/password on " + VAULT_PREFIX
VAULT_SUBCOMMAND_NAMES = []string{VAULT_PREFIX + "store", VAULT_PREFIX + "list"}
VAULT_SUBCOMMAND_DESC = []string{"store", "lists"}
VAULT_DISPLAY_COLOR = "#E2EAF4"
)

func ConnectUI() string {
return Connect()
}

func StoreUI(userInput string) string {

var parser string

return Create(userInput, parser)
}

func ListUI() string {
return List()
}

```



Expand Down
64 changes: 45 additions & 19 deletions cmds/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package cmds

import (
"fmt"
"os"
"strings"
"time"

"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
custom "github.com/jalpp/passdiy/extend"
hcp "github.com/jalpp/passdiy/hcpvault"
opass "github.com/jalpp/passdiy/onepassword"
cmd "github.com/jalpp/passdiy/password"
Expand All @@ -23,16 +25,16 @@ var (
hashDesc = "Generate hash value of a password with Argon2id or bcrypthash"
argonhashDesc = "Generate hash value of a password with Argon2id"
bcrpthashDesc = "Generate hash value of a password with bcrypt algorithm"
hcpvaultstoreDesc = "Store a new secret to Hashicorp Vault"
hcpvaultconnectDesc = "Generate HCP API token and connect to Hashicorp Vault"
hcpvaultlistDesc = "List HCP Vault secrets log details"
opassstoreDesc = "Store a new secret to 1Password in password format"
opasslistDesc = "List 1Password Vault item names"
hcpvaultstoreDesc = hcp.VAULT_SUBCOMMAND_DESC[1]
hcpvaultconnectDesc = hcp.VAULT_SUBCOMMAND_DESC[0]
hcpvaultlistDesc = hcp.VAULT_SUBCOMMAND_DESC[2]
opassstoreDesc = opass.VAULT_SUBCOMMAND_DESC[0]
opasslistDesc = opass.VAULT_SUBCOMMAND_DESC[1]
mainpassDesc = "Generate strong passwords from various algorithms"
mainpinDesc = "Generate strong pins from various algorithms"
maintokenDesc = "Generate strong token from various algorithms"
hcpDesc = "Manage Token/Password on Hashicorp Vault"
opassDesc = "Manage Token/Password on 1Password"
hcpDesc = hcp.VAULT_MAIN_DESC
opassDesc = opass.VAULT_MAIN_DESC
configDesc = "Config PassDIY password, token, pin, salt char lengths"
)

Expand Down Expand Up @@ -97,14 +99,34 @@ func CreateCommandItems() []list.Item {
}

hcpItems := []CommandItem{
{title: "hcpvaultstore", desc: hcpvaultstoreDesc},
{title: "hcpvaultconnect", desc: hcpvaultconnectDesc},
{title: "hcpvaultlist", desc: hcpvaultlistDesc},
{title: hcp.VAULT_SUBCOMMAND_NAMES[1], desc: hcpvaultstoreDesc},
{title: hcp.VAULT_SUBCOMMAND_NAMES[0], desc: hcpvaultconnectDesc},
{title: hcp.VAULT_SUBCOMMAND_NAMES[2], desc: hcpvaultlistDesc},
}

opassItems := []CommandItem{
{title: "1passstore", desc: opassstoreDesc},
{title: "1passlist", desc: opasslistDesc},
{title: opass.VAULT_SUBCOMMAND_NAMES[0], desc: opassstoreDesc},
{title: opass.VAULT_SUBCOMMAND_NAMES[1], desc: opasslistDesc},
}

customItems := []CommandItem{
{title: custom.VAULT_SUBCOMMAND_NAMES[0], desc: custom.VAULT_SUBCOMMAND_DESC[0]},
{title: custom.VAULT_SUBCOMMAND_NAMES[1], desc: custom.VAULT_SUBCOMMAND_DESC[1]},
}

if strings.ToLower(os.Getenv("USE_PASDIY_CUSTOM_VAULT")) == "true" {
return []list.Item{
CommandItem{title: "pass", desc: mainpassDesc, Subcmd: passItems},
CommandItem{title: "pin", desc: mainpinDesc, Subcmd: pinItems},
CommandItem{title: "token", desc: maintokenDesc, Subcmd: tokenItems},
CommandItem{title: "salt", desc: saltDesc},
CommandItem{title: "pwp", desc: pwpDesc},
CommandItem{title: "config", desc: configDesc, Subcmd: configItems},
CommandItem{title: "hash", desc: hashDesc, Subcmd: hashItems},
CommandItem{title: hcp.VAULT_PREFIX, desc: hcpDesc, Subcmd: hcpItems},
CommandItem{title: opass.VAULT_PREFIX, desc: opassDesc, Subcmd: opassItems},
CommandItem{title: custom.VAULT_PREFIX, desc: custom.VAULT_MAIN_DESC, Subcmd: customItems},
}
}

return []list.Item{
Expand All @@ -115,8 +137,8 @@ func CreateCommandItems() []list.Item {
CommandItem{title: "pwp", desc: pwpDesc},
CommandItem{title: "config", desc: configDesc, Subcmd: configItems},
CommandItem{title: "hash", desc: hashDesc, Subcmd: hashItems},
CommandItem{title: "hcpvault", desc: hcpDesc, Subcmd: hcpItems},
CommandItem{title: "1pass", desc: opassDesc, Subcmd: opassItems},
CommandItem{title: hcp.VAULT_PREFIX, desc: hcpDesc, Subcmd: hcpItems},
CommandItem{title: opass.VAULT_PREFIX, desc: opassDesc, Subcmd: opassItems},
}
}

Expand Down Expand Up @@ -181,16 +203,20 @@ func HandleCommand(input, userInput string) string {
return cmd.SetMulCount(userInput)
case "configsalt":
return cmd.SetSaltLength(userInput)
case "hcpvaultstore":
case hcp.VAULT_SUBCOMMAND_NAMES[1]:
return hcp.StoreUI(userInput)
case "hcpvaultconnect":
case hcp.VAULT_SUBCOMMAND_NAMES[0]:
return hcp.ConnectUI()
case "hcpvaultlist":
case hcp.VAULT_SUBCOMMAND_NAMES[2]:
return hcp.ListUI()
case "1passstore":
case opass.VAULT_SUBCOMMAND_NAMES[0]:
return opass.StoreUI(userInput)
case "1passlist":
case opass.VAULT_SUBCOMMAND_NAMES[1]:
return opass.ListUI()
case custom.VAULT_SUBCOMMAND_NAMES[0]:
return custom.StoreUI(userInput)
case custom.VAULT_SUBCOMMAND_NAMES[1]:
return custom.ListUI()
default:
return fmt.Sprintf("Unknown command: %s", input)
}
Expand Down
31 changes: 31 additions & 0 deletions extend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Config custom vault to use PassDIY TUI

to config custom vaults that are not currently supported by Passdiy all you have to do is edit the interface.go file and define your custom implementation of the functions, then you set `export USE_PASDIY_CUSTOM_VAULT=true` and PassDIY will automatically interface the custom vault

```go
package extend

var (
VAULT_PREFIX = "pref"
VAULT_MAIN_DESC = "Manage token/password on " + VAULT_PREFIX
VAULT_SUBCOMMAND_NAMES = []string{VAULT_PREFIX + "store", VAULT_PREFIX + "list"}
VAULT_SUBCOMMAND_DESC = []string{"store", "lists"}
VAULT_DISPLAY_COLOR = "#E2EAF4"
)

func ConnectUI() string {
return Connect()
}

func StoreUI(userInput string) string {

var parser string

return Create(userInput, parser)
}

func ListUI() string {
return List()
}

```
11 changes: 11 additions & 0 deletions extend/connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package extend

// add connect implementation for vault here

func connectHelper() {

}

func Connect() string {
return "Extended Vault Connect Message"
}
11 changes: 11 additions & 0 deletions extend/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package extend

// add create implementation for vault here

func createHelper() {

}

func Create(name string, val string) string {
return "Extanded Vault Create Message"
}
24 changes: 24 additions & 0 deletions extend/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package extend

var (
VAULT_PREFIX = "pref"
VAULT_MAIN_DESC = "Manage token/password on " + VAULT_PREFIX
VAULT_SUBCOMMAND_NAMES = []string{VAULT_PREFIX + "store", VAULT_PREFIX + "list"}
VAULT_SUBCOMMAND_DESC = []string{"store", "lists"}
VAULT_DISPLAY_COLOR = "#E2EAF4"
)

func ConnectUI() string {
return Connect()
}

func StoreUI(userInput string) string {

var parser string

return Create(userInput, parser)
}

func ListUI() string {
return List()
}
11 changes: 11 additions & 0 deletions extend/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package extend

// add list implementation for vault here

func listHelper() {

}

func List() string {
return "Extanded Vault List Message"
}
24 changes: 16 additions & 8 deletions hcpvault/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package hcpvault

import "strings"

var (
VAULT_PREFIX = "hcpvault"
VAULT_MAIN_DESC = "Manage Token/Password on Hashicorp Vault"
VAULT_SUBCOMMAND_NAMES = []string{VAULT_PREFIX + "connect", VAULT_PREFIX + "store", VAULT_PREFIX + "list"}
VAULT_SUBCOMMAND_DESC = []string{"Generate HCP API token and connect to Hashicorp Vault", "Store a new secret to Hashicorp Vault", "List HCP Vault secrets log details"}
VAULT_DISPLAY_COLOR = "#FFDE59"
)

func ConnectUI() string {
return Connect()
}

func ListUI() string {
var list string = List()
if strings.Contains(list, "Unauthorized") {
return "Please connect to Hashicorp vault via hcpvaultconnect"
}
return list
}

func StoreUI(userInput string) string {
parts := strings.SplitN(userInput, "=", 2)
if len(parts) == 2 {
Expand All @@ -23,3 +23,11 @@ func StoreUI(userInput string) string {
}
return "Invalid format. Use 'name=value'."
}

func ListUI() string {
var list string = List()
if strings.Contains(list, "Unauthorized") {
return "Please connect to Hashicorp vault via hcpvaultconnect"
}
return list
}
8 changes: 8 additions & 0 deletions onepassword/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ package onepassword

import "strings"

var (
VAULT_PREFIX = "1pass"
VAULT_MAIN_DESC = "Manage Token/Password on 1Password"
VAULT_SUBCOMMAND_NAMES = []string{VAULT_PREFIX + "store", VAULT_PREFIX + "list"}
VAULT_SUBCOMMAND_DESC = []string{"Store a new secret to 1Password in password format", "List 1Password Vault item names"}
VAULT_DISPLAY_COLOR = "#4CAAF7"
)

func StoreUI(userInput string) string {
parts := strings.SplitN(userInput, "|", 3)
if len(parts) == 3 {
Expand Down

0 comments on commit 68cb930

Please sign in to comment.