Commit Graph

639 Commits

Author SHA1 Message Date
Steven Clark
293e8b8ac5
Fix enterprise failure of TestCRLIssuerRemoval (#23038)
This fixes the enterprise failure of the test
 ```
  === FAIL: builtin/logical/pki TestCRLIssuerRemoval (0.00s)
     crl_test.go:1456:
         	Error Trace:	/home/runner/actions-runner/_work/vault-enterprise/vault-enterprise/builtin/logical/pki/crl_test.go:1456
         	Error:      	Received unexpected error:
         	            	Global, cross-cluster revocation queue cannot be enabled when auto rebuilding is disabled as the local cluster may not have the certificate entry!
         	Test:       	TestCRLIssuerRemoval
         	Messages:   	failed enabling unified CRLs on enterprise

 ```
2023-09-13 08:11:52 -04:00
Alexander Scheel
e2ff1f1c71
Clean up unused CRL entries when issuer is removed (#23007)
* Clean up unused CRL entries when issuer is removed

When a issuer is removed, the space utilized by its CRL was not freed,
both from the CRL config mapping issuer IDs to CRL IDs and from the
CRL storage entry. We thus implement a two step cleanup, wherein
orphaned CRL IDs are removed from the config and any remaining full
CRL entries are removed from disk.

This relates to a Consul<->Vault interop issue (#22980), wherein Consul
creates a new issuer on every leadership election, causing this config
to grow. Deleting issuers manually does not entirely solve this problem
as the config does not fully reclaim space used in this entry.

Notably, an observation that when deleting issuers, the CRL was rebuilt
on secondary clusters (due to the invalidation not caring about type of
the operation); for consistency and to clean up the unified CRLs, we
also need to run the rebuild on the active primary cluster that deleted
the issuer as well.

This approach does allow cleanup on existing impacted clusters by simply
rebuilding the CRL.

Co-authored-by: Steven Clark <steven.clark@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add test case on CRL removal

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

* Add changelog entry

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

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Co-authored-by: Steven Clark <steven.clark@hashicorp.com>
2023-09-12 20:56:47 +00:00
Thomas Schweizer-Bolzonello
958eb96bab
Fix typo OSCP -> OCSP (#22586) 2023-08-28 18:39:01 +00: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
8f646d52be
Refactor sign-intermediate API response (#22269)
* Refactor sign-intermediate API response

 - Allow the sign-intermediate response handling code to be shared
   across different API calls.

* Add missing cieps.go
2023-08-10 09:58:07 -04:00
Steven Clark
64460dd58b
Refactor logic on applying leaf_not_after_behavior (#22230)
- Allow us to call and apply an issuer's leaf_not_after_behavior
   to a leaf certificate from various locations.
2023-08-08 13:39:54 +00:00
Steven Clark
8a174b05b0
Add timeouts to ACME test contexts (#22205)
- The Golang ACME library will retry on failures until the passed in
   context times out. So if a test is broken it will never end until
   the context expires.
 - The timeouts are rather large to avoid some issues with slow CI
   runners, that have already triggered on a nightly 32 bit run
2023-08-04 11:09:37 -04:00
Steven Clark
66052d5431
Refactor ACME for enterprise CIEPS integration (#22188) 2023-08-03 11:24:46 -04:00
Kushneryk Pavel
64f92b40fc
bug(20562): allowed_domains are compared case-sensitive if they use g… (#22126)
* bug(20562): allowed_domains are compared case-sensitive if they use glob patterns

* bug(20562): review fixes
2023-08-02 11:09:10 -04:00
Steven Clark
6ff7d38f6a
Refactor sign/issue response logic to be usable by CIEPS codebase (#22053)
- Extract out the sign/issue certificate (non-CA) response into
   a function that can be used by the CIEPS sign/issue API handlers.
2023-07-25 15:11:09 -04:00
Steven Clark
068da27a2d
Use hclog instead of t.Logf within PKI ACME test suite (#22049)
- Avoid issues with t.Logf data race issues if a log message is
   called post test completion from a background go routine.
2023-07-25 13:24:39 -04:00
Max Bowsher
e057ee0750
OpenAPI: Define default response structure for ListOperations (#21934)
* OpenAPI: Define default response structure for ListOperations

Almost all Vault ListOperation responses have an identical response
schema. Update the OpenAPI generator to know this, and remove a few
instances where that standard response schema had been manually
copy/pasted into place in individual endpoints.

* changelog

* Only render StandardListResponse schema, if an operation uses it

* Teach the response schema validation test helper about the default list schema too

---------

Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com>
2023-07-25 11:22:33 -04:00
Alexander Scheel
4ec5e22ade
Fix ACME tidy to not reference acmeContext (#21870)
* Fix ACME tidy to not reference acmeCtx

acmeContext is useful for when we need to reference things with a ACME
base URL, but everything used in tidy doesn't need this URL as it is not
coming from an ACME request.

Refactor tidy to remove references to acmeContext, including dependent
functions in acme_state.go.

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

* Remove spurious log message

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

* Draft Tidy Acme Test with Backdate Storage + Backdate Sysxsx

* Fixes to ACME tidy testing

Co-authored-by: kitography <khaines@mit.edu>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Correctly set account kid to update account status

Co-authored-by: kitography <khaines@mit.edu>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add TestTidyAcmeWithSafetyBuffer

Co-authored-by: kitography <khaines@mit.edu>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add test for disabling tidy operation

Co-authored-by: kitography <khaines@mit.edu>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add acme_account_safety_buffer to auto-tidy config

Resolve: #21872

Co-authored-by: kitography <khaines@mit.edu>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add tests verifying tidy safety buffers

Co-authored-by: kitography <khaines@mit.edu>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add changelog entry

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

* Add account status validations and order cleanup tests

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Co-authored-by: kitography <khaines@mit.edu>
Co-authored-by: Steve Clark <steven.clark@hashicorp.com>
2023-07-17 14:54:28 -04:00
Laurent
366693c78d
Add a parameter to allow ExtKeyUsage field usage from a role within ACME (#21702)
* imprv: Add a parameter to allow ExtKeyUsage field usage from a role

* chore: Add the changelog entry

* imprv: Reword UI and changelog

* doc: Add allow_role_extkeyusage in parameter list

* imprv: Align variable names with existing fields/codebase

* Add unit test and tweak some labels

---------

Co-authored-by: Steve Clark <steven.clark@hashicorp.com>
2023-07-17 09:31:13 -04:00
Alexander Scheel
8c7e5d7a3a
Mark config dirty if read differs from state (#21835)
* Refactor CRL writing config to passthrough cache

When reading the CRL config via API endpoint, always read through to the
disk, updating the cache in the process. Similarly, when writing to the
CRL config, read first from disk (updating the cache), and on write,
also write back through the cache, providing consistency without the
need to invalidate through markConfigDirty(...).

This will form the basis of the new pattern for config caching.

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

* Refactor ACME writing config to passthrough cache

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

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-07-14 13:12:26 +00:00
Steven Clark
d01f354aa2
Update TestProperAuthing test (#21841)
- Updating existing entries in OSS so that this can be backported.
 - The proper fix on main going forward it to remove these ENT only
   entries and move them into the enterprise only file
2023-07-14 06:56:06 -04:00
Max Bowsher
e47dd9df53
OpenAPI: Separate ListOperation from ReadOperation (#21723)
* OpenAPI: Separate ListOperation from ReadOperation

Historically, since Vault's ReadOperation and ListOperation both map to
the HTTP GET method, their representation in the generated OpenAPI has
been a bit confusing.

This was partially mitigated some time ago, by making the `list` query
parameter express whether it was required or optional - but only in
a way useful to human readers - the human had to know, for example, that
the schema of the response body would change depending on whether `list`
was selected.

Now that there is an effort underway to automatically generate API
clients from the OpenAPI spec, we have a need to fix this more
comprehensively. Fortunately, we do have a means to do so - since Vault
has opinionated treatment of trailing slashes, linked to operations
being list or not, we can use an added trailing slash on the URL path to
separate list operations in the OpenAPI spec.

This PR implements that, and then fixes an operation ID which becomes
duplicated, with this change applied.

See also hashicorp/vault-client-go#174, a bug which will be fixed by
this work.

* Set further DisplayAttrs in auth/github plugin

To mask out more duplicate read/list functionality, now being separately
generated to OpenAPI client libraries as a result of this change.

* Apply requested changes to operation IDs

I'm not totally convinced its worth the extra lines of code, but
equally, I don't have strong feelings about it, so I'll just make the
change.

* Adjust logic to prevent any possibility of generating OpenAPI paths with doubled final slashes

Even in the edge case of improper use of regex patterns and operations.

* changelog

* Fix TestSudoPaths to pass again... which snowballed a bit...

Once I looked hard at it, I found it was missing several sudo paths,
which led to additional bug fixing elsewhere.

I might need to pull some parts of this change out into a separate PR
for ease of review...

* Fix other tests

* More test fixing

* Undo scope creep - back away from fixing sudo paths not shown as such in OpenAPI, at least within this PR

Just add TODO comments for now.
2023-07-13 13:36:52 -04:00
Steven Clark
8d74143872
Add additional debug output to TestCertStorageMetrics (#21793)
- Add a little more debug to try and understand how we could get the
   following error I saw within GHA
```
    path_tidy_test.go:769: Created root and leaf certificate, deleted leaf, but a got a certificate count of 2
```
 - Fix some other issues discovered while running the test through
   stress locally
2023-07-13 09:03:23 -04:00
Steven Clark
11691b3b37
Allow PKI enterprise to influence TestProperAuthing test case (#21761)
- Allow enterprise repository to hook into and influence the proper
   authing test so we don't have to add values to OSS for enterprise
   work
2023-07-11 13:11:28 -04:00
Steven Clark
1bed33a399
Add the ability to add enterprise only backend features in PKI - OSS (#21748)
To allow us to support CIEPS backend state, allow the backend to
contain enterprise only state variables. Also allow us to implement
enterprise only hooks into the various backend functions to initialize,
periodicFunc, cleanup and invalidate.
2023-07-11 10:05:23 -04:00
Alexander Scheel
b0fb3b1420
pre-commit hook for formatting backend code (#21682)
* Add backend format linting to pre-commit hook

By taking a slight penalty with each commit, we can ensure that
contributors follow the format behavior by default (if they run hooks),
making accidental PRs without proper formatting less likely.
Additionally, fix gofmtcheck to align with the Makefile, fixing the
corresponding fmtcheck target for use with the hook.

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

* Fix formatting errors

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

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-07-10 16:49:47 +00:00
Steven Clark
e29842e49e
Address data races in TestCertStorageMetrics due to plugin reloading (#21679)
- There's a race within the Plugin reloading mechanism that isn't
   trivial to address. To silence some of the failures, switch this
   test to use sealing of the cores instead of the plugin reload
   mechanism
2023-07-10 09:31:34 -04:00
Steven Clark
bce4b7a3e5
Attempt to address autoloading issues within Bind backend tests (#21694)
- We've seen a few issues with bind's auto-loading of configuration
   too quickly at bad times leading to it having partial configurations
   or not all files/permissions being restored properly during it's read
   attempt.
 - See if the freeze/thaw rndc commands will help out with these timing
   issues
2023-07-07 16:29:39 -04:00
Alexander Scheel
072f0dd7c8
Add explicit tests for Extensions, other Subject attributes (#21651)
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-07-07 11:29:22 -04:00
Steven Clark
9b9017a926
Add the ability for enterprise to override PKI backend attributes during setup (#21618) 2023-07-06 16:16:17 -04: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
e3b3c7a8de
Fix OpenAPI spec definitions for PKI EAB APIs (#21458)
* Fix OpenAPI spec definitions for PKI EAB APIs

 - Do not generate duplicate operation ids for the various new-eab apis
 - Fill out proper operation verb for eab delete call
 - Pluralize operation verb for list-eab-keys api
 - Fill out proper response data for new-eab and list-eab-keys

* Add cl
2023-06-27 08:44:21 -04:00
Anton Averchenkov
df304012f3
openapi: Fix response schema for PKI Issue requests (#21449)
* openapi: Fix response schema for PKI Issue requests

* tests

* changelog

* another expiration for generate/rotate root

* more type fixes from @stevendpclark
2023-06-26 13:31:56 -04:00
Alexander Scheel
15aee2e0ba
Fix re-migration of existing CA bundles (#21316)
* Fix re-migration of existing version 1 storage bundles

Related: VAULT-17307

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

* Add test for v1->v2 migration post-issuer deletion

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

* Add changelog entry

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

* Add known-issue about PKI double migration

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

* Update website/content/partials/pki-double-migration-bug.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/partials/pki-double-migration-bug.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/partials/pki-double-migration-bug.mdx

* Additional clarity around known issue

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

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>
2023-06-21 20:34:51 +00:00
Violet Hynes
3a46ecc389
Replace all remaining time.ParseDurations with parseutil.ParseDurationSeconds (#21357)
* Replace all time.ParseDurations with testutil.ParseDurationSeconds

* Changelog

* Import formatting

* Import formatting

* Import formatting

* Import formatting

* Semgrep rule that runs as part of CI
2023-06-20 14:37:46 -04:00
Steven Clark
042dd57811
Supporting PR for Enterprise ACME PR cluster tests (#21275)
* Supporting PR for Enterprise ACME PR cluster tests

 - Some changes within the OSS test helpers to help in the ACME Enterprise test cases.

* Don't rename existing helper method to make oss/ent merge easier
2023-06-15 21:12:49 +00:00
Matt Schultz
8cc7be234a
Adds automated ACME tests using Caddy. (#21277)
* Adds automated ACME tests using Caddy.

* Do not use CheckSignatureFrom method to validate TLS-ALPN-01 challenges

* Uncomment TLS-ALPN test.

* Fix validation of tls-alpn-01 keyAuthz

Surprisingly, this failure was not caught by our earlier, but unmerged
acme.sh tests:

> 2023-06-07T19:35:27.6963070Z [32mPASS[0m builtin/logical/pkiext/pkiext_binary.Test_ACME/group/acme.sh_tls-alpn (33.06s)

from https://github.com/hashicorp/vault/pull/20987.

Notably, we had two failures:

 1. The extension's raw value is not used, but is instead an OCTET
    STRING encoded version:

    > The extension has the following ASN.1 [X.680] format :
    >
    > Authorization ::= OCTET STRING (SIZE (32))
    >
    > The extnValue of the id-pe-acmeIdentifier extension is the ASN.1
    > DER encoding [X.690] of the Authorization structure, which
    > contains the SHA-256 digest of the key authorization for the
    > challenge.
 2. Unlike DNS, the SHA-256 is directly embedded in the authorization,
    as evidenced by the `SIZE (32)` annotation in the quote above: we
    were instead expecting this to be url base-64 encoded, which would
    have a different size.

This failure was caught by Matt, testing with Caddy. :-)

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

* Quick gofmt run.

* Fix challenge encoding in TLS-ALPN-01 challenge tests

* Rename a PKI test helper that retrieves the Vault cluster listener's cert to distinguish it from the method that retrieves the PKI mount's CA cert. Combine a couple of Docker file copy commands into one.

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Co-authored-by: Steve Clark <steven.clark@hashicorp.com>
Co-authored-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-06-15 20:44:09 +00:00
Alexander Scheel
052719b9a8
Allow issuance of root certs no AIA when templating is enabled (#21209)
* Ignore templated AIA on root generation

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

* Add test case verifying that roots generate OK

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

* Add changelog entry

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

* Add warning on generation

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

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-06-14 13:35:17 -04:00
Alexander Scheel
b346b52b62
Correctly validate ACME PoP against public key (#21190)
* Correctly validate ACME PoP against public key

ACME's proof of possession based revocation uses a signature from the
private key, but only sends the public copy along with the request.
Ensure the public copy matches the certificate, instead of failing to
cast it to a private key.

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

* Add ACME revocation tests

* Clarify commentary in acmeRevocationByPoP

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

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Co-authored-by: Steve Clark <steven.clark@hashicorp.com>
2023-06-14 12:01:16 -04:00
Steven Clark
3b14cd2061
Allow CSRs with basic constraint extension with IsCA=false (#21149)
* Allow CSRs with basic constraint extension with IsCA=false

 - We previously forbid any CSR with a basic constraint extension within the CSR.
 - It was discovered that some ACME clients (Proxmox ACME client) do send us this extension with a value of IsCA to false.
 - So allow the extension to be set within the ACME CSR with
   a value of IsCA set to false
 - Add a test for both the IsCA=true and IsCA=false use-cases and make sure we don't actually set the extension back within the generated certificate.

* PR feedback

 - Move basic constraint function to sdk, increase test coverage
 - Error out on extra characters being returned from the asn1 unmarshalling.

* make fmt
2023-06-13 13:15:37 -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
Alexander Scheel
9f87bcfb3b
Fix race in DNS test server configs (#21024)
When writing DNS configs, make sure to push the zone file prior to
writing the reference to the zone in the named.conf.options file.
Otherwise, when adding the initial domain (or any subsequent domains,
which isn't really used by these tests), a race occurs between Docker,
writing the updated config files, and the bind daemon, detecting that
mtime has changed on the named.conf.options file and reloading it
and any referenced zone files.

This should fix the error seen in some tests:

> /etc/bind/named.conf:9: parsing failed: file not found

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-06-07 08:10:16 -04:00
Kit Haines
df975cf04e
Add Config Test. (#20989) 2023-06-06 09:55:42 -04:00
Kit Haines
61d35391a7
Add CN-only and DNS-only tests to ACME test suite (#20996)
* Add CN-only and DNS-only tests to ACME test suite

* Future-proof check validity.

* Add IP-address check-validation.
2023-06-06 09:54:16 -04:00
Steven Clark
ddaf5038f2
Limit ACME issued certificates to a max of 90 days (#20981)
* Limit ACME issued certificates to a max of 90 days

 - If the normal NotAfter date that is calculated from the mount/issuer/role TTL values is greater than 90 days, override the TTL value to a 90-day value.

* Add changelog
2023-06-06 09:51:23 -04:00
Alexander Scheel
8e576cf226
Add more tests around issuers, roles, and directories (#20991)
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-06-05 14:58:39 -04:00
Steven Clark
0bd356f6cd
Generate ACME EAB tokens that do not start with '-' (#20945)
* Generate ACME EAB tokens that do not start with -

 - To avoid people having issues copying EAB tokens and using them on command lines when they start with - from the base64 encoded values, append a prefix.
 - Remove the key_bits data from the eab api, not really useful and now technically wrong
 - Fix up some issues with tests not running in parallel.
 - Update docs to reflect new EAB apis.

* Add ACME directory to the various EAB output APIs

* Update EAB token prefix to be divisable by 3

 - Our decoded prefix was not divisable by 3, which meant the last
   character might be tweaked by the rest of the input
2023-06-05 14:38:03 +00:00
Steven Clark
3dbdee528a
Attempt to resolve flaky test TestAcmeBasicWorkflow test (#20960)
* Attempt to resolve flaky test TestAcmeBasicWorkflow test

 - Since we can't control the challenge engine, flush the validation records it leverages prior to manually updating the authorization/challenge statuses

 ```
     path_acme_test.go:261: csr: &{[] [] [] [] 0 [] 0 0 <nil> CN=*.localdomain [] [] [] [localhost.localdomain *.localdomain] [] [] []}
     path_acme_test.go:300:
         	Error Trace:	/home/runner/actions-runner/_work/vault-enterprise/vault-enterprise/builtin/logical/pki/path_acme_test.go:300
         	Error:      	Received unexpected error:
         	            	403 urn:ietf:params:acme:error:orderNotReady: The request attempted to finalize an order that is not ready to be finalized: order is status pending, needs to be in ready state
         	Test:       	TestAcmeBasicWorkflow/role
         	Messages:   	failed finalizing order
 ```

* make fmt
2023-06-02 14:34:15 -04:00
Kit Haines
e63dc30507
Change from default_role to default_directory_policy (#20935)
* Change from default_role to default_directory_policy to allow future improvements.

* Helper functions

* Use the helper function and make fmt.

* Do not allow the zero-length role "".

* Semgrep doesn't like shadowing errors that are impossible to hit, so fix that.

* Add default to switch branches.

* Add/fix docs.

* Fix wrong requestedRole
2023-06-01 22:06:30 +00: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
Alexander Scheel
4b60ffd5ef
Fix enabling tidy_acme=true in auto-tidy config (#20889)
This should help to prevent the issue of missing tidy configurations
in the future, by placing all related configuration options at the
top with common validation logic.

However, short from this approach is ensuring that each config option
can be specified independently. Thus, the test allows (for any added
and properly tracked tidy operations) verifying that we have enabled
proper storage/retention of that attribute.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2023-05-31 13:16:12 +00:00
Steven Clark
000d754c40
Make ACME EAB keys specific to the ACME directory they are created within (#20803)
* Update EAB management urls underneath pki/eab

 - It was decided that for ease of ACLing, the management
   paths for EAB apis should be outside of the acme path
   prefix
 - Delete duplicated tests, rely on the proper cluster
   based tests for EAB management.

* Update ACME EAB creation paths to be directory specific

 - Make the EAB creation APIs directory specific.
 - This commit is still missing the enforcement that
   they can be redeemed on a specific path.

* Enforce EAB tokens per ACME directory context like accounts

 - Do not allow an EAB from one ACME directory to be used
   in another.
 - Rework the ACME directory function to simply get the path from the request instead of parsing out the role/issuer name.
 - Add some commentary around expectations if operators change issuer names

* Add an EAB certbot integration test

 - Verify with the 3rd party certbot cli that our EAB workflow works as expected.

* Fix unit test

 - Unit test wasn't setting up r.Path within the request
   that we now use to determine the acme directory.
2023-05-30 11:49:01 -04:00
Steven Clark
12d851de37
Only accept challenges on payload is {}, not "" (#20843)
- "" represents a POST-as-GET request which should just
   return the challenge object and not accept it.
 - "{}" as a payload will accept the challenge.
2023-05-30 11:03:12 -04:00