kongfig
kongfig copied to clipboard
Invariant Violation: Unable to find a consumer for
Hello,
I had the same problem reported in issue-118. I tried the branch fix-118. Now i get
Invariant Violation: Unable to find a consumer for xxxxxx I do not have any consumer definition in the config file. Only api, plugin(acl and auth)
Thanks
Any update on this? Facing same issue
I have the same problem running Kongfig v1.5.3 against Kong 0.12.3 - both running in Docker. Kongfig has been working fine for the last 12 months, until I added the first consumer specific plugin in Kong.
After succesfull creation of a consumer specific plugin, every attempt to change the Kong configuration with Kongfig fails with the following error:
Invariant Violation: Unable to find a consumer for 5f905965-2fa9-4887-ad76-a03cc9dac146
Invariant Violation: Unable to find a consumer for 5f905965-2fa9-4887-ad76-a03cc9dac146
at invariant (/usr/local/lib/node_modules/kongfig/node_modules/invariant/invariant.js:40:15)
at getConsumerById (/usr/local/lib/node_modules/kongfig/lib/stateSelector.js:22:29)
at fixPluginUsername (/usr/local/lib/node_modules/kongfig/lib/stateSelector.js:59:33)
at Array.map (<anonymous>)
at fixApiPluginUsername (/usr/local/lib/node_modules/kongfig/lib/stateSelector.js:67:42)
at Array.map (<anonymous>)
at exports.default (/usr/local/lib/node_modules/kongfig/lib/stateSelector.js:72:40)
at /usr/local/lib/node_modules/kongfig/lib/readKongApi.js:46:64
at process._tickCallback (internal/process/next_tick.js:68:7)
With 5f905965-2fa9-4887-ad76-a03cc9dac146
the Kong consumer id that was used in the consumer specific plugin.
Note that Kongfig fails even if the change that is to be applied is completely unrelated
The issue can be recreated as follows to a clean install of Kong :
Add the first API using Kongfig:
host: 'kong:8001'
apis:
- name: first-api
attributes:
uris:
- /v1/first-api
strip_uri: false
preserve_host: true
upstream_url: 'http://first-api'
retries: 5
upstream_connect_timeout: 60000
upstream_read_timeout: 60000
upstream_send_timeout: 60000
https_only: false
http_if_terminated: true
Output:
Loading config kongfig-first-api.yml
Apply config to kong:8001
Kong version: 0.12.3
POST http://kong:8001/apis
{ uris: [ '/v1/first-api' ],
strip_uri: false,
preserve_host: true,
upstream_url: 'http://first-api',
retries: 5,
upstream_connect_timeout: 60000,
upstream_read_timeout: 60000,
upstream_send_timeout: 60000,
https_only: false,
http_if_terminated: true,
name: 'first-api' }
201 Created { created_at: 1533882703207,
strip_uri: false,
id: '0e44a4a4-4072-47ff-b206-5bb5eabb6cbe',
name: 'first-api',
http_if_terminated: true,
https_only: false,
retries: 5,
uris: [ '/v1/first-api' ],
upstream_url: 'http://first-api',
upstream_send_timeout: 60000,
upstream_read_timeout: 60000,
upstream_connect_timeout: 60000,
preserve_host: true }
Create a consumer test-user
:
host: 'kong:8001'
consumers:
- username: test-user
acls: []
credentials: []
Output:
Loading config kongfig-consumer.yml
Apply config to kong:8001
Kong version: 0.12.3
POST http://kong:8001/consumers
{ username: 'test-user' }
201 Created { created_at: 1533882819570,
username: 'test-user',
id: 'c0c16e6f-c437-42cd-bc38-1f3c688aafdc' }
Create a second API with a rate-limiting policy for consumer test-user
:
host: 'kong:8001'
apis:
- name: second-api
plugins:
- name: rate-limiting
attributes:
username: test-user
enabled: true
config:
fault_tolerant: true
redis_database: 0
policy: local
limit_by: consumer
redis_timeout: 2000
hide_client_headers: false
redis_port: 6379
second: 100
attributes:
uris:
- /v1/second-api
strip_uri: false
preserve_host: true
upstream_url: 'http://second-api'
retries: 5
upstream_connect_timeout: 60000
upstream_read_timeout: 60000
upstream_send_timeout: 60000
https_only: false
http_if_terminated: true
consumers:
- username: test-user
Output:
Loading config kongfig-second-api.yml
Apply config to kong:8001
Kong version: 0.12.3
consumer test-user is up to date
POST http://kong:8001/apis
{ uris: [ '/v1/second-api' ],
strip_uri: false,
preserve_host: true,
upstream_url: 'http://second-api',
retries: 5,
upstream_connect_timeout: 60000,
upstream_read_timeout: 60000,
upstream_send_timeout: 60000,
https_only: false,
http_if_terminated: true,
name: 'second-api' }
201 Created { created_at: 1533883280053,
strip_uri: false,
id: '110b32f8-f5a4-4f0b-9e50-ffcc7ebdfe71',
name: 'second-api',
http_if_terminated: true,
https_only: false,
retries: 5,
uris: [ '/v1/second-api' ],
upstream_url: 'http://second-api',
upstream_send_timeout: 60000,
upstream_read_timeout: 60000,
upstream_connect_timeout: 60000,
preserve_host: true }
POST http://kong:8001/apis/110b32f8-f5a4-4f0b-9e50-ffcc7ebdfe71/plugins
{ consumer_id: 'c0c16e6f-c437-42cd-bc38-1f3c688aafdc',
enabled: true,
config:
{ fault_tolerant: true,
redis_database: 0,
policy: 'local',
limit_by: 'consumer',
redis_timeout: 2000,
hide_client_headers: false,
redis_port: 6379,
second: 100 },
name: 'rate-limiting' }
201 Created { created_at: 1533883280116,
config:
{ second: 100,
redis_database: 0,
policy: 'local',
limit_by: 'consumer',
redis_timeout: 2000,
hide_client_headers: false,
redis_port: 6379,
fault_tolerant: true },
id: '2d637380-7bbc-4e54-a547-5a99a02c7a76',
enabled: true,
name: 'rate-limiting',
api_id: '110b32f8-f5a4-4f0b-9e50-ffcc7ebdfe71',
consumer_id: 'c0c16e6f-c437-42cd-bc38-1f3c688aafdc' }
Now try to add a third API:
host: 'kong:8001'
apis:
- name: third-api
attributes:
uris:
- /v1/third-api
strip_uri: false
preserve_host: true
upstream_url: 'http://third-api'
retries: 5
upstream_connect_timeout: 60000
upstream_read_timeout: 60000
upstream_send_timeout: 60000
https_only: false
http_if_terminated: true
Error:
Loading config /config/kongfig-third-api.yml
Apply config to kong:8001
Kong version: 0.12.3
Invariant Violation: Unable to find a consumer for c0c16e6f-c437-42cd-bc38-1f3c688aafdc
Invariant Violation: Unable to find a consumer for c0c16e6f-c437-42cd-bc38-1f3c688aafdc
at invariant (/usr/local/lib/node_modules/kongfig/node_modules/invariant/invariant.js:40:15)
at getConsumerById (/usr/local/lib/node_modules/kongfig/lib/stateSelector.js:22:29)
at fixPluginUsername (/usr/local/lib/node_modules/kongfig/lib/stateSelector.js:59:33)
at Array.map (<anonymous>)
at fixApiPluginUsername (/usr/local/lib/node_modules/kongfig/lib/stateSelector.js:67:42)
at Array.map (<anonymous>)
at exports.default (/usr/local/lib/node_modules/kongfig/lib/stateSelector.js:72:40)
at /usr/local/lib/node_modules/kongfig/lib/readKongApi.js:46:64
at process._tickCallback (internal/process/next_tick.js:68:7)
Please let me know if anyone has a solution for this.
I tested this with branch. feat/consumer-refs. This branch works fine for this issue. @CyExy was this branch merged to master? https://github.com/mybuilder/kongfig/pull/80 mentions some were merged to master. can you please confirm.
As far as I can tell this issue happens only when there are plugins defined for a specific consumer, while having the ignoreConsumer
option set to true
(either explicitly or implicitly by not defining it in the Kongfig schema).
Example is defining schema as
apis:
- name: some-api
ensure: "present"
attributes:
upstream_url: http://some.upstream
uris: /some-uri
Running it as is would work all the time, but if you define a consumer manually and attach any plugin to it, this is when the error happens


Rerunning the above schema now fails with the error Invariant Violation: Unable to find a consumer for 5b032027-3687-4f10-aca2-d4191f1d9b72
(5b032027-3687-4f10-aca2-d4191f1d9b72 is the consumer ID I manually created).
Tracing the code it seems that if the ignoreConsumer
flag is set to true (which it is if you don't provide a consumers array longer than zero in length in your schema), Kongfig won't try to fetch existing consumers, which causes it to fail in fixPluginUsername
in the stateSelector
.
I tried to manually modify the code of cli-apply
to always have ignoreConsumer
set to false
and it worked in my testing environment (although I'm not sure of it's side effects).
@aragorn3012 afixing it in your thrid API schema would be to add the consumers as a non-empty array, this way you force Kongfig to fetch existing consumers.
Not sure but I think there should be an option for it such that we force ignoreConsumers to false 🤔 since I think it is a valid use case for the consumers to not be defined in the schema always 🤔
Currently the workaround we're going to go with is add the following consumers array to our schema (since at the moment control consumers through Kongfig isn't our desired use case)
consumers:
- username: _____
ensure: removed