I was working on CORS with Gravitee : So I tested an API that I configured CORS for, but apparetly CORS allow all origin *, though I could check the configuration is active
And then I think about Traefik : How are CORS configured at the Traefik level ? This is question I need to check, before I can confirm that The CORS configuration at the Gravitee level is actually applied, for the API
Checking what allow-access-origin-* are allowed for a given API in Gravitee
my first test checks if rules are there configured :
I just solved part of the issue : now CORS config is applied by Gravitee, and Traefik does not mess with it, fr sure.
the fix was to "re-deploy" API :
after configuring CORS, the API we configured, in my example /apiverte goes into an out-of-sync state, and that, I remembered from the Web UI notifications.
So I ran again the DEPLOY operation, but that was not enough ,
Therefore I ran the whole cycle to DEPLOY/ASK FOR REVIEW/ACCEPT REVIEW/START, but adding first a STOP ( n + 1 = 0, if it's a cycle... So adding one more step brings back to zero state, the initial state, whatever it is) : et voilà (it perfectly worked).
Note : I think everytime we invoke Gravitee APIM API with the HTTP PUT method, we get to the OUT OF SYNC state, and must the exact same way "redeploy" the API
see the output of the test you can run yourself to check CORS config is applied :
* So indeed, now My Configuration on Gravitee Applies for sure, we no longer have :
```bashjbl@poste-devops-jbl-16gbram:~/atelier-helm$ cat masortie.out | grep 'access-control-allow-'
< access-control-allow-origin: *
access-control-allow-origin: *
Now, What I do not understand, is how to test the configured CORS actually block any access... :
<
{"results":[{"gender":"male","name":{"title":"Mr","first":"Per","last":"Grøstad"},"location":{"street":{"number":5071,"name":"Eiriks gate"},"city":"Fannrem","state":"Akershus","country":"Norway","postcode":"0240","coordinates":{"latitude":"56.9742","longitude":"-102.9261"},"timezone":{"offset":"-9:00","description":"Alaska"}},"email":"per.grostad@example.com","login":{"uuid":"c4182206-4729-4c8c-8bc3-f1b033f90adc","username":"silverduck992","password":"rebels","salt":"tBlKUGWW","md5":"5d65c6e03be544bc643c5f0ad75809b7","sha1":"2397e927eb28eb8f48144b2ac806b7c6520ed477","sha256":"f85a40e6f5fa2d9c0b07622ef83a4c0c423b1341ad9cb4f8e9d761c023ad29b3"},"dob":{"date":"1949-05-04T17:48:47.690Z","age":71},"registered":{"date":"2014-11-13T18:59:50.434Z","age":6},"phone":"31950687","cell":"45957016","id":{"name":"FN","value":"04054909581"},"picture":{"large":"https://randomuser.me/api/portraits/men/4.jpg","medium":"https://randomuser.me/api/portraits/med/men/4.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/men/* Curl_http_done: called premature == 0
Connection #0 to host ${GRAVITEE_APIM_GATEWAY_HOST} left intact
4.jpg"},"nat":"NO"}],"info":{"seed":"54d4804140fbf3c2","results":1,"page":1,"version":"1.3"}}jibl@poste-devops-jbl-16gbram:~/atelier-helm/config-api-verte/configs/jullet/semaine2/integration$
Re-deploy an Out-Of-Sync API in Gravitee
Here below is the shell script that I tested (works) :
about this script, you will notice that many env variables are valued from local files, : the ae just json responses persisted ro files while creating/configuring the '/apiverte' for the first time. So here just use the values you have tfor your own api, and your Gravtiee APIM an AM APIs token
so here is the script that worked (some operations are redundant, i just want to keep the exact sequence that I ran, to get to success, though simplification may be done afterwards) :
# -------------------------------------------------------------------------
# ENV 'Gravitee APIM API'
# Gravitee APIM version : `1.30.11`
# -------------------------------------------------------------------------
#
export GRAVITEE_APIM_USER_NAME=admin
export GRAVITEE_APIM_USER_PWD=admin
export GRAVITEE_APIM_API_HOST=apim.gravitee.io
export GRAVITEE_APIM_API_HOST=127.0.0.1
export GRAVITEE_APIM_API_PORT=8484
export GRAVITEE_APIM_API_PROTOCOL=https
export GRAVITEE_APIM_API_PROTOCOL=http
# --
export GRAVITEE_APIM_API_TOKEN=$(cat ./my.gravitee-apim.api.token.json | jq -r '.token')
echo "GRAVITEE_APIM_API_TOKEN=[${GRAVITEE_APIM_API_TOKEN}]"
# re-deploy out of sync api like DEMO WEB UI : is it just running the deploy operation again ?
export URL_APPEL_GRAVITEE_APIM_API="${GRAVITEE_APIM_API_PROTOCOL}://${GRAVITEE_APIM_API_HOST}:${GRAVITEE_APIM_API_PORT}/management/apis/${MY_API_GRAVITEE_UID}/deploy"
curl -k -X POST ${URL_APPEL_GRAVITEE_APIM_API} -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer ${GRAVITEE_APIM_API_TOKEN}" | jq .
# re-deploy out of sync api like DEMO WEB UI : is it just running the deploy operation again ? No, did not work fro me.
# --- STOP the API
# So (n+1=0) to return to initial state : first : stop the started API
export MY_API_GRAVITEE_UID=$(cat my.gravitee-apim.apiVerte.json | jq .id | awk -F '"' '{print $2}')
echo "MY_API_GRAVITEE_UID=[${MY_API_GRAVITEE_UID}]"
# could be either START or STOP
export GRAVITEE_API_LICYCLE_ACTION=STOP
export URL_APPEL_GRAVITEE_APIM_API="${GRAVITEE_APIM_API_PROTOCOL}://${GRAVITEE_APIM_API_HOST}:${GRAVITEE_APIM_API_PORT}/management/apis/${MY_API_GRAVITEE_UID}?api=${MY_API_GRAVITEE_UID}&action=${GRAVITEE_API_LICYCLE_ACTION}"
curl -k -X POST ${URL_APPEL_GRAVITEE_APIM_API} -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer ${GRAVITEE_APIM_API_TOKEN}"
# --- DEPLOY API
export MY_API_GRAVITEE_UID=$(cat my.gravitee-apim.apiVerte.json | jq .id | awk -F '"' '{print $2}')
echo "MY_API_GRAVITEE_UID=[${MY_API_GRAVITEE_UID}]"
export URL_APPEL_GRAVITEE_APIM_API="${GRAVITEE_APIM_API_PROTOCOL}://${GRAVITEE_APIM_API_HOST}:${GRAVITEE_APIM_API_PORT}/management/apis/${MY_API_GRAVITEE_UID}/deploy?api=${MY_API_GRAVITEE_UID}"
curl -k -X POST ${URL_APPEL_GRAVITEE_APIM_API} -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer ${GRAVITEE_APIM_API_TOKEN}" | jq .
# ---
# --- REVIEW API before STARTING IT
# --- https://docs.gravitee.io/apim/1.x/management-api/1.30/#operation/doReviewAction
#
export MY_API_GRAVITEE_UID=$(cat my.gravitee-apim.apiVerte.json | jq .id | awk -F '"' '{print $2}')
echo "MY_API_GRAVITEE_UID=[${MY_API_GRAVITEE_UID}]"
# could be either "ASK" or "ACCEPT"
export GRAVITEE_API_REVIEWS_ACTION=ASK
export GRAVITEE_API_REVIEWS_MSG="I am $(whoami) -bot and silently reviewed the Gravitee API of UID [${MY_API_GRAVITEE_UID}]"
export GRAVITEE_API_REVIEWS_MSG="simpleotherreviewmessageforurlencoding"
export URL_APPEL_GRAVITEE_APIM_API="${GRAVITEE_APIM_API_PROTOCOL}://${GRAVITEE_APIM_API_HOST}:${GRAVITEE_APIM_API_PORT}/management/apis/${MY_API_GRAVITEE_UID}/reviews?api=${MY_API_GRAVITEE_UID}&action=${GRAVITEE_API_REVIEWS_ACTION}"
# That'"s going to be the reviewer's (me) comment"
export PAYLOAD="{
\"message\": \"${GRAVITEE_API_REVIEWS_MSG}\"
}"
curl -ivk -X POST ${URL_APPEL_GRAVITEE_APIM_API} --data "${PAYLOAD}" -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer ${GRAVITEE_APIM_API_TOKEN}"
# The HTTP 204 No Content success status response code indicates that the request has succeeded, but that the client doesn't need to go away from its current page. A 204 response is cacheable by default. An ETag header is included in such a response.
# The common use case is to return 204 as a result of a PUT request, updating a resource, without changing the current content of the page displayed to the user. If the resource is created, 201 Created is returned instead. If the page should be changed to the newly updated page, the 200 should be used instead.
# --- ALSO NEED TO ACCEPT REVIEW
# --- (Note VALIDATION COULD BE SET TO AUTO ACCEPT DEPLOYMENTS)
export GRAVITEE_API_REVIEWS_ACTION=ACCEPT
export GRAVITEE_API_REVIEWS_MSG="I am $(whoami) -bot and silently reviewed the Gravitee API of UID [${MY_API_GRAVITEE_UID}]"
export GRAVITEE_API_REVIEWS_MSG="acceptingapiotherreviewfrombot"
export URL_APPEL_GRAVITEE_APIM_API="${GRAVITEE_APIM_API_PROTOCOL}://${GRAVITEE_APIM_API_HOST}:${GRAVITEE_APIM_API_PORT}/management/apis/${MY_API_GRAVITEE_UID}/reviews?api=${MY_API_GRAVITEE_UID}&action=${GRAVITEE_API_REVIEWS_ACTION}"
# That'"s going to be the reviewer's (me) comment"
export PAYLOAD="{
\"message\": \"${GRAVITEE_API_REVIEWS_MSG}\"
}"
curl -k -X POST ${URL_APPEL_GRAVITEE_APIM_API} --data "${PAYLOAD}" -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer ${GRAVITEE_APIM_API_TOKEN}"
# expected : HTTP 204
# --- (RE-)START the API
export MY_API_GRAVITEE_UID=$(cat my.gravitee-apim.apiVerte.json | jq .id | awk -F '"' '{print $2}')
echo "MY_API_GRAVITEE_UID=[${MY_API_GRAVITEE_UID}]"
# could be either START or STOP
export GRAVITEE_API_LICYCLE_ACTION=START
export URL_APPEL_GRAVITEE_APIM_API="${GRAVITEE_APIM_API_PROTOCOL}://${GRAVITEE_APIM_API_HOST}:${GRAVITEE_APIM_API_PORT}/management/apis/${MY_API_GRAVITEE_UID}?api=${MY_API_GRAVITEE_UID}&action=${GRAVITEE_API_LICYCLE_ACTION}"
curl -k -X POST ${URL_APPEL_GRAVITEE_APIM_API} -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer ${GRAVITEE_APIM_API_TOKEN}"
Comparing to swagger.io 's Petstore CORS Configuration
Yeah, I am no way near a working configuration on my Gravitee API, even though I did the configuration :
Description of issue
Gravitee APIM version :
1.30.11
Gravitee
: So I tested an API that I configured CORS for, but apparetly CORS allow all origin*
, though I could check the configuration is activeGravitee
level is actually applied, for the APIChecking what
allow-access-origin-*
are allowed for a given API inGravitee
Solution found : but stil...
I just solved part of the issue : now
CORS
config is applied byGravitee
, andTraefik
does not mess with it, fr sure.the fix was to "re-deploy" API :
CORS
, theAPI
we configured, in my example/apiverte
goes into an out-of-sync state, and that, I remembered from theWeb UI
notifications.DEPLOY
operation, but that was not enough ,DEPLOY
/ASK FOR REVIEW
/ACCEPT REVIEW
/START
, but adding first a STOP (n + 1 = 0
, if it's a cycle... So adding one more step brings back to zero state, the initial state, whatever it is) : et voilà (it perfectly worked).Gravitee APIM API
with the HTTPPUT
method, we get to the OUT OF SYNC state, and must the exact same way "redeploy" the APIsee the output of the test you can run yourself to check
CORS
config is applied :< {"results":[{"gender":"male","name":{"title":"Mr","first":"Per","last":"Grøstad"},"location":{"street":{"number":5071,"name":"Eiriks gate"},"city":"Fannrem","state":"Akershus","country":"Norway","postcode":"0240","coordinates":{"latitude":"56.9742","longitude":"-102.9261"},"timezone":{"offset":"-9:00","description":"Alaska"}},"email":"per.grostad@example.com","login":{"uuid":"c4182206-4729-4c8c-8bc3-f1b033f90adc","username":"silverduck992","password":"rebels","salt":"tBlKUGWW","md5":"5d65c6e03be544bc643c5f0ad75809b7","sha1":"2397e927eb28eb8f48144b2ac806b7c6520ed477","sha256":"f85a40e6f5fa2d9c0b07622ef83a4c0c423b1341ad9cb4f8e9d761c023ad29b3"},"dob":{"date":"1949-05-04T17:48:47.690Z","age":71},"registered":{"date":"2014-11-13T18:59:50.434Z","age":6},"phone":"31950687","cell":"45957016","id":{"name":"FN","value":"04054909581"},"picture":{"large":"https://randomuser.me/api/portraits/men/4.jpg","medium":"https://randomuser.me/api/portraits/med/men/4.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/men/* Curl_http_done: called premature == 0
Re-deploy an Out-Of-Sync API in
Gravitee
Here below is the shell script that I tested (works) :
Comparing to swagger.io 's Petstore CORS Configuration