Zuul prefix when more than a single /path - netflix-zuul

I have a service with this path http://myhost.com/v2/1234/brand/order/issues/123 that needs to send the actual call to http://anotherhost.com/issues/123.
If I want to avoid the solution to write a ZuulFilter
Is there a way, with the configuration to say: the prefix is /v2/*/*/order/issues and just use 123?
zuul:
routes:
test2:
path: /v2/*/*/orders/issues/**
url: http://anotherhost.com/issues/
stripPrefix: true

No, there's no way to configure such behaviour. You need to create custom ZuulFilter
By default Zuul will only strip prefixes that do not contain special characters. e.g.
zuul:
routes:
test1:
path: /orders/** <--- '/orders' is stripped
url: http://anotherhost.com/issues/
test2:
path: /*/orders/** <--- nothing is stripped
url: http://anotherhost.com/issues/

Related

Configure `:path` header for envoy ratelimiting

I'm trying to use envoy ratelimiting functionality and need to ratelimit based on the entire url in my request, e.g. https://myenvoy.com/path/to/smth
Here is a part of my envoy.yaml
routes:
- match: { prefix: "/" }
route:
cluster: backend
rate_limits:
- stage: 0
actions:
- {request_headers: {header_name: ":path", descriptor_key: "path"}}
When I run
curl -k https://myenvoy.com/path/to/smth
The above configuration creates descriptor value /path/to/smth whereas I would like to have descriptor of value https://myenvoy.com/path/to/smth
Is it possible to configure that with envoy?
Thank you
PS: I looked at these header values and tried to use some, but it didn't help
https://github.com/envoyproxy/envoy/blob/master/source/common/http/headers.h
From further investigation,
- {request_headers: {header_name: "host", descriptor_key: "host"}}
does the job

Prevent swagger-codegen (OpenAPI 2.0) url-encoding of string format: URI [duplicate]

I have an API which allows any arbitrary path to be passed in, for example all of these:
/api/tags
/api/tags/foo
/api/tags/foo/bar/baz
Are valid paths. I tried to describe it as follows:
/tags{tag_path}:
get:
parameters:
- name: tag_path
in: path
required: true
type: string
default: "/"
However, https://generator.swagger.io encodes slashes in the path, so it doesn't work. So is there a way to describe my API in Swagger?
This is not supported as of OpenAPI 3.1, and I have to resort to a workaround.
If I have a path /tags{tag_path} and I enter something like this as tag_path: /foo/bar, then the actual query request URL will be: /tags%2Ffoo%2Fbar. So, I just added support for that on my backend: the endpoint handler for /tags* urldecodes the path (which is %2Ffoo%2Fbar), and it becomes /foo/bar again.
Yes, a hack, but it works, and it's better than nothing. In my case, tag names can't contain the / character, so there's no conflict. Your mileage may vary, of course.
If you are using a framework like Connexion, chances are it does support a wildcard path parameter (even though it is not in the OpenAPI spec).
Here is an example for Connexion.
paths:
/pages/{path}:
get:
# (...)
parameters:
- name: "path"
in: path
description: "Remainder of path, including slashes."
schema:
type: string
format: path
The difference is the format: path added.

Swagger: wildcard path parameters

I have an API which allows any arbitrary path to be passed in, for example all of these:
/api/tags
/api/tags/foo
/api/tags/foo/bar/baz
Are valid paths. I tried to describe it as follows:
/tags{tag_path}:
get:
parameters:
- name: tag_path
in: path
required: true
type: string
default: "/"
However, https://generator.swagger.io encodes slashes in the path, so it doesn't work. So is there a way to describe my API in Swagger?
This is not supported as of OpenAPI 3.1, and I have to resort to a workaround.
If I have a path /tags{tag_path} and I enter something like this as tag_path: /foo/bar, then the actual query request URL will be: /tags%2Ffoo%2Fbar. So, I just added support for that on my backend: the endpoint handler for /tags* urldecodes the path (which is %2Ffoo%2Fbar), and it becomes /foo/bar again.
Yes, a hack, but it works, and it's better than nothing. In my case, tag names can't contain the / character, so there's no conflict. Your mileage may vary, of course.
If you are using a framework like Connexion, chances are it does support a wildcard path parameter (even though it is not in the OpenAPI spec).
Here is an example for Connexion.
paths:
/pages/{path}:
get:
# (...)
parameters:
- name: "path"
in: path
description: "Remainder of path, including slashes."
schema:
type: string
format: path
The difference is the format: path added.

Authorize redirection loop with FOSOAuth2 and FOSUser

I'm trying to make FOSUserBundle work with FOSOAuthServerBundle
, and I'm struggling with oauth_authorize, getting a 302 redirection loop.
Here is what I have in my security.yml (simplified):
firewalls:
oauth_authorize:
pattern: ^/oauth/v2/auth
form_login:
provider: fos_userbundle
check_path: /oauth/v2/auth/login_check
login_path: /oauth/v2/auth/login
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/oauth/v2/auth/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
I have to specify the login_path because the default /login doesn't match oauth_authorize pattern.
I've added the /oauth/v2/auth/login route in my bundle, but even with a dummy controller, it's never called. I just get 302 redirections until Firefox says it's enough.
Someone in the comments here suggested to add $ at the end of the pattern regex, but then the routes doesn't match.
The log gives me:
security.INFO: An AuthenticationException was thrown; redirecting to authentication entry point. {"exception":"[object] (Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code: 0): A Token was not found in the TokenStorage. at /home/arthur/PhpstormProjects/rss-api/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php:53)"} []
Am I missing something?
EDIT: symfony 3.0 and oauth-server-bundle 1.5
I was indeed missing something, the anonymous directive which prevents the firewall to block the access.
firewalls:
oauth_authorize:
pattern: ^/oauth/v2/auth
form_login:
provider: fos_userbundle
check_path: /oauth/v2/auth/login_check
login_path: /oauth/v2/auth/login
anonymous: true

How to parameterize the API base path in OpenAPI (Swagger)?

I have an URL like this:
/id/{idnumber}/status
In this URL, /id/{idnumber} is the API base path, and /status is the resource.
I know that OpenAPI (Swagger) allows parameters in paths, like so:
paths:
/id/{number}/status:
but this is not what I need, because /id/{idnumber} is the base path and not part of the resoruce path.
Is there any way to have a parameter in the base path?
host: my.api.com
basePath: /id/{idnumber} # <---
paths:
/status:
Parameterized base paths are supported in OpenAPI 3.x, using server variables:
openapi: 3.0.0
...
servers:
- url: https://my.api.com/id/{number}
variables:
number:
default: '-1'
Note that server variables MUST have a default value - it will be used if the client does not supply a value.
For details, see:
Server Object and Server Variable Object sections of the the OpenAPI 3.0 Specification
API Server and Base URL on swagger.io
I don't think basePath allows variables.
For your case, you don't need to use basePath. You can simply put /id/{idnumber} in the URL path. For example:
"/pet/{petId}": {

Resources