Creating a key through the dashboard

Hi,

I am trying to create a new key from the dashboard but I get:

Failed to save new session object to Tyk: Failed to create key: Post http://localhost:8080/tyk/keys/create: EOF

Thanks

1 Like

What version of Tyk gateway & Tyk dashboard are you using?

I just restarted tyk-gateway and worked. Thanks for the quick response

1 Like

Great, you’re welcome!

I deployed tyk on a public server. I managed to create a new API but I was not able to create a key. The page is still loading. Please help
thanks

From the logs I see:
time=“Jul 29 04:27:44” level=error msg=“Request failed: Get http://api.wecollect.com:3000/register/node: dial tcp 54.179.170.120:3000: i/o timeout”

Hi, can you confirm that api.wecollect.com:3000 is reachable?

Using curl:

curl -v http://api.wecollect.com:3000/

yes it is reachable. I made some configurations in the config files. I receive:

level=error msg=“Failed to register node, retrying in 5s”

What versions are you using?

api gateway 2.2
dashboard 1.2

Can you run tyk with --debug and share your log output? This will give me a better perspective.

You may also share it via private message!

1 Like

Hi, I am having the same issue - running tyk + dashboard in Docker, 1.2 + 2.2.0.21. Stack trace is below. Thanks!

tyk_dashboard_1 | time=“Nov 3 18:33:20” level=error msg=“Failed to create key: Post http: //tyk:8080/tyk/keys/create: EOF”
tyk_dashboard_1 | time=“Nov 3 18:33:20” level=warning msg=“Failed create:Failed to create key: Post http: //tyk:8080/tyk/keys/create: EOF”
tyk_dashboard_1 | time=“Nov 3 18:33:20” level=error msg=“Failed to save new session object to Tyk: Failed to create key: Post http: //tyk:8080/tyk/keys/create: EOF”
tyk_1 | time=“Nov 3 18:33:20” level=info msg=“Reset quota for key.” inbound-key=“****50a1” key=quota-636cf1bf
tyk_1 | 2016/11/03 18:33:20 http: panic serving 172.19.0.7:40986: runtime error: invalid memory address or nil pointer dereference
tyk_1 | goroutine 232791 [running]:
tyk_1 | net/http.(*conn).serve.func1(0xc420214000)
tyk_1 | /usr/local/go/src/net/http/server.go:1491 +0x12a
tyk_1 | panic(0xb0e780, 0xc420012040)
tyk_1 | /usr/local/go/src/runtime/panic.go:458 +0x243
tyk_1 | main.createKeyHandler(0xf58260, 0xc42015a0d0, 0xc4200be1e0)
tyk_1 | /home/tyk/go/src/github.com/lonelycode/tyk/api.go:1337 +0x2933
tyk_1 | main.CheckIsAPIOwner.func1(0xf58260, 0xc42015a0d0, 0xc4200be1e0)
tyk_1 | /home/tyk/go/src/github.com/lonelycode/tyk/middleware_api_security_handler.go:24 +0x2ae
tyk_1 | net/http.HandlerFunc.ServeHTTP(0xc4203fa210, 0xf58260, 0xc42015a0d0, 0xc4200be1e0)
tyk_1 | /usr/local/go/src/net/http/server.go:1726 +0x44
tyk_1 | github.com/gorilla/mux.(*Router).ServeHTTP(0xc420151ea0, 0xf58260, 0xc42015a0d0, 0xc4200be1e0)
tyk_1 | /home/tyk/go/src/github.com/gorilla/mux/mux.go:98 +0x255
tyk_1 | net/http.(*ServeMux).ServeHTTP(0x1011f00, 0xf58260, 0xc42015a0d0, 0xc4200be1e0)
tyk_1 | /usr/local/go/src/net/http/server.go:2022 +0x7f
tyk_1 | net/http.serverHandler.ServeHTTP(0xc420444280, 0xf58260, 0xc42015a0d0, 0xc4200be1e0)
tyk_1 | /usr/local/go/src/net/http/server.go:2202 +0x7d
tyk_1 | net/http.(*conn).serve(0xc420214000, 0xf58d20, 0xc420212740)
tyk_1 | /usr/local/go/src/net/http/server.go:1579 +0x4b7
tyk_1 | created by net/http.(*Server).Serve
tyk_1 | /usr/local/go/src/net/http/server.go:2293 +0x44d

Hi quietcat, can you share your configuration files, tyk.conf and tyk_analytics.conf?

