Hey there,
We are using a Golang plugin to do the auth for tyk. However it causes problems when using multiple policies.
We’re using same keys for different APIs. However, for example, if we just use one API key to access one of our APIs (alpha-api
), then send a request to another API (beta-api
) endpoint (using the same key), a 403 “disallowed” error will pop up. After the cache is cleared (for us 5 minutes), then the key can be used to access the beta-api
We realized it’s because of our policies settings:
{
"alpha-api": {
"access_rights": {
"apple-api": {
"allowed_urls": [],
"api_id": "alpha-api",
"api_name": "alpha-api",
"versions": [
"Default"
]
}
},
"active": true,
"name": "Default policy for alpha-api",
"org_id": "1",
"per": 60,
"rate": 300,
"state": "active"
},
"beta-api": {
"access_rights": {
"beta-api": {
"allowed_urls": [],
"api_id": "beta-api",
"api_name": "beta-api",
"versions": [
"Default"
]
}
},
"active": true,
"name": "Default policy for beta-api",
"org_id": "1",
"per": 60,
"rate": 300,
"state": "active"
}
}
So our solution is to apply multiple policies when do the caching in Golang auth plugin:
object.Session = &coprocess.SessionState{
LastUpdated: time.Now().String(),
IdExtractorDeadline: extractorDeadline,
Metadata: map[string]string{
"token": authKey,
},
// the default policy id for an api is its api id
//ApplyPolicies: []string{apiId},
ApplyPolicies: []string{"alpha-api", "beta-api"},
}
This solves the disallowed
403 error. however, the rate limits set in the polices file are messed up. As you can see in the policies file example above, the rate
is set to 300. But in our test, in one minute, after I sent 100 requests to alpha-api
then 200 requests to beta-api
, the rate limits takes effect and I get 429 error.
I think it might be a bug for supporting multiple policies, or do you have any better ideas to solve this? Thank you!