tyk icon indicating copy to clipboard operation
tyk copied to clipboard

[TT-10197] Policy is not created by gateway rest api

Open cuttingedge1109 opened this issue 2 years ago • 9 comments

Branch/Environment/Version

  • Branch/Version: v4.1rc10
  • Environment: On-prem

Describe the bug I tried to create policies using Gateway API, more specifically /tyk/policies. The api returns http code 200 but i cannot find policy added.

Reproduction steps Steps to reproduce the behavior:

curl --location --request POST 'http://tyk-gateway:8080/tyk/policies' \
--header 'x-tyk-authorization: foo' \
--header 'Content-Type: application/json' \
--data-raw '{
  "name": "new policy",
  "quota_max": 60,
  "quota_renewal_rate": 60,
  "allowance": 100,
  "rate": 100,
  "per": 5,
  "org_id": "53ac07777cbb8c2d53000002"
}'

It returns

{
    "key": "",
    "status": "ok",
    "action": "added"
}

But i cannot find that in the policy list. Even after reboot or reload gateway.

Expected behavior A new policy should be added.

Configuration (tyk config file): I use the default configuration file for oss gateway.

...
  "policies": {
    "policy_source": "file",
    "policy_record_name": "/opt/tyk-gateway/policies/policies.json"
  },
...

cuttingedge1109 avatar Apr 13 '22 06:04 cuttingedge1109

@cuttingedge1109 thanks for raising this up. We're going to check this as well, and in terms of a possible fix, this will be provided in the same time with the official 4.1 relase.

lghiur avatar Apr 15 '22 08:04 lghiur

I see the doc for the GW that shows the polices endpoint but for OSS is it supposed to work? or just files approach? I get 404 when hitting that endpoint.

Thanks!

brahama avatar May 04 '22 23:05 brahama

I see the doc for the GW that shows the polices endpoint but for OSS is it supposed to work? or just files approach? I get 404 when hitting that endpoint.

Thanks!

Yeah, there is no api endpoint defined for policies in stable versions. But you can find that in 4.1.0-rcN versions. I tested and it works as expected.

cuttingedge1109 avatar May 09 '22 13:05 cuttingedge1109

@lghiur So i think policies api endpoint part in the doc should be removed because 4.0 doesn't support policy api endpoint yet.

cuttingedge1109 avatar May 09 '22 13:05 cuttingedge1109

@cuttingedge1109 thanks for pointing that out, we will work in removing the policies endpoint documentation!

lghiur avatar May 09 '22 13:05 lghiur

This was opened for release candidate version. Closing this thread as this already works in full release versions from 4.1.0 and above.

oluwaseyeayinla avatar Mar 06 '23 21:03 oluwaseyeayinla

I use version 4.3.3, and this still does not work.

curl --location 'http://localhost:8888/tyk/policies' \
--header 'x-tyk-authorization: xxx' \
--header 'Content-Type: application/json' \
--data '{
    "id": "app_repository_jwt_policy",
    "name": "app_repository_jwt_policy",
    "org_id": "default",
    "rate": 1000,
    "per": 1,
    "quota_max": -1,
    "quota_renewal_rate": 60,
    "access_rights": {
      "app_repository_jwt": {
        "api_id": "app_repository_jwt",
        "versions": [
          "Default"
        ]
      }
    }
  }'

Response:

{
    "key": "app_repository_jwt_policy",
    "status": "ok",
    "action": "added"
}

List system policies:

curl --location 'http://localhost:8888/tyk/policies' \
--header 'x-tyk-authorization: xxx'

Response:

[]

konsti avatar Mar 22 '23 19:03 konsti

It works after defining the policy_path in the tyk.conf. Otherwise, Tyk does not know how to save the policy.

It would be less irritating if the API returned an error if that setting was missing.

konsti avatar Mar 22 '23 19:03 konsti

Hi @konsti

Thanks for reporting this - and the fix that you found!

We'll review the opportunity to improve the documentation to ensure that others don't hit this problem - and I've logged the suggestion of an error message which we will aim to implement when we have bandwidth.

We're always open to PRs from the community, if you fancy giving it a try to get this in more quickly?

Thanks for supporting Tyk!

andyo-tyk avatar Apr 24 '23 17:04 andyo-tyk