tyk.conf:
{ "listen_port": 8080, "secret": "352d20ee67be67f6340b4c0605b044b7", "node_secret": "352d20ee67be67f6340b4c0605b044b7", "template_path": "/opt/tyk-gateway/templates", "tyk_js_path": "/opt/tyk-gateway/js/tyk.js", "middleware_path": "/opt/tyk-gateway/middleware", "use_db_app_configs": false, "db_app_conf_options": { "connection_string": "http://tyk_dashboard:3000", "node_is_segmented": false, "tags": ["test2"] }, "app_path": "/opt/tyk-gateway/apps/", "storage": { "type": "redis", "host": "redis", "port": 6379, "username": "", "password": "", "database": 0, "optimisation_max_idle": 100 }, "enable_analytics": false, "analytics_config": { "type": "mongo", "csv_dir": "/tmp", "mongo_url": "", "mongo_db_name": "", "mongo_collection": "", "purge_delay": -1, "ignored_ips": [] }, "health_check": { "enable_health_checks": true, "health_check_value_timeouts": 30 }, "optimisations_use_async_session_write": true, "enable_non_transactional_rate_limiter": true, "enable_sentinel_rate_limiter": false, "allow_master_keys": false, "policies": { "policy_source": "service", "policy_connection_string": "http://tyk_dashboard:3000", "policy_record_name": "tyk_policies" }, "hash_keys": true, "close_connections": true }

tyk_analytics.conf
{ "listen_port": 3000, "tyk_api_config": { "Host": "http://tyk", "Port": "8080", "Secret": "352d20ee67be67f6340b4c0605b044b7" }, "mongo_url": "mongodb://mongo:27017/tyk_analytics", "page_size": 10, "admin_secret": "12345", "shared_node_secret": "352d20ee67be67f6340b4c0605b044b7", "redis_port": 6379, "redis_host": "redis", "redis_password": "", "enable_cluster": false, "force_api_defaults": false, "notify_on_change": true, "license_key": "<omitted, valid key string>", "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": false, "disable_org_slug_prefix": true, "hostname": "", "override_hostname": "www.tyk-portal-test.com", "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": { "languages": null, "hide_help": false, "default_lang": "", "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": "", "secret": "" } }, "tagging_options": { "tag_all_apis_by_org": false }, "use_sharded_analytics": false, "enable_aggregate_lookups": false, "aggregate_lookup_cutoff": "", "maintenance_mode": false, "allow_explicit_policy_id": false }

Can you reference the guide you used to perform this installation? Is it the “Docker quickstart”?

It seems that some parameters in tyk.conf should be changed, like use_db_app_configs (should be true).

Also it would be good to know if your hostnames are ok, did you modify /etc/hosts?

I set use_db_app_configs to false on purpose, I want to have as much configuration as possible done via json so that the stack can be instantiated from a repository, either in kubernetes or docker-compose. Name resolution is also done by the container.

/etc/hosts piece is only relevant to the developer portal as far as I can see, so I haven’t done anything about it yet

Ok, one problem is - if you look at file api.go, line 1337 - thisAPISpec is dereferenced where it was earlier tested to be nil

Here’s my docker-compose.yml
version: ‘2’

services:
    mongo:
        image: mongo
        command: ["mongod", "--smallfiles"]
        hostname: mongo
        ports:
            - "27017:27017"
        volumes:
            - /data/db
    redis:
        image: redis
        hostname: redis
        ports:
            - "6379:6379"
    nginx:
        image: nginx:latest
        hostname: nginx
        ports:
            - "8280:80"
    tyk:
        image: tykio/tyk-gateway
        ports:
            - "80:8080"
            - "8080:8080"
        volumes:
            - ./tyk.conf:/opt/tyk-gateway/tyk.conf
            - ./apps:/opt/tyk-gateway/apps
    tyk_dashboard:
        image: tykio/tyk-dashboard:latest
        ports:
            - "3000:3000"
            - "5000:5000"
        volumes:
            - ./tyk_analytics.conf:/opt/tyk-dashboard/tyk_analytics.conf
    sampleservice:
        image: sampleservice

And apps/sampleservice.json:
{
“name”: “Sampleservice”,
“api_id”: “1”,
“org_id”: “default”,
“definition”: {
“location”: “header”,
“key”: “version”
},
“auth”: {
“auth_header_name”: “authorization”
},
“version_data”: {
“not_versioned”: true,
“versions”: {
“Default”: {
“name”: “Default”,
“expires”: “3000-01-02 15:04”,
“use_extended_paths”: true,
“extended_paths”: {
“ignored”: [],
“white_list”: [],
“black_list”: []
}
}
}
},
“proxy”: {
“listen_path”: “/sampleservice/api”,
“target_url”: “http://sampleservice/api”,
“strip_listen_path”: true
},
“enable_batch_request_support”: true
}

Ok, so there are two problems here:

  1. The panic is caused because the API that you are trying to create the key for is not loaded in the gateway, this can happen for many reasons, the gateway boot-up log will show you if it exists or not, or why it was skipped. This panic has been fixed in the latest upcoming version, but even if this key was created, you would find that you would get a 404 if you used it too soon because the gateway has not yet made this API active.

  2. You must either use the gateway in file-baed mode, or in dashboard mode, the two do not mix well and we don’t really support it. In file-based mode everything must be done as a file on disk, and you do not need any of the settings for the gateway to register with the dashboard. So pick one and we can help :slight_smile:

M.