Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI/merge main #14997

Merged
merged 44 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e53aedd
Vault documentation: changing references from learn to tutorial (#14844)
taoism4504 Apr 1, 2022
cf44b62
UI/Only show form values if have read access (#14794)
hellobontempo Apr 1, 2022
7dc8b43
modified text (#14854)
taoism4504 Apr 1, 2022
931562e
fixed a link issue (#14850)
taoism4504 Apr 1, 2022
1bde37c
docs: add known issue to 1.10 release notes (#14859)
austingebauer Apr 1, 2022
59451c2
Vault 3999 Change permissions for directory/archive created by debug …
akshya96 Apr 4, 2022
8352661
Vault 3992 ToB Config and Plugins Permissions (#14817)
akshya96 Apr 4, 2022
93472f3
updated references from learn to tutorial (#14866)
taoism4504 Apr 4, 2022
10833d4
updated references from learn to tutorial (#14867)
taoism4504 Apr 4, 2022
e249005
changed reference from learn to tutorial (#14868)
taoism4504 Apr 4, 2022
7d92a63
Fix handling of default zero SignatureBits value with Any key type in…
cipherboy Apr 4, 2022
7aef98e
Subtle docs change for allow_store_key (#14889)
sgmiller Apr 4, 2022
3cf641c
Adds Vault version prerelease and metadata to logical.PluginEnvironme…
austingebauer Apr 5, 2022
f90e139
docs: fix formatting on plugin upgrade page (#14874)
fairclothjm Apr 5, 2022
99e202d
Update CC docs (#14714)
vishalnayak Apr 5, 2022
d537c2e
Docs improvements for Managed Keys (#14756)
sgmiller Apr 5, 2022
98bb642
sdk/useragent: plugin version string consistent with Vault version st…
austingebauer Apr 5, 2022
e23ff1b
clean up (#14911)
Monkeychip Apr 5, 2022
561a2ee
website: fix usages of img tag (#14910)
Apr 5, 2022
64ba057
remove mount_accessor from the docs (#14927)
raskchanky Apr 6, 2022
16a23cc
Add extra test coverage to PKI (#14767)
stevendpclark Apr 6, 2022
7d520d4
Use WriteWithContext in auth helpers (#14775)
averche Apr 6, 2022
18ee7d9
Add ability to pass certificate PEM bytes to vault/api (#14753)
averche Apr 6, 2022
9c6d25a
Respect increment value in grace period calculations (api/LifetimeWat…
averche Apr 6, 2022
74248e1
Mount flag syntax to mitigate confusion from KV-v2 path discrepancies…
digivava Apr 6, 2022
601acf5
Update vault-plugin-auth-gcp to newest pseudo-version (#14923)
robmonte Apr 6, 2022
3b34ab8
docs: added hello-vault-spring repo link to developer-qs.mdx. (#14928)
Apr 6, 2022
df30e05
OIDC Login Bug (#14916)
zofskeez Apr 7, 2022
ca45941
Fix handling of SignatureBits for ECDSA issuers (#14943)
cipherboy Apr 7, 2022
55afadf
Bug Fix and Glimmerize secret-edit component (#14941)
Monkeychip Apr 7, 2022
311910b
Agent error log level is mismatched (#14424)
swenson Apr 7, 2022
48b43e9
UI/Add months to activity serializer (#14942)
hellobontempo Apr 7, 2022
e7b5b2a
Revert the WithContext changes to vault tests (#14947)
averche Apr 7, 2022
c22a584
adding env var (#14958)
akshya96 Apr 7, 2022
33e5b32
Fix dead link for JWT supported algorithms (#14953)
tomhjp Apr 7, 2022
ec1a3cf
Don't clone OutputCurlString value (#14968)
digivava Apr 8, 2022
bacfe5a
Ensure initialMmapSize is 0 on Windows (#14977)
raskchanky Apr 8, 2022
76ed511
Vault 3992 documentation changes (#14918)
akshya96 Apr 8, 2022
5f4e32e
aws auth displayName (#14954)
jlestrada Apr 8, 2022
f258885
Add Windows error (#14982)
yhyakuna Apr 8, 2022
fd73653
Warnings indicating ignored and replaced parameters (#14962)
vishalnayak Apr 11, 2022
361b213
Fix edit capabilities call in auth method (#14966)
arnav28 Apr 11, 2022
4e94e0d
Merge branch 'main' into ui/upgrade-3.28
Monkeychip Apr 11, 2022
dd65dc3
make linting fix
Monkeychip Apr 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/auth/approle/approle.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func NewAppRoleAuth(roleID string, secretID *SecretID, opts ...LoginOption) (*Ap
}

func (a *AppRoleAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, error) {
if ctx == nil {
ctx = context.Background()
}

loginData := map[string]interface{}{
"role_id": a.roleID,
}
Expand All @@ -125,7 +129,7 @@ func (a *AppRoleAuth) Login(ctx context.Context, client *api.Client) (*api.Secre

// if the caller indicated that the value was actually a wrapping token, unwrap it first
if a.unwrap {
unwrappedToken, err := client.Logical().Unwrap(secretIDValue)
unwrappedToken, err := client.Logical().UnwrapWithContext(ctx, secretIDValue)
if err != nil {
return nil, fmt.Errorf("unable to unwrap response wrapping token: %w", err)
}
Expand All @@ -135,7 +139,7 @@ func (a *AppRoleAuth) Login(ctx context.Context, client *api.Client) (*api.Secre
}

path := fmt.Sprintf("auth/%s/login", a.mountPath)
resp, err := client.Logical().Write(path, loginData)
resp, err := client.Logical().WriteWithContext(ctx, path, loginData)
if err != nil {
return nil, fmt.Errorf("unable to log in with app role auth: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion api/auth/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func NewAWSAuth(opts ...LoginOption) (*AWSAuth, error) {
// variables. To specify a path to a credentials file on disk instead, set
// the environment variable AWS_SHARED_CREDENTIALS_FILE.
func (a *AWSAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, error) {
if ctx == nil {
ctx = context.Background()
}

loginData := make(map[string]interface{})
switch a.authType {
case ec2Type:
Expand Down Expand Up @@ -182,7 +186,7 @@ func (a *AWSAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, e
}

path := fmt.Sprintf("auth/%s/login", a.mountPath)
resp, err := client.Logical().Write(path, loginData)
resp, err := client.Logical().WriteWithContext(ctx, path, loginData)
if err != nil {
return nil, fmt.Errorf("unable to log in with AWS auth: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion api/auth/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func NewAzureAuth(roleName string, opts ...LoginOption) (*AzureAuth, error) {
// Login sets up the required request body for the Azure auth method's /login
// endpoint, and performs a write to it.
func (a *AzureAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, error) {
if ctx == nil {
ctx = context.Background()
}

jwtResp, err := a.getJWT()
if err != nil {
return nil, fmt.Errorf("unable to get access token: %w", err)
Expand All @@ -110,7 +114,7 @@ func (a *AzureAuth) Login(ctx context.Context, client *api.Client) (*api.Secret,
}

path := fmt.Sprintf("auth/%s/login", a.mountPath)
resp, err := client.Logical().Write(path, loginData)
resp, err := client.Logical().WriteWithContext(ctx, path, loginData)
if err != nil {
return nil, fmt.Errorf("unable to log in with Azure auth: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion api/auth/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func NewGCPAuth(roleName string, opts ...LoginOption) (*GCPAuth, error) {
// endpoint, and performs a write to it. This method defaults to the "gce"
// auth type unless NewGCPAuth is called with WithIAMAuth().
func (a *GCPAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, error) {
if ctx == nil {
ctx = context.Background()
}

loginData := map[string]interface{}{
"role": a.roleName,
}
Expand All @@ -86,7 +90,7 @@ func (a *GCPAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, e
}

path := fmt.Sprintf("auth/%s/login", a.mountPath)
resp, err := client.Logical().Write(path, loginData)
resp, err := client.Logical().WriteWithContext(ctx, path, loginData)
if err != nil {
return nil, fmt.Errorf("unable to log in with GCP auth: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion api/auth/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ func NewKubernetesAuth(roleName string, opts ...LoginOption) (*KubernetesAuth, e
}

func (a *KubernetesAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, error) {
if ctx == nil {
ctx = context.Background()
}

loginData := map[string]interface{}{
"jwt": a.serviceAccountToken,
"role": a.roleName,
}

path := fmt.Sprintf("auth/%s/login", a.mountPath)
resp, err := client.Logical().Write(path, loginData)
resp, err := client.Logical().WriteWithContext(ctx, path, loginData)
if err != nil {
return nil, fmt.Errorf("unable to log in with Kubernetes auth: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion api/auth/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func NewLDAPAuth(username string, password *Password, opts ...LoginOption) (*LDA
}

func (a *LDAPAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, error) {
if ctx == nil {
ctx = context.Background()
}

loginData := make(map[string]interface{})

if a.passwordFile != "" {
Expand All @@ -103,7 +107,7 @@ func (a *LDAPAuth) Login(ctx context.Context, client *api.Client) (*api.Secret,
}

path := fmt.Sprintf("auth/%s/login/%s", a.mountPath, a.username)
resp, err := client.Logical().Write(path, loginData)
resp, err := client.Logical().WriteWithContext(ctx, path, loginData)
if err != nil {
return nil, fmt.Errorf("unable to log in with LDAP auth: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion api/auth/userpass/userpass.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func NewUserpassAuth(username string, password *Password, opts ...LoginOption) (
}

func (a *UserpassAuth) Login(ctx context.Context, client *api.Client) (*api.Secret, error) {
if ctx == nil {
ctx = context.Background()
}

loginData := make(map[string]interface{})

if a.passwordFile != "" {
Expand All @@ -107,7 +111,7 @@ func (a *UserpassAuth) Login(ctx context.Context, client *api.Client) (*api.Secr
}

path := fmt.Sprintf("auth/%s/login/%s", a.mountPath, a.username)
resp, err := client.Logical().Write(path, loginData)
resp, err := client.Logical().WriteWithContext(ctx, path, loginData)
if err != nil {
return nil, fmt.Errorf("unable to log in with userpass auth: %w", err)
}
Expand Down
52 changes: 31 additions & 21 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
EnvVaultAddress = "VAULT_ADDR"
EnvVaultAgentAddr = "VAULT_AGENT_ADDR"
EnvVaultCACert = "VAULT_CACERT"
EnvVaultCACertBytes = "VAULT_CACERT_BYTES"
EnvVaultCAPath = "VAULT_CAPATH"
EnvVaultClientCert = "VAULT_CLIENT_CERT"
EnvVaultClientKey = "VAULT_CLIENT_KEY"
Expand Down Expand Up @@ -172,9 +173,14 @@ type Config struct {
// used to communicate with Vault.
type TLSConfig struct {
// CACert is the path to a PEM-encoded CA cert file to use to verify the
// Vault server SSL certificate.
// Vault server SSL certificate. It takes precedence over CACertBytes
// and CAPath.
CACert string

// CACertBytes is a PEM-encoded certificate or bundle. It takes precedence
// over CAPath.
CACertBytes []byte

// CAPath is the path to a directory of PEM-encoded CA cert files to verify
// the Vault server SSL certificate.
CAPath string
Expand Down Expand Up @@ -266,12 +272,13 @@ func (c *Config) configureTLS(t *TLSConfig) error {
return fmt.Errorf("both client cert and client key must be provided")
}

if t.CACert != "" || t.CAPath != "" {
if t.CACert != "" || len(t.CACertBytes) != 0 || t.CAPath != "" {
c.curlCACert = t.CACert
c.curlCAPath = t.CAPath
rootConfig := &rootcerts.Config{
CAFile: t.CACert,
CAPath: t.CAPath,
CAFile: t.CACert,
CACertificate: t.CACertBytes,
CAPath: t.CAPath,
}
if err := rootcerts.ConfigureTLS(clientTLSConfig, rootConfig); err != nil {
return err
Expand Down Expand Up @@ -313,6 +320,7 @@ func (c *Config) ReadEnvironment() error {
var envAddress string
var envAgentAddress string
var envCACert string
var envCACertBytes []byte
var envCAPath string
var envClientCert string
var envClientKey string
Expand Down Expand Up @@ -343,6 +351,9 @@ func (c *Config) ReadEnvironment() error {
if v := os.Getenv(EnvVaultCACert); v != "" {
envCACert = v
}
if v := os.Getenv(EnvVaultCACertBytes); v != "" {
envCACertBytes = []byte(v)
}
if v := os.Getenv(EnvVaultCAPath); v != "" {
envCAPath = v
}
Expand Down Expand Up @@ -398,6 +409,7 @@ func (c *Config) ReadEnvironment() error {
// Configure the HTTP clients TLS configuration.
t := &TLSConfig{
CACert: envCACert,
CACertBytes: envCACertBytes,
CAPath: envCAPath,
ClientCert: envClientCert,
ClientKey: envClientKey,
Expand Down Expand Up @@ -576,7 +588,6 @@ func (c *Client) CloneConfig() *Config {
newConfig.CheckRetry = c.config.CheckRetry
newConfig.Logger = c.config.Logger
newConfig.Limiter = c.config.Limiter
newConfig.OutputCurlString = c.config.OutputCurlString
newConfig.SRVLookup = c.config.SRVLookup
newConfig.CloneHeaders = c.config.CloneHeaders
newConfig.CloneToken = c.config.CloneToken
Expand Down Expand Up @@ -990,22 +1001,21 @@ func (c *Client) clone(cloneHeaders bool) (*Client, error) {
defer config.modifyLock.RUnlock()

newConfig := &Config{
Address: config.Address,
HttpClient: config.HttpClient,
MinRetryWait: config.MinRetryWait,
MaxRetryWait: config.MaxRetryWait,
MaxRetries: config.MaxRetries,
Timeout: config.Timeout,
Backoff: config.Backoff,
CheckRetry: config.CheckRetry,
Logger: config.Logger,
Limiter: config.Limiter,
OutputCurlString: config.OutputCurlString,
AgentAddress: config.AgentAddress,
SRVLookup: config.SRVLookup,
CloneHeaders: config.CloneHeaders,
CloneToken: config.CloneToken,
ReadYourWrites: config.ReadYourWrites,
Address: config.Address,
HttpClient: config.HttpClient,
MinRetryWait: config.MinRetryWait,
MaxRetryWait: config.MaxRetryWait,
MaxRetries: config.MaxRetries,
Timeout: config.Timeout,
Backoff: config.Backoff,
CheckRetry: config.CheckRetry,
Logger: config.Logger,
Limiter: config.Limiter,
AgentAddress: config.AgentAddress,
SRVLookup: config.SRVLookup,
CloneHeaders: config.CloneHeaders,
CloneToken: config.CloneToken,
ReadYourWrites: config.ReadYourWrites,
}
client, err := NewClient(newConfig)
if err != nil {
Expand Down
29 changes: 21 additions & 8 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,24 +262,37 @@ func TestDefaulRetryPolicy(t *testing.T) {

func TestClientEnvSettings(t *testing.T) {
cwd, _ := os.Getwd()

caCertBytes, err := os.ReadFile(cwd + "/test-fixtures/keys/cert.pem")
if err != nil {
t.Fatalf("error reading %q cert file: %v", cwd+"/test-fixtures/keys/cert.pem", err)
}

oldCACert := os.Getenv(EnvVaultCACert)
oldCACertBytes := os.Getenv(EnvVaultCACertBytes)
oldCAPath := os.Getenv(EnvVaultCAPath)
oldClientCert := os.Getenv(EnvVaultClientCert)
oldClientKey := os.Getenv(EnvVaultClientKey)
oldSkipVerify := os.Getenv(EnvVaultSkipVerify)
oldMaxRetries := os.Getenv(EnvVaultMaxRetries)

os.Setenv(EnvVaultCACert, cwd+"/test-fixtures/keys/cert.pem")
os.Setenv(EnvVaultCACertBytes, string(caCertBytes))
os.Setenv(EnvVaultCAPath, cwd+"/test-fixtures/keys")
os.Setenv(EnvVaultClientCert, cwd+"/test-fixtures/keys/cert.pem")
os.Setenv(EnvVaultClientKey, cwd+"/test-fixtures/keys/key.pem")
os.Setenv(EnvVaultSkipVerify, "true")
os.Setenv(EnvVaultMaxRetries, "5")
defer os.Setenv(EnvVaultCACert, oldCACert)
defer os.Setenv(EnvVaultCAPath, oldCAPath)
defer os.Setenv(EnvVaultClientCert, oldClientCert)
defer os.Setenv(EnvVaultClientKey, oldClientKey)
defer os.Setenv(EnvVaultSkipVerify, oldSkipVerify)
defer os.Setenv(EnvVaultMaxRetries, oldMaxRetries)

defer func() {
os.Setenv(EnvVaultCACert, oldCACert)
os.Setenv(EnvVaultCACertBytes, oldCACertBytes)
os.Setenv(EnvVaultCAPath, oldCAPath)
os.Setenv(EnvVaultClientCert, oldClientCert)
os.Setenv(EnvVaultClientKey, oldClientKey)
os.Setenv(EnvVaultSkipVerify, oldSkipVerify)
os.Setenv(EnvVaultMaxRetries, oldMaxRetries)
}()

config := DefaultConfig()
if err := config.ReadEnvironment(); err != nil {
Expand Down Expand Up @@ -513,8 +526,8 @@ func TestClone(t *testing.T) {
if parent.MaxRetries() != clone.MaxRetries() {
t.Fatalf("maxRetries don't match: %v vs %v", parent.MaxRetries(), clone.MaxRetries())
}
if parent.OutputCurlString() != clone.OutputCurlString() {
t.Fatalf("outputCurlString doesn't match: %v vs %v", parent.OutputCurlString(), clone.OutputCurlString())
if parent.OutputCurlString() == clone.OutputCurlString() {
t.Fatalf("outputCurlString was copied over when it shouldn't have been: %v and %v", parent.OutputCurlString(), clone.OutputCurlString())
}
if parent.SRVLookup() != clone.SRVLookup() {
t.Fatalf("SRVLookup doesn't match: %v vs %v", parent.SRVLookup(), clone.SRVLookup())
Expand Down
25 changes: 16 additions & 9 deletions api/lifetime_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ type LifetimeWatcherInput struct {

// The new TTL, in seconds, that should be set on the lease. The TTL set
// here may or may not be honored by the vault server, based on Vault
// configuration or any associated max TTL values.
// configuration or any associated max TTL values. If specified, the
// minimum of this value and the remaining lease duration will be used
// for grace period calculations.
Increment int

// RenewBehavior controls what happens when a renewal errors or the
Expand Down Expand Up @@ -257,7 +259,7 @@ func (r *LifetimeWatcher) doRenewWithOptions(tokenMode bool, nonRenewable bool,

initialTime := time.Now()
priorDuration := time.Duration(initLeaseDuration) * time.Second
r.calculateGrace(priorDuration)
r.calculateGrace(priorDuration, time.Duration(r.increment)*time.Second)
var errorBackoff backoff.BackOff

for {
Expand Down Expand Up @@ -345,7 +347,7 @@ func (r *LifetimeWatcher) doRenewWithOptions(tokenMode bool, nonRenewable bool,
// extending. Once it stops extending, we've hit the max and need to
// rely on the grace duration.
if remainingLeaseDuration > priorDuration {
r.calculateGrace(remainingLeaseDuration)
r.calculateGrace(remainingLeaseDuration, time.Duration(r.increment)*time.Second)
}
priorDuration = remainingLeaseDuration

Expand Down Expand Up @@ -373,16 +375,21 @@ func (r *LifetimeWatcher) doRenewWithOptions(tokenMode bool, nonRenewable bool,
}
}

// calculateGrace calculates the grace period based on a reasonable set of
// assumptions given the total lease time; it also adds some jitter to not have
// clients be in sync.
func (r *LifetimeWatcher) calculateGrace(leaseDuration time.Duration) {
if leaseDuration <= 0 {
// calculateGrace calculates the grace period based on the minimum of the
// remaining lease duration and the token increment value; it also adds some
// jitter to not have clients be in sync.
func (r *LifetimeWatcher) calculateGrace(leaseDuration, increment time.Duration) {
minDuration := leaseDuration
if minDuration > increment && increment > 0 {
minDuration = increment
}

if minDuration <= 0 {
r.grace = 0
return
}

leaseNanos := float64(leaseDuration.Nanoseconds())
leaseNanos := float64(minDuration.Nanoseconds())
jitterMax := 0.1 * leaseNanos

// For a given lease duration, we want to allow 80-90% of that to elapse,
Expand Down
Loading