Developer's API key not honoring associated policies

Hi Martin,

No problem, I’ll have a go with 2.1. We don’t have too big a catalog setup so should be handy enough. Thanks anyhow!

1 Like

Hi Donal,

Did version 2.1 fix the issue?

I am facing same issue when upgrade tyk version.
I have just upgraded TYK version from to 2.0 and after that we are start getting “Rate Limit Exceeded” error for API key.

The policy key associated with set have all values set correctly
Allow number of requests : 1000
per (seconds) : 60
Max Quota (Requests per period): enter -1 for unlimited quota : -1
A key created now expires:Never (–) : Do not expire key

If I check the key configuration then I can see associated policy is correct but other other parameters value is null.

Allow number of requests : 0
per (seconds) : 0
Max Quota (Requests per period): enter -1 for unlimited quota : 0
A key created now expires:Never (–) : null

and If I set these value manually then it works fine.
On version version same(We are using script to create policy which is same) was working fine.

Many Thanks
Mamta

Can you confirm that the policy is being loaded by the Tyk gateway on start?

Tyk will list all policies it is using when it starts up or hot reloads, if the Policy ID isn’t there then the policy is not active.

Actually, can yu start the gateway and give us the log output from when it was started?

Hi Mamta, No I haven’t tried 2.1 yet, will do soon though

I am getting this exception in 2.1 as well.

I am seeing the following messages in the gateway log files.Wonder if this is issue is due to the error highlighted.

