Showing posts with label Tyk. Show all posts
Showing posts with label Tyk. Show all posts

Tuesday, July 26, 2016

Setting up Tyk Portal and Developer Registrations

There was this long running bug that is hitting us from setting up the Tyk portal. The issue was with Tyk not allowing custom domains from being set up as portal. While the settings as advised in Tyk mention the dashboard and portal port as 3000, ideally it should be set as 80 to get the portal configured seamlessly. I learned it hard-way after so many attempts on getting this done on port 3000.


Setting up Portal Domain
Add to /etc/hosts file:
127.0.0.1 dashboard.tyk-local.com
127.0.0.1 portal.tyk-local.com
Most probably Apache2 or some other web server would already be listening on the port 80. Make sure to stop it to release the port.

Stop Apache2 Web Server

/etc/init.d/apache2 stop

Configure Tyk Gateway

sudo /opt/tyk-gateway/install/setup.sh --dashboard=http://dashboard.tyk-local.com --listenport=8080 --redishost=localhost --redisport=6379 --domain=""


Configure Tyk Dashboard

sudo /opt/tyk-dashboard/install/setup.sh --listenport=80 --redishost=localhost --redisport=6379 --mongo=mongodb://127.0.0.1/tyk_analytics --tyk_api_hostname=127.0.0.1 --tyk_node_hostname=http://127.0.0.1 --tyk_node_port=8080 --portal_root=/portal --domain="dashboard.tyk-local.com"


Configure Tyk Pump

sudo /opt/tyk-pump/install/setup.sh --redishost=localhost --redisport=6379 --mongo=mongodb://127.0.0.1/tyk_analytics


Initial start to set up the Tyk license


sudo service tyk-pump start
sudo service tyk-dashboard start

Access http://dashboard.tyk-local.com/ and add the license in the prompt.

Restart the Tyk Dashboard and start the Tyk Gateway
sudo service tyk-dashboard restart
sudo service tyk-gateway start


Fix the Tyk bootstrap script to listen at port 80

gedit /opt/tyk-dashboard/install/bootstrap.sh and remove :3000 from all the references, since we are going to use the default port 80, instead of port 3000 as the dashboard port.


#!/bin/bash
# Usage ./bootstrap.sh DASHBOARD_HOSTNAME

LOCALIP=$1
RANDOM_USER=$(env LC_CTYPE=C tr -dc "a-z0-9" < /dev/urandom | head -c 10)
PASS="test123"

