-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* vault-agent-cache: squashed 250+ commits * Add proper token revocation validations to the tests * Add more test cases * Avoid leaking by not closing request/response bodies; add comments * Fix revoke orphan use case; update tests * Add CLI test for making request over unix socket * agent/cache: remove namespace-related tests * Strip-off the auto-auth token from the lookup response * Output listener details along with configuration * Add scheme to API address output * leasecache: use IndexNameLease for prefix lease revocations * Make CLI accept the fully qualified unix address * export VAULT_AGENT_ADDR=unix://path/to/socket * unix:/ to unix://
- Loading branch information
1 parent
5dd50ef
commit e39a5f2
Showing
26 changed files
with
4,283 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cache | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io/ioutil" | ||
|
||
hclog "github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/vault/api" | ||
) | ||
|
||
// APIProxy is an implementation of the proxier interface that is used to | ||
// forward the request to Vault and get the response. | ||
type APIProxy struct { | ||
logger hclog.Logger | ||
} | ||
|
||
type APIProxyConfig struct { | ||
Logger hclog.Logger | ||
} | ||
|
||
func NewAPIProxy(config *APIProxyConfig) Proxier { | ||
return &APIProxy{ | ||
logger: config.Logger, | ||
} | ||
} | ||
|
||
func (ap *APIProxy) Send(ctx context.Context, req *SendRequest) (*SendResponse, error) { | ||
client, err := api.NewClient(api.DefaultConfig()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
client.SetToken(req.Token) | ||
client.SetHeaders(req.Request.Header) | ||
|
||
fwReq := client.NewRequest(req.Request.Method, req.Request.URL.Path) | ||
fwReq.BodyBytes = req.RequestBody | ||
|
||
// Make the request to Vault and get the response | ||
ap.logger.Info("forwarding request", "path", req.Request.URL.Path, "method", req.Request.Method) | ||
resp, err := client.RawRequestWithContext(ctx, fwReq) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Parse and reset response body | ||
respBody, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
ap.logger.Error("failed to read request body", "error", err) | ||
return nil, err | ||
} | ||
if resp.Body != nil { | ||
resp.Body.Close() | ||
} | ||
resp.Body = ioutil.NopCloser(bytes.NewBuffer(respBody)) | ||
|
||
return &SendResponse{ | ||
Response: resp, | ||
ResponseBody: respBody, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cache | ||
|
||
import ( | ||
"testing" | ||
|
||
hclog "github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/vault/api" | ||
"github.com/hashicorp/vault/helper/jsonutil" | ||
"github.com/hashicorp/vault/helper/logging" | ||
"github.com/hashicorp/vault/helper/namespace" | ||
) | ||
|
||
func TestCache_APIProxy(t *testing.T) { | ||
cleanup, client, _, _ := setupClusterAndAgent(namespace.RootContext(nil), t, nil) | ||
defer cleanup() | ||
|
||
proxier := NewAPIProxy(&APIProxyConfig{ | ||
Logger: logging.NewVaultLogger(hclog.Trace), | ||
}) | ||
|
||
r := client.NewRequest("GET", "/v1/sys/health") | ||
req, err := r.ToRetryableHTTP() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
resp, err := proxier.Send(namespace.RootContext(nil), &SendRequest{ | ||
Request: req.Request, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var result api.HealthResponse | ||
err = jsonutil.DecodeJSONFromReader(resp.Response.Body, &result) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !result.Initialized || result.Sealed || result.Standby { | ||
t.Fatalf("bad sys/health response") | ||
} | ||
} |
Oops, something went wrong.