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

Policy: HTTP proxy #1080

Merged
merged 6 commits into from
Jul 26, 2019
Merged

Policy: HTTP proxy #1080

merged 6 commits into from
Jul 26, 2019

Conversation

eloycoto
Copy link
Contributor

This policy adds the option to set a service to use a http proxy (As is
in use for HTTP_PROXY parameter)

This service will allow Apicast users to send the traffic over a proxy
and do request modifications in 3-party proxies.

Traffic flow:

	   ,-.
	   `-'
	   /|\
		|            ,-------.          ,---------.          ,----------.
	   / \           |Apicast|          |HTTPPROXY|          |APIBackend|
	  User           `---+---'          `----+----'          `----------'
	   |  GET /resource  |                   |                    |
	   | --------------->|                   |                    |
	   |                 |                   |                    |
	   |                 |  Get /resource    |                    |
	   |                 |------------------>|                    |
	   |                 |                   |                    |
	   |                 |                   |  Get /resource/    |
	   |                 |                   | - - - - - - - - - >|
	   |                 |                   |                    |
	   |                 |                   |     response       |
	   |                 |                   |<- - - - - - - - - -|
	   |                 |                   |                    |
	   |                 |     response      |                    |
	   |                 |<------------------|                    |
	   |                 |                   |                    |
	   |                 |                   |                    |
	   | <---------------|                   |                    |
	  User           ,---+---.          ,----+----.          ,----------.
	   ,-.           |Apicast|          |HTTPPROXY|          |APIBackend|
	   `-'           `-------'          `---------'          `----------'
	   /|\
		|
	   / \

Configuration:

{
  "services": [
	{
	  "id": 200,
	  "backend_version":  1,
	  "backend_authentication_type": "service_token",
	  "backend_authentication_value": "token-value",
	  "proxy": {
		"hosts": [
		  "one"
		],
		"api_backend": "https://echo-api.3scale.net/",
		"proxy_rules": [
		  {
			"pattern": "/",
			"http_method": "GET",
			"metric_system_name": "hits",
			"delta": 1
		  }
		],
		"policy_chain": [
		  {
			"name": "apicast.policy.apicast"
		  },
		  {
			"name": "apicast.policy.http_proxy",
			"configuration": {
				"all_proxy": "http://192.168.15.103:8888/",
				"https_proxy": "https://192.168.15.103:8888/",
				"http_proxy": "https://192.168.15.103:8888/"
			}
		  }
		]
	  }
	}
  ]
}

@eloycoto eloycoto changed the title Policy: HTTP proxy WIP: Policy: HTTP proxy Jun 28, 2019
@eloycoto eloycoto force-pushed the HTTPProxyPolicy branch 3 times, most recently from 4d35291 to 5a64c3b Compare June 28, 2019 14:53
@eloycoto eloycoto force-pushed the HTTPProxyPolicy branch 3 times, most recently from c6e5abb to e8ae68a Compare July 22, 2019 09:22
@eloycoto eloycoto changed the title WIP: Policy: HTTP proxy Policy: HTTP proxy Jul 22, 2019
@eloycoto eloycoto requested a review from davidor July 22, 2019 09:43
@eloycoto eloycoto marked this pull request as ready for review July 22, 2019 15:03
@eloycoto eloycoto requested a review from a team as a code owner July 22, 2019 15:03
@davidor
Copy link
Contributor

davidor commented Jul 24, 2019

@eloycoto The commit with title Policy: Add http_proxy integration test appears as empty here, and I can't see any integration tests in other commits, so I guess something went wrong.

@mikz
Copy link
Contributor

mikz commented Jul 24, 2019

Also, the feature + tests should be in the same commit anyway :)

