@@ -12,11 +12,6 @@ import (
12
12
"github.com/splunk/vault-plugin-splunk/clients/splunk"
13
13
)
14
14
15
- const (
16
- SEARCHHEAD = "search_head"
17
- INDEXER = "indexer"
18
- )
19
-
20
15
func (b * backend ) pathCredsCreate () * framework.Path {
21
16
return & framework.Path {
22
17
Pattern : "creds/" + framework .GenericNameRegex ("name" ),
@@ -129,20 +124,23 @@ func (b *backend) credsReadHandlerStandalone(ctx context.Context, req *logical.R
129
124
return resp , nil
130
125
}
131
126
132
- func findNode (nodeFQDN string , hosts []splunk.ServerInfoEntry ) (bool , error ) {
127
+ func findNode (nodeFQDN string , hosts []splunk.ServerInfoEntry , roleConfig * roleConfig ) (bool , error ) {
133
128
for _ , host := range hosts {
134
129
// check if node_fqdn is in either of HostFQDN or Host. User might not always the FQDN on the cli input
135
130
if host .Content .HostFQDN == nodeFQDN || host .Content .Host == nodeFQDN {
136
- // Return true if the requested node is a search head
131
+ // Return true if the requested node type is allowed
132
+ if strutil .StrListContains (roleConfig .AllowedNodeTypes , "*" ) {
133
+ return true , nil
134
+ }
137
135
for _ , role := range host .Content .Roles {
138
- if role == SEARCHHEAD {
136
+ if strutil . StrListContainsGlob ( roleConfig . AllowedNodeTypes , role ) {
139
137
return true , nil
140
138
}
141
139
}
142
- return false , fmt .Errorf ("host: %s isn't search head; creating ephemeral creds is only supported for search heads " , nodeFQDN )
140
+ return false , fmt .Errorf ("host %q does not have an allowed node type " , nodeFQDN )
143
141
}
144
142
}
145
- return false , fmt .Errorf ("host: %s not found" , nodeFQDN )
143
+ return false , fmt .Errorf ("host %q not found" , nodeFQDN )
146
144
}
147
145
148
146
func (b * backend ) credsReadHandlerMulti (ctx context.Context , req * logical.Request , d * framework.FieldData ) (* logical.Response , error ) {
@@ -181,7 +179,7 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
181
179
b .Logger ().Error ("Error while reading SearchPeers from cluster master" , err )
182
180
return nil , errwrap .Wrapf ("unable to read searchpeers from cluster master: {{err}}" , err )
183
181
}
184
- _ , err = findNode (nodeFQDN , nodes )
182
+ _ , err = findNode (nodeFQDN , nodes , role )
185
183
if err != nil {
186
184
return nil , err
187
185
}
@@ -207,7 +205,6 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
207
205
if err != nil {
208
206
return nil , errwrap .Wrapf ("error generating new password: {{err}}" , err )
209
207
}
210
- conn .Params ().BaseURL = nodeFQDN
211
208
opts := splunk.CreateUserOptions {
212
209
Name : username ,
213
210
Password : passwd ,
0 commit comments