ESC[90m[Jun 14 16:19:46]ESC[0m ESC[32m INFOESC[0m ESC[36mhost-check-mgr:ESC[0m Starting Poller
ESC[90m[Jun 14 16:19:46]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m Setting up Server
ESC[90m[Jun 14 16:19:46]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m --> Standard listener (http)
ESC[90m[Jun 14 16:19:46]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m Registering node.
ESC[90m[Jun 14 16:19:46]ESC[0m ESC[31mERRORESC[0m Failed to register node, retrying in 5s
ESC[90m[Jun 14 16:19:51]ESC[0m ESC[31mERRORESC[0m Failed to register node, retrying in 5s
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mdashboard:ESC[0m Node registered ESC[32midESC[0m=f7c84cab-969d-44c5-65ea-46663707e46a
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m Starting heartbeat.
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m Detected 2 APIs
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m --> Loading API: Test Api
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m ----> Tracking: (no host)
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m ----> Checking security policy: Token
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m --> Loading API: Post API
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m ----> Tracking: (no host)
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m ----> Checking security policy: Token
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mhost-check-mgr:ESC[0m Loading uptime tests…

ESC[90m[Jun 14 16:19:56]ESC[0m ESC[31mERRORESC[0m Failed to decode body: json: cannot unmarshal string into Go value of type []main.DBPolicy

ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m Gateway started (v2.1.0.2)
ESC[90m[Jun 14 16:19:56]ESC[0m ESC[32m INFOESC[0m ESC[36mmain:ESC[0m --> Listening on port: 8080

@sandeep in your case it probably is, the policy has not loaded because of a comms issue with the dashboard.

Hi Martin - I am unable to figure out why I am getting this error. Can you tell me what is wrong? Here are my config files.

gateway.conf -

{
“listen_port”: xxxxxxxxxxxx,
“node_secret”: xxxxxxxxxxxx,
“secret”: xxxxxxxxxxxx,
“template_path”: “/opt/tyk-gateway/templates”,
“tyk_js_path”: “/opt/tyk-gateway/js/tyk.js”,
“use_db_app_configs”: true,
“db_app_conf_options”: {
“connection_string”: xxxxxxxxxxxx,
“node_is_segmented”: false,
“tags”: []
},
“app_path”: “/opt/tyk-gateway/apps”,
“middleware_path”: “/opt/tyk-gateway/middleware”,
“storage”: {
“type”: “redis”,
“host”: xxxxxxxxxxxx,
“port”: xxxxxxxxxxxx,
“username”: “”,
“password”: “”,
“database”: 0,
“optimisation_max_idle”: 2000,
“optimisation_max_active”: 6000
},
“enable_analytics”: true,
“analytics_config”: {
“type”: “mongo”,
“csv_dir”: “/tmp”,
“mongo_url”: xxxxxxxxxxxx,
“mongo_db_name”: “tyk_analytics”,
“mongo_collection”: “tyk_analytics”,
“purge_delay”: 100,
“ignored_ips”: [],
“enable_detailed_recording”: false,
“enable_geo_ip”: false,
“geo_ip_db_path”: “”
},
“health_check”: {
“enable_health_checks”: false,
“health_check_value_timeouts”: 60
},
“optimisations_use_async_session_write”: true,
“allow_master_keys”: false,
“policies”: {
“policy_source”: “service”,
“policy_connection_string”: xxxxxxxxxxxx,
“policy_record_name”: “tyk_policies”
},
“hash_keys”: true,
“suppress_redis_signal_reload”: false,
“close_connections”: true,
“enforce_org_quotas”: false,
“enforce_org_data_detail_logging”: false,
“experimental_process_org_off_thread”: true,
“enable_non_transactional_rate_limiter”: true,
“enable_sentinel_rate_limiter”: false,
“local_session_cache”: {
“disable_cached_session_state”: false
},
“uptime_tests”: {
“disable”: false,
“config”: {
“enable_uptime_analytics”: false,
“failure_trigger_sample_size”: 3,
“time_wait”: 300,
“checker_pool_size”: 50
}
},
“hostname”: “”,
“enable_custom_domains”: true,
“enable_jsvm”: true
}

dashboard.conf

{
“listen_port”: xxxxxxxxxxxx,
“tyk_api_config”: {
“Host”: xxxxxxxxxxxx,
“Port”: xxxxxxxxxxxx,
“Secret”: xxxxxxxxxxxx,
},
“mongo_url”: xxxxxxxxxxxx,
“page_size”: 10,
“admin_secret”: xxxxxxxxxxxx,
“shared_node_secret”: xxxxxxxxxxxx,
“redis_port”: xxxxxxxxxxxx,
“redis_host”: xxxxxxxxxxxx,
“redis_password”: “”,
“enable_cluster”: false,
“force_api_defaults”: false,
“notify_on_change”: true,
“license_key”: xxxxxxxxxxxx,
“redis_database”: 0,
“redis_hosts”: null,
“hash_keys”: true,
“email_backend”: {
“enable_email_notifications”: false,
“code”: “”,
“settings”: null,
“default_from_email”: “”,
“default_from_name”: “”
},
“hide_listen_path”: false,
“sentry_code”: “”,
“sentry_js_code”: “”,
“use_sentry”: false,
“enable_master_keys”: false,
“enable_duplicate_slugs”: true,
“show_org_id”: true,
“host_config”: {
“enable_host_names”: true,
“disable_org_slug_prefix”: true,
“hostname”: xxxxxxxxxxxx,
“override_hostname”: “”,
“portal_domains”: “”,
“portal_root_path”: “/portal”,
“generate_secure_paths”: false
},
“http_server_options”: {
“use_ssl”: false,
“certificates”: [
{
“domain_name”: “”,
“cert_file”: “”,
“key_file”: “”
}
],
“min_version”: 0
},
“ui”: {
“login_page”: {},
“nav”: {},
“uptime”: {},
“portal_section”: null,
“designer”: {},
“dont_show_admin_sockets”: false,
“dont_allow_license_management”: false,
“dont_allow_license_management_view”: false
},
“home_dir”: “/opt/tyk-dashboard”,
“identity_broker”: {
“enabled”: false,
“host”: {
“connection_string”: xxxxxxxxxxxx,
“secret”: xxxxxxxxxxxx,
}
},
“tagging_options”: {
“tag_all_apis_by_org”: false
},
“use_sharded_analytics”: false,
“maintenance_mode”: false,
“allow_explicit_policy_id”: false
}

@sandeep which error? This is a very long thread.

The error that I have quoted in my previous post. ie

ESC[90m[Jun 14 16:19:56]ESC[0m ESC[31mERRORESC[0m Failed to decode body: json: cannot unmarshal string into Go value of type []main.DBPolicy

Is this happening every time you do a hot reload or only on the initial start?

The error occurs everytime I restart.

@sandeep Do you have policies to load?

Yes, I’ve defined 2 policies.

Very odd, I can’t seem to replicate it with fresh db’s and policies.

When you do a hot reload, does it happen again?

I went to the policy page and just clicked update without making any change. Still getting the error.

[Jun 17 12:29:20] INFO pub-sub: Reloading endpoints
[Jun 17 12:29:20] INFO Initiating reload
[Jun 17 12:29:30] ERROR Failed to decode body: json: cannot unmarshal string into Go value of type []main.DBPolicy
[Jun 17 12:29:31] INFO main: Detected 2 APIs
[Jun 17 12:29:32] INFO main: --> Loading API: Test Api
[Jun 17 12:29:32] INFO main: ----> Tracking: (no host)
[Jun 17 12:29:32] INFO main: ----> Checking security policy: Token
[Jun 17 12:29:32] INFO main: --> Loading API: Post API
[Jun 17 12:29:32] INFO main: ----> Tracking: (no host)
[Jun 17 12:29:32] INFO main: ----> Checking security policy: Token
[Jun 17 12:29:32] INFO host-check-mgr: Loading uptime tests…
[Jun 17 12:29:32] INFO main: API reload complete

@sandeep is your policy connection string the same as the other one?

I’ve removed the "“policy_record_name”: “tyk_policies” field from gateway.conf and the error has disappeared.

However, the initial issue still remains. The API key created by when I approve the developer key request has rate as 0 messages in 0 seconds. It has the correct policy associated with it with rate as 1000 every 1 second. However, when the developers use this api key they geta "rate limit exceeded " error.

You need the record name, otherwise policies won’t load :slight_smile:

The issue is something to do with your connection string, it’s not allowing the connection.

The issue is resolved now. You were right it was to do with connection string. I had set it to http://dashboard-ip:port/ with a slash at the end. I’ve removed the / at the end and restarted the server. The policies are now loading and rate limit is working correctly. Thanks Martin for your help.

1 Like

Is this possibly what I was seeing too? I haven’t tried the update since