Skip to content

Commit

Permalink
Read cert and JWT from filesystem by default
Browse files Browse the repository at this point in the history
  • Loading branch information
eh-steve committed Jun 26, 2020
1 parent b176a54 commit 798c499
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"io/ioutil"

"github.com/briankassouf/jose/jws"
"github.com/hashicorp/vault/sdk/framework"
Expand Down Expand Up @@ -106,15 +107,27 @@ func (b *kubeAuthBackend) pathConfigWrite(ctx context.Context, req *logical.Requ
return logical.ErrorResponse("no host provided"), nil
}

localCACert, _ := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")

localTokenReviewer, _ := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/token")

pemList := data.Get("pem_keys").([]string)
caCert := data.Get("kubernetes_ca_cert").(string)
issuer := data.Get("issuer").(string)
disableIssValidation := data.Get("disable_iss_validation").(bool)
if len(pemList) == 0 && len(caCert) == 0 {
return logical.ErrorResponse("one of pem_keys or kubernetes_ca_cert must be set"), nil
if len(localCACert) > 0 {
caCert = string(localCACert)
} else {
return logical.ErrorResponse("one of pem_keys or kubernetes_ca_cert must be set"), nil
}
}

tokenReviewer := data.Get("token_reviewer_jwt").(string)
if len(tokenReviewer) == 0 && len(localTokenReviewer) > 0 {
tokenReviewer = string(localTokenReviewer)
}

if len(tokenReviewer) > 0 {
// Validate it's a JWT
_, err := jws.ParseJWT([]byte(tokenReviewer))
Expand Down

0 comments on commit 798c499

Please sign in to comment.