Commit Graph

23 Commits

Author SHA1 Message Date
mikaelcabot 6b461a0adf fix: bundle download failed - context canceled
Bundle download failed: bundle read failed: archive read failed: context canceled

Signed-off-by: mikaelcabot <mikaelcabot@gmail.com>
2020-08-24 09:23:32 -07:00
Ashutosh Narkar b48aba82b0 plugins/rest: Add response header timeout for REST client
This commit adds a new configurable timeout to the Services
config to set the amount of time to wait for the server's
response headers. With this change, the client will no longer
wait indefinitely for the HTTP request to complete.

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2020-08-19 05:10:05 -07:00
Patrick East dd683027c0 plugins/rest/aws: Include port in Host header
The AWS v4 signing feature for bundle requests would automatically
add a `Host` header by using the URL hostname. This would break for
URLs that specified a port number (eg: https://127.0.0.1:9000/). That
causes issues with sending a valid request.

This commit changes to use the `URL.Host` which will have the full
`host:port` string, when a port was specified.

Fixes: #2568
Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-07-22 15:07:10 -07:00
Nick Williams d60c9fe018 Implement IMDSv2 for AWS metadata service
Fixes: #2482
Signed-off-by: Nick Williams <nhw@me.com>
2020-06-26 12:37:33 -07:00
Kamil Piotrowski a4412df0fa Add AWS_SESSION_TOKEN and AWS_SECURITY_TOKEN to aws environemnt credentials
AWS_SESSION_TOKEN or AWS_SECURITY_TOKEN is required when signing AWS requests
using ENV credentials from IAM assumed role. Missing token
results with S3 403 error when trying to download bundle.

Signed-off-by: Kamil Piotrowski <kamil.piotrowski@nordcloud.com>
2020-05-04 11:32:37 -07:00
Ashutosh Narkar 5d2b9df39d plugins: Additive updates to services when discovery enabled
Earlier with discovery enabled, there was no protection against accidental
changes to the discovery service. This change prevents the discovery service
from being modified by checking it's config in the service bundle.

Fixes #2058

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2020-04-29 06:36:10 -04:00
Torin Sandall e21a93330e Revert "plugins: Additive updates to services when discovery enabled"
This reverts commit d67c0f7f13.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-04-17 13:03:08 -04:00
Ashutosh Narkar d67c0f7f13 plugins: Additive updates to services when discovery enabled
Earlier with discovery enabled updates to the 'services' configuration
was not allowed to protect against accidental changes to the discovery service
itself. Since adding new services could be useful, this change allows modifications
to the 'services' configuration. The only exception is that the service used to download
the discovery bundle cannot be modified.

Fixes #2058

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2020-04-16 20:46:14 -07:00
Ashutosh Narkar a5be4f49a2 plugins: Add support to specify bearer token path
This change updates the bearer token config to allow clients to specify
a path to the token. With this refreshing tokens becomes easier as OPA
will now reload the token from file.

Fixes #2241

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2020-04-10 17:29:29 -07:00
Patrick East af86b60432 Fix url error checking for go 1.14
It seems as though go 1.14 changes some of the url errors to have
quotes around some fields. To make things compatible across a wider
number of platforms we can relax the checks a tiny bit to only look
at the actual error string and ignore the quoted part.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-04-06 11:09:45 -07:00
Patrick East e46400d232 Create new HTTP rest client for each download
The HTTP client we were using for bundle downloads was being loaded
once and then re-used. This was problematic for users that configure
cert files and then have them change.

This updates the client wrapper in OPA to re-create the underlying
client for each request.

Fixes: #1898
Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-12-13 12:39:14 -08:00
Patrick East b48c534722 Run make fmt with new goimports cmd
Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-09-27 09:55:11 -04:00
Patrick East 1a673b8fd6 Add User-Agent to rest client as default header
This can be overridden by custom header configuration for services,
or requests but will default to something like:

`Open Policy Agent/<version> (<os>, <arch>)`

This is set on all outbound requests for status, decision logs, bundle
and discovery downloads, http requests from policies, etc.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-07-17 13:30:03 -07:00
Nick Williams a360905c5d Support AWS signatures for bundle HTTP operations
ref. Issue #1340

Signed-off-by: Nick Williams <nhw@me.com>
2019-06-03 21:52:27 +02:00
Stephan Renatus c77f9ed228 plugin/rest: avoid zero values in http.Transport{}
When instantiating a http.Transport struct without providing non-zero
values for some of its fields, it will leak connections.

The docs hint at this (https://golang.org/pkg/net/http/#Transport):

  By default, Transport caches connections for future re-use. This may
  leave many open connections when accessing many hosts. This behavior
  can be managed using Transport's CloseIdleConnections method and the
  MaxIdleConnsPerHost and DisableKeepAlives fields.

See this issue for details: https://github.com/golang/go/issues/19620

I have not observed any leaks in the wild for this, but I'm also
not using this plugin. I came to fix this because I had recently
introduced a bug in the server tests -- they were altering the
settings for the global http.DefaultTransport when my intention
was to create a copy. Digging in while fixing that revealed this
other location. (The fix for the server tests is in the next commit).

Signed-off-by: Stephan Renatus <srenatus@chef.io>
2019-01-18 07:46:52 -08:00
Torin Sandall 61420f8e71 Add support for specifying services as object (#1046)
* Fix typo in run short description

Signed-off-by: Torin Sandall <torinsandall@gmail.com>

* Add support for specifying services as object

Previously the services configuration had to be specified as an array,
for example:

services:
- name: foo
  url: https://example.com

In some cases, it's easier to structure the configuration as an object.
Specifically, the Helm package manager does not allow you to override
values nested under arrays. These changes allow the services
configuration to be structured as an object:

services:
  foo:
    url: https://example.com

Ref: https://github.com/helm/helm/issues/1987

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-30 08:02:30 -07:00
Kim Christensen d52bfaa0b2 Only allow insecure TLS when HTTPS is used
Signed-off-by: Kim Christensen <kimworking@gmail.com>
2018-10-24 21:53:05 -07:00
Kim Christensen 6f3f5b34a9 Add support for client certificates
Adds support for usings client certificates to authenticate against
service endpoints. It also enables users to allow insecure TLS
connections to service endpoints.

Fixes #684

Signed-off-by: Kim Christensen <kimworking@gmail.com>
2018-10-24 21:53:05 -07:00
Kim Christensen 318bb20d86 Add tests for existing functionality
Adds tests for the existing REST client functionality

Signed-off-by: Kim Christensen <kimworking@gmail.com>
2018-10-24 21:53:05 -07:00
Torin Sandall 72c5301ec1 Add response debug logging to REST client
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-10 13:58:36 -07:00
Torin Sandall 0f93fb83a9 Add byte slice message body to REST client
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-10 13:58:36 -07:00
Torin Sandall a475f32f82 Add message body support to REST client
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-09 11:05:06 -07:00
Torin Sandall f131cfcff3 Add support for bundle downloading
Previously, policies and data had to be pushed into OPA via the REST API
or loaded via command line arguments at startup.

With these changes, OPA can now be configured to pull down bundles of
policy and data from remote HTTP servers. When a bundle is downloaded
successfully, the policies and data are loaded out of the bundle file
and inserted into storage.
2018-03-16 08:51:37 -07:00