Commit Graph

14 Commits

Author SHA1 Message Date
Steven Clark
bce085bd3f
Fix issue building urls with IPv6 IPs for ACME http-01 challenges (#28718)
* Fix ACME http-01 challenges for IPv6 IPs

 - We weren't properly encapsulating the IPv6 IP within the url provided
   to the http client with [].

* Add cl

* Cleanup a test println
2024-10-16 14:26:44 -04:00
Scott Miller
a0af792437
Adds ACME specific error types to errors returned by challenge validation functions. (#28678)
* wip

* Change test expectation

* changelog

* remove ultimately unnecessary changes

* adjust unit test again
2024-10-15 17:13:13 +00:00
Victor Rodriguez
8fd63b0a60
Remove direct usage of logical/pki's storageContext.Backend field (#27401)
* Add method storageContext.Logger().

* Add method storageContext.System().

* Add method storageContext.CrlBuilder().

* Add method storageContext.GetUnifiedTransferStatus().

* Add method storageContext.GetPkiManagedView().

* Add method storageContext.GetCertificateCounter().

* Add method storageContext.UseLegacyBundleCaStorage().

* Add method storageContext.GetRevokeStorageLock().

* Add acmeState to acmeContext.

Make acmeState accessible from acmeContext, so that storageContext doesn't have
to be used for this purpose.

* Decouple getAndValidateAcmeRole() from storageContext.Backend.

* Don't access Backend.ciepsState through storageContext.

* Add method storageContext.GetRole().

* Change signature of getCiepsAcmeSettings for CE compatibility.
2024-06-07 14:18:17 -04:00
Steven Clark
dbfaa6f81a
Stop processing ACME verifications when active node is stepped down (#23278)
- Do not load existing ACME challenges persisted within storage on non-active nodes. This was the main culprit of the issues, secondary nodes would load existing persisted challenges trying to resolve them but writes would fail leading to the excessive logging.
    - We now handle this by not starting the ACME background thread on non-active nodes, while also checking within the scheduling loop and breaking out. That will force a re-reading of the Closing channel that should have been called by the PKI plugin's Cleanup method.

- If a node is stepped down from being the active node while it is actively processing a verification, we could get into an infinite loop due to an ErrReadOnly error attempting to clean up a challenge entry

- Add a maximum number of retries for errors around attempting to decode,fetch challenge/authorization entries from disk. We use double the number of "normal" max attempts for these types of errors, than we would for normal ACME retry attempts to avoid collision issues. Note that these additional retry attempts are not persisted to disk and will restart on every node start

- Add a 1 second backoff to any disk related error to not immediately spin on disk/io errors for challenges.
2023-09-26 13:59:13 -04:00
hashicorp-copywrite[bot]
0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License.

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUS-1.1

* Fix test that expected exact offset on hcl file

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
2023-08-10 18:14:03 -07:00
Steven Clark
5ce57dbd00
Fix incorrect role ttl parameters in ACME tests (#21585)
- The ACME tests were using ttl_duration and max_ttl_duration instead
   of ttl and max_ttl as input parameters to roles.
 - Add missing copyright headers
2023-07-05 14:17:15 -04:00
Steven Clark
c855ba6a90
Signal ACME challenge engine if existing challenges were loaded on startup (#21115)
* Signal ACME challenge engine if existing challenges were loaded

 - Addresses an issue of existing challenges on disk not being processed until a new challenge is accepted when Vault restarts
 - Move loading of existing challenges from the plugin's initialize method into the challenge engine's thread
 - Add docker test that validates we addressed the issue and ACME works across standby nodes.

* Add cl
2023-06-12 15:09:20 +00:00
Alexander Scheel
f079b7b0a4
Add TLS-ALPN-01 Challenge Type to ACME (#20943)
* Add ACME TLS-ALPN-01 Challenge validator to PKI

This adds support for verifying the last missing challenge type,
TLS-ALPN-01 challenges, using Go's TLS library. We wish to add this as
many servers (such as Caddy) support transparently renewing certificates
via this protocol, without influencing the contents of sites served.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Enable suggesting, validating tls-alpn-01 in PKI

Notably, while RFC 8737 is somewhat vague about what identifier types
can be validated with this protocol, it does restrict SANs to be only
DNSSans; from this, we can infer that it is not applicable for IP
typed identifiers. Additionally, since this must resolve to a specific
domain name, we cannot provision it for wildcard identifiers either.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Fix test expectations to allow ALPN challenges

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add tls-alpn-01 as a supported challenge to docs

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add test for tls-alpn-01 challenge verifier

This hacks the challenge engine to allow non-standard (non-443) ports,
letting us use a local server listener with custom implementation.

In addition to the standard test cases, we run:

 - A test with a longer chain (bad),
 - A test without a DNSSan (bad),
 - A test with a bad DNSSan (bad),
 - A test with some other SANs (bad),
 - A test without a CN (good),
 - A test without any leaf (bad), and
 - A test without the extension (bad).

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add changelog entry

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Update builtin/logical/pki/acme_challenges.go

Co-authored-by: Alexander Scheel <alex.scheel@hashicorp.com>

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Co-authored-by: Kit Haines <khaines@mit.edu>
2023-06-07 16:34:00 +00:00
Alexander Scheel
08c1efa4d4
Gracefully handle CSRs without CNs (#20982)
* Allow not specifying CN on CSR

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add test case validating behavior

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add notice about failure to validate

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-06-07 08:15:19 -04:00
Steven Clark
8dde8ae29e
Fix order, authorization, challenge status when failing to validate a challenge (#20914)
* Fix ACME computed order status

* Return validation errors and status updates for authorizations

 - We now populate the error field within challenges with the error results from the challenge
 - Update the status of the challenge and authorizations to invalid when we give up on the challenge
 - Verify that only a single challenge within a given authorization can be accepted to avoid race conditions.
2023-06-01 13:33:38 -04:00
Steven Clark
1072c61e08
Add PKI ACME IP SANS test case (#20398)
* Add PKI ACME IP SANS test case

 - Leveraging the new Vault docker based tests along with nginx and
   the Go ACME library, verify that Vault can properly perform ACME
   validations for IP identifiers

* Formatting
2023-04-27 16:05:23 -04:00
Alexander Scheel
37852757b0
Add custom DNS resolver to ACME configuration (#20400)
* Handle caching of ACME config

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add DNS resolvers to ACME configuration

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add custom DNS resolver to challenge verification

This required plumbing through the config, reloading it when necessary,
and creating a custom net.Resolver instance.

Not immediately clear is how we'd go about building a custom DNS
validation mechanism that supported multiple resolvers. Likely we'd need
to rely on meikg/dns and handle the resolution separately for each
container and use a custom Dialer that assumes the address is already
pre-resolved.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Improvements to Docker harness

 - Expose additional service information, allowing callers to figure out
   both the local address and the network-specific address of the
   service container, and
 - Allow modifying permissions on uploaded container files.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add infrastructure to run Bind9 in a container for tests

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Validate DNS-01 challenge works

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-04-27 15:30:29 -04:00
Alexander Scheel
924129c699
Add ACME DNS validator (#20293)
* Add DNS challenge validation to ACME

This allows us to validate against wildcard domain names, as the HTTP-01
challenge does not support wildcard validation.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Properly delay challenge retry attempts

Previously we'd essentially semi-busy wait for a challenge to become
retry-able, as the queue itself had no knowledge of the retry after
value of the validation attempt. Now, we plumb through this value into
the queue itself, to aide selection of validations to attempt.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-04-21 13:08:27 -04:00
Alexander Scheel
dae04a8795
Add acme challenge validation engine (#20221)
* Allow creating storageContext with timeout

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add challenge validation engine to ACME

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Initialize the ACME challenge validation engine

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Trigger challenge validation on endpoint submission

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Fix GetKeyThumbprint to use raw base64

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Point at localhost for testing

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add cleanup of validation engine

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-04-19 12:31:19 -04:00