echo "Creating Organisation"
ORGDATA=$(curl --silent --header "admin-auth: 12345" --header "Content-Type:application/json" --data '{"owner_name": "Default Org.","owner_slug": "default", "cname_enabled": true, "cname": ""}' http://$LOCALIP/admin/organisations 2>&1)
#echo $ORGDATA
ORGID=$(echo $ORGDATA | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["Meta"]')
echo "ORGID: $ORGID"

echo "Adding new user"
USER_DATA=$(curl --silent --header "admin-auth: 12345" --header "Content-Type:application/json" --data '{"first_name": "John","last_name": "Smith","email_address": "'$RANDOM_USER'@default.com","password":"'$PASS'", "active": true,"org_id": "'$ORGID'"}' http://$LOCALIP/admin/users 2>&1)
#echo $USER_DATA
USER_CODE=$(echo $USER_DATA | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["Message"]')
echo "USER AUTH: $USER_CODE"

USER_LIST=$(curl --silent --header "authorization: $USER_CODE" http://$LOCALIP/api/users 2>&1)
#echo $USER_LIST

USER_ID=$(echo $USER_LIST | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["users"][0]["id"]')
echo "NEW ID: $USER_ID"

echo "Setting password"
OK=$(curl --silent --header "authorization: $USER_CODE" --header "Content-Type:application/json" http://$LOCALIP/api/users/$USER_ID/actions/reset --data '{"new_password":"'$PASS'"}')

echo ""

echo "DONE"
echo "===="
echo "Login at http://$LOCALIP/"
echo "User: $RANDOM_USER@default.com"
echo "Pass: $PASS"
echo ""


Save and exit the bootstrap script and execute it.

sudo /opt/tyk-dashboard/install/bootstrap.sh dashboard.tyk-local.com



root@llovizna:/home/pradeeban#  sudo /opt/tyk-dashboard/install/bootstrap.sh dashboard.tyk-local.com
Creating Organisation
ORGID: 579794145ee8571e46000001
Adding new user
USER AUTH: 6936a780a8e448fd73e3d7ef64eb8059
NEW ID: 5797941458149ac06a14e801
Setting password

DONE
====
Login at http://dashboard.tyk-local.com/
User: c9og13fnc8@default.com
Pass: test123

Tyk Developer Portal
Now you are good to log in to the Tyk Dashboard with the given credentials.

Set Portal domain
portal.tyk-local.com

This would give a message, "CNAME updated"
Now if you access http://portal.tyk-local.com/portal/ it would says "Home page not found". This is expected as you have not set up the portal and the welcome page yet. 

Follow the below document to get this set up.

Once you have set this up, your portal is ready for the developers to register, log in, and consumes the APIs defined in the API catalogue.

Monday, July 11, 2016

Tyk Dashboard crashed after setting the portal domain

So I set the portal domain to be as the same with the dashboard. Later, I was instructed that it is not permitted to have the portal domain same as the dashboard.

However, now I am left with the below error which does not simply disappear when I reconfigure Tyk.

panic: http: multiple registrations for dashboard.tyk-local.com:3000/

goroutine 1 [running]:
panic(0xa60f80, 0xc820370be0)
    /usr/local/go/src/runtime/panic.go:464 +0x3e6
net/http.(*ServeMux).Handle(0xc820356d50, 0xc82036f7e0, 0x1d, 0x7f5a221595d8, 0xc82027af20)
    /usr/local/go/src/net/http/server.go:1926 +0x297
main.GenerateRoutes()
    /home/tyk/go/src/github.com/lonelycode/tyk-analytics/Main.go:733 +0x41b7
main.main()
    /home/tyk/go/src/github.com/lonelycode/tyk-analytics/Main.go:750 +0x59


I basically had to drop the Mongo table, and then reconfigure Tyk to get everything back in place.

In Mongo shell:
> use tyk_analytics
switched to db tyk_analytics
> db.dropDatabase();
{ "dropped" : "tyk_analytics", "ok" : 1 }

Wednesday, July 6, 2016

Tyk 2.0 in Centos

There are some minor changes in setting up Tyk 1.9 and Tyk 2.0, and also some differences between setting up on Ubuntu vs Centos.

Installing Tyk 2.0 on Centos is described here.

sudo /opt/tyk-gateway/install/setup.sh --dashboard=http://lion.bmi.emory.edu:3000 --listenport=8080 --redishost=localhost --redisport=6379 --domain=""


sudo /opt/tyk-dashboard/install/setup.sh --listenport=3000 --redishost=localhost --redisport=6379 --mongo=mongodb://127.0.0.1/tyk_analytics --tyk_api_hostname=localhost --tyk_node_hostname=http://localhost --tyk_node_port=8080 --portal_root=/portal --domain="lion.bmi.emory.edu"



sudo /opt/tyk-pump/install/setup.sh --redishost=localhost --redisport=6379 --mongo=mongodb://127.0.0.1/tyk_analytics


sudo service tyk-pump start
sudo service tyk-dashboard start

http://lion.bmi.emory.edu:3000/


sudo service tyk-dashboard restart
sudo service tyk-gateway start


sudo /opt/tyk-dashboard/install/bootstrap.sh  lion.bmi.emory.edu

Friday, May 20, 2016

Tyk with Apache Directory Studio

So I was getting all sort of weird errors due to mismatch in the dn. Then we decided to switch to Apache Directory Studio from OpenLDAP, as it is more user-friendly. Finally, I got Tyk configured with LDAP, thanks to Apache Directory Studio.


First, I had to configure the profiles.json of Tyk.
[{
    "ActionType": "GenerateOrLoginUserProfile",
    "ID": "4",
    "OrgID": "573cb5c7a57xxxdeb1f78000001",
    "ProviderConfig": {
        "FailureRedirect": "http://dashboard.tyk-local.com:3000/?fail=true",
        "LDAPAttributes": [],
        "LDAPPort": "10389",
        "LDAPServer": "localhost",
        "LDAPUserDN": "cn=*USERNAME*,ou=people,dc=sharmalab,dc=bmi,dc=emory,dc=edu"
    },
    "ProviderName": "ADProvider",
    "ReturnURL": "http://dashboard.tyk-local.com:3000/tap",
    "Type": "passthrough"
}
]

and also tib.conf, reflecting the ports and all.
{
    "Secret": "934893845123491xxx238192381486djfhr87234827348",
    "HttpServerOptions": {
        "UseSSL": false,     
        "CertFile": "./certs/server.pem",
        "KeyFile": "./certs/server.key"
    },
    "BackEnd": {
        "Name": "in_memory",
        "ProfileBackendSettings": {},
        "IdentityBackendSettings": {
            "Hosts" : {
                "localhost": "6379"
            },
            "Password": "",
            "Database": 0,
            "EnableCluster": false,
            "MaxIdle": 1000,
            "MaxActive": 2000
        }
    },
    "TykAPISettings": {
        "GatewayConfig": {
            "Endpoint": "http://dashboard.tyk-local.com",
            "Port": "8080",
            "AdminSecret": "54321"
        },
        "DashboardConfig": {
            "Endpoint": "http://dashboard.tyk-local.com",
            "Port": "3000",
            "AdminSecret": "12345"
        }
    }
}

Finally, I was able to send a POST request to http://localhost:3010/auth/4/ldap?username=pradeeban&password=34%$%$4w33

INFO[0008] [AD AUTH] User bind successful: pradeeban   
INFO[0008] [TYK ID HANDLER] Creating identity for: {map[] ADProvider pradeeban@ADProvider    pradeeban    }

Wednesday, May 18, 2016

Configuring Tyk with the Identity Broker in Ubuntu 14.04 LTS

Tyk Dashboard
For the past couple of days, I have been evaluating Tyk with the Identity Broker in Ubuntu. Thanks Martin for helping me in a series of on-going discussion threads, I have managed to make most of it working. This post is a live document. ;)


Add to /etc/hosts file:
127.0.0.1 dashboard.tyk-local.com
127.0.0.1 portal.tyk-local.com

Configure Tyk Gateway
sudo /opt/tyk-gateway/install/setup.sh --dashboard=http://dashboard.tyk-local.com:3000 --listenport=8080 --redishost=localhost --redisport=6379 --domain=""


Configure Tyk Dashboard
sudo /opt/tyk-dashboard/install/setup.sh --listenport=3000 --redishost=localhost --redisport=6379 --mongo=mongodb://127.0.0.1/tyk_analytics --tyk_api_hostname=127.0.0.1 --tyk_node_hostname=http://127.0.0.1 --tyk_node_port=8080 --portal_root=/portal --domain="dashboard.tyk-local.com"


Configure Tyk Pump
sudo /opt/tyk-pump/install/setup.sh --redishost=localhost --redisport=6379 --mongo=mongodb://127.0.0.1/tyk_analytics


sudo service tyk-pump start
sudo service tyk-dashboard start

http://dashboard.tyk-local.com:3000/

Add the license in the prompt.

sudo service tyk-dashboard restart
sudo service tyk-gateway start

sudo /opt/tyk-dashboard/install/bootstrap.sh dashboard.tyk-local.com

Now you are good to start Tyk.

However, to enable TIB, you need to do some more steps.

In /opt/tyk-dashboard/tyk_analytics.conf

    "identity_broker": {
        "enabled": true,
        "host": {
            "connection_string": "http://localhost:3010",
            "secret": "934893845123491238192381486djfhr87234827348"
        }
    },

Make sure the shared secrets match in tyk-analytics.conf and tib.conf of tib.
https://tyk.io/docs/tyk-dashboard-v1-0/configuration/

Now restart everything.
sudo service tyk-pump stop
sudo service tyk-dashboard stop
sudo service tyk-gateway stop

sudo service tyk-pump start
sudo service tyk-dashboard start
sudo service tyk-gateway start

Start TIB
cd /home/pradeeban/programs/tib-v0.1
./tib


Find the logs.
sudo tail -f /var/log/upstart/tyk-dashboard.log
sudo tail -f /var/log/upstart/tyk-gateway.log
sudo tail -f /var/log/upstart/tyk-pump.log