"name": "apicast.policy.apicast"
},
{
"name": "apicast.policy.http_proxy",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's important to clarify that this only applies to the API backend and not the 3scale backend (apisonator).

and terminated, traffic for this policy will be:

```
@startuml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look good when I open the file with the View file option in GitHub.

# HTTP proxy policy

This policy allows users to define a HTTP proxy where the traffic will be send
and terminated, traffic for this policy will be:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by terminated here?


## Caveats

- This policy will disable all load-balancing policies and traffic will be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asking just in case. Does the order in the chain matter?

"type": "string"
},
"https_proxy": {
"description": "Defines a HTTP proxy to be used for connecting to HTTP services. Authentication is not supported",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be HTTPS instead of HTTP.

end
end

for _, proto in ipairs(proxies) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local ipairs = ipairs ?

@@ -108,6 +108,12 @@ local function find_proxy_url(request)
local uri = parse_request_uri(request)
if not uri then return end

-- request can have a local proxy defined and env variables have lower
-- priority, if the proxy is defined in the request that will be used.
if request.proxy_uri then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified:

return request.proxy_uri or _M.find(uri)

local proxy = proxy_policy.new({
all_proxy = all_proxy_val
})
assert.same(proxy:find_proxy("http"), resty_url.parse(all_proxy_val))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all these tests, I think we should check what export returns instead of find_proxy, because export is what should be exposed to other modules.

using proxy: $TEST_NGINX_HTTP_PROXY

=== TEST 3: using HTTPS proxy for backend
--- ONLY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

location /transactions/authrep.xml {
access_by_lua_block {
assert = require('luassert')
assert.equal('https', ngx.var.scheme)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't all this be in upstream instead of backend ?

@eloycoto eloycoto force-pushed the HTTPProxyPolicy branch 4 times, most recently from 8fa98a0 to c947504 Compare July 26, 2019 12:50
@eloycoto eloycoto requested a review from davidor July 26, 2019 13:04

An example HTTP proxy transformation can be the following project; this project
transforms the response given by and endpoint and converts the body to
uppercaint and convert the body to uppercase.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence does not sound right.

CHANGELOG.md Outdated
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Introduce possibility of specifying policy order restrictions in their schemas. APIcast now shows a warning when those restrictions are not respected [#1088](https://github.com/3scale/APIcast/pull/1088), [THREESCALE-2896](https://issues.jboss.org/browse/THREESCALE-2896)
- Added new parameters to logging policy to allow custom access log [PR #1081](https://github.com/3scale/APIcast/pull/1089) [THREESCALE-1234](https://issues.jboss.org/browse/THREESCALE-1234)[THREESCALE-2876](https://issues.jboss.org/browse/THREESCALE-2876)
- Added http_proxy policy to use an HTTP proxy in api_backed calls. [THREESCALE-2696](https://issues.jboss.org/browse/THREESCALE-2696)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add the link to this PR as well.

@@ -0,0 +1,48 @@
local policy = require('apicast.policy')
local _M = policy.new('http_proxy')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the version? It's needed in order to make the feature of checking the order of policies work.
I needed to add the version in all the policies here: https://github.com/3scale/APIcast/pull/1088/files
In the future we might want to see if there's a better way to do this.


function _M:export()
return {
get_http_proxy = function(_, uri)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this function needs the first param.
Can't we get rid of it and then just call context.get_http_proxy(self.uri) from the upstream module instead of context:get_http_proxy(self.uri) ?

eloycoto added 6 commits July 26, 2019 16:41
This policy adds the option to set a service to use a http proxy (As is
in use for HTTP_PROXY parameter)

This service will allow Apicast users to send the traffic over a proxy
and do request modifications in 3-party proxies.

Traffic flow:

```
       ,-.
       `-'
       /|\
        |            ,-------.          ,---------.          ,----------.
       / \           |Apicast|          |HTTPPROXY|          |APIBackend|
      User           `---+---'          `----+----'          `----------'
       |  GET /resource  |                   |                    |
       | --------------->|                   |                    |
       |                 |                   |                    |
       |                 |  Get /resource    |                    |
       |                 |------------------>|                    |
       |                 |                   |                    |
       |                 |                   |  Get /resource/    |
       |                 |                   | - - - - - - - - - >|
       |                 |                   |                    |
       |                 |                   |     response       |
       |                 |                   |<- - - - - - - - - -|
       |                 |                   |                    |
       |                 |     response      |                    |
       |                 |<------------------|                    |
       |                 |                   |                    |
       |                 |                   |                    |
       | <---------------|                   |                    |
      User           ,---+---.          ,----+----.          ,----------.
       ,-.           |Apicast|          |HTTPPROXY|          |APIBackend|
       `-'           `-------'          `---------'          `----------'
       /|\
        |
       / \

```

Configuration:
```
{
  "services": [
    {
      "id": 200,
      "backend_version":  1,
      "backend_authentication_type": "service_token",
      "backend_authentication_value": "token-value",
      "proxy": {
        "hosts": [
          "one"
        ],
        "api_backend": "https://echo-api.3scale.net/",
        "proxy_rules": [
          {
            "pattern": "/",
            "http_method": "GET",
            "metric_system_name": "hits",
            "delta": 1
          }
        ],
        "policy_chain": [
          {
            "name": "apicast.policy.apicast"
          },
          {
            "name": "apicast.policy.http_proxy",
            "configuration": {
                "all_proxy": "http://192.168.15.103:8888/",
                "https_proxy": "https://192.168.15.103:8888/",
                "http_proxy": "https://192.168.15.103:8888/"
            }
          }
        ]
      }
    }
  ]
}
```

Signed-off-by: Eloy Coto <[email protected]>
This commit adds the integration test for the http proxy policy.

Signed-off-by: Eloy Coto <[email protected]>
Add readme for http_proxy configuration.

Signed-off-by: Eloy Coto <[email protected]>
Signed-off-by: Eloy Coto <[email protected]>
@eloycoto eloycoto requested a review from davidor July 26, 2019 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants