Skip to content

Commit 2eab893

Browse files
author
Chris S. Kim
committed
backport of commit 227762e
1 parent cea299a commit 2eab893

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

agent/connect/ca/provider_vault.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ type VaultProvider struct {
7171
spiffeID *connect.SpiffeIDSigning
7272
logger hclog.Logger
7373

74+
// isConsulMountedIntermediate is used to determine if we should tune the
75+
// mount if the VaultProvider is ever reconfigured. This is at most a
76+
// "best guess" to determine whether this instance of Consul created the
77+
// intermediate mount but will not be able to tell if an existing mount
78+
// was created by Consul (in a previous running instance) or was external.
7479
isConsulMountedIntermediate bool
7580
}
7681

@@ -398,29 +403,33 @@ func (v *VaultProvider) setupIntermediatePKIPath() error {
398403
return fmt.Errorf("unexpected error while fetching intermediate CA: %w", err)
399404
}
400405
} else {
401-
// If Consul was responsible for mounting the intermediate PKI path
402-
// we should update the mount with any new config.
403-
if v.isConsulMountedIntermediate {
404-
// This codepath requires the Vault policy:
405-
//
406-
// path "/sys/mounts/<intermediate_pki_path>/tune" {
407-
// capabilities = [ "update" ]
408-
// }
409-
//
410-
err := v.tuneMountNamespaced(v.config.IntermediatePKINamespace, v.config.IntermediatePKIPath, &mountConfig)
411-
if err != nil {
406+
v.logger.Info("Found existing Intermediate PKI path mount",
407+
"namespace", v.config.IntermediatePKINamespace,
408+
"path", v.config.IntermediatePKIPath,
409+
)
410+
411+
// This codepath requires the Vault policy:
412+
//
413+
// path "/sys/mounts/<intermediate_pki_path>/tune" {
414+
// capabilities = [ "update" ]
415+
// }
416+
//
417+
err := v.tuneMountNamespaced(v.config.IntermediatePKINamespace, v.config.IntermediatePKIPath, &mountConfig)
418+
if err != nil {
419+
if v.isConsulMountedIntermediate {
412420
v.logger.Warn("Intermediate PKI path was mounted by Consul but could not be tuned",
413421
"namespace", v.config.IntermediatePKINamespace,
414422
"path", v.config.IntermediatePKIPath,
415423
"error", err,
416424
)
425+
} else {
426+
v.logger.Debug("Failed to tune Intermediate PKI mount. 403 Forbidden is expected if Consul does not have tune capabilities for the Intermediate PKI mount (i.e. using Vault-managed policies)",
427+
"namespace", v.config.IntermediatePKINamespace,
428+
"path", v.config.IntermediatePKIPath,
429+
"error", err,
430+
)
417431
}
418432

419-
} else {
420-
v.logger.Info("Found existing Intermediate PKI path mount",
421-
"namespace", v.config.IntermediatePKINamespace,
422-
"path", v.config.IntermediatePKIPath,
423-
)
424433
}
425434
}
426435

0 commit comments

Comments
 (0)