{"id":45154,"date":"2017-01-25T11:14:11","date_gmt":"2017-01-25T05:44:11","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=45154"},"modified":"2017-01-25T11:14:11","modified_gmt":"2017-01-25T05:44:11","slug":"enabling-oauth-2-0-on-kong-with-ssl-termination-on-load-balancer","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/enabling-oauth-2-0-on-kong-with-ssl-termination-on-load-balancer\/","title":{"rendered":"Enabling OAuth 2.0 On Kong With SSL Termination on Load Balancer"},"content":{"rendered":"<p><a href=\"https:\/\/getkong.org\/about\/\">Kong<\/a> is a widely used open source, scalable, customizable API Gateway\/Middleware and is one of the most popular tools in the market because of its rich functionality and a wide range of open source supported plugins. Those who are new to Kong can go through the <a href=\"https:\/\/getkong.org\/about\/\">Kong&#8217;s documentation<\/a>.<\/p>\n<p><strong>Use Case:<\/strong> This blog is all about enabling OAuth 2.0 in Kong when you are terminating the SSL on the load balancer. I am using <a title=\"AWS Elastic Load Balancer Cookbook\" href=\"http:\/\/www.tothenew.com\/blog\/aws-elastic-load-balancer-cookbook\/\">AWS Elastic Load Balancer<\/a> for the demonstration.<br \/>\n<strong>Note: \u00a0<\/strong>I am using this <a href=\"https:\/\/github.com\/PGBI\/kong-dashboard\">dashboard<\/a> for accessing kong admin.<\/p>\n<p>As we all <a title=\"DevOps developers\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">DevOps developers<\/a> know, enabling OAuth 2.0 is a security measure for the applications and requires TLS for the communication. According to Kong&#8217;s documentation, OAuth 2.0 plugin requires the APIs (which needs to be secured with OAuth 2.0) to have a trusted and valid SSL certificate.<\/p>\n<p>There might be cases where you don&#8217;t want to configure SSL on Kong node. For eg. in my case, I am using free trusted SSL certificate provided by Amazon Certificate Manager which you can only use on \u00a0ELB and Cloudfront.<br \/>\n<strong><br \/>\nX-Forwarded-Proto Support in Kong:<\/strong>\u00a0When you terminate the SSL on ELB, it adds an additional header named X-Forwarded-Proto to the request which is set to HTTPS and Kong uses this header to detect whether the original request was a valid https request or not. So with this support in Kong, you can enable OAuth 2.0 in Kong without adding your SSL certificate files to the Kong.<\/p>\n<p><b>Required Listeners for the ELB Configuration:<br \/>\n<\/b>For this setup, the elastic load balancer should listen to incoming traffic on the port 443 SSL\/HTTPS which must be passed to 8443 SSL\/HTTPS (reserved SSL port) of Kong.<\/p>\n<p><strong>Steps for adding OAuth 2.0 Plugin in Kong while terminating SSL on the ELB.<br \/>\n1) Adding an API<\/strong><br \/>\n<strong>\u00a0<\/strong>In this demonstration, I am enabling OAuth on petstore<a href=\"http:\/\/petstore.swagger.io\/\"> API<\/a> which is freely available on the internet. I am using the above mentioned Kong plugin to perform all the admin operations. You can add a test API as shown in the picture below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45250 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/blog-kong-addingApi.png\" alt=\" Adding an API\" width=\"547\" height=\"447\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/blog-kong-addingApi.png 547w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/blog-kong-addingApi-300x245.png 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/p>\n<p><strong>2) Accessing the added API without OAuth 2.0.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45253 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_2_8600873239.png\" alt=\"Accessing the added API without OAuth 2.0.\" width=\"889\" height=\"556\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_2_8600873239.png 889w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_2_8600873239-300x187.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_2_8600873239-624x390.png 624w\" sizes=\"(max-width: 889px) 100vw, 889px\" \/><\/p>\n<p><strong>3) Adding a consumer to enable OAuth credentials.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45255 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_4_7746376425.png\" alt=\"Adding a consumer to enable OAuth credentials\" width=\"902\" height=\"482\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_4_7746376425.png 902w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_4_7746376425-300x160.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_4_7746376425-624x333.png 624w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/p>\n<p><strong>4) Adding OAuth 2.0 plugin to the API.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45247 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/blog-kong-add-oauth2-plugin.png\" alt=\"Adding OAuth 2.0 plugin to the API\" width=\"919\" height=\"580\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/blog-kong-add-oauth2-plugin.png 919w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/blog-kong-add-oauth2-plugin-300x189.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/blog-kong-add-oauth2-plugin-624x393.png 624w\" sizes=\"(max-width: 919px) 100vw, 919px\" \/><\/p>\n<p><strong>5) Accessing API without generating token.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45254 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_2_5469152938.png\" alt=\"Accessing API without generating token\" width=\"882\" height=\"356\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_2_5469152938.png 882w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_2_5469152938-300x121.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_2_5469152938-624x251.png 624w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/p>\n<p><strong>6) Generating access token with the help of valid consumer credentials.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45252 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_5_5587717261.png\" alt=\"Generating access token\" width=\"888\" height=\"516\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_5_5587717261.png 888w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_5_5587717261-300x174.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_5_5587717261-624x362.png 624w\" sizes=\"(max-width: 888px) 100vw, 888px\" \/><\/p>\n<p><strong>7) Accessing the API using valid access token after passing it in request headers.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-45251 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_8_2114263474.png\" alt=\"Accessing the API using valid access token\" width=\"891\" height=\"550\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_8_2114263474.png 891w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_8_2114263474-300x185.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/01\/imageedit_8_2114263474-624x385.png 624w\" sizes=\"(max-width: 891px) 100vw, 891px\" \/><\/p>\n<p>By following the above steps, you can use OAuth 2.0 on Kong with SSL termination on ELB. In my next blog, I&#8217;ll be writing more about Kong plugins.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kong is a widely used open source, scalable, customizable API Gateway\/Middleware and is one of the most popular tools in the market because of its rich functionality and a wide range of open source supported plugins. Those who are new to Kong can go through the Kong&#8217;s documentation. Use Case: This blog is all about [&hellip;]<\/p>\n","protected":false},"author":170,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":20},"categories":[2348,1],"tags":[4386,4385,4384,4387],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/45154"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/170"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=45154"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/45154\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=45154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=45154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=45154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}