cli
cli copied to clipboard
cf map-route --path '/test;v' fails on second call
- [x] I reviewed open and closed github issues that may be related to my problem.
- [x] I tried updating to the latest version of the CF CLI to see if it fixed my problem.
- [x] I attempted to run the command with
CF_TRACE=1to help debug the issue. - [x] I am reporting a bug that others will be able to reproduce.
- n/a If this is an issue for the v7 beta release, I've read through the official docs and the release notes.
Describe the bug and the command you saw an issue with
When mapping a route with a path that contains a semicolon, it succeeds the first time but fails on the second call.
What happened
stephan@WDFN34095835A:~/testapp$ cf map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path '/test;v'
Creating route testapp94095.cfapps.sap.hana.ondemand.com/test;v for org uptime / space test as D047883...
FAILED
Error resolving route:
Server error, status code: 400, error code: 210004, message: The path is taken: /test;v
Expected behavior Call succeeds as it does for the path '/test':
stephan@WDFN34095835A:~/testapp$ cf map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path '/test'
Creating route testapp94095.cfapps.sap.hana.ondemand.com/test for org uptime / space test as D047883...
OK
Route testapp94095.cfapps.sap.hana.ondemand.com/test already exists
Adding route testapp94095.cfapps.sap.hana.ondemand.com/test to app testapp1 in org uptime / space test as D047883...
OK
To Reproduce
Given a simple hello world app:
mkdir testapp && cd testapp
cat > index.html <<'EOF'
<!DOCTYPE html>
<html>
<body>
<h1>Hello World</h1>
</body>
</html>
EOF
mkdir -p test
cp index.html test/
cf push testapp1 -p . -m 128M -b binary_buildpack -c 'python3 -m http.server 8080' --no-route --no-start
Map routes to the app using a path with and without a semicolon:
stephan@WDFN34095835A:~/testapp$ cf map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path /test
Creating route testapp94095.cfapps.sap.hana.ondemand.com/test for org uptime / space test as D047883...
OK
Adding route testapp94095.cfapps.sap.hana.ondemand.com/test to app testapp1 in org uptime / space test as D047883...
OK
stephan@WDFN34095835A:~/testapp$ cf map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path '/test;v'
Creating route testapp94095.cfapps.sap.hana.ondemand.com/test;v for org uptime / space test as D047883...
OK
Adding route testapp94095.cfapps.sap.hana.ondemand.com/test;v to app testapp1 in org uptime / space test as D047883...
OK
Start the app:
stephan@WDFN34095835A:~/testapp$ cf start testapp1
Starting app testapp1 in org uptime / space test as D047883...
Staging app and tracing logs...
...
Waiting for app to start...
name: testapp1
requested state: started
routes: testapp94095.cfapps.sap.hana.ondemand.com/test, testapp94095.cfapps.sap.hana.ondemand.com/test;v
last uploaded: Fri 30 Aug 11:27:35 DST 2019
stack: cflinuxfs3
buildpacks: binary
type: web
instances: 1/1
memory usage: 128M
start command: python3 -m http.server 8080
state since cpu memory disk details
#0 running 2019-08-30T09:27:50Z 0.0% 2.1M of 128M 24K of 1G
Both routes are mapped and they work. The one with the semicolon returns a 404 which stems from the app. Don't know how the Python web server deals with a semicolon in the path but this is not relevant for the issue.
stephan@WDFN34095835A:~/testapp$ curl https://testapp94095.cfapps.sap.hana.ondemand.com/test/
<!DOCTYPE html>
<html>
<body>
<h1>Hello World</h1>
</body>
</html>
stephan@WDFN34095835A:~/testapp$ curl https://testapp94095.cfapps.sap.hana.ondemand.com/test/^C
stephan@WDFN34095835A:~/testapp$ curl 'https://testapp94095.cfapps.sap.hana.ondemand.com/test;v/'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Error response</title>
</head>
<body>
<h1>Error response</h1>
<p>Error code: 404</p>
<p>Message: File not found.</p>
<p>Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.</p>
</body>
</html>
Now I rerun the route mapping (this may e.g. happen during a blue-green deployment):
stephan@WDFN34095835A:~/testapp$ cf map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path /test
Creating route testapp94095.cfapps.sap.hana.ondemand.com/test for org uptime / space test as D047883...
OK
Route testapp94095.cfapps.sap.hana.ondemand.com/test already exists
Adding route testapp94095.cfapps.sap.hana.ondemand.com/test to app testapp1 in org uptime / space test as D047883...
OK
stephan@WDFN34095835A:~/testapp$ cf map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path '/test;v'
Creating route testapp94095.cfapps.sap.hana.ondemand.com/test;v for org uptime / space test as D047883...
FAILED
Error resolving route:
Server error, status code: 400, error code: 210004, message: The path is taken: /test;v
The route mapping without semicolon succeeds but the one with a semicolon fails.
When running with -v I see the following CF API call failing:
REQUEST: [2019-08-30T13:43:13+02:00]
GET /v2/routes?inline-relations-depth=1&q=host%3Atestapp94095%3Bdomain_guid%3A9aa474f9-3f82-4967-a2e1-dfe0cd155064%3Bpath%3A%2Ftest%3Bv HTTP/1.1
Host: api.cf.sap.hana.ondemand.com
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/json
User-Agent: go-cli 6.46.1+4934877ec.2019-08-23 / linux
RESPONSE: [2019-08-30T13:43:13+02:00]
HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 114
Content-Type: application/json;charset=utf-8
Date: Fri, 30 Aug 2019 11:43:13 GMT
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;
X-Content-Type-Options: nosniff
X-Ratelimit-Limit: 40000
X-Ratelimit-Remaining: 39984
X-Ratelimit-Reset: 1567168899
X-Vcap-Request-Id: aeccd93f-5c10-4f29-719b-212b853069ca::35039c3f-335d-43a8-af8a-85d0336be3b9
{
"description": "The query parameter is invalid: v",
"error_code": "CF-BadQueryParameter",
"code": 10005
}
FAILED
Error resolving route:
Server error, status code: 400, error code: 210004, message: The path is taken: /test;v
Looks like there is an issue with encoding (or with the decoding in CC) of the semicolon in the GET /v2/routes.
Provide more context
-
platform and shell details ( e.g. Mac OS X 10.11 iTerm) Win10 with bash (WSL)
-
version of the CLI you are running
stephan@WDFN34095835A:~/testapp$ cf --version
cf version 6.46.1+4934877ec.2019-08-23
- version of the CC API Release you are on cf-deployment 11.0.0
stephan@WDFN34095835A:~/testapp$ cf api
api endpoint: https://api.cf.sap.hana.ondemand.com
api version: 2.139.0
Note: As of January 2019, we no longer support API versions older than CF Release v284/CF Deployment v1.7.0 (CAPI Release: 1.46.0 (APIs 2.100.0 and 3.35.0).
Note: In order to complete the v7 beta cf CLI in a timely matter, we develop and test against the latest CAPI release candidate. When v7 cf CLI is generally available, we will start supporting official CC API releases again.
We have created an issue in Pivotal Tracker to manage this:
https://www.pivotaltracker.com/story/show/168216803
The labels on this github issue will be updated when the story is started.
The same scenario works with cf7 beta cli:
stephan@WDFN34095835A:~/testapp$ cf7 --version
cf7 version 7.0.0-beta.24+71d763254.2019-08-20
stephan@WDFN34095835A:~/testapp$ cf7 push testapp1 -p . -m 128M -b binary_buildpack -c 'python3 -m http.server 8080' --no-route --no-start
Creating app testapp1...
Pushing app testapp1 to org uptime / space test as D047883...
...
Waiting for API to complete processing files...
name: testapp1
requested state: stopped
routes:
last uploaded:
stack:
buildpacks:
type: web
instances: 0/1
memory usage: 128M
start command: python3 -m http.server 8080
state since cpu memory disk details
#0 down 2019-08-30T12:36:56Z 0.0% 0 of 0 0 of 0
stephan@WDFN34095835A:~/testapp$ cf7 map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path /test
Creating route testapp94095.cfapps.sap.hana.ondemand.com/test for org uptime / space test as D047883...
OK
Mapping route testapp94095.cfapps.sap.hana.ondemand.com/test to app testapp1 in org uptime / space test as D047883...
OK
stephan@WDFN34095835A:~/testapp$ cf7 map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path '/test;v'
Creating route testapp94095.cfapps.sap.hana.ondemand.com/test;v for org uptime / space test as D047883...
OK
Mapping route testapp94095.cfapps.sap.hana.ondemand.com/test;v to app testapp1 in org uptime / space test as D047883...
OK
# cf7 start testapp1 doesn't work yet due to missing droplet (known limitation)
stephan@WDFN34095835A:~/testapp$ cf push testapp1 -p . -m 128M -b binary_buildpack -c 'python3 -m http.server 8080'
Pushing app testapp1 to org uptime / space test as D047883...
Getting app info...
...
Waiting for app to start...
name: testapp1
requested state: started
routes: testapp94095.cfapps.sap.hana.ondemand.com/test, testapp94095.cfapps.sap.hana.ondemand.com/test;v
last uploaded: Fri 30 Aug 14:38:11 DST 2019
stack: cflinuxfs3
buildpacks: binary
type: web
instances: 1/1
memory usage: 128M
start command: python3 -m http.server 8080
state since cpu memory disk details
#0 running 2019-08-30T12:38:29Z 0.0% 0 of 128M 0 of 1G
stephan@WDFN34095835A:~/testapp$ cf7 map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path /test
Mapping route testapp94095.cfapps.sap.hana.ondemand.com/test to app testapp1 in org uptime / space test as D047883...
App 'testapp1' is already mapped to route 'testapp94095.cfapps.sap.hana.ondemand.com/test'.
OK
stephan@WDFN34095835A:~/testapp$ cf7 map-route testapp1 cfapps.sap.hana.ondemand.com --hostname testapp94095 --path '/test;v'
Mapping route testapp94095.cfapps.sap.hana.ondemand.com/test;v to app testapp1 in org uptime / space test as D047883...
App 'testapp1' is already mapped to route 'testapp94095.cfapps.sap.hana.ondemand.com/test;v'.
OK
Hi @stephanme thanks for creating this. It sounds like this is a bug with CC API @selzoc @ssisil, any ideas if ; is a forbidden character? We have a few GitHub issues similar to this one re: forbidden characters.
I don't think it's a bug in the v2 CC API per se - the q parameter that the CLI uses to ask for routes with the given host/path/domain (without the url escaping):
GET /v2/routes?inline-relations-depth=1&q=host:test1;domain_guid:98e7bfc8-a666-4243-9b3d-47fe17752a53;path:/test;v
as you can see, the ; character is used to separate the different segments of the query, so the v is being interpreted as another segment (which is not valid) and that's why you get the "The query parameter is invalid: v" error. In the eyes of the v2 api, you have asked for a path of /test
On the v3 api, the query is
GET /v3/routes?domain_guids=98e7bfc8-a666-4243-9b3d-47fe17752a53&hosts=test1&paths=/test;v
Notice that the query format is different, and instead of a q parameter with multiple segments, we instead have hosts and paths query parameters. So in the v2 api, the path is actually interpreted as /test;v.
Perhaps the v6 cli could instead use this endpoint to check if a route exists? http://apidocs.cloudfoundry.org/11.1.0/routes/check_a_http_route_exists.html
Thanks for reporting this issue @stephanme and providing detailed reproduction steps. Thanks also to @selzoc for debugging this further.
This is where in the CLI code we currently build the CAPI request to find the existing route.
We thought of a few different options for fixing this:
- As Chris says, it seems most sensible to use the alternative
/v2/routes/reservedendpoint here. - We considered if it would be possible to jump to the v3 endpoint, but this was introduced relatively recently and is not available in all versions covered by our support window.
- We wondered if it was possible to escape the semi-colon in the CAPI custom query syntax but could see no support in the CAPI code for allowing us to do this.
We think we are likely to also see this problem elsewhere where semi-colons are provided to the ?q parameter.
We're not sure how this will be prioritized, but we have added a contributions welcome label in the meantime.
Thanks!
@acrmp && @bwasmith
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed.