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

Commit f0886fd

Browse files
author
Michael Weber
committed
Fix lease expiration for non-master nodes
plumb node name through to lease data.
1 parent 3407929 commit f0886fd

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

path_config_connection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (b *backend) pathConfigConnection() *framework.Path {
3535
},
3636
"is_standalone": &framework.FieldSchema{
3737
Type: framework.TypeBool,
38-
Description: "Whether this is a standalone or multi-node deployment",
38+
Description: `Whether this is a standalone or multi-node deployment. Default: false`,
3939
Default: false,
4040
},
4141
"allowed_roles": &framework.FieldSchema{
@@ -64,7 +64,7 @@ func (b *backend) pathConfigConnection() *framework.Path {
6464
Default: "tls12",
6565
Description: trimIndent(`
6666
Minimum TLS version to use. Accepted values are "tls10", "tls11" or
67-
"tls12". Defaults to "tls12".`),
67+
"tls12". Default: "tls12".`),
6868
},
6969
"pem_bundle": &framework.FieldSchema{
7070
Type: framework.TypeString,
@@ -87,7 +87,7 @@ func (b *backend) pathConfigConnection() *framework.Path {
8787
"connect_timeout": &framework.FieldSchema{
8888
Type: framework.TypeDurationSecond,
8989
Default: "30s",
90-
Description: `The connection timeout to use. Default: 30s.`,
90+
Description: `The connection timeout to use. Default: 30s.`,
9191
},
9292
},
9393

path_creds_create.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313

1414
const (
1515
SEARCHHEAD = "search_head"
16-
INDEXER = "indexer"
16+
INDEXER = "indexer"
1717
)
18+
1819
func (b *backend) pathCredsCreate() *framework.Path {
1920
return &framework.Path{
2021
Pattern: "creds/" + framework.GenericNameRegex("name"),
@@ -161,7 +162,7 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
161162
}
162163
// Check if isStandalone is set
163164
if config.IsStandalone {
164-
return nil, fmt.Errorf("expected is_standalone to be set for connection: %q", role.Connection)
165+
return nil, fmt.Errorf("expected is_standalone to be unset for connection: %q", role.Connection)
165166
}
166167

167168
// If role name isn't in allowed roles, send back a permission denied.
@@ -186,8 +187,8 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
186187

187188
// Re-create connection for node
188189
config.URL = "https://" + nodeFQDN + ":8089"
189-
config.ID = ""
190-
conn, err = b.ensureConnection(ctx, config)
190+
// XXX config.ID = ""
191+
conn, err = config.newConnection(ctx) // XXX cache
191192
if err != nil {
192193
return nil, err
193194
}
@@ -230,6 +231,7 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
230231
"username": username,
231232
"role": name,
232233
"connection": role.Connection,
234+
"node_fqdn": nodeFQDN,
233235
})
234236
resp.Secret.TTL = role.DefaultTTL
235237
resp.Secret.MaxTTL = role.MaxTTL

secret_creds.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/hashicorp/vault/logical"
99
"github.com/hashicorp/vault/logical/framework"
10+
"github.com/splunk/vault-plugin-splunk/clients/splunk"
1011
)
1112

1213
const secretCredsType = "creds"
@@ -35,6 +36,12 @@ func (b *backend) secretCredsRenewHandler(ctx context.Context, req *logical.Requ
3536
return nil, fmt.Errorf("error during renew: could not find role with name %q", roleName)
3637
}
3738

39+
nodeFQDN := ""
40+
nodeFQDNRaw, ok := req.Secret.InternalData["node_fqdn"]
41+
if ok {
42+
nodeFQDN = nodeFQDNRaw.(string)
43+
}
44+
3845
// Make sure we increase the VALID UNTIL endpoint for this user.
3946
ttl, _, err := framework.CalculateTTL(b.System(), req.Secret.Increment, role.DefaultTTL, 0, role.MaxTTL, 0, req.Secret.IssueTime)
4047
if err != nil {
@@ -51,7 +58,7 @@ func (b *backend) secretCredsRenewHandler(ctx context.Context, req *logical.Requ
5158
if err != nil {
5259
return nil, err
5360
}
54-
conn, err := b.ensureConnection(ctx, config)
61+
conn, err := b.ensureNodeConnection(ctx, config, nodeFQDN)
5562
if err != nil {
5663
return nil, err
5764
}
@@ -74,6 +81,11 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
7481
if !ok {
7582
return nil, fmt.Errorf("unable to convert connection name")
7683
}
84+
nodeFQDN := ""
85+
nodeFQDNRaw, ok := req.Secret.InternalData["node_fqdn"]
86+
if ok {
87+
nodeFQDN = nodeFQDNRaw.(string)
88+
}
7789
usernameRaw, ok := req.Secret.InternalData["username"]
7890
if !ok {
7991
return nil, fmt.Errorf("username is missing on the lease")
@@ -84,7 +96,7 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
8496
if err != nil {
8597
return nil, err
8698
}
87-
conn, err := b.ensureConnection(ctx, config)
99+
conn, err := b.ensureNodeConnection(ctx, config, nodeFQDN)
88100
if err != nil {
89101
return nil, err
90102
}
@@ -95,3 +107,15 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
95107
}
96108
return nil, nil
97109
}
110+
111+
func (b *backend) ensureNodeConnection(ctx context.Context, config *splunkConfig, nodeFQDN string) (*splunk.API, error) {
112+
b.Logger().Debug(fmt.Sprintf("connection for node_fqdn: [%s]", nodeFQDN))
113+
if nodeFQDN == "" {
114+
return b.ensureConnection(ctx, config)
115+
}
116+
117+
// we connect to a node, not the cluster master
118+
nodeConfig := *config
119+
nodeConfig.URL = "https://" + nodeFQDN + ":8089"
120+
return nodeConfig.newConnection(ctx) // XXX cache
121+
}

0 commit comments

Comments
 (0)