1803 Commits

Author SHA1 Message Date
Violet Hynes
dbecbcec18
VAULT-27384 Fix faulty assignments and unchecked errors (#27810)
* VAULT-27384 Fix faulty assignments and unchecked errors

* Another missed error

* Small refactor
2024-07-22 16:53:02 -04:00
John-Michael Faircloth
d6a588b8d2
db: refactor postgres test helpers (#27811)
* db: refactor postgres test helpers

* fix references to refactored test helper

* fix references to refactored test helper

* fix failing test
2024-07-19 09:47:34 -05:00
Steven Clark
2d7a3fba99
PKI: Refactor common role path policy code into common area (#27759) 2024-07-11 13:22:33 -04:00
Steven Clark
054f5b182a
Return the proper serial number in OCSP verification errors (#27696)
* Return the proper serial number in OCSP verification errors

 - We returned the issuer's certificate number instead of the serial
   number of the actual certificate we validated from an OCSP request.

 - The problematic serial number within the error are never shown
   currently in Vault. The only user of this library is cert-auth
   which swallows errors around revoked certificates and returns
   a boolean false instead of the actual error message.

* Add cl

* Use previously formatted serial in error msg
2024-07-09 09:03:34 -04:00
Scott Miller
30f457f32b
Handle missing serial number more gracefully (#27681)
* Handle missing serial number more gracefully

* remove poc code

* changelog
2024-07-03 21:01:26 +00:00
Ben Ash
a05deb5f37
AWS secrets: add support for STS session tags (#27620)
Adds support for configuring session tags for assume role operations.
2024-07-02 10:48:52 -04:00
Victor Rodriguez
c4fcb4a086
Move fetchCertBySerial back into the main PKI package. (#27461)
* Move fetchCertBySerial back into the main PKI package.

In order to avoid polluting the issuing package with StorageContext, move
fetchCertBySerial back to the main PKI package. Note that this requires that
FetchRevocationInfo also be moved back to the main package.

* Run make fmt.
2024-06-12 15:53:40 +00:00
Steven Clark
405a3f426f
Add GetFullCaChain method to PKI issuer (#27451) 2024-06-11 16:39:28 -04:00
Steven Clark
d152de025d
Pin generated proto files to 1.34.2 (#27438) 2024-06-11 12:29:45 -04:00
Victor Rodriguez
67515c7e4a
Ongoing refactoring of PKI revocation code (#27427)
* Move resolveIssuerCRLPath to PKI issuing package.

* Move fetchCertBySerial to PKI issuing package.

* Move fetchRevocationInfo to PKI revocation package.

* Make associateRevokedCertWithIsssuer a method of RevocationInfo.

* Move serialFromCert and normalizeSerial to PKI parsing package.

* Move writeUnifiedRevocationEntry to PKI revocation package.

* Run make fmt.
2024-06-11 09:25:14 -04:00
Victor Rodriguez
eb8496e874
Commence refactoring to decouple revocation code from main PKI backend (#27417)
* Rename crlConfig to CrlConfig.

Rename defaultCrlConfig to DefaultCrlConfig.

* Move CrlConfig and DefaultCrlConfig to new package pki/revocation.

* Rename revocationInfo to RevocationInfo.

* Move RevocationInfo to pki/revocation.

* Add StorageContext interface to PKI's revocation package.

* Add CrlBuilderType interface to pki_backend package.

The purpose of the interface is to make it possible to gradually move (refactor)
CrlBuilder to the revocation package.

* Move CrlConfig and DefaultCrlConfig to package pki_backend.

* Make StorageContext.CrlBuilder() return a CrlBuilderType.

Add methods SetLastDeltaRebuildCheckTime() and ShouldInvalidate() to
CrlBuilderType.

* Move fetchIssuerMapForRevocationChecking to PKI's revocation package.

* Run make fmt.
2024-06-10 16:41:47 +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
3fef0fad8e
Add support for read/write unauthed endpoints in PKI authing test (#27396)
- Within SCEP we need to expose an unauthed API endpoint that has
   a handler for both GET and POST requests. This use-case wasn't
   supported in the TestProperAuthing test which this adds.
2024-06-07 09:58:15 -04:00
Kit Haines
b86f4afbbd
OSS changes to rename metadata cert_metadata (#27365)
* OSS changes to rename metadata cert_metadata

* OSS changes to functions.
2024-06-05 18:17:04 +00:00
Kit Haines
b2877f7050
Store metadata when it is an empty string (such as role, serial number, etc...) (#27303) 2024-05-31 12:33:04 -04:00
Victor Rodriguez
417376341a
Use hash_algorithm parameter on Transit's verify HMAC requests. (#27211)
Use hash_algorithm parameter on Transit's verify HMAC requests.

Parameter 'algorithm' has been deprecated in favour of 'hash_algorithm', so
update the pathHMACVerify() handler to use it when it is present.
2024-05-24 11:12:23 -04:00
Rachel Culpepper
0b02c5d56c
Fix ed25519 key type in ca_util (#27093)
* fix ed25519 key type

* add changelog

* fix other case and add tests

* add other test

* add headers
2024-05-22 09:27:45 -05:00
Kit Haines
927df50a95
community edition changes to enable certificate metadata ent (#26951) 2024-05-10 18:49:20 +00:00
Steven Clark
f8cad5e344
PKI cert metadata should not cross cluster boundaries (#26919) 2024-05-09 22:30:42 -04:00
Rachel Culpepper
a7b6f3490f
Add cert metadata fields for tidy (#26867)
* add cert metadata fields for tidy

* fix import

* add missing fields to schema

* add new fields to expected value

* change error
2024-05-09 15:12:23 -05:00
Steven Clark
0637f5e316
PKI: Change sign-intermediate to truncate notAfter by default (behavior change) (#26796)
* PKI: Change sign-intermediate to truncate notAfter by default

 - The PKI sign-intermediate API allowed an end-user to request a TTL
   value that would extend beyond the signing issuer's notAfter. This would
   generate an invalid CA chain when properly validated.
 - We are now changing the default behavior to truncate the returned certificate
   to the signing issuer's notAfter.
 - End-users can get the old behavior by configuring the signing issuer's
   leaf_not_after_behavior field to permit, and call sign-intermediary
   with the new argument enforce_leaf_not_after_behavior to true. The
   new argument could also be used to enforce an error instead of truncating
   behavior if the signing issuer's leaf_not_after_behavior is set to err.

* Add cl

* Add cl and upgrade note

* Apply suggestions from code review

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

---------

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>
2024-05-09 11:22:04 -04:00
Steven Clark
fe2b4c6f7a
PKI: Allow operators to increase the maximum TTL for ACME issued certificates (#26797)
* PKI: Allow operators to increase the maximum TTL for ACME issued certificates

* Add cl
2024-05-09 10:41:28 -04:00
Mike Palmiotto
2d75711019
make proto 1.34.1 (#26856) 2024-05-07 14:33:18 +00:00
Steven Clark
e7778e2018
Address go format and proto linting issues (#26782)
* make fmt

* Fix various issues with new proto file
2024-05-02 12:03:06 -04:00
Scott Miller
9f5da77fa0
Certificate Metadata, CE components (#26710)
* Certificate Metadata, CE components

* License headers

* make proto

* move pathFetchMetadata to ENT

* move pathFetchMetadata path to ENT

* correct stub sig

* Issuers may not be available in legacy CA storage, shouldn't fail issue/sign

* clarify error msg
2024-05-01 15:19:53 -05:00
Paul Banks
259313648f
Fix places where we fail to propagate storage errors like ErrReadOnly (#26711) 2024-05-01 15:46:23 +01:00
Rachel Culpepper
d2aad917bb
vault-24958: add cmac key types for import and export (#26610)
* add cmac key types to export

* set rsa public key and add cmac key types for wrapping

* add cmac types to import and export

* add cmac export key type

* fix import key type

* add cmac to policy import

* add enterprise checks

* fix imports
2024-04-24 08:13:19 -05:00
Steven Clark
20863afca5
Transit operations on CMAC key types should fail on CE (#26582)
- Due to the amount of shared code for various key operations, have
   a general failure mechanism for CMAC key types within Transit when
   operating in CE
2024-04-22 14:29:00 -04:00
Steven Clark
ff500ca1c3
Add Transit CMAC stubs in CE (#26552) 2024-04-22 13:19:04 -04:00
Rachel Culpepper
9ebcbf6a0c
vault-24597: add key types and key creation for CMAC (#25967)
* add key types for cmac for transit key creation

* add test for key creation

* fix test logic and add cases

* fix logic for hmac

* add go doc

* fix key size and add check for HMAC key
2024-04-19 09:39:59 -05:00
Scott Miller
fd9e113c82
Use a less strict URL validation for PKI issuing and crl distribution urls (#26477)
* Use a less strict URL validation for PKI issuing and crl distribution urls

* comma handling

* limit to ldap

* remove comma hack

* changelog

* Add unit test validating ldap CRL urls

---------

Co-authored-by: Steve Clark <steven.clark@hashicorp.com>
2024-04-18 17:35:33 +00:00
Peter Wilson
8bee54c89d
VAULT-24452: audit refactor (#26460)
* Refactor audit code into audit package
* remove builtin/audit
* removed unrequired files
2024-04-18 08:25:04 +01:00
Christopher Swenson
961bf20bdb
Use enumer to generate String() methods for most enums (#25705)
We have many hand-written String() methods (and similar) for enums.
These require more maintenance and are more error-prone than using
automatically generated methods. In addition, the auto-generated
versions can be more efficient.

Here, we switch to using https://github.com/loggerhead/enumer, itself
a fork of https://github.com/diegostamigni/enumer, no longer maintained,
and a fork of the mostly standard tool
https://pkg.go.dev/golang.org/x/tools/cmd/stringer.
We use this fork of enumer for Go 1.20+ compatibility and because
we require the `-transform` flag to be able to generate
constants that match our current code base.

Some enums were not targeted for this change:
2024-04-17 11:14:14 -07:00
Christopher Swenson
a65d9133a1
database: Avoid race condition in connection creation (#26147)
When creating database connections, there is a race
condition when multiple goroutines try to create the
connection at the same time. This happens, for
example, on leadership changes in a cluster.

Normally, the extra database connections are cleaned
up when this is detected. However, some database
implementations, notably Postgres, do not seem to
clean up in a timely manner, and can leak in these
scenarios.

To fix this, we create a global lock when creating
database connections to prevent multiple connections
from being created at the same time.

We also clean up the logic at the end so that
if (somehow) we ended up creating an additional
connection, we use the existing one rather than
the new one. This by itself would solve our
problem long-term, however, would still involve
many transient database connections being created
and immediately killed on leadership changes.

It's not ideal to have a single global lock for
database connection creation. Some potential
alternatives:

* a map of locks from the connection name to the lock.
  The biggest downside is the we probably will want to
  garbage collect this map so that we don't have an
  unbounded number of locks.
* a small pool of locks, where we hash the connection
  names to pick the lock. Using such a pool generally
  is a good way to introduce deadlock, but since we
  will only use it in a specific case, and the purpose
  is to improve performance for concurrent connection
  creation, this is probably acceptable.

Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com>
2024-03-26 16:58:07 +00:00
Josh Black
012c3422f8
Add acme clients internal data structures and adjust tests (#26020)
* add acme clients internal data structures and adjust tests

* fix another acme test

* replace manual list with ActivityClientTypes

* add changelog
2024-03-19 09:24:54 -07:00
Steven Clark
94d42235cf
Address OCSP client caching issue (#25986)
* Address OCSP client caching issue

 - The OCSP cache built into the client that is used by cert-auth
   would cache the responses but when pulling out a cached value the
   response wasn't validating properly and was then thrown away.

 - The issue was around a confusion of the client's internal status
   vs the Go SDK OCSP status integer values.

 - Add a test that validates the cache is now used

* Add cl

* Fix PKI test failing now due to the OCSP cache working

 - Remove the previous lookup before revocation as now the OCSP
   cache works so we don't see the new revocation as we are actually
   leveraging the cache
2024-03-18 19:11:14 +00:00
Austin Gebauer
df57ff46ff
Add stubs for plugin WIF (#25657)
* Add stubs for plugin wif

* add header to sdk file

* drop changelog to move it

* fix test
2024-02-27 12:10:43 -08:00
Josh Black
fa13dbd381
add gosimport to make fmt and run it (#25383)
* add gosimport to make fmt and run it

* move installation to tools.sh

* correct weird spacing issue

* Update Makefile

Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>

* fix a weird issue

---------

Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>
2024-02-13 14:07:02 -08:00
Steven Clark
7463055f07
Transit: Release locks using defer statements (#25336)
* Transit: Release locks using defer statements

 - Leverage defer statements to Unlock the fetched policy
   to avoid issues with forgetting to manually Unlock during
   each return statement

* Add cl
2024-02-09 14:06:23 -05:00
Kit Haines
9536129091
Fix test to be less flacky (#25243)
* Fix test to be less flacky

* Fix duration to be asymmetrical, and try diff calculation more obviously.
2024-02-08 14:44:05 -05:00
Christopher Swenson
55d2dfb3d0
database: Emit event notifications (#24718)
Including for failures to write credentials and failure to rotate.
2024-02-05 10:30:00 -08:00
Kit Haines
99c74f5c80
Base Binary Cert and CSR Parse functions. (#24958)
* Base Binary Cert and CSR Parse functions.

* Add otherSANS parsing.

* Notate what doesn't exist on a CSR.

* Fix otherSans call err-checking and add basic-constriants to CSR

* Move BasicConstraint parsing to be optionally set.

* Refactored to use existing ParseBasicConstraintsExtension.

* Add handling for the ChangeSubjectName ext on CSR that is needed for EST

* Remove ChangeSubjectName - it's an attribute, not an extension, and there is no clean way to parse it, so pair down for now.

* Make these public methods, so they can be used in vault.

* Add unit tests for certutil.ParseCertificateToCreationParameters.

Also add unit tests for certutil.ParseCertificateToFields.

* Cleanup TestParseCertificate.

* Add unit tests for certutil.ParseCsrToCreationParameters and ParseCsrToFields.

* Fix return values for  "add_basic_constraints" in certutil.ParseCsrToFields.

Add a test for parsing CSRs where "add_basic_constraints" is false.

* Clear up some todos.

* Add a test for certutil.ParseCertificateToCreationParameters for non-CA cert.

* Tweak TestParseCertificate/full_non_CA_cert.

* Basics of three remaining fields - keyUsage; extKeyUsage; PolicyIdentifiers

* Fix tests and err handling

* Add unit tests for policy_identifiers; ext_key_usage_oids; key_usage

* Add test on ext_key_usage_oids

* Remove duplicate usages elsewhere.

* Add error handling to csr-checks.

* Remove extranames on returned types.

* Remove useless function.

---------

Co-authored-by: Victor Rodriguez <vrizo@hashicorp.com>
2024-02-01 10:03:43 -05:00
Tom Proctor
78ef25e70c
HTTP API for pinning plugin versions (#25105) 2024-01-30 10:24:33 +00:00
vinay-gopalan
fcf7cf6c22
WIF support for AWS secrets engine (#24987)
* add new plugin wif fields to AWS Secrets Engine

* add changelog

* go get awsutil v0.3.0

* fix up changelog

* fix test and field parsing helper

* godoc on new test

* require role arn when audience set

* make fmt

---------

Co-authored-by: Austin Gebauer <agebauer@hashicorp.com>
Co-authored-by: Austin Gebauer <34121980+austingebauer@users.noreply.github.com>
2024-01-29 11:34:57 -08:00
Mike Palmiotto
43be9fc18a
Request Limiter (#25093)
This commit introduces two new adaptive concurrency limiters in Vault,
which should handle overloading of the server during periods of
untenable request rate. The limiter adjusts the number of allowable
in-flight requests based on latency measurements performed across the
request duration. This approach allows us to reject entire requests
prior to doing any work and prevents clients from exceeding server
capacity.

The limiters intentionally target two separate vectors that have been
proven to lead to server over-utilization.

- Back pressure from the storage backend, resulting in bufferbloat in
  the WAL system. (enterprise)
- Back pressure from CPU over-utilization via PKI issue requests
  (specifically for RSA keys), resulting in failed heartbeats.

Storage constraints can be accounted for by limiting logical requests
according to their http.Method. We only limit requests with write-based
methods, since these will result in storage Puts and exhibit the
aforementioned bufferbloat.

CPU constraints are accounted for using the same underlying library and
technique; however, they require special treatment. The maximum number
of concurrent pki/issue requests found in testing (again, specifically
for RSA keys) is far lower than the minimum tolerable write request
rate. Without separate limiting, we would artificially impose limits on
tolerable request rates for non-PKI requests. To specifically target PKI
issue requests, we add a new PathsSpecial field, called limited,
allowing backends to specify a list of paths which should get
special-case request limiting.

For the sake of code cleanliness and future extensibility, we introduce
the concept of a LimiterRegistry. The registry proposed in this PR has
two entries, corresponding with the two vectors above. Each Limiter
entry has its own corresponding maximum and minimum concurrency,
allowing them to react to latency deviation independently and handle
high volumes of requests to targeted bottlenecks (CPU and storage).

In both cases, utilization will be effectively throttled before Vault
reaches any degraded state. The resulting 503 - Service Unavailable is a
retryable HTTP response code, which can be handled to gracefully retry
and eventually succeed. Clients should handle this by retrying with
jitter and exponential backoff. This is done within Vault's API, using
the go-retryablehttp library.

Limiter testing was performed via benchmarks of mixed workloads and
across a deployment of agent pods with great success.
2024-01-26 14:26:21 -05:00
Kuba Wieczorek
71afc5bdb4
Swap calls to t.Log to a corehelpers test logger in ACME tests (#25096) 2024-01-26 18:20:44 +00:00
Tom Proctor
af27ab3524
Add version pinning to plugin catalog (#24960)
Adds the ability to pin a version for a specific plugin type + name to enable an easier plugin upgrade UX. After pinning and reloading, that version should be the only version in use.

No HTTP API implementation yet for managing pins, so no user-facing effects yet.
2024-01-26 17:21:43 +00:00
Rachel Culpepper
ec404c0d30
add changes for EST tests (#25089) 2024-01-26 08:22:53 -06:00
Kit Haines
ab8887c875
Migration of OtherSANs Parsing Call to SDK helper from pki-issuer (#24946)
* Migration of OtherSANs Parsing Call to SDK helper from pki-issuer

* Based on PR feedback from Steve, remove internal variable, reference certutil directly.
2024-01-19 09:21:51 -05:00
Kit Haines
fb71d7f3c8
make-fmt (#24940) 2024-01-18 20:00:00 +00:00