<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[3scale-ninja-toolbook - Medium]]></title>
        <description><![CDATA[Find end to end demos &amp; guides showcasing the very best features in the 3scale API Management platform. - Medium]]></description>
        <link>https://medium.com/3scale-ninja-toolbook?source=rss----7dc3a256860a---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>3scale-ninja-toolbook - Medium</title>
            <link>https://medium.com/3scale-ninja-toolbook?source=rss----7dc3a256860a---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 19:02:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/3scale-ninja-toolbook" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scripting the 3scale API: Bulk delete applications for a single account]]></title>
            <link>https://medium.com/3scale-ninja-toolbook/scripting-the-3scale-api-bulk-delete-applications-for-a-single-account-b321ce6a2fb2?source=rss----7dc3a256860a---4</link>
            <guid isPermaLink="false">https://medium.com/p/b321ce6a2fb2</guid>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[3scale]]></category>
            <category><![CDATA[red-hat-3scale]]></category>
            <category><![CDATA[api-management]]></category>
            <dc:creator><![CDATA[Kev Price]]></dc:creator>
            <pubDate>Tue, 31 Oct 2023 16:59:17 GMT</pubDate>
            <atom:updated>2023-10-31T16:59:17.596Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zd-vE5RxO8YbON3u" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The 3scale APIs are numerous and flexible. However, sometimes they don’t always quite fit the use case and some additional scripting is required to leverage the available operations.</p><h4>Scenario</h4><p>A large number of applications were accidentally created under a single account by a malformed script. Now the account needs to be deleted along with all the children objects but there is a problem; if hundreds of applications or more were created then any attempts to delete the account by API (<em>Account delete</em>) or the GUI (<em>Applications list </em><strong><em>by account</em></strong><em> &amp; Account delete</em>) will timeout. This is primarily due to the fact the API endpoints to be used here take longer than the default 40 second timeout and/or they are not paginated.</p><h4>Solution</h4><p>A script to perform this task is hosted on <a href="https://github.com/kevprice83/3scale-ninja-toolbelt/tree/main/API%20scripts/Fetch%20%26%20Delete%20Applications">this GitHub repository</a>.</p><p>The following API endpoints are used by the script:</p><ul><li><strong>Application list (all services)</strong> <em>“/admin/api/applications.json”</em></li><li><strong>Application delete <em>“</em></strong><em>/admin/api/accounts/{account_id}/applications/{id}.json”</em></li></ul><p>The first endpoint is from the <strong>Service Applications </strong>API and applications are scoped by service so to be able to retrieve only the applications belonging to the account in question some additional filtering will need to be performed in our script. Also important to note that this API is <em>paginated.</em></p><p>The second endpoint is from the <strong>Account Applications</strong> API and takes a single application ID as a resource so the script will need to loop through all the applications retrieved from the first request and delete one by one. This is also safer as it does not introduce too much load on the server in case there are thousands of applications.</p><h4>Prerequisites</h4><p><em>Although these are standard libraries in most Linux distros please ensure the following tools have these minimum versions as any potential incomaptibilities with older versions cannot be guaranteed:</em></p><ul><li><a href="https://curl.se/">cURL</a> 7.79.1</li><li><a href="https://jqlang.github.io/jq/"><em>JQ</em></a><em> v1.6</em></li><li><a href="https://www.gnu.org/software/bash/">GNU bash</a>, version 5.1.8</li></ul><h4>Using the script</h4><p>This has been used on the 3scale versions 2.13 and 2.14, it is recommended to test the script on a dummy account before using it especially if the 3scale version is older or newer than the stated versions above.</p><p>The shellscript can be downloaded or cloned from <a href="https://github.com/kevprice83/3scale-ninja-toolbelt/tree/main/API%20scripts/Fetch%20%26%20Delete%20Applications">this public GitHub repository</a>.</p><p>Make the script executable:</p><pre>chmod +x fetch_and_delete_applications.sh</pre><p>Print the usage prompt from the script:</p><pre>./fetch_and_delete_applications.sh<br>&quot;Usage: &lt;https://ADMIN_PORTAL_URL&gt; &lt;ACCOUNT_ID&gt; &lt;ACCESS_TOKEN&gt;&quot;</pre><p>Example usage:</p><pre>./fetch_and_delete_applications.sh https://tenant-admin.lvh.me 1234567890 myaccesstoken12345</pre><h4>More insights on what the script does</h4><p>In case you want to extend or modify the script to better suit your needs here are more details on what it does.</p><p>After providing the 3 usage parameters to the executable the script will first retrieve all applications on the Tenant and filter them according to the account_id passed as the second argument. It will print all of the IDs to <em>stdout </em>as well as the account ID to which they belong.</p><p>The script then prompts the user for input:</p><pre>Do you wish to delete the applications retrieved for account {some_account_id} with Org Name: My Org? (select option 1 or 2)<br>1) Yes<br>2) No</pre><p>This is to allow the user to verify that the correct account has been filtered and therefore the correct applications which belong to it. If option 2 is chosen the script will exit without further processing and if option 1 is chosen then it will proceed to delete all the applications retrieved previously one by one. There is a 1 second sleep between each HTTP request to ensure that the server is not overloaded so it could take some hours to complete. Adjust the sleep duration as required.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b321ce6a2fb2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/3scale-ninja-toolbook/scripting-the-3scale-api-bulk-delete-applications-for-a-single-account-b321ce6a2fb2">Scripting the 3scale API: Bulk delete applications for a single account</a> was originally published in <a href="https://medium.com/3scale-ninja-toolbook">3scale-ninja-toolbook</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to configure OpenShift Monitoring/Grafana to monitor 3scale]]></title>
            <link>https://medium.com/3scale-ninja-toolbook/how-to-configure-openshift-monitoring-grafana-to-monitor-3scale-f3492e1760de?source=rss----7dc3a256860a---4</link>
            <guid isPermaLink="false">https://medium.com/p/f3492e1760de</guid>
            <category><![CDATA[openshift-4]]></category>
            <category><![CDATA[3scale]]></category>
            <category><![CDATA[grafana]]></category>
            <dc:creator><![CDATA[Takayuki Konishi]]></dc:creator>
            <pubDate>Wed, 13 Jul 2022 06:52:50 GMT</pubDate>
            <atom:updated>2022-07-13T06:52:19.374Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>This document will walk you through how to configure OpenShift Monitoring/Grafana to monitor 3scale.</p><h3>Environment</h3><ul><li><a href="https://www.openshift.com/products/container-platform">Red Hat OpenShift Container Platform</a> 4.10</li><li><a href="https://www.redhat.com/en/technologies/jboss-middleware/3scale">Red Hat 3scale API Management</a> 2.12</li></ul><h3>Differences from <a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.12/html/operating_3scale/monitoring-threescale">Operating 3scale document</a></h3><p>The document explains how to configure Prometheus via the community Prometheus operator. On the other hand, this article uses OpenShift Monitoring instead of the operator. OpenShift Monitoring includes Prometheus, and the Prometheus UI is integrated into the Monitoring page in the OpenShift console. Although Prometheus custom resource is mandatory when using the community operator, you don’t have to create that in this article.</p><h3>Procedure</h3><h4>Enable monitoring for user-defined projects on OpenShift</h4><ol><li>Create cluster-monitoring-config ConfigMap in openshift-monitoring namespace.</li></ol><pre>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: cluster-monitoring-config<br>  namespace: openshift-monitoring<br>data:<br>  config.yaml: |<br>    enableUserWorkload: true</pre><p>2. Confirm these pods are running.</p><pre>$ oc get pod -n openshift-user-workload-monitoring<br>NAME                                  READY   STATUS    RESTARTS   AGE<br>prometheus-operator-c7bdc5c48-znvkh   2/2     Running   0          2m26s<br>prometheus-user-workload-0            6/6     Running   0          2m23s<br>thanos-ruler-user-workload-0          3/3     Running   0          2m20s </pre><p><strong>Note:</strong> You can only install either the prometheus-operator or the community one.</p><h4>Deploy Grafana</h4><ol><li>On Operator Hub, install Grafana Operator in the same project as 3scale.</li></ol><p><strong>Note:</strong> The grafana-oprator in OperatorHub can refer to GrafanaDashboard resources only in the same namespace as the grafana-operator for now (<a href="https://issues.redhat.com/browse/THREESCALE-7087?focusedCommentId=19301604&amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-19301604">reference</a>).</p><p><strong>Disclaimer: Unsupported Procedure</strong> <em>The following information has been provided by Red Hat, but is outside the scope of the posted Service Level Agreements and support procedures. The information is provided as-is and unsupported by Red Hat. The intent of this article is to provide information to accomplish the system’s needs. Use of the information in this article at the user’s own risk</em></p><p>2. Create Grafana resource.</p><pre>apiVersion: integreatly.org/v1alpha1<br>kind: Grafana<br>metadata:<br>  name: grafana<br>spec:<br>  config:<br>    auth:<br>      disable_signout_menu: true<br>    auth.anonymous:<br>      enabled: true<br>    log:<br>      level: warn<br>      mode: console<br>    security:<br>      admin_password: secret<br>      admin_user: root<br>  dashboardLabelSelector:<br>    - matchExpressions:<br>        - key: app<br>          operator: In<br>          values:<br>            - 3scale-api-management<br>  ingress:<br>    enabled: true </pre><p>3. Confirm the thanos-querier route in openshift-monitoring.</p><p>$ oc get route -n openshift-monitoring</p><p>4. Add cluster-monitoring-view role to grafana-serviceaccount service account.</p><pre>$ oc project &lt;your 3scale project&gt;<br>$ oc adm policy add-cluster-role-to-user cluster-monitoring-view -z grafana-serviceaccount</pre><p>5. Get access token of grafana-serviceaccount.</p><pre>$ oc serviceaccounts get-token grafana-serviceaccount</pre><p>6. Create Grafana Datasource resource that refers to the thanos-querier service.</p><pre>apiVersion: integreatly.org/v1alpha1<br>kind: GrafanaDataSource<br>metadata:<br>  name: prometheus-grafanadatasource<br>  namespace:  &lt;your 3scale project&gt;<br>spec:<br>  datasources:<br>  - access: proxy<br>    editable: true<br>    isDefault: true<br>    jsonData:<br>      httpHeaderName1: &#39;Authorization&#39;<br>      timeInterval: 5s<br>      tlsSkipVerify: true<br>    name: Prometheus<br>    secureJsonData:<br>      httpHeaderValue1: &#39;Bearer &lt;ACCESS_TOKEN&gt;&#39;<br>    type: prometheus<br>    url: &#39;&lt;https://thanos-querier.openshift-monitoring.route&gt;&#39;<br>  name: prometheus-grafanadatasource.yaml</pre><p><strong>Note:</strong> If you get CORS error like this message, try to use http instead of https for testing purpose and investigate the cause once the connection is confirmed.</p><pre>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://thanos-querier-openshift-... (Reason: CORS request did not succeed).</pre><h4>Configure monitoring option to APIManager</h4><ol><li>Add monitoring parameter to APIManager.</li></ol><pre>apiVersion: apps.3scale.net/v1alpha1<br>kind: APIManager<br>metadata:<br>  name: apimanager1<br>spec:<br>  wildcardDomain: &lt;apps.example.com&gt;<br>  monitoring:<br>    enabled: true</pre><h4>Confirm OpenShift Monitoring</h4><ol><li>In the Developer perspective, Open Observe → Metrics.</li><li>On the pulldown menu, select Custom Query.</li><li>Enter a PromQL that refers to a 3scale’s metric like this</li></ol><pre>rate(nginx_http_connections{container=&quot;apicast-production&quot;}[1m])</pre><p>4. Confirm the PromQL executed.</p><figure><img alt="PromQL result" src="https://cdn-images-1.medium.com/max/1024/1*nyqQ8ruoPaxLImajaSYMcA.png" /></figure><p>5. Open Alert tab.</p><p>6. Confirm 3scale alerts are listed.</p><figure><img alt="Alert list" src="https://cdn-images-1.medium.com/max/960/1*GxkFaonVFOxlbE4dU7zZtA.png" /></figure><p>7. Send requests to the production APIcast of an API that results in authentication failure.</p><p>8. Confirm ThreescaleApicastHttp4xxErrorRate alert is Pending state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*uKBnrVTLHEZRXRA1JSZVfQ.png" /></figure><p>For more details about alerts, refer to <a href="https://access.redhat.com/documentation/en-us/openshift_container_platform/4.10/html/monitoring/managing-alerts">the OpenShift document</a>.</p><h4>Confirm Grafana</h4><ol><li>Open https://grafana-route-3scale.apps.&lt;ocp base domain&gt;.</li><li>Open the Manage menu.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/0*ycC_GNHg9mUJekEq" /></figure><p>3. 3scale dashboards are listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*ixGO0hXmE05g3Uq_RIysfw.png" /></figure><p>4. For example, click 3scale/ 3scale / Apicast. APIcast dashboard will be displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1pAxADHgn4co1vJisA6LQQ.png" /></figure><h3>References</h3><ul><li><a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.12/html/operating_3scale/monitoring-threescale">Monitoring 3scale</a></li><li><a href="https://github.com/3scale/3scale-operator/blob/master/doc/operator-monitoring-resources.md">3scale-operator/operator-monitoring-resources.md</a></li><li><a href="https://access.redhat.com/documentation/en-us/openshift_container_platform/4.10/html/monitoring/enabling-monitoring-for-user-defined-projects">OpenShift Container Platform — Enabling monitoring for user-defined projects</a></li><li><a href="https://access.redhat.com/solutions/5335491">Custom Grafana Dashboard for custom metrics</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3492e1760de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/3scale-ninja-toolbook/how-to-configure-openshift-monitoring-grafana-to-monitor-3scale-f3492e1760de">How to configure OpenShift Monitoring/Grafana to monitor 3scale</a> was originally published in <a href="https://medium.com/3scale-ninja-toolbook">3scale-ninja-toolbook</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Metrics policy in 3scale]]></title>
            <link>https://medium.com/3scale-ninja-toolbook/custom-metrics-policy-in-3scale-6c9eb3df90f6?source=rss----7dc3a256860a---4</link>
            <guid isPermaLink="false">https://medium.com/p/6c9eb3df90f6</guid>
            <category><![CDATA[3scale]]></category>
            <dc:creator><![CDATA[Chamal Abeywardhana]]></dc:creator>
            <pubDate>Thu, 26 Nov 2020 01:06:16 GMT</pubDate>
            <atom:updated>2020-11-26T03:52:05.034Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to use the custom metrics policy to capture status code analytics</h4><p>Co-author: <a href="https://medium.com/@kev.price83">Kev Price</a></p><h3>Summary</h3><p>Custom metrics policy is a new APICast policy, which was introduced on 3scale version 2.9.</p><p>I was intrigued to know how I can configure this policy. Also I wanted to understand the usage scenarios for this policy. This blog post will provide a detailed step by step guide on how to configure the policy, test and debug it.</p><h3>Example Scenarios</h3><p>Keeping track of a metric based on a specific response status code. The usage is that default 3scale response codes analytics will only capture the response statuses into the buckets of 2XX, 4XX and 5XX. In case you want to capture upstream status codes for 203,302,403,…, you could use this <a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.9/html/administering_the_api_gateway/apicast_policies#custom-metrics">Custom Metric policy</a>.</p><h3>Step by step guide</h3><h3>Prerequisites</h3><p>To complete this step by step tutorial you will need the following:</p><ul><li>3scale 2.9 On-premises deployment.</li><li>Private backend API that returns HTTP status codes. For the purpose of this tutorial use this (<a href="https://github.com/chamalabey/3scale-private-api">3scale-private-api</a>)</li><li>Binary download of <a href="https://ngrok.com/download">ngrok</a></li></ul><h3>Setup</h3><p>Following are the steps to be followed before you can proceed to the <a href="https://docs.google.com/document/d/1DjNi8L6t_3ou4ynKfk9VocvEId3FMpKgCT8Fw5lPhiM/edit#heading=h.skho1qgcg9dm">End to end flow</a>. For the purpose of this demonstration, the <a href="https://github.com/chamalabey/3scale-private-api">3scale-private-api</a> application was used as the private backend.</p><ul><li>Install and deploy the <a href="https://github.com/chamalabey/3scale-private-api/blob/master/README.md">private API backend</a>. This simple application will return a response with the status code based on the status code passed in the request URL(“/status/203”).</li><li>The above example application will be listening to the requests on the port 3000. Expose that port to the internet via ngrok application by executing the command below. Note that the public URL which gets generated by ngrok will only be valid for 8 hours on the free tier.</li></ul><pre>./ngrok http 3000</pre><ul><li>When you execute the above command, you will get an output similar to the following</li></ul><pre>Forwarding <a href="http://8fcf5e08d900.ngrok.io/">http://8fcf5e08d900.ngrok.io</a> -&gt; localhost:30<br>Forwarding <a href="https://8fcf5e08d900.ngrok.io/">https://8fcf5e08d900.ngrok.io</a> -&gt; localhost:3000</pre><ul><li>Copy the above HTTPS url and use the URL as your backend.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/0*kBY7WWIFeNscgyq-" /><figcaption>Adding backend to the product</figcaption></figure><ul><li>If the above backend is not configured to your API product, please <a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.9/html/getting_started/first-steps#adding-backends-product">configure it to the product</a>.</li><li>Configure a new metric on the product to be updated based on the response code. Note that you can create any number of metrics with <strong>System name</strong> formatted like <strong>system-{</strong><em>HTTP-STATUS-CODE</em><strong>}</strong> for all the HTTP status codes you would like to capture.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6sf_AVJYmNcWlP1i" /><figcaption>New metric on the product</figcaption></figure><ul><li>Add the <a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.9/html/administering_the_api_gateway/apicast_policies#custom-metrics">custom metric policy</a> to your service configuration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GW5cnQuNSJZs0oVa" /><figcaption>Add Custom Metrics to policy to the policy list</figcaption></figure><ul><li>Configure the policy as follows</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/0*-kWobJrU5_h4DOTH" /></figure><ul><li>Then update the policy chain and promote the service configuration to staging/production environments of your API Product.</li></ul><h3>End to end flow</h3><ul><li>Make sure the <a href="https://github.com/chamalabey/3scale-private-api/blob/master/README.md">API backend</a> application is running and exposed via ngrok. Also the private base URL of the service backend is correctly configured to the ngrok generated URL.</li><li>Make a request to APICast with the correct credentials to invoke the service configured. Note the request URL below will match the metric “status-203”. Note that you will have to use the “-k” option if you have self-signed certificates.</li></ul><pre>curl “https://api-3scale-apicast-staging.apps-crc.testing:443/status/203?user_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot; -k</pre><ul><li>You should receive a response similar to the following</li></ul><pre>status code 203 set to the header</pre><ul><li>Make another request as follows to update the metric “status-303”</li></ul><pre>curl “<a href="https://api-3scale-apicast-staging.apps-crc.testing/status/203?user_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">https://api-3scale-apicast-staging.apps-crc.testing:443/status/303?user_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>&quot; -k</pre><ul><li>Go to Product Analytics-&gt; Traffic page to check whether the above mentioned metrics are updated accordingly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/0*HwPTHAtEMpwbqE_e" /><figcaption>Analytics graph for the status-203 metric</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/0*ccvmIymuu-NCn9_5" /><figcaption>Analytics graph for the status-303 metric</figcaption></figure><ul><li>If you have added more metricses they will be updated based on status codes you have passed in.</li></ul><h3>Additional Notes</h3><p>If you would like to find out all the liquid variables available in each step of APICast, you can use the <a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.8/html/administering_the_api_gateway/apicast_policies#liquid_context_debug">Liquid Context Debug</a> policy. This is useful if you want to use the available variables to write complex logical expressions, which we are not going to cover in this post.</p><p>Let’s see how to inspect the host header using liqud expression.</p><p>Following are the steps.</p><ul><li>Add the <a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.8/html/administering_the_api_gateway/apicast_policies#liquid_context_debug">Liquid Context Debug</a> policy to the policy chain</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/0*shY8WeM41X7FmS7p" /><figcaption>Liquid Contect Debug policy in the policy chain</figcaption></figure><ul><li>Note that the above policy needs to be placed before APIcast policy or the upstream policy in the policy chain.</li><li>The <a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.8/html/administering_the_api_gateway/apicast_policies#liquid_context_debug">Liquid Context Debug</a> policy will not work at all, when you have more than one backends in your product configuration.</li><li>After adding the policy to the service, make a request to the APICast as you normally do.</li><li>The response will be a JSON response with additional variables available in each context. Following is a snippet from an example request.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*mZXR5YXCeYWwo3j1BQUG6Q.png" /><figcaption>Liquid context debug response</figcaption></figure><ul><li>Note the variables like host, query, headers available under original_request variable. You can access those values using Liquid tags in policies which support liquid values.</li><li>For example you can access original host name by using the liquid tag</li></ul><pre>{{original_request[&#39;host&#39;]}}</pre><h3>Conclusion</h3><p>In this article you have learned how to use the custom metrics policy to capture the analytics on status codes which 3scale by default will not individually capture. Also you learn how to use the Liquid Context Debug policy to find out the variables available which can be used in the APICast policies.</p><p>I hope this guide provided you sufficient tools to implement a solution similar to the one described. Feel free to comment with any suggestion to improve this content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c9eb3df90f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/3scale-ninja-toolbook/custom-metrics-policy-in-3scale-6c9eb3df90f6">Custom Metrics policy in 3scale</a> was originally published in <a href="https://medium.com/3scale-ninja-toolbook">3scale-ninja-toolbook</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Personal access token rotation in 3scale]]></title>
            <link>https://medium.com/3scale-ninja-toolbook/personal-access-token-rotation-in-3scale-d1f535b3c23f?source=rss----7dc3a256860a---4</link>
            <guid isPermaLink="false">https://medium.com/p/d1f535b3c23f</guid>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[access-token]]></category>
            <category><![CDATA[3scale]]></category>
            <category><![CDATA[webhooks]]></category>
            <dc:creator><![CDATA[Samuele Illuminati]]></dc:creator>
            <pubDate>Mon, 28 Sep 2020 07:17:15 GMT</pubDate>
            <atom:updated>2020-09-29T14:40:02.805Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to rotate 3scale access tokens</h4><p>Co-author: <a href="https://medium.com/@kev.price83">Kev Price</a></p><h3>Summary</h3><p>This guide is meant to show how it is possible to enable “Access token rotation”, allowing 3scale to use temporary Access Tokens that will be invalidated once they have been used for their purpose.</p><p>By the end of this tutorial you should be able to implement a similar setup where the Access token rotation is taken care of completely by 3scale and your external webhook listener service and will take place automatically after a specific event occurs upon which a webhook is triggered.</p><p><strong>Important:</strong> This guide has nothing to do with access tokens used with the 3scale gateway as part of any OAuth or OpenID Connect flows.</p><h3>Example scenario</h3><p>Creating an Application via the 3scale API requires an Access Token to be provided in order for the request to be authorized. Access tokens need Read and Write permissions to the Account Management API and do not expire by default: for this reason the default settings may not be considered secure enough and hence this solution would be applicable.</p><p>It is possible to configure 3scale to revoke (delete) an Access Token that was specifically created to be used against the Application Create endpoint, once the task that it was meant for is finalised.</p><p>This guide demonstrates how this configuration can be implemented for the following scenario: <em>I want my Access Tokens to be single-use, so that after the token is used for creating an Application via the 3scale API it will be automatically revoked.</em></p><h3>Step by step guide</h3><h3>Prerequisites</h3><ul><li>3scale 2.8 On-premises and later OR 3scale SaaS Enterprise</li><li>Webhook listener service (<a href="https://github.com/samugi/3scale-AccessTokenRevoker/tree/demo">example app</a> can be used to follow this tutorial)</li></ul><h3>Setup</h3><p>The following steps should be completed in full before proceeding to the <em>End to End flow in action</em> section. For the purpose of following this tutorial the example app <a href="https://github.com/samugi/3scale-AccessTokenRevoker/tree/demo">AccessTokenRevoker</a> can be used but it’s recommended that you implement your own webhook listener service in the language you prefer.</p><ul><li><a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.9/html/creating_the_developer_portal/custom-signup-fields">Create a custom field definition</a> on the <em>Application</em> object, make it <em>Hidden</em>. Set the <em>Name</em> field and<em> Label</em> field, in this example they will be token_value and Token Value respectively. The <em>Name</em> field is important here because that is the parameter which will be parsed from the webhook object later.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*TO5ti66FXeODwlen-rpmhQ.png" /><figcaption>Creation of a new custom field definition</figcaption></figure><ul><li><a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.9/html/creating_the_developer_portal/webhooks#introducing_webhooks">Configure 3scale webhooks</a> to deliver upon admin portal actions and specifically for the<em> Application created</em> event.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_GgMl4BY6X7Z1um27oaQnw.png" /><figcaption>Webhooks configuration</figcaption></figure><ul><li>Deploy an application running as an external service to 3scale where the 3scale webhooks will be delivered, parsed and that subsequently makes an API call to 3scale to rotate the <em>Access token</em>.</li><li>See the <a href="https://github.com/samugi/3scale-AccessTokenRevoker/blob/demo/README.md">example app instructions</a> to deploy and configure it to follow along with the steps. Here is an example command that can be used to start the example app:</li></ul><pre>node app.js --url &quot;https://{TENANT | ACCOUNT}-admin.{WILDCARD_DOMAIN | 3scale.net}&quot;</pre><ul><li>API call to 3scale should pass the value of the custom field <em>Token Value</em> as both the access_token and id parameters to the <em>Personal Access Token Delete</em> API. Here is an example of a curl request the application should implement in order to successfully revoke the token:</li></ul><pre>curl -X DELETE &quot;https://{TENANT | ACCOUNT}-admin.{WILDCARD_DOMAIN | 3scale.net}/admin/api/personal/access_tokens/${ACCESS_TOKEN}.json&quot; -d &#39;access_token=${ACCESS_TOKEN}&#39;</pre><h3>End to end flow in action</h3><ul><li>Admin user <a href="https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.9/html/admin_portal_guide/tokens#creating-access-tokens">creates an access token</a> with read/write permissions and scope for the Account Management API</li><li>User creates an application from the 3scale API and will be required to add a value to the field created in the <em>Setup </em>section. The value of this field should be equal to the <em>Access Token</em> created in the previous step.</li><li>Here is an example of a curl request to the 3scale API that can be used to create a new application and rotate the token (notice the <em>token_value </em>field is being assigned the <em>Access Token</em> as a value in the request POST data):</li></ul><pre>curl -X POST &quot;https://{TENANT | ACCOUNT}-admin.{WILDCARD_DOMAIN | 3scale.net}/admin/api/accounts/${ACCOUNT_ID}/applications.xml&quot; -d &#39;access_token=${ACCESS_TOKEN}&amp;plan_id=${PLAN_ID}&amp;name=${APPLICATION_NAME}&amp;description=demo&amp;token_value=${ACCESS_TOKEN}&#39;</pre><ul><li>The 3scale webhook will be triggered on the <em>Application created</em> event.</li><li>This is an example of what the webhook’s request body looks like. The token value is visible as part of the extra_fields object in: req.body.event.object[0].application[0].extra_fields[0].token_value[0]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*b4TCKZqyiSx_Kpuj6CKQag.png" /><figcaption>Webhook object</figcaption></figure><ul><li>The external service listening for 3scale webhooks will receive the object and should parse the body for the custom field defined previously e.g. token_value and then store this value for the API call to 3scale.</li></ul><p>Once the token has been deleted then it will no longer function and cleaning it up from the hidden field on the Application at this point is optional given that the field is configured as <em>hidden</em> at the beginning and is no longer valid.</p><p>Alternatively in the set up phase you can set the custom field definition to <em>required</em> instead of <em>hidden</em> which will prevent the user from creating an application without setting this important field. Bear in mind that by doing this the custom field will be visible by default to developers if they have access to the developer portal and that can pose a security threat while the access token is still valid. As a further step you can ensure that the field is not rendered in HTML by customising the liquid templates in the developer portal. That’s beyond the scope of this article, hence will not be covered.</p><h3>Conclusion</h3><p>In this article you have learned how some of the 3scale features can be combined to form a flow that can be used for access tokens rotation. This is an example of how 3scale users can make use of access tokens to access all the features available via the 3scale API, by still avoiding any security leak thanks to the temporary tokens.</p><h3>What’s next?</h3><p>This workflow can be configured to fit the requirements of the API provider to rotate tokens after any of the supported webhook events are triggered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dz_NoX-tTaXY_6DJ6Sh54g.png" /><figcaption>Available webhook events</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1f535b3c23f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/3scale-ninja-toolbook/personal-access-token-rotation-in-3scale-d1f535b3c23f">Personal access token rotation in 3scale</a> was originally published in <a href="https://medium.com/3scale-ninja-toolbook">3scale-ninja-toolbook</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>