Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 50788b2

Browse files
committed
app rolename as vault paths. added cli parameter for rolename.
1 parent bb66938 commit 50788b2

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ PLAY RECAP *********************************************************************
122122
### Running kubectl & helm via gostint
123123
Using a KUBECONFIG stored base64 encoded in the vault as a secret:
124124
```
125-
$ vault kv put secret/k8s_cluster_1 kubeconfig_base64=$(base64 -w0 admin.conf)
125+
$ vault kv put secret/k8s_cluster_1 kubeconfig_base64=$(base64 -w0 ~/k8s/openstack/admin.conf)
126126
Success! Data written to: secret/k8s_cluster_1
127127
```
128128
Test kubectl can use the vaulted config:
@@ -181,7 +181,7 @@ path "auth/token/create" {
181181
path "auth/approle/role/gostint-role/secret-id" {
182182
capabilities = ["update"]
183183
}
184-
path "transit/encrypt/gostint" {
184+
path "transit/encrypt/gostint-role" {
185185
capabilities = ["update"]
186186
}
187187
EOF
@@ -196,7 +196,7 @@ vault write auth/approle/role/gostint-client-role \
196196
```
197197
Get the Role_Id for the AppRole:
198198
```
199-
vault read /auth/approle/role/gostint-client-role/role-id
199+
vault read auth/approle/role/gostint-client-role/role-id
200200
```
201201
For this example we will use PUSH mode on the AppRole (not the secret_id was a
202202
random uuid) - you would probably prefer to use PULL mode in production:

clientapi/clientapi.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type APIRequest struct {
6262
AppRoleID *string
6363
AppSecretID *string // AppRole auth or Token
6464
Token *string
65+
GoStintRole *string
6566
JobJSON *string // request can be whole JSON:
6667
QName *string // or can be passed as parameters:
6768
ContainerImage *string
@@ -342,7 +343,10 @@ func RunJob(c *APIRequest, debugLogging bool, pollSecs int, waitFor bool) (*GetR
342343

343344
debug("Getting Wrapped Secret_ID for the AppRole")
344345
vc.SetWrappingLookupFunc(func(op, path string) string { return "1h" })
345-
sec, err = vc.Logical().Write("auth/approle/role/gostint-role/secret-id", nil)
346+
sec, err = vc.Logical().Write(
347+
fmt.Sprintf("auth/approle/role/%s/secret-id", *c.GoStintRole),
348+
nil,
349+
)
346350
if err != nil {
347351
return nil, err
348352
}
@@ -358,7 +362,10 @@ func RunJob(c *APIRequest, debugLogging bool, pollSecs int, waitFor bool) (*GetR
358362
data = map[string]interface{}{
359363
"plaintext": base64.StdEncoding.EncodeToString(jsonBytes),
360364
}
361-
sec, err = vc.Logical().Write("transit/encrypt/gostint", data)
365+
sec, err = vc.Logical().Write(
366+
fmt.Sprintf("transit/encrypt/%s", *c.GoStintRole),
367+
data,
368+
)
362369
if err != nil {
363370
return nil, err
364371
}

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func main() {
9494
c.AppSecretID = flag.String("vault-secretid", "", "Vault App Secret ID (can read file e.g. '@secret_id.txt')")
9595
c.Token = flag.String("vault-token", "", "Vault token - used instead of App Role (can read file e.g. '@token.txt')")
9696

97+
c.GoStintRole = flag.String("gostint-approle", "gostint-role", "Vault App Role Name of GoStint to run job on (can read file e.g. '@gostint_role.txt')")
98+
9799
c.JobJSON = flag.String("job-json", "", "JSON Job request")
98100

99101
c.QName = flag.String("qname", "", "Job Queue to submit to, overrides value in job-json")
@@ -127,6 +129,8 @@ func main() {
127129
chkError(err)
128130
err = tryResolveFile(c.Token)
129131
chkError(err)
132+
err = tryResolveFile(c.GoStintRole)
133+
chkError(err)
130134
err = tryResolveFile(c.JobJSON)
131135
chkError(err)
132136

0 commit comments

Comments
 (0)