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

[Bug] HTTP 415 when creating Automated Rules using multipart/form-data #1490

Closed
andrewazores opened this issue May 11, 2023 · 0 comments · Fixed by #1499
Closed

[Bug] HTTP 415 when creating Automated Rules using multipart/form-data #1490

andrewazores opened this issue May 11, 2023 · 0 comments · Fixed by #1499
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@andrewazores
Copy link
Member

andrewazores commented May 11, 2023

Current Behavior:

POSTing a multipart/form-data to /api/v2/rules always produces an HTTP 415 error response.

Expected Behavior:

The rule should be created whether submitted as multipart/form-data, application/x-www-form-urlencoded, or application/json.

Related to https://github.com/cryostatio/cryostat/pull/1072

Steps To Reproduce:

  1. sh run.sh
  2. Try to POST a multipart form:
$ curl -vk -F name="firstRule" -F matchExpression="target.labels[\"app\"]==\"jfr-sb-app\"" -F eventSpecifier="template=Profiling,type=TARGET" https://localhost:8181/api/v2/rules -H 'Accept: application/json' -H 'Content-Type: multipart/form-data'
*   Trying 127.0.0.1:8181...
* Connected to localhost (127.0.0.1) port 8181 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS header, Finished (20):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS header, Finished (20):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: C=CA; O=Cryostat; CN=cryostat
*  start date: Feb  2 02:03:33 2023 GMT
*  expire date: Feb  2 02:03:33 2024 GMT
*  issuer: C=CA; O=Cryostat; CN=cryostat
*  SSL certificate verify result: self-signed certificate (18), continuing anyway.
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
> POST /api/v2/rules HTTP/1.1
> Host: localhost:8181
> User-Agent: curl/7.85.0
> Accept: application/json
> Content-Length: 419
> Content-Type: multipart/form-data; boundary=------------------------1b58d77f95f35fe9
> 
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* We are completely uploaded and fine
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Mark bundle as not supporting multiuse
< HTTP/1.1 415 Unsupported Media Type
< content-type: application/json
< content-length: 87
< 
* Connection #0 to host localhost left intact
{"meta":{"type":"text/plain","status":"Unsupported Media Type"},"data":{"reason":null}}
  1. Try the same submission using a urlencoded-form:
$ curl -vk -d name="firstRule" -d matchExpression="target.labels[\"app\"]==\"jfr-sb-app\"" -d eventSpecifier="template=Profiling,type=TARGET" https://localhost:8181/api/v2/rules -H 'Accept: application/json'
*   Trying 127.0.0.1:8181...
* Connected to localhost (127.0.0.1) port 8181 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS header, Finished (20):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS header, Finished (20):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: C=CA; O=Cryostat; CN=cryostat
*  start date: Feb  2 02:03:33 2023 GMT
*  expire date: Feb  2 02:03:33 2024 GMT
*  issuer: C=CA; O=Cryostat; CN=cryostat
*  SSL certificate verify result: self-signed certificate (18), continuing anyway.
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
> POST /api/v2/rules HTTP/1.1
> Host: localhost:8181
> User-Agent: curl/7.85.0
> Accept: application/json
> Content-Length: 111
> Content-Type: application/x-www-form-urlencoded
> 
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< location: /api/v2/rules/firstRule
< content-type: application/json
< content-length: 85
< 
* Connection #0 to host localhost left intact
{"meta":{"type":"application/json","status":"Created"},"data":{"result":"firstRule"}}
  1. Try a submission as JSON:
$ curl -vk -H 'Content-Type: application/json' -d '{"name":"secondRule","matchExpression":"false","eventSpecifier":"template=Profiling,type=TARGET"}' https://localhost:8181/api/v2/rules -H 'Accept: application/json'
*   Trying 127.0.0.1:8181...
* Connected to localhost (127.0.0.1) port 8181 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS header, Finished (20):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS header, Finished (20):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: C=CA; O=Cryostat; CN=cryostat
*  start date: Feb  2 02:03:33 2023 GMT
*  expire date: Feb  2 02:03:33 2024 GMT
*  issuer: C=CA; O=Cryostat; CN=cryostat
*  SSL certificate verify result: self-signed certificate (18), continuing anyway.
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
> POST /api/v2/rules HTTP/1.1
> Host: localhost:8181
> User-Agent: curl/7.85.0
> Content-Type: application/json
> Accept: application/json
> Content-Length: 97
> 
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< location: /api/v2/rules/secondRule
< content-type: application/json
< content-length: 86
< 
* Connection #0 to host localhost left intact
{"meta":{"type":"application/json","status":"Created"},"data":{"result":"secondRule"}}
@andrewazores andrewazores added bug Something isn't working good first issue Good for newcomers labels May 11, 2023
@andrewazores andrewazores moved this to Todo in 2.3.1 release May 11, 2023
@andrewazores andrewazores moved this to Todo in 2.4.0 release May 11, 2023
@andrewazores andrewazores moved this from Todo to Backlog in 2.4.0 release May 23, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in 2.3.1 release Jun 2, 2023
@github-project-automation github-project-automation bot moved this from Backlog to Done in 2.4.0 release Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
No open projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants