Kong: Tags should allow any string as a tag

Created on 26 Aug 2020  路  7Comments  路  Source: Kong/kong

Summary

I want to assign key values strings to my consumer tags but I get a schema violation error any time there are characters like =, :, |

Is there any way around this validation?

{
  "message": "schema violation (tags.1: invalid value: a=b)",
  "name": "schema violation",
  "fields": {
    "tags": [
      "invalid value: a=b"
    ]
  },
  "code": 2
}

https://discuss.konghq.com/t/change-the-validation-rules-on-tags/6971

As a work around I am encoding values in hex, but this is not ideal.

Steps To Reproduce

  1. Add a conumer with tag k=v, k|v, etc
  2. schema violation

Additional Details & Logs

  • Kong version v2.1.2
tasfeature

Most helpful comment

custom plugin

example:

function plugin:access(conf)
    plugin.super.access(self)

    local consumer = kong.client.get_consumer()
    kong.service.request.set_header("tag", serialize(consumer.tags))

end

All 7 comments

There is some discussion about this in this PR:
https://github.com/Kong/kong/pull/5451

In general there is no technical reason to allow more chars in tags. But as this has popped now at least twice or more, perhaps we should consider supporting more.

I am sure some people would love to use unicode powers of emoticons as labels too :-)

Is there a way to forward a consumers tags to the backend service? I was hoping to use the tags feature to provide additional metadata about a consumer.

Could you just create perhaps a profile plugin that creates profiles table that has UNIQUE consumer_id as a foreign key (in pg) to consumers table. We can certainly look how to enhance tags, but I feel like storing extra info about consumers is not a good use for tags. We could also perhaps think about adding meta column to consumers itself (e.g. a hash -> key -> value (string:string) field). But yes, these are just some thoughts of mine.

custom plugin

example:

function plugin:access(conf)
    plugin.super.access(self)

    local consumer = kong.client.get_consumer()
    kong.service.request.set_header("tag", serialize(consumer.tags))

end

I went for the custom plugin solution, thanks for the suggestion!

Was this page helpful?
0 / 5 - 0 ratings