<?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[Stories by Simon Moser on Medium]]></title>
        <description><![CDATA[Stories by Simon Moser on Medium]]></description>
        <link>https://medium.com/@sdmoser?source=rss-bd5f78cde561------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*92jIQ83Or7qX4NMC.</url>
            <title>Stories by Simon Moser on Medium</title>
            <link>https://medium.com/@sdmoser?source=rss-bd5f78cde561------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:23:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sdmoser/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[How to emit more IBM Cloud Code Engine metrics into IBM Cloud Monitoring]]></title>
            <link>https://medium.com/@sdmoser/how-to-emit-more-ibm-cloud-code-engine-metrics-into-ibm-cloud-monitoring-023ec51a3091?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/023ec51a3091</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[code-engine]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[ibm-cloud]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Mon, 22 Jun 2026 09:56:43 GMT</pubDate>
            <atom:updated>2026-06-22T09:56:43.170Z</atom:updated>
            <content:encoded><![CDATA[<h3>Written by</h3><p>Simon Daniel Moser (smoser@de.ibm.com)<br>Distinguished Engineer for Containers @ IBM Cloud</p><p>Enrico Regge (reggeenr@de.ibm.com)<br>Software Architect @ IBM Cloud</p><p>Norman Boewing (boewing@de.ibm.com)<br>Software Engineer @ IBM Cloud</p><p>If you’ve managed a production system for more than five minutes, you know the story: there is no such thing as enough logs or enough metrics. IBM Cloud Code Engine already gives you solid observability out of the box, but as every engineer eventually learns, “solid” is never the same as “enough.” The real trick is spotting what’s missing <em>before</em> the 2 a.m. outage taps you on the shoulder and asks why you didn’t instrument that one critical thing. In this blog post, we’ll show you how to easily add meaningful, sleep‑preserving metrics to your Code Engine apps — because the only acceptable 2 a.m. alert is the one you never receive!</p><p>First, we’ll introduce a small asset you can install into your IBM Cloud Code Engine project. It uses well‑known technologies like Prometheus to expand the set of metrics you can scrape from your Code Engine applications and jobs. We’ll then walk you through the built‑in dashboard that comes with the asset, which lets you visualize those metrics effortlessly. In the second half of the blog, we’ll show you how to emit fully custom metrics — either by instrumenting your own code or by using a metrics library for your application’s programming language.</p><p>Let’s look at how metrics can be emitted to IBM Cloud Monitoring with Sysdig. Metrics can be written either through the Sysdig agent or through Prometheus Remote Write, and these approaches behave very differently. The Sysdig agent runs directly on a host or node and automatically scrapes system‑level, container, and application metrics. Prometheus Remote Write, by contrast, allows an existing Prometheus server to push metrics to a Monitoring instance over HTTPS without deploying any agent. This makes remote write ideal for environments where agents cannot run, such as IBM Cloud Code Engine. Because Code Engine is a fully managed, multitenant service, users cannot access the underlying nodes and therefore cannot deploy Sysdig agents, making remote write the only viable option. In this model, Prometheus simply sends the scraped metrics, optionally filtered or relabeled, to the region‑specific ingestion endpoint. This distinction is important for cost planning: Sysdig agents are billed per instance and include unlimited metric ingestion, whereas Prometheus Remote Write has no agent fee but charges based on the volume of metrics ingested. For multitenant environments like Code Engine that rely entirely on remote write, controlling metric volume — through relabeling, filtering, or reducing series — is essential to keeping monitoring costs <a href="https://cloud.ibm.com/docs/monitoring?topic=monitoring-about-collect-metrics">predictable</a>. More details can be found here: <a href="https://cloud.ibm.com/docs/monitoring?topic=monitoring-prometheus_remote_write">https://cloud.ibm.com/docs/monitoring?topic=monitoring-prometheus_remote_write</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YoTj50QaOpnrimOSpoqWVQ.png" /></figure><p>In order to leverage the Prometheus Remote Write mechanism with your application or job running on IBM Cloud Code Engine, we need to install a small asset that we’re going to call metrics-collector. Figure 1 illustrates the setup used in this tutorial for IBM Cloud Code Engine. The metrics collector is essentially a job that runs in daemon mode, meaning it stays active indefinitely rather than completing and terminating like a normal batch job. Inside this job, two embedded processes run side by side: project‑metrics‑endpoint and prometheus‑agent. The project‑metrics‑endpoint component reads the available Kubernetes‑style CPU and memory metrics exposed by Code Engine and converts them into a Prometheus‑compatible format. The prometheus‑agent then scrapes both these kube‑metrics and any custom application or job metrics, and forwards them to the Monitoring instance using Prometheus Remote Write.</p><p>Now let’s look at how to bring the metrics‑collector to life so you can take advantage of all the metrics it can provide. In the next section, we’ll walk through the detailed steps for instantiating a IBM Cloud Monitoring instance, deploying the metrics-collector. Furthermore, we’ll create an IAM Trusted Profile to establish a trust relationship between the metrics-collector and the IBM Cloud Monitoring instance, which makes this integration work.</p><ul><li>Install <a href="https://jqlang.org/">jq</a>. On MacOS, you can use following <a href="https://formulae.brew.sh/formula/jq">brew formulae</a> to do a brew install jq.</li><li>Install the IBM Cloud CLI including the Code Engine plugin as described in the <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-cecli-getstart">Code Engine documentation</a></li><li>Perform all necessary login steps to IBM Cloud</li><li>Target the IBM Cloud region of your choice</li></ul><pre>REGION=eu-es<br><br>ibmcloud target -r $REGION</pre><ul><li>Create an IBM Cloud Monitoring instance</li></ul><pre>MONITORING_INSTANCE_NAME=&quot;&lt;yourMonitoringInstanceName&gt;&quot;<br><br>ibmcloud resource service-instance-create \<br>    &quot;$MONITORING_INSTANCE_NAME&quot; \<br>    sysdig-monitor graduated-tier $REGION \<br>    -p &#39;{&quot;default_receiver&quot;: false}&#39;<br><br>MONITORING_INSTANCE_GUID=$(ibmcloud resource service-instance &quot;$MONITORING_INSTANCE_NAME&quot; -o JSON|jq -r &#39;.[0].guid&#39;)<br><br>MONITORING_INGESTION_FQDN=&quot;ingest.prws.private.${REGION}.monitoring.cloud.ibm.com&quot;</pre><p>Create or select the Code Engine project of your choice; e.g. ibmcloud ce project create --name custom-metrics-sample or ibmcloud ce project select --name &lt;yourProjectName&gt;</p><ul><li>Create an IAM Trusted Profile to entitle Code Engine to send metrics to the monitoring instance</li></ul><pre>ibmcloud iam trusted-profile-create metrics-collector-profile \<br>     --description &quot;Trusted profile for Code Engine metrics collector&quot;</pre><ul><li>Entitle the Code Engine job called “metrics-collector“ within the project that we’ve just created to make use of this project</li></ul><pre>CE_PROJ_NAME=&quot;$(ibmcloud ce proj current --output json|jq -r &#39;.name&#39;)&quot;<br><br>ibmcloud iam trusted-profile-rule-create metrics-collector-profile \<br>     --name code-engine-rule \<br>     --type Profile-CR \<br>     --cr-type CE \<br>     --conditions claim:project_name,operator:EQUALS,value:&quot;$CE_PROJ_NAME&quot; \<br>     --conditions claim:component_type,operator:EQUALS,value:&quot;job&quot; \<br>     --conditions claim:component_name,operator:EQUALS,value:&quot;metrics-collector&quot;</pre><ul><li>Assign Viewer and Writer access to the trusted profile</li></ul><pre>ibmcloud iam trusted-profile-policy-create metrics-collector-profile \<br>    --roles Viewer,Writer \<br>    --service-name sysdig-monitor \<br>    --service-instance $MONITORING_INSTANCE_GUID</pre><ul><li>Create a Code Engine job, called metrics-collector, which will ingest the custom metrics to the monitoring instance in the respective region (see: <a href="https://cloud.ibm.com/docs/monitoring?topic=monitoring-endpoints#prometheus_remote_write_endpoints">https://cloud.ibm.com/docs/monitoring?topic=monitoring-endpoints#prometheus_remote_write_endpoints</a>)</li></ul><pre>ibmcloud ce job create \<br>    --name metrics-collector \<br>    --image &quot;icr.io/codeengine/metrics-collector:latest&quot; \<br>    --mode daemon \<br>    --cpu 0.25 \<br>    --memory 0.5G \<br>    --service-account reader \<br>    --trusted-profiles-enabled \<br>    --env INTERVAL=30 \<br>    --env METRICS_ENABLED=true \<br>    --env METRICS_REMOTE_WRITE_FQDN=$MONITORING_INGESTION_FQDN \<br>    --env CE_PROJECT_NAME=&quot;$(ibmcloud ce proj current --output json|jq -r &#39;.name&#39;)&quot; \<br>    --env MONITORING_INSTANCE_GUID=&quot;$MONITORING_INSTANCE_GUID&quot; \<br>    --env MONITORING_REGION=&quot;$REGION&quot; \<br>    --env TRUSTED_PROFILE_NAME=&quot;metrics-collector-profile&quot;</pre><ul><li>Submit the metrics collector as daemon job run</li></ul><pre>ibmcloud ce jobrun submit \<br>    --job metrics-collector</pre><p>Now that the metrics collector is installed and running, let’s look at the different types of metrics it can collect. In this tutorial, we distinguish between resource metrics and user-defined metrics. In general, Code Engine already provides a set of built‑in metrics out of the box, which vary depending on the workload type — apps, jobs, or functions. These built‑in metrics focus on general observability and the overall state of your workloads, such as the number of desired, actual, or pending instances, concurrency levels, and other high‑level indicators. We refer to these as platform metrics. While platform metrics offer a solid overview of the health and configuration of an application, they do not provide enough detail for debugging or troubleshooting issues at the level of individual runtime instances.</p><p>That now changes as the metrics collector adds resource metrics to the mix. Once the collector is up running, IBM Cloud Monitoring automatically provides a prebuilt dashboard that visualizes the available resource metrics.</p><p>Keep in mind that it may take a few minutes for the dashboard to appear and start showing data. To find it, start opening <a href="https://cloud.ibm.com/observability/monitoring">https://cloud.ibm.com/observability/monitoring</a> and select your Monitoring instance by clicking on “Dashboard”. Once inside, navigate to “Dashboards” and locate the dashboard named “<em>IBM Cloud Code Engine — Component Resource Overview</em>”. Open the dashboard and watch as it begins to populate with resource metrics from your Code Engine components 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mIuvmBSLlpsnzOIZwLLotA.png" /></figure><p>While this provides a solid foundation, deeper insight often requires instrumenting your application to emit user-defined metrics. These metrics can capture behaviours that Code Engine does not provide by default — for example, tracking inbound and outbound network requests, queue depths, cache performance, or internal processing times. Custom metrics enrich the built‑in metrics and give you the fine‑grained visibility needed to understand performance characteristics and troubleshoot issues within your application logic.</p><p>To instrument your application and emit custom metrics, the standard approach is to use the Prometheus client libraries available for most popular programming languages. In the following example, we’ll demonstrate this using Node.js, and later in the article we’ll show how to apply the same concepts in other languages your application might be written in. For a complete reference of how the metrics setup works in Node.js, you can review the sample implementation here: <a href="https://github.com/IBM/CodeEngine/blob/main/metrics-examples/node/app.mjs">https://github.com/IBM/CodeEngine/blob/main/metrics-examples/app.mjs</a>.</p><pre>import promClient from &quot;prom-client&quot;;<br><br>...<br><br>// Create a registry to register the metrics<br>const register = new promClient.Registry();<br><br>// Define a custom prefix for all metrics<br>const METRICS_NAME_PREFIX = process.env.METRICS_NAME_PREFIX || &quot;mymetrics_node_&quot;;<br><br>...<br>// Define and start the custom HTTP server<br>// which provides the business logic<br>...<br><br>// Define the metrics server<br>const metricsApp = express();<br>const metricsPort = 2112;<br><br>// Expose metrics endpoint<br>metricsApp.get(&quot;/metrics&quot;, async (req, res) =&gt; {<br>  res.set(&quot;Content-Type&quot;, register.contentType);<br>  res.end(await register.metrics());<br>});<br><br>// Start the metrics server<br>const metricsServer = metricsApp.listen(metricsPort, () =&gt; {<br>  console.log(`Metrics server is running at http://localhost:${metricsPort}`);<br>});</pre><p>In the example above, the application exposes custom Prometheus metrics securely by running a dedicated HTTP server instead of attaching the `/metrics` endpoint to the main application server. This prevents internal metrics from being exposed to end users, as the metrics server is only reachable from within the same Code Engine project — allowing components like the metrics‑collector to scrape the data while keeping it isolated from external traffic. This approach cleanly separates business logic from observability concerns and ensures that only trusted, in‑project components can access the metrics endpoint. Now that we’ve configured this additional HTTP server inside the Code Engine app or job to serve custom metrics, we can move on to collecting and processing those metrics.</p><h3>Inbound metrics</h3><p>We are starting with an example of counting all incoming requests to this application instance along with the requests method and path. We recommend to collect information about request method, path, return code and the duration it takes to handle the entire request.</p><p>In combination this information may be effectively used to debug problems when receiving calls within an application.</p><pre>...<br>// Create a custom counter metric with path and method labels<br>const counter = new promClient.Counter({<br>  name: `${METRICS_NAME_PREFIX}requests_total`,<br>  help: &quot;Total number of requests&quot;,<br>  labelNames: [&quot;method&quot;, &quot;path&quot;],<br>});<br><br>// Register the metric<br>register.registerMetric(counter);<br><br>...<br><br>// Setup the Node.js express server<br>const app = express();<br>app.use(express.json());<br>const router = express.Router();<br>app.use(&quot;/&quot;, router);<br><br>// Middleware to count all requests with path and method<br>router.use((req, res, next) =&gt; {<br>  counter.inc({ method: req.method, path: req.path });<br>  next();<br>});<br><br>// Start the default HTTP server AND the metrics server</pre><h3>Outbound metrics</h3><p>For outgoing requests from an application instance the following example shows measurement of outbound call durations along with the requests target, method and its status_code. We recommend to collect this information to effectively debug problems related to upstream dependencies of an application like an external database or an authentication service so that issues of those upstream dependencies can easily be debugged.</p><pre>// Outbound HTTP call metrics<br>const outboundCallDuration = new promClient.Histogram({<br>  name: `${METRICS_NAME_PREFIX}outbound_request_duration_seconds`,<br>  help: &quot;Duration of outbound HTTP requests in seconds&quot;,<br>  labelNames: [&quot;target&quot;, &quot;method&quot;, &quot;status_code&quot;],<br>  buckets: [0.1, 0.5, 1, 2, 5, 10],<br>});<br>register.registerMetric(outboundCallDuration);<br><br>const outboundCallTotal = new promClient.Counter({<br>  name: `${METRICS_NAME_PREFIX}outbound_requests_total`,<br>  help: &quot;Total number of outbound HTTP requests&quot;,<br>  labelNames: [&quot;target&quot;, &quot;method&quot;, &quot;status_code&quot;],<br>});<br>register.registerMetric(outboundCallTotal);<br><br>...<br><br>// Make outbound HTTP call with metrics<br>async function makeOutboundCall(endpoint, method = &quot;GET&quot;) {<br>  const url = `${HTTPBIN_BASE_URL}${endpoint}`;<br>  const startTime = Date.now();<br><br>  try {<br>    const response = await fetch(url, { method });<br>    const duration = (Date.now() - startTime) / 1000;<br>    const statusCode = response.status.toString();<br><br>    // Record metrics<br>    outboundCallDuration.observe({ target: HTTPBIN_BASE_URL, method, status_code: statusCode }, duration);<br>    outboundCallTotal.inc({ target: HTTPBIN_BASE_URL, method, status_code: statusCode });<br><br>    return { success: true, status: response.status, duration, data: await response.text() };<br>  } catch (error) {<br>    const duration = (Date.now() - startTime) / 1000;<br><br>    // Record error metrics<br>    outboundCallDuration.observe({ target: HTTPBIN_BASE_URL, method, status_code: &quot;error&quot; }, duration);<br>    outboundCallTotal.inc({ target: HTTPBIN_BASE_URL, method, status_code: &quot;error&quot; });<br><br>    return { success: false, error: error.message, duration };<br>  }<br>}<br>...</pre><h3>Wrap business logic</h3><p>The following example shows measurement of compute intensive operations within an application. We recommend to collect this to pinpoint exact root causes for applications that fail to respond in a timely fashion.</p><pre>const computeDuration = new promClient.Histogram({<br>  name: `${METRICS_NAME_PREFIX}compute_duration_seconds`,<br>  help: &quot;Duration of compute-intensive operations in seconds&quot;,<br>  labelNames: [&quot;operation&quot;],<br>  buckets: [0.5, 1, 2, 3, 5],<br>});<br>register.registerMetric(computeDuration);<br><br>...<br><br>function doSomethingMeaningful() {<br>  // Instrument compute-intensive data handling<br>  const computeStart = Date.now();<br><br>  // TODO some compute-intensive business logic processing<br><br>  // Collect this metric<br>  const actualComputeDuration = (Date.now() - computeStart) / 1000;<br>  computeDuration.observe({ operation: &quot;data_processing&quot; }, actualComputeDuration);<br>} </pre><h3>Language specific metrics</h3><p>In the examples above, we demonstrated how to emit custom metrics using Node.js, but the same approach works across many programming languages thanks to the standard Prometheus client libraries maintained by the Prometheus community. Popular options include the Python client (<a href="https://github.com/prometheus/client_python),">https://github.com/prometheus/client_python),</a> the Java client (<a href="https://github.com/prometheus/client_java),">https://github.com/prometheus/client_java),</a> and the Go client (<a href="https://github.com/prometheus/client_golang).">https://github.com/prometheus/client_golang).</a> These libraries can be used in a similar fashion to instrument your application and expose metrics in a format compatible with the metrics‑collector.</p><p>In addition to custom metrics, these libraries also offer language‑specific default metrics — for example, Java’s garbage‑collector metrics or Node.js process metrics. Enabling them typically requires just a small snippet of code, such as:</p><pre>if (process.env.METRICS_COLLECT_NODE_METRICS_ENABLED === &quot;true&quot;) {<br>  promClient.collectDefaultMetrics({ register, prefix: METRICS_NAME_PREFIX });<br>}</pre><p>However, it’s important to enable such defaults with caution. While they can provide valuable insights, these built‑in runtime metrics can be very detailed and may produce a large number of data points. This increases metric cardinality and can lead to higher ingestion costs when data is sent to IBM Cloud Monitoring.</p><h3>Deploying a practical example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQusXYKP9o3aF_u0T-BW-w.png" /></figure><p>The command below demonstrates how to deploy the Node.js sample metrics-examples as an application.</p><pre>APP_NAME=&quot;metrics-example-app&quot;<br><br>ibmcloud ce application create \<br>    --name &quot;$APP_NAME&quot; \<br>    --src &quot;https://github.com/IBM/CodeEngine&quot; \<br>    --build-context-dir &quot;metrics-examples/node&quot; \<br>    --memory 0.5G \<br>    --cpu 0.25 \<br>    --env HTTPBIN_BASE_URL=https://httpbin.org<br><br>APP_URL=$(ibmcloud ce app get --name &quot;$APP_NAME&quot; --output url)</pre><p>To let the metrics‑collector know that a Code Engine app or job exposes user-defined metrics, the component needs to be annotated. Annotations are a native Kubernetes concept, and while Code Engine is built on Kubernetes, the service intentionally abstracts most of that complexity so you can focus on your workloads rather than the underlying platform. Because of this design choice, certain low‑level knobs — like adding custom annotations — are not exposed through the regular Code Engine API. In the rare cases where you need this kind of advanced control, Code Engine allows you to access the underlying Kubernetes resources directly through the Kubernetes CLI (see: <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-kubernetes">https://cloud.ibm.com/docs/codeengine?topic=codeengine-kubernetes</a>). This provides a clean escape hatch: the platform stays simple for day‑to‑day use, but you still retain the flexibility to apply Kubernetes‑level configuration when it’s truly needed, such as enabling custom metric scraping. Follow the 6 steps in the example below to set the annotation:</p><pre>CE_PROJECT=$(ibmcloud ce project current --output json|jq -r &#39;.name&#39;)<br><br>ibmcloud ce project select --name &quot;$CE_PROJECT&quot; --kubecfg<br><br>PATCH_REMOVE_BUILD_LABEL=&#39;[{&quot;op&quot;:&quot;remove&quot;,&quot;path&quot;:&quot;/spec/template/metadata/labels/codeengine.cloud.ibm.com~1pause-build&quot;}]&#39;<br><br>kubectl patch kservice &quot;$APP_NAME&quot; --type=json -p=&quot;$PATCH_REMOVE_BUILD_LABEL&quot;<br><br>PATCH_ENABLE_METRICS_COLLECTION=&#39;[<br>    {&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/metadata/annotations/codeengine.cloud.ibm.com~1userMetricsScrape&quot;,&quot;value&quot;:&quot;true&quot;},<br>    {&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/metadata/annotations/codeengine.cloud.ibm.com~1userMetricsPath&quot;,&quot;value&quot;:&quot;/metrics&quot;},<br>    {&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/metadata/annotations/codeengine.cloud.ibm.com~1userMetricsPort&quot;,&quot;value&quot;:&quot;2112&quot;}<br>]&#39;<br><br>kubectl patch kservice &quot;$APP_NAME&quot; --type=json -p=&quot;$PATCH_ENABLE_METRICS_COLLECTION&quot;</pre><p>To round things off, it’s worth noting that the example in this blog post focuses on instrumenting a Code Engine application, but the ability to collect custom metrics isn’t limited to apps. The same approach works for other Code Engine resource types as well, including jobs. If you want to explore these scenarios further, you can find additional details and examples in the project’s README: <a href="https://github.com/IBM/CodeEngine/blob/main/metrics-examples/README.md">https://github.com/IBM/CodeEngine/blob/main/metrics-examples/README.md</a>. Having said that, let’s complete this setup by importing a dashboard that visualizes the custom emitted by the network-test-app application:</p><ul><li>Load the latest version of the “<em>My custom Code Engine metrics</em>” dashboard</li></ul><pre>CE_CUSTOM_METRICS_DASHBOARD=$(curl -sL https://raw.githubusercontent.com/IBM/CodeEngine/main/metrics-examples/my-custom-code-engine-metrics-dashboard.json)</pre><ul><li>Import the dashboard into IBM Cloud Monitoring</li></ul><pre>curl -X POST https://$REGION.monitoring.cloud.ibm.com/api/v3/dashboards \<br>    -H &quot;Authorization: $(ibmcloud iam oauth-tokens --output JSON|jq -r &#39;.iam_token&#39;)&quot; \<br>    -H &quot;IBMInstanceID: $MONITORING_INSTANCE_GUID&quot; \<br>    -H &quot;Content-Type: application/json&quot; \<br>    -d &quot;{\&quot;dashboard\&quot;: $CE_CUSTOM_METRICS_DASHBOARD}&quot;</pre><ul><li>Once the import is complete, open <a href="https://cloud.ibm.com/observability/monitoring">https://cloud.ibm.com/observability/monitoring</a> in your browser and select your Monitoring instance by clicking the Dashboard link</li><li>Navigate to Dashboard Manager</li><li>Switch to the My Dashboards tab</li><li>Look for the dashboard named &quot;<em>My custom Code Engine Metrics</em>&quot;</li><li>Open it to explore the user-defined metrics generated by the sample application you just deployed</li></ul><p>You can use the ready-to-use load script “<a href="https://github.com/IBM/CodeEngine/blob/main/metrics-examples/load-test.sh">load-test.sh</a>“ to generate some random load on the application, after downloading it to your local workstation:</p><pre>curl -sL &quot;https://raw.githubusercontent.com/IBM/CodeEngine/main/metrics-examples/load-test.sh&quot; &gt; load-test.sh<br><br>chmod +x ./load-test.sh<br><br>TARGET_URL=$APP_URL DURATION=3600 CONCURRENT_REQUESTS=10 ./load-test.sh</pre><p>Note: While the dashboard itself is available immediately after import, it can take up to a few minutes for panels to populate with data points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WwacepH-wboPW_oqh2obsA.png" /></figure><h3>Conclusion &amp; Next steps</h3><p>By putting the metrics‑collector in place and combining it with both Code Engine’s built‑in observability and your own custom instrumentation, you gain a far more complete picture of how your applications behave in production. You’re no longer limited to platform‑level signals — you can surface the metrics that matter to your business logic and troubleshoot issues long before they turn into firefighting sessions. In this article, we demonstrated how to enhance metric emission for IBM Cloud Code Engine apps and jobs, from expanding the available platform metrics to emitting fully user-defined metrics you define. The lightweight asset you deploy alongside your application gives you full control over what metrics you collect, how they’re processed, what gets visualized, and ultimately how much you spend — since you decide exactly what is sent to IBM Cloud Monitoring.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=023ec51a3091" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting Code Engine to private backends using Private Path]]></title>
            <link>https://medium.com/@sdmoser/connecting-code-engine-to-private-backends-using-private-path-592379f193d0?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/592379f193d0</guid>
            <category><![CDATA[ibm-cloud]]></category>
            <category><![CDATA[code-engine]]></category>
            <category><![CDATA[private-connectivity]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Mon, 19 Jan 2026 08:41:38 GMT</pubDate>
            <atom:updated>2026-01-19T08:41:38.033Z</atom:updated>
            <content:encoded><![CDATA[<h3>Written by</h3><p>Simon Daniel Moser (smoser@de.ibm.com)<br>Distinguished Engineer for Containers @ IBM Cloud</p><p>Enrico Regge (reggeenr@de.ibm.com)<br>Software Architect @ IBM Cloud</p><p>Some time ago, we published a <a href="https://medium.com/@sdmoser/connecting-your-ibm-cloud-code-engine-applications-to-various-backends-using-satellite-connector-072f4340b4c7">blog post</a> on how to connect your Code Engine applications to various backends over private connections using IBM Cloud Satellite Connector. While Satellite Connectors remain a flexible, all‑purpose solution, some use cases can now be addressed with simpler, more targeted options. In particular, when you need private connectivity within IBM Cloud’s VPC network, the new private path capability offers a much easier setup. In this article, we revisit the example from the earlier blog and adapt it to private path, giving you a straightforward way to compare both approaches and choose the one that best fits your requirements.</p><p>Let’s recap: To understand the challenge of connecting an Application from Code Engine to somewhere over the private network, recall that Code Engine itself runs on IBM Cloud’s Virtual Private Cloud (VPC) infrastructure. Because it is a fully managed service — designed specifically to spare customers from operating their own infrastructure — the underlying VPC is controlled by the Code Engine team rather than by the customer. Normally, if you wanted to connect one VPC to another, you would create VPE gateways in both the source and target VPC and link them. But since customers do not own the VPC in which their Code Engine apps run, and cannot create their own VPEs there for security reasons, they appear to have no straightforward way to establish private connectivity from their application to other destinations.</p><p>In oder to illustrate this, we’ll be using this <a href="https://github.com/IBM/CodeEngine/tree/main/private-path-to-vpc-vsi">example</a>: As a user, I want to access my database backend on TCP port XYZ from workload deployed on Code Engine, without exposing my VPC to the public internet. Figure 1 depicts the architecture of the sample:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t4kvpwszvxGxrui-H8yuCg.png" /></figure><ul><li>On the left hand side, you see the above mentioned, Code Engine owned VPC that host your application or job (green box)</li><li>On the right hand side, you see your own VPC, running a Virtual Server with a Postgres DB installed on it that you want to connect to (dark blue box)</li><li>The light blue and red boxes represent the private path components that must be created so they can communicate with each other<br>- <strong>Private Path VPE Gateways:</strong> Gateways created in the consumer VPC to connect to a Private Path service. Each consuming VPC must create a separate gateway for every Private Path service instance it needs to reach.<br>- <strong>Private Path Service:</strong> Defines the service configuration, including endpoints, policies, and the network load balancer used to handle inbound traffic.<br>- <strong>Private Path NLB:</strong> The network load balancer that receives and routes all inbound requests sent to the Private Path service endpoints.<br>- <strong>Policies:</strong> Control how connection requests are handled at provisioning time. Policies can auto‑approve, deny, or require review of requests from consuming accounts. These policies apply only during provisioning. After a connection is established, the consuming VPC can send traffic through the Private Path service regardless of the policy settings.</li></ul><h3>Setup and Configuration</h3><p>With the architecture in place, we’ll now walk through the example: first deploying all needed VPC components including the VSI that hosts the PostgreSQL instance, then adding the Private Path service and connecting it to the Code Engine project, and finally confirming that app and the job can connect to the database.</p><p>For those, who want to skip the manual setup and skip forward to a running example, please checkout the sample code that we’ve published at <a href="https://github.com/IBM/CodeEngine/tree/main/private-path-to-vpc-vsi">https://github.com/IBM/CodeEngine/tree/main/private-path-to-vpc-vsi</a>. To ease setup, feel free to use the “run“ script that we published along with the sample source code, of the app and the job.</p><ul><li>Install <a href="https://jqlang.org/">jq</a>. On MacOS, you can use following <a href="https://formulae.brew.sh/formula/jq">brew formulae</a> to do a brew install jq.</li><li>Install and configure the IBM Cloud CLI<br>- Install the IBM Cloud CLI including the Code Engine plugin as described in the <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-cecli-getstart">Code Engine documentation</a><br>- Perform all necessary login steps to IBM Cloud<br>- Target the IBM Cloud region of your choice</li></ul><pre>REGION=EU-ES<br><br>ibmcloud target -r $REGION</pre><ul><li>Create the Virtual Private Cloud (VPC) that will host the Private Path and the VSI</li></ul><pre>vpc_name=private-path-sample-vpc<br><br>ibmcloud is vpc-create $vpc_name</pre><ul><li>Create a Public Gateway, a Subnet, a Network ACL and a Security Group</li></ul><pre>ibmcloud is public-gateway-create ${vpc_name}-gateway $vpc_name $REGION-1<br><br>ibmcloud is network-acl-create ${vpc_name}-acl $vpc_name --rules &#39;[{ &quot;name&quot;: &quot;egress&quot;, &quot;action&quot;: &quot;allow&quot;, &quot;destination&quot;: &quot;0.0.0.0/0&quot;, &quot;direction&quot;: &quot;outbound&quot;, &quot;source&quot;: &quot;0.0.0.0/0&quot;, &quot;protocol&quot;: &quot;all&quot; }, { &quot;name&quot;: &quot;ingress&quot;, &quot;action&quot;: &quot;allow&quot;, &quot;destination&quot;: &quot;0.0.0.0/0&quot;, &quot;direction&quot;: &quot;inbound&quot;, &quot;source&quot;: &quot;0.0.0.0/0&quot;, &quot;protocol&quot;: &quot;all&quot; }]&#39;<br><br>ibmcloud is subnet-create ${vpc_name}-subnet $vpc_name --zone $REGION-1 --ipv4-address-count 16 --pgw ${vpc_name}-gateway --acl ${vpc_name}-acl<br><br>ibmcloud is security-group-create ${vpc_name}-group $vpc_name<br><br>ibmcloud is security-group-rule-add ${vpc_name}-group outbound tcp --port-min 443 --port-max 443 --vpc $vpc_name<br><br>ibmcloud is security-group-rule-add ${vpc_name}-group outbound udp --port-min 53 --port-max 53 --vpc $vpc_name<br><br>ibmcloud is security-group-rule-add ${vpc_name}-group outbound all --remote 166.9.0.0/16 --vpc $vpc_name<br><br>ibmcloud is security-group-rule-add ${vpc_name}-group outbound all --remote 161.26.0.0/16 --vpc $vpc_name</pre><ul><li>Next, create a file on your local workstation, called userdata-vsi-originserver.sh</li></ul><pre>#!/bin/bash<br>touch /tmp/init_started<br><br># ==========================<br># nginx installation<br># ==========================<br>dnf -y install nginx<br>rm -f /usr/share/nginx/html/index.html<br>echo &quot;Hello world from `hostname`&quot; &gt; /usr/share/nginx/html/index.html<br>chmod go+r /usr/share/nginx/html/index.html<br>systemctl enable nginx<br>systemctl start nginx<br>systemctl status nginx<br>touch /tmp/nginx_done<br><br># ==========================<br># PostgreSQL installation<br># ==========================<br>yum install postgresql-server postgresql-contrib -y<br>postgresql-setup initdb<br>systemctl start postgresql<br>systemctl enable postgresql<br>echo &quot;host all all 0.0.0.0/0 md5&quot; &gt;&gt; /var/lib/pgsql/data/pg_hba.conf<br>echo &quot;listen_addresses = &#39;*&#39;&quot; &gt;&gt; /var/lib/pgsql/data/postgresql.conf<br>sudo systemctl restart postgresql<br><br># ==========================<br># PostgreSQL init<br># ==========================<br>useradd dbuser<br>sudo -i -u postgres bash &lt;&lt; EOF<br>createuser dbuser<br>createdb guestbookdb -O dbuser <br>psql -c &quot;ALTER USER dbuser PASSWORD &#39;myPassw0rd!&#39;;&quot;<br>EOF<br>touch /tmp/postgresql_done<br><br><br>touch /tmp/init_done</pre><ul><li>Now, that all the required components are in place, we can go ahead and create a VSI instance</li></ul><pre>ibmcloud is instance-create ${vpc_name}-originserver $vpc_name $REGION-1 cx2-2x4 ${vpc_name}-subnet \<br>--image ibm-centos-stream-10-amd64-5 \<br>--boot-volume &quot;{\&quot;name\&quot;: \&quot;boot-vol-attachment-name\&quot;, \&quot;volume\&quot;: {\&quot;name\&quot;: \&quot;${vpc_name}-originserver-boot-vol\&quot;, \&quot;capacity\&quot;: 100, \&quot;profile\&quot;: {\&quot;name\&quot;: \&quot;general-purpose\&quot;}}, \&quot;delete_volume_on_instance_delete\&quot;: true}&quot; \  <br>--host-failure-policy restart \  --primary-network-interface &quot;{\&quot;name\&quot;: \&quot;eth0\&quot;, \&quot;allow_ip_spoofing\&quot;: false, \&quot;auto_delete\&quot;: true, \&quot;subnet\&quot;: {\&quot;name\&quot;:\&quot;${vpc_name}-subnet\&quot;}, \&quot;primary_ip\&quot;: {\&quot;auto_delete\&quot;: true}, \&quot;security_groups\&quot;: [{\&quot;name\&quot;: \&quot;${vpc_name}-group\&quot;}]}&quot; \  <br>--user-data @userdata-vsi-originserver.sh </pre><ul><li>Create the Private Path network load balancer, it pool and listener. To learn more about this configuration step, please see <a href="https://cloud.ibm.com/docs/vpc?topic=vpc-ppnlb-ui-creating-private-path-network-load-balancer&amp;interface=cli">https://cloud.ibm.com/docs/vpc?topic=vpc-ppnlb-ui-creating-private-path-network-load-balancer&amp;interface=cli</a></li></ul><pre>ibmcloud is load-balancer-create ${vpc_name}-ppnlb private-path --family network --subnet ${vpc_name}-subnet<br><br>ibmcloud is load-balancer-pool-create ${vpc_name}-ppnlb-pg-pool ${vpc_name}-ppnlb weighted_round_robin tcp 10 2 5 tcp --health-monitor-port 80<br><br>ibmcloud is load-balancer-pool-member-create ${vpc_name}-ppnlb ${vpc_name}-ppnlb-pg-pool 5432 ${vpc_name}-originserver <br><br>ppnlb_pg_pool_id=$(ibmcloud is load-balancer-pool ${vpc_name}-ppnlb ${vpc_name}-ppnlb-pg-pool --output JSON | jq -r &#39;.id&#39;)<br><br>ibmcloud is load-balancer-listener-create ${vpc_name}-ppnlb --port-min 5432 --port-max 5432 --protocol tcp --default-pool $ppnlb_pg_pool_id</pre><ul><li>Create the Private Path service including the service endpoint, which is a FQDN, that is used to connect into the VPC. To learn more about this configuration step, please see <a href="https://cloud.ibm.com/docs/vpc?topic=vpc-private-path-service-about&amp;interface=cli">https://cloud.ibm.com/docs/vpc?topic=vpc-private-path-service-about&amp;interface=cli</a></li></ul><pre>random_chars=$(openssl rand -hex 6)<br><br>pps_service_endpoint=&quot;my-db.ce-${random_chars}.intra&quot;<br><br>ibmcloud is private-path-service-gateway-create --name ${vpc_name}-pps --default-access-policy permit --zonal-affinity true --service-endpoints $pps_service_endpoint --load-balancer ${vpc_name}-ppnlb</pre><ul><li>To expose the Private Service to other accounts (e.g. the Code Engine service account) make sure to publish it</li></ul><pre>ibmcloud is private-path-service-gateway-publish ${vpc_name}-pps</pre><ul><li>Before heading over to Code Engine, it is important that you obtain the CRN of the Private Path service as this is needed in later setup steps. The CRN value looks similar to this one: crn:v1:bluemix:public:is:eu-es:a/7658687ea07db8396963ebe2b8e1897d::private-path-service-gateway:r050–29977fba-f00c-4bbc-b0a5–659b7941094c</li></ul><pre>ibmcloud is private-path-service-gateway ${vpc_name}-pps</pre><ul><li>Create or select the Code Engine project of your choice;</li></ul><pre>ibmcloud ce project create - name private-path-sample or <br>ibmcloud ce project select - name &lt;yourProjectName&gt;</pre><ul><li>Create a the VPE Gateway Connection in the context of the Code Engine project to enable this project to connect to the Private Path service.</li></ul><pre>ibmcloud ce connectivity outbound create - name my-private-path-connection - format private_path_service_gateway - pps-crn &lt;your-private-path-crn&gt;</pre><ul><li>Observe the initialization of the Private Path service gateway: ibmcloud ce connectivity outbound get — name my-private-path-connection</li><li>Once it reached the status ready, it lists information such as the Endpoints, listed in the Private path service section of the output shown below. From within the project, your workload can access the Private Path network load balancer by issuing requests towards these endpoints</li></ul><pre>Getting allowed outbound destination &#39;my-private-path-connection&#39;...<br>OK<br><br>Project name:  private-path-sample  <br>Name:          my-private-path-connection  <br>Format:        private_path_service_gateway  <br><br>Private path service:    <br>  CRN:        crn:v1:bluemix:public:is:eu-es:a/7658687ea07db8396963ebe2b8e1897d::private-path-service-gateway:r050-29977fba-f00c-4bbc-b0a5-659b7941094c  <br>  Status:     ready  <br>  Name:       private-path-sample-vpc-pps  <br>  Endpoints:    <br>    my-db.ce-813513fa4c04.intra  <br><br>VPE gateway:             <br>  Name:                    code-engine-prod-eu-es-53fdba  <br>  Code Engine account ID:  0d852dce0bc442ddb2831ffae1a04e31  <br>  Creation timestamp:      2025-12-15T09:56:22Z  <br>  IP addresses:              <br>    192.168.70.83  <br>    192.168.166.68  <br>    192.168.102.77 </pre><ul><li>Create a Code Engine secret, that contains connectivity information, such as the Private Path service endpoint, and credentials to authenticate in the database</li></ul><pre>ibmcloud ce secret create --name pg-credentials --format generic \<br>  --from-literal PGHOST=$pps_service_endpoint \<br>  --from-literal PGPORT=5432 \<br>  --from-literal PGUSER=dbuser \<br>  --from-literal PGPASSWORD=myPassw0rd! \<br>  --from-literal PGDATABASE=guestbookdb</pre><ul><li>Create a Code Engine job, which will insert a random entry into the database on each job run instance execution</li></ul><pre>ibmcloud ce job create - name my-ce-job\<br> - image icr.io/codeengine/ce-to-private-path/job \<br> - env-from-secret pg-credentials \<br> - memory 0.5G \<br> - cpu 0.25</pre><ul><li>Submit a jobrun with 10 instances, to fill the database with some content: ibmcloud ce jobrun submit — job my-ce-job — array-size 10 — wait</li><li>Create a Code Engine app, that can be used to query the database entries</li></ul><pre>ibmcloud ce app create - name my-ce-app \<br> - image icr.io/codeengine/ce-to-private-path/app \<br> - env-from-secret pg-credentials \<br> - memory 0.5G \<br> - cpu 0.25</pre><p>Now, everything is in place. Let us quickly walk through the most important parts of our solution:</p><ol><li>The VPC VSI that hosts the custom database</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBYSbsbTk6LnwZSlmngFBQ.png" /></figure><p>2. The Private Path network load balancer, which defines one or many backend pools that are distributing incoming requests to backends, such as VSIs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*poFxzpXgWvO5ER7IjX89xg.png" /></figure><p>3. The Private Path service that exposes the network load balancer through the service endpoints my-db.ce-813513fa4c04.intra</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qh5C8CJP9kCpnlfRLskXyQ.png" /></figure><p>4. The Private Path connection in the Code Engine project, making sure that this Code Engine project can connect to the Private Path service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dCPinReCrhc3JDN2LPPz0g.png" /></figure><p>5. Finally, let us open the application URL and see whether the application can read entries from the database:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6dmdBOYnaQJoCORAKVB_w.png" /></figure><p>To create more entries in the database, simply submit another job run: ibmcloud ce jobrun submit — job my-ce-job — array-size 10 — wait</p><p>Congratulations — you’ve successfully established a private connection to your database using Private Path. Before we move on, here are two important technical clarifications. First, since Private Path enables a connection from a multi‑tenant service like Code Engine into your VPC, you might wonder whether this opens the door to unwanted or malicious traffic. It does not. In principle, at runtime Code Engine isolates its tenants and makes sure that only those projects that are connected with a certain private path can actually reach it. Furthermore, Code Engine only allows to setup such a connection from a Code Engine <strong>project</strong> that resides either in the same IBM Cloud account as the target VPC or within the same Enterprise Account Family. Projects outside of those boundaries can neither connect with your VPC, nor can they reach your VPC through Private Path, ensuring that your environment remains safe and fully under your control.</p><p>Secondly, review the account policies you configured in the sample. For simplicity, we allowed all inbound connections in this example, but that is not what you would do in a real production environment. In practice, we recommend setting the default policy for connection requests to “Deny all requests”. For the specific connections you want to permit, you can mark them as “Review all requests,” which introduces an approval step for added scrutiny, or as “Permit all requests” if you prefer to allow them automatically without the review process.</p><h3>Conclusion and Outlook</h3><p>In this article, we demonstrated Private Path, a VPC‑native option for connecting a Code Engine application to a backend over the private network, reducing exposure and supporting compliance requirements. The benefits of Private Path, which can also be used with other IBM Cloud services, include a simpler setup compared to Satellite Connectors or full VPE gateway configurations, and the fact that it uses native VPC networking. This gives network administrators better visibility and control, unlike Satellite Connector, which operates as an encrypted tunnel with limited insight. Private Path is also fully managed, whereas Satellite Connector tunnels require operational maintenance by the user.</p><p>However, both connection methods have their place. Private Path is best when you need private connectivity within IBM Cloud’s internal network. When both your workload and the target service</p><p>a) reside in IBM Cloud VPC, and that includes scenarios where you connect to on-premises through e.g. a VPC and the direct Link service,</p><p>b) you cannot create your own VPE, and</p><p>c) you want a straightforward, low‑overhead setup without deploying intermediate components.</p><p>Satellite Connector is recommended when you need private connectivity from IBM Cloud to on‑premises systems, other clouds, or external network locations. It is also suitable when you want a single, consistent mechanism to link multiple environments and are comfortable managing a Connector instance.</p><p>In this blog post, as well as in the Satellite Connector blog post, we used a VSI as the target for the connection. However, that example represents only a small part of what both integration patterns can support. The figure below shows how Private Path can connect to:</p><ul><li>a VSI in a VPC</li><li>an OpenShift cluster hosted in a VPC</li><li>on‑premises environments or any other external network (see also how to <a href="https://cloud.ibm.com/docs/pattern-saas-to-onprem-private-path?topic=pattern-saas-to-onprem-private-path-overview">connect cloud services to on-premises environments with Private Path</a>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lsqr8ohxfco2nDTGa5YoQQ.png" /></figure><p>The same connectivity options are available when using Satellite Connector. If you’re unsure which approach is best for your environment, feel free to contact us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=592379f193d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using COS bucket mounts as persistent storage in Code Engine]]></title>
            <link>https://medium.com/@sdmoser/using-cos-bucket-mounts-as-persistent-storage-in-code-engine-12d279e046a8?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/12d279e046a8</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-storage]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[ibm-cloud]]></category>
            <category><![CDATA[code-engine]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Fri, 09 Jan 2026 09:44:36 GMT</pubDate>
            <atom:updated>2026-01-09T09:44:36.426Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Written by</strong></h3><p>Simon Daniel Moser (smoser@de.ibm.com)<br>Distinguished Engineer for Containers @ IBM Cloud</p><p>Enrico Regge (reggeenr@de.ibm.com)<br>Software Architect @ IBM Cloud</p><p><a href="https://www.ibm.com/products/code-engine">IBM Cloud Code Engine</a> is IBM Cloud’s all‑purpose serverless platform, capable of running 12-factor web apps, functions, batch jobs, and general containers (this collection is called compute variants in the further course of this article). However, until recently, Code Engine had one shortcoming: All its compute variants could only save data by writing to a database or using <a href="https://www.ibm.com/products/cloud-object-storage">Cloud Object Storage (COS)</a> through an API; mounting a persistent filesystem wasn’t possible.</p><p>Just recently, we wrote a <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-3-d97de417fc2f">blog</a> using JupyterLab as an example where this limitation got in our way. JupyterLab is a popular tool for data scientists, and Code Engine makes it easy and cost‑efficient to run. But any data stored inside the Jupyter notebook environment lived only on the container’s ephemeral disk. When the app scaled down (a very common and intended use case for serverless computing), that data disappeared — far from ideal.</p><p>Now, as mentioned above, you could e.g. call some Cloud Object Storage API to persist that data, but that doesn’t work for software like JupyterLab where you can’t modify the source code to integrate such calls. For these “as‑is” applications, containers, or jobs, filesystem mounts are essential. They let you expose persistent storage directly into the filesystem, and using COS‑backed mounts aligns well with serverless patterns because COS itself is serverless as well, meaning the storage costs scale with the usage.</p><p>There are, however, scenarios where COS mounts aren’t ideal — for example, low‑latency, highly concurrent workloads like relational databases. Object Storage has higher latency and offers no coordination for concurrent writes. The Code Engine <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-persistent-data-store&amp;interface=ui#pds-limitations">documentation</a> lists more things to watch out for and covers these considerations in more detail. But for our Jupyter use case, none of these limitations matter, so let’s look at what the new persistent storage capabilities offer and how to use them.</p><p>Before diving in, let’s briefly review the system architecture of the sample. Figure 1 shows all required resources:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FVaoW5phDMYrCAMYbJkaPA.png" /></figure><ul><li>An IBM Code Engine project (“jupyter‑labs”) in a region of your choice</li><li>A Code Engine application (“jupyter‑lab”) deployed in that project and exposed to the public internet</li><li>A Cloud Object Storage (COS) instance (“jupyter‑labs‑cos”) with a regional bucket in the same region as the Code Engine project</li><li>An HMAC‑based service credential for the COS instance to allow bucket access</li></ul><p>To connect the Code Engine application with COS, we configure a persistent data store:</p><ul><li>A COS credential derived from the HMAC key is created and referenced by the persistent data store</li><li>The data store is configured with the bucket name</li><li>At runtime, Code Engine mounts the bucket into the application’s filesystem</li></ul><h3>Setup and Configuration</h3><p>With the architecture in place, we’ll now walk through the example: first deploying a plain JupyterLab instance (using a fixed password), then adding and connecting the persistent storage, and finally confirming that data in the bucket persists even when the application scales down.</p><ul><li>Install <a href="https://jqlang.org/">jq</a>. On MacOS, you can use following <a href="https://formulae.brew.sh/formula/jq">brew formulae</a> to do a brew install jq. <br>- Install and configure the IBM Cloud CLI <br>- Install the IBM Cloud CLI including the Code Engine plugin as described in the <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-cecli-getstart">Code Engine documentation</a></li><li>Perform all necessary login steps to IBM Cloud</li><li>Create or select a Code Engine project <br>- Create or select the Code Engine project of your choice; e.g.</li></ul><pre>ibmcloud ce project create - name jupyter-labs or <br>ibmcloud ce project select - name &lt;yourProjectName&gt;</pre><ul><li>Once the project had been created or selected, run the following commands to initialize environment variables in your current terminal session that are required later on</li></ul><pre>CE_PROJECT=$(ibmcloud ce project current --output json)<br><br>REGION=$(echo &quot;$CE_PROJECT&quot; | jq -r &#39;.region_id&#39;)<br><br>CE_INSTANCE_GUID=$(echo &quot;$CE_PROJECT&quot; | jq -r &#39;.guid&#39;)<br><br>echo &quot;CE project guid: ${CE_INSTANCE_GUID}, region: ${REGION}&quot;</pre><ul><li>Create the Jupyter Labs app</li></ul><pre>ibmcloud ce app create --name jupyter-lab --image &quot;quay.io/jupyter/minimal-notebook:latest&quot; --command &quot;jupyter&quot; --command &quot;lab&quot; --command &quot;--ip&quot; --command &quot;*&quot; --command &quot;--NotebookApp.allow_origin&quot; --command &quot;*&quot; --max-scale 1 --service-account &quot;none&quot; --port 8888</pre><ul><li>Open the browser using the URL that is printed in the command output to load the Jupyter Lab.<br>- On your first attempt to open the Jupyter Lab, you’ll be greeted with the page shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*51CDtf4YLrqPzVxH3nIaVg.png" /></figure><ul><li>To obtain the current token, print the application logs</li></ul><pre>ibmcloud ce application logs - application jupyter-lab</pre><ul><li>Copy the value of the token parameter printed in the log lines into your clipboard, e.g. b610… in the example</li></ul><pre>http://localhost:8888/lab?token=b610e8a24c5e581b61779f833d1c36931e1b9c346bc1211d</pre><ul><li>Switch back to the website, and paste that value in “Password or Token” field and hit “login”</li><li>If you are interested to learn more such Jupyter configuration, take a look at the public documentation on “<a href="https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html#running-a-public-jupyter-server">Running a public Jupyter Server</a>“</li></ul><p>Once, you passed the authentication, you’ll be greeted with the Juypter Labs Launcher. That’s it …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f7IFPeHqLNByW4J9mG2vGg.png" /></figure><p>… not quite yet. While it was pretty easy to bring a Jupyter Lab running on Code Engine, the capabilities of that setup are not meeting our requirements, yet. While you can explore and use Jupyter in the current setup, you’ll notice that all your data (notebooks, your configured password) is gone one Code Engine scales down your app. In the second part of the solution setup, we’ll add a persistence layer.</p><ul><li>Create the COS instance and the bucket<br>-COS_INSTANCE_NAME=jupyter-labs --cos should to define a environment Variable in your Terminal for the COS instance name<br>- ibmcloud resource service-instance-create ${COS_INSTANCE_NAME} cloud-object-storage standard global -d premium-global-deployment-iam to create an actual COS instance by that name <br>- COS_INSTANCE_ID=$(ibmcloud resource service-instance ${COS_INSTANCE_NAME} — output json | jq -r ‘.[0]| .id’ to define a environment Variable in your terminal for the COS instance ID<br>- ibmcloud cos config crn -crn ${COS_INSTANCE_ID} — force <br>- ibmcloud cos config auth -method IAM to set the authentication mode to IBM Cloud IAM <br>- ibmcloud cos config region — region ${REGION} to set the region to your preferred region<br>- ibmcloud cos config endpoint-url --url s3.${REGION}.cloud-object-storage.appdomain.cloud to set the endpoint URL to the georegional endpoint<br>- COS_BUCKET_NAME=${CE_INSTANCE_GUID}-jupyter-labs to create an environment variable in your terminal for the bucket name<br>- ibmcloud cos bucket-create --class smart --bucket $COS_BUCKET_NAME to create an actual COS bucket with that name</li><li>Create the COS Service credentials and store them as a Code Engine secret</li></ul><pre>COS_HMAC_CREDENTIALS=$(ibmcloud resource service-key-create ${COS_INSTANCE_NAME}-codeengine-mounts Writer --instance-id $COS_INSTANCE_ID --parameters &#39;{&quot;HMAC&quot;:true}&#39; --output JSON)<br><br>COS_HMAC_CREDENTIALS_ACCESS_KEY_ID=$(echo &quot;$COS_HMAC_CREDENTIALS&quot;|jq -r &#39;.credentials.cos_hmac_keys.access_key_id&#39;)<br><br>COS_HMAC_CREDENTIALS_SECRET_ACCESS_ID=$(echo &quot;$COS_HMAC_CREDENTIALS&quot;|jq -r &#39;.credentials.cos_hmac_keys.secret_access_key&#39;)</pre><ul><li>Create a Code Engine secret</li></ul><pre>ibmcloud ce secret create --name cos-secret --format hmac --access-key-id ${COS_HMAC_CREDENTIALS_ACCESS_KEY_ID} --secret-access-key ${COS_HMAC_CREDENTIALS_SECRET_ACCESS_ID}</pre><ul><li>Create the Code Engine persistent data store. Please see our documentation to learn more about “<a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-persistent-data-store">Working with persistent data stores</a>” in Code Engine</li></ul><pre>ibmcloud ce persistentdatastore create --name jupyter-labs-data-store --cos-bucket-name $COS_BUCKET_NAME --cos-access-secret cos-secret</pre><ul><li>Update the Jupyter Lab app and add persistent storage</li></ul><pre>ibmcloud ce app update --name jupyter-lab --image &quot;quay.io/jupyter/minimal-notebook:latest&quot; --scale-down-delay 600 --cpu 1 -memory 4G --mount-data-store /mnt/jupyter=jupyter-labs-data-store:work/ --mount-data-store /home/jovyan/.jupyter=jupyter-labs-data-store:config/ --command &quot;jupyter&quot; --command &quot;lab&quot; --command &quot;--ip&quot; --command &quot;*&quot; --command &quot;--NotebookApp.allow_origin&quot; -command &quot;*&quot; --command &quot;--notebook-dir&quot; --command &quot;/mnt/jupyter&quot; --max-scale 1 --service-account &quot;none&quot; --port 8888</pre><p>After the update got applied, you’ll notice that your Jupyter Lab forgot your password. Repeat these steps:</p><ul><li>ibmcloud ce application logs --application jupyter-lab</li><li>Copy the value of the token parameter printed in the log lines into your clipboard, e.g. b610… in the example<br> <a href="http://localhost:8888/lab?token=b610e8a24c5e581b61779f833d1c36931e1b9c346bc1211d">http://localhost:8888/lab?token=b610e8a24c5e581b61779f833d1c36931e1b9c346bc1211d</a></li></ul><p>This will obtain the temporary token from the logs to you clipboard and allow you to log in. To avoid this in the future, you can set your new, own password in that same screen.</p><p>Once you are logged in, click on e.g. the tile “Python2 (ipykernel)” under the “notebook section. This will your new, own notebook (which will be stored in the COS bucket).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPs5iatPlf6K9KnjgJcIVw.png" /></figure><p>To proof that your data is stored in the IBM Cloud Object Storage that we created as part of this blog post, let us take a look at the bucket and its objects. In the IBM Cloud console, navigate to <a href="https://cloud.ibm.com/objectstorage/instances">https://cloud.ibm.com/objectstorage/instances</a> and select your bucket. In the Objects tab, you’ll see that two base folders “config“ and “work“ have been created. After navigating into the “work“ folder, you should see something similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vPb_cp8Tlow2u0pPV7Z6IQ.png" /></figure><p>Now enforce a restart by applying an update ibmcloud ce app update --name jupyter-lab… even after various restarts you’ll notice that your notebook in the COS bucket is still around. 🎉</p><p>It’s time to recap what we have done so far. We deployed a JupyterLab environment, which is straightforward because Jupyter is largely agnostic to the underlying infrastructure as long as compute and a filesystem are available. On Code Engine, the filesystem is ephemeral by default, meaning it exists only for the lifetime of an instance and is not shared across instances. In Unix systems, the standard way to introduce persistent or remote storage is through <a href="https://en.wikipedia.org/wiki/Mount_(Unix)">mounting</a>, which lets an external filesystem appear as part of the local one. This is exactly what Code Engine provides when you define a mount‑data‑store option such as /home/jovyan/.jupyter=jupyter-labs-data-store:config/. In the next section, we break down this configuration to illustrate its capabilities.</p><ul><li>/home/jovyan/.jupyter — The first part, describes the mount point within the containers file system and defines where remote folders and files should appear</li><li>jupyter-labs-data-storejupyter-labs-data-store — The second part, relates to the name of the Code Engine persistent data store entity. As part of our blog post, we specified a COS bucket and the credentials (read and write) to access it.</li><li>config/— The last part, defines the prefix / location in the target COS bucket that should be mounted. If not set, Code Engine mounts the entire bucket.</li></ul><p>For COS mounts, Code Engine uses the open‑source tool <a href="https://github.com/s3fs-fuse/s3fs-fuse">s3fs</a>, which can mount S3‑compatible storage buckets as directories while preserving the underlying object format. This lets you interact with Object Storage through familiar shell commands — such as ls for listing or cp for copying — and also enables legacy applications that expect local filesystem access. However, s3fs does not provide the same performance or semantics as a native filesystem. For many workloads, such as JupyterLab, this is sufficient, but others may require stronger guarantees. To determine whether s3fs fits your needs, we recommend reviewing the limitations documented both in the <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-persistent-data-store&amp;interface=ui#pds-limitations">Code Engine documentation</a> and in the <a href="https://github.com/s3fs-fuse/s3fs-fuse?tab=readme-ov-file#limitations">s3fs project</a>.</p><p>This blog focused on using COS as a simple and effective persistence layer. Still, some scenarios require other storage types, such as file or block storage, which may better meet low‑latency or high‑concurrency needs. If your workload falls into that category, we invite you to get in touch with us so we can discuss the alternatives available.</p><h3>Conclusion and Outlook</h3><p>One limitation of this example is that the configuration file, including hashed user credentials, is stored in the COS bucket — something that would not pass a security review. To address this, we recommend integrating an external OIDC authentication mechanism. Details on how to do this are available in our blog post “<a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-3-d97de417fc2f">Advanced OIDC integrations with Code Engine</a>“.</p><p>Looking ahead, this scenario can be extended by including a pre‑packaged Code Engine SDK in the container image. Together with IBM Cloud trusted profiles, this would allow the notebook to call Code Engine APIs directly. As a result, you could run your data science workflows in JupyterLab while off‑loading compute‑intensive tasks — such as large‑scale data processing or PDF text extraction with tools like <a href="https://github.com/docling-project/docling">docling</a> — to Code Engine fleets. Wouldn’t that be nice? But that’s a topic for another blog article someday …</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12d279e046a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IBM Cloud Code Engine Authentication with OIDC — Part 3]]></title>
            <link>https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-3-d97de417fc2f?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/d97de417fc2f</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[ibm-cloud]]></category>
            <category><![CDATA[code-engine]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[oidc]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Thu, 04 Dec 2025 10:10:57 GMT</pubDate>
            <atom:updated>2025-12-04T10:10:57.325Z</atom:updated>
            <content:encoded><![CDATA[<h3>IBM Cloud Code Engine Authentication with OIDC — Part 3</h3><h3>Part 3: Advanced OIDC integrations with Code Engine</h3><p><strong>Written by</strong></p><p>Simon Daniel Moser (smoser@de.ibm.com)<br>Distinguished Engineer for Containers @ IBM Cloud</p><p>Enrico Regge (reggeenr@de.ibm.com)<br>Software Architect @ IBM Cloud</p><p>In the <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-2-f4940b41483a?postPublishedType=initial">second part</a> of this article series, we demonstrated how to secure access to a Code Engine application using an OAuth2 Proxy with GitHub as the external OIDC provider. In that setup, the OAuth2 Proxy served two main purposes: authenticating users and routing traffic to the origin application. In more advanced scenarios, however, it can be beneficial to separate these responsibilities — using one component for routing traffic and another for authentication and enforcing access policies. For example, if you have two applications (App A and App B) that both need protection, the previous approach would require deploying a separate OAuth2 Proxy in front of each app.</p><p>Wouldn’t it be simpler to have a single authentication component that validates users once and then routes them to App A or App B as appropriate? The good news is that this setup is possible without creating a custom routing solution. You can use a standard reverse proxy such as <strong>Nginx</strong> to handle routing, while an <strong>OAuth2 Proxy</strong> manages authentication to ensure that only authorized users reach the applications. Conceptually, this “OAuth2 Proxy” is similar to the one from <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-2-f4940b41483a">Part 2</a>, but it works alongside the reverse proxy instead of performing both roles. In Figure 1, the “Proxy app” represents the reverse proxy (e.g., Nginx), and the “OIDC app” represents the authentication service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*6mdj9Hub5NNVHfkwSCD_Kg.png" /></figure><p>Let’s look at how the request flow in this setup differs from the one in <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-2-f4940b41483a">Part 2</a>: Reverse proxies such as Nginx include a feature called <strong>authentication sub‑requests</strong>, provided by the <a href="https://nginx.org/en/docs/http/ngx_http_auth_request_module.html">auth_request module</a>. This mechanism allows the proxy to delegate authentication checks to a separate service — in our case, the OIDC app.</p><p>Here’s what happens step by step:</p><ol><li>A user sends a request to the reverse proxy app (for example, Nginx).</li></ol><p>2+3. The proxy makes a sub‑request (auth_request) to the authentication backend — the OIDC app, and redirects the the user request to the OIDC app.</p><p>4+5. The OIDC app verifies the user’s credentials or session by contacting the OIDC SSO provider to perform a login. If the OIDC app responds with an HTTP 2xx status code (meaning “success”), the authenticated request is redirected back to the oidc app.</p><p>6. OIDC app verifies authorization code and obtains user information with the OIDC SSO provider and, if successful, redirects the authenticated request back to the oidc app</p><p>7. Authenticated User request is redirected to the reverse proxy app, where the proxy makes a sub‑request (auth_request) to the authentication backend — the OIDC app, again.</p><p>8. If successful, Nginx forwards (proxy_pass) the original request to the protected application (Origin app).</p><p>Anywhere in the flow, if the response is anything else (such as 401 Unauthorized), Nginx blocks access or redirects the user to the login flow.</p><p>This setup clearly separates <strong>routing</strong> from <strong>authentication</strong>. The reverse proxy (for example, Nginx) focuses on directing traffic to the correct backend service, while the OIDC app handles user authentication and access control.</p><p>Using a dedicated reverse proxy also brings several practical benefits. For instance, the OAuth2 Proxy we used in <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-2-f4940b41483a">Part 2 </a>can struggle in scenarios where the backend application needs to establish WebSocket connections. A full-featured reverse proxy such as Nginx supports WebSockets natively, so this limitation no longer applies. By introducing Nginx as the routing layer, you gain greater flexibility and compatibility with a variety of backend communication patterns.</p><p>In the next section, we’ll put this capability to use by showing how to run an <strong>access-protected Jupyter Notebook</strong> on <strong>IBM Cloud Code Engine</strong>. This setup would not have been possible with the approach from <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-2-f4940b41483a">Part 2</a>, because Jupyter Notebooks rely heavily on dynamic WebSocket connections — something the OAuth2 Proxy could not handle at the time of writing.</p><h3>Setup and Configuration</h3><p>In this section, we will prepare the environment and required resources for running a more advanced sample with IBM Cloud Code Engine. The source code of this example has been published to the following repository <a href="https://github.com/IBM/CodeEngine/tree/main/auth-oidc-proxy">https://github.com/IBM/CodeEngine/tree/main/auth-oidc-proxy</a>:</p><p>1. Install and configure the IBM Cloud CLI</p><ul><li>Install the IBM Cloud CLI including the Code Engine plugin as described in the <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-cecli-getstart">Code Engine documentation</a></li><li>Perform all necessary login steps to IBM Cloud</li></ul><p>2. Create or select a Code Engine project</p><ul><li>Create or select the Code Engine project of your choice; e.g.</li></ul><pre>ibmcloud ce project create - name oidc-sample or <br>ibmcloud ce project select - name &lt;yourProjectName&gt;</pre><ul><li>Once the project had been created or selected, run the following commands to initialize environment variables in your current terminal session that are required later on:</li></ul><pre>CE_PROJECT=$(ibmcloud ce project current --output json)<br>CE_PROJECT_DOMAIN=$(echo &quot;$CE_PROJECT&quot; | jq -r &#39;.domain&#39;)<br>CE_PROJECT_NAMESPACE=$(echo &quot;$CE_PROJECT&quot; | jq -r &#39;.kube_config_context&#39;)<br>ROOT_DOMAIN=.${CE_PROJECT_NAMESPACE}.${CE_PROJECT_DOMAIN}<br>echo &quot;CE root domain: ${ROOT_DOMAIN}&quot;</pre><p>3. Deploy a <a href="https://jupyter.org/">JupyterLab</a>, which is a web-based interactive development environment for data science, scientific computing, and machine learning</p><pre>ibmcloud ce app create --name jupyter-lab \<br>    --image &quot;quay.io/jupyter/minimal-notebook:latest&quot; \<br>    --max-scale 1 \<br>    --scale-down-delay 600 \<br>    --command &quot;jupyter&quot; \<br>    --command &quot;lab&quot; \<br>    --command &quot;--ip&quot; \<br>    --command &quot;*&quot; \<br>    --command &quot;--NotebookApp.allow_origin&quot; \<br>    --command &quot;*&quot; \<br>    --command &quot;--NotebookApp.token&quot; \<br>    --command &quot;&#39;&#39;&quot; \<br>    --command &quot;--NotebookApp.password&quot; \<br>    --command &quot;&#39;&#39;&quot; \<br>    --service-account &quot;none&quot; \<br>    --port 8888 \<br>    --visibility project</pre><p>4. To provide necessary configuration information, we’ll eventually create a Code Engine secret that exposes relevant information to the application as environment variables. For now, let us use a temporary file located on your local workstation, called oidc-proxy.properties that contains the following content:</p><pre>OIDC_CLIENT_ID=&lt;see next steps&gt;<br>OIDC_CLIENT_SECRET=&lt;see next steps&gt;<br>COOKIE_ENCRYPTION_KEY=&lt;see next steps&gt;<br>AUTHZ_USER_PROPERTY=login<br>AUTHZ_ALLOWED_USERS=&lt;see next steps&gt;<br>OIDC_PROVIDER_AUTHORIZATION_ENDPOINT=https://github.com/login/oauth/authorize<br>OIDC_PROVIDER_TOKEN_ENDPOINT=https://github.com/login/oauth/access_token<br>OIDC_PROVIDER_USERINFO_ENDPOINT=https://api.github.com/user</pre><p><strong>OIDC_CLIENT_ID &amp; OIDC_CLIENT_SECRET</strong></p><p>Before registering a new GitHub OAuth app, we’ll need to determine the homepage and callback URLs of our application. In principal both URL pattern starts with: https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud</p><p>The &lt;app-name&gt; should correspond to the public facing name that you want to surface. Assuming, you’ll want to expose your app with the name jupyter-proxy, the run the following command in your local terminal to craft the base URL:</p><pre>echo &quot;https://jupyter-proxy${ROOT_DOMAIN}&quot;</pre><p>Register a new OAuth app in GitHub.com</p><ol><li>On github.com, navigate to Settings &gt; Developer Settings <a href="https://github.com/settings/applications/new">https://github.com/settings/applications/new</a></li><li>Provide an application name; e.g. my-jupyter-sample</li><li>Put in the jupyter-proxy app (that we will create in a moment) URL as Homepage URL; e.g. https://jupyter-proxy${ROOT_DOMAIN}/</li><li>As Authorization callback URL use the value of the URL of the jupyter-auth app (that we will create in a moment) and append the route /auth/callback/; e.g. <a href="https://jupyter-auth${ROOT_DOMAIN}">https://jupyter-auth${ROOT_DOMAIN}</a>/auth/callback</li><li>Complete this step by clicking “Register application“</li><li>On the next page, GitHub.com provides necessary meta information and credentials necessary to establish the trust relation with the application that initiates the OIDC flow</li><li>Copy the Client ID and paste into the oauth2-proxy.propertiesas value for the property OAUTH2_PROXY_CLIENT_ID</li><li>Click “Generate a new client secret“, to obtain a new client secret. Use the value as property OAUTH2_PROXY_CLIENT_SECRET</li></ol><p><strong>COOKIE_ENCRYPTION_KEY</strong></p><p>As the value for the property COOKIE_ENCRYPTION_KEY, we’ll generate an base64 encoded sequence of random bytes.</p><p>In order to make sure that the authentication flow will only be performed once per user session, the app will use a cookie that stores the authentication context. To protect those sensitive information from malicious actors, it is encrypted using symmetric encryption method and by applying AES 256 CBC as encryption algorithm that utilizes the provided key. If you have the openssl tool installed on your machine, the following command can be used to generate and encryption key from your terminal window:</p><pre>openssl rand -base64 32</pre><p><strong>AUTHZ_USER_PROPERTY &amp; AUTHZ_ALLOWED_USERS</strong></p><p>So far, we only explored authentication capabilities, which make sure that only authenticated users can access your workload. With this example, we’ll also tap into authorization capabilities, which allows to authorize authenticated user based on profile attributes (e.g. login name, email address, groups). A typical real world scenario would protect your app by only allowing users that are able to enterprise OIDC SSO challenge (=authentication) AND who are member of a certain group within the enterprise directory service (=authorization).</p><p>For our example we’ll apply a configuration that will only allow a single user to access the app, by specifying AUTHZ_USER_PROPERTY=login and AUTHZ_ALLOWED_USERS=&lt;your-github-com-login-name&gt;. For a full list of available user properties, see the <a href="https://docs.github.com/en/rest/users/users#get-the-authenticated-user">GitHub.com REST API documentation</a>.</p><p>5. Now, that we have all configuration values at hand, let us create the Code Engine secret, that will make sure to pass them along to the deployed app.</p><pre>ibmcloud ce secret create -name oidc-proxy-credentials -from-env-file oidc-proxy.properties</pre><p>6. Next, we’ll deploy the authentication and authorization app that will be called on each incoming request to verify whether the caller is authenticated and authorized</p><pre>ibmcloud ce app create --name jupyter-auth \<br>        --image &quot;icr.io/codeengine/auth-oidc-proxy/auth&quot; \<br>        --max-scale 1 \<br>        --cpu 0.125 \<br>        --memory 0.25G \<br>        --scale-down-delay 600 \<br>        --port 8080 \<br>        --env-from-secret oidc-proxy-credentials \<br>        --env COOKIE_DOMAIN=&quot;$ROOT_DOMAIN&quot; \<br>        --env REDIRECT_URL=&quot;https://jupyter-proxy${ROOT_DOMAIN}&quot; \<br>        --env OIDC_REDIRECT_URL=&quot;https://jupyter-auth${ROOT_DOMAIN}/auth/callback&quot;</pre><p>Lastly, we’ll deploy the proxy application that is in charge to check authorization</p><pre>ibmcloud ce app create --name jupyter-proxy \<br>        --image &quot;icr.io/codeengine/auth-oidc-proxy/nginx&quot; \<br>        --max-scale 1 \<br>        --cpu 0.5 \<br>        --memory 1G \<br>        --scale-down-delay 600 \<br>        --env ORIGIN_APP_FQDN=&quot;jupyter-proxy${ROOT_DOMAIN}&quot; \<br>        --env ORIGIN_APP_NAME=jupyter-lab \<br>        --env AUTH_APP_NAME=jupyter-auth \<br>        --port 8080</pre><p>Now, that we do have everything in place, let us call the jupyter-proxy app by opening a browser and calling the proxy app endpoint. Once the login procedure has been passed, you’ll be greeted with the JupyterLab dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w4oKKOH57Ic3RGPGK4rB5Q.png" /></figure><p>And yes, you are now able to run a remote JupyterLab allowing you to create und execute notebooks on IBM Cloud Code Engine 🙂</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IuU0qKZrq7QRVgjQnM04FQ.png" /></figure><p>Next, let’s do a deep dive into one key aspects of the implementation and take a closer look at the nginx proxy that makes sure that you JupyterLab is protected properly. The following code snippet depicts the nginx configuration. In the root route “/”, each request will be handled by first sending a subrequest to the /auth route.</p><ul><li>If that subrequest is causing a 401 response, the user will be directed to the login endpoint.</li><li>If that subrequest succeeds, the request will be forwarded to the origin app, the jupyter-lab.</li></ul><p>Pay attention to the proxy_set_header statements that set the Upgrade and Connection headers, which make sure that Websocket support is being enabled, a feature being heavily used by the JupyterLab.</p><p>Also, notice that requests to both backend apps are being realised through project internal URLs (svc.cluster.local).</p><pre>server {<br><br>    listen 8080;<br>    server_name ${ORIGIN_APP_FQDN};<br>    root         /opt/app-root/src;<br><br>    location / {        <br>        auth_request /auth;<br>        error_page 401 = /auth/login;<br>        <br>        proxy_pass http://${ORIGIN_APP_NAME}.${CE_SUBDOMAIN}.svc.cluster.local;<br>        proxy_set_header Host ${ORIGIN_APP_NAME}.${CE_SUBDOMAIN}.svc.cluster.local;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Auth-Request-Redirect $request_uri;<br>        proxy_pass_request_headers      on;<br>        <br>        # WebSocket support<br>        proxy_http_version 1.1;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header Connection $connection_upgrade;<br>        proxy_read_timeout 86400;<br>    }<br><br>    location /auth {<br>        proxy_pass http://${AUTH_APP_NAME}.${CE_SUBDOMAIN}.svc.cluster.local;<br>        proxy_set_header Host ${AUTH_APP_NAME}.${CE_SUBDOMAIN}.svc.cluster.local;<br>        proxy_pass_request_body off;<br>        proxy_set_header        Content-Length &quot;&quot;;<br>        proxy_set_header        X-Original-URI $request_uri;<br>        proxy_pass_request_headers      on;<br>        <br>        proxy_http_version 1.1;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header Connection $connection_upgrade;<br>        proxy_read_timeout 86400;<br>    }<br>}</pre><p>In this example, we are just focusing on the Nginx configuration. The mechanics of the OIDC app setup is similar to the setup described in <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-f098c819a32b">Part 1</a> of this blog post series. The full source code of the auth app is available here: <a href="https://github.com/IBM/CodeEngine/tree/main/auth-oidc-proxy/auth">https://github.com/IBM/CodeEngine/tree/main/auth-oidc-proxy/auth</a></p><h3>Summary and Conclusion</h3><p>For the blog series <strong>OIDC with IBM Cloud Code Engine, </strong>here’s a quick recap of what you’ve learned:</p><ul><li><a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-f098c819a32b"><strong>Part 1</strong></a><strong>:</strong> We demonstrated a do‑it‑yourself approach to securing access to a Code Engine application using OIDC with GitHub identities. You learned how to redirect users to an identity provider, obtain an ID token, and establish a session.</li><li><a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-2-f4940b41483a"><strong>Part 2</strong></a><strong>:</strong> We explored a simpler, no‑code method for protecting your application — using an <strong>OAuth2 Proxy</strong> with GitHub as the external OIDC provider.</li><li><strong>Part 3:</strong> We applied these concepts to a real‑world example that uses <strong>WebSockets and Jupyter Notebooks</strong>, showing why separating routing from authentication is beneficial in advanced scenarios. We also discussed how to define more fine‑grained permissions, such as user‑ or group‑specific authorization.</li></ul><p>With that, we conclude our series. However, given Jupyter notebooks are very very popular in the Data Science Community, but a JupyterLab is only worth half without persistent storage, as you will notice that your notebooks are going to be deleted as soon the app instance scales down. We’ll be releasing another blog post soon that talks about how a new Code Engine feature makes it easy to use persistent storage and so preserves your Jupyter notebooks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d97de417fc2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IBM Cloud Code Engine Authentication with OIDC — Part 2]]></title>
            <link>https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-2-f4940b41483a?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4940b41483a</guid>
            <category><![CDATA[code-engine]]></category>
            <category><![CDATA[ibm-cloud]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[oidc]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Tue, 02 Dec 2025 09:04:55 GMT</pubDate>
            <atom:updated>2025-12-04T10:15:40.572Z</atom:updated>
            <content:encoded><![CDATA[<h3>IBM Cloud Code Engine Authentication with OIDC — Part 2</h3><h3>Part 2: Utilize an OIDC proxy to protect your Code Engine Apps</h3><p><strong>Written by</strong></p><p>Simon Daniel Moser (smoser@de.ibm.com)<br>Distinguished Engineer for Containers @ IBM Cloud</p><p>Enrico Regge (reggeenr@de.ibm.com)<br>Software Architect @ IBM Cloud</p><p>In the<a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-f098c819a32b"> first part </a>of this article series, we demonstrated how to secure access to a Code Engine application using OIDC with an external identity provider. As you may recall, this approach required modifications to the application’s source code. However, in many scenarios you may not have that flexibility — updating the application code is not always feasible or even possible.</p><p>In such cases, OIDC supports another integration pattern: placing a reverse proxy in front of your application. The proxy handles authentication and ensures that only requests from legitimate callers reach your application. This architecture provides an additional security advantage as well: only the reverse proxy is exposed to the internet, while your application runs behind it on a private network.</p><p>As you might expect, the reverse OAuth proxy is the key component in this approach. Because implementing such a proxy from scratch is non-trivial, our example uses the battle-tested, open-source OAuth2 Proxy available at the project’s website <a href="https://oauth2-proxy.github.io/oauth2-proxy/">https://oauth2-proxy.github.io/oauth2-proxy/</a>. We recommend considering the same solution if you plan to secure your own application using this integration pattern.</p><p>Figure 1 below illustrates the component setup and authentication flow:</p><ol><li><strong>Initial Request</strong><br>The flow begins when a user accesses your application’s URL without presenting any authentication token (for example, a header, cookie, or session identifier). The application’s public URL is served by the OAuth proxy that sits in front of it.</li><li><strong>Redirect to OIDC Provider</strong><br>Detecting the absence of valid authentication, the proxy immediately redirects the user to the configured OIDC provider to initiate the login process.</li><li><strong>User Authentication</strong><br>The user then authenticates with the OIDC provider. Once authentication succeeds, the provider redirects the user back to the proxy, this time including the required authorization code or token.</li><li><strong>Token Verification</strong><br>The proxy validates the authorization code or token and retrieves the user information from the OIDC provider.</li><li><strong>Forwarding to the Application</strong><br>If verification is successful, the proxy forwards the request to your application. This communication occurs over the private network, ensuring that only authenticated traffic reaches the application.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*NncVVt7Uymdn5SeeZRjzsA.png" /></figure><h3>Setup and Configuration</h3><p>In this section, we will prepare the environment and required resources for running the sample application with IBM Cloud Code Engine:</p><p>1. Install and configure the IBM Cloud CLI</p><ul><li>Install the IBM Cloud CLI including the Code Engine plugin as described in the <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-cecli-getstart">Code Engine documentation</a>,</li><li>Perform all necessary login steps to IBM Cloud</li></ul><p>2. Create or select a Code Engine project</p><ul><li>Create or select the Code Engine project of your choice; e.g. ibmcloud ce project create — name oidc-sample or ibmcloud ce project select — name &lt;yourProjectName&gt;</li></ul><p>3. Deploy a sample application</p><ul><li>Deploy a simple “Hello World” application provided in the Code Engine samples under <a href="https://github.com/IBM/CodeEngine/tree/main/hello">https://github.com/IBM/CodeEngine/tree/main/hello</a></li></ul><pre>ibmcloud ce app create -name origin-app -image icr.io/codeengine/hello -visibility project</pre><p>Please note: This app is configured with the visibility “project”. Hence, it does not expose a public endpoint to the internet and is only reachable from other components deployed in the same Code Engine project. To make this internal URL known to the oauth2-proxy app, we’ll store its value in an environment variable in your terminal session.</p><pre>ORIGIN_APP_URL=$(ibmcloud ce app get -n origin-app - output project-url)</pre><p>4. Prepare configuration for oauth2-proxy</p><ul><li>To provide necessary configuration information, we’ll eventually create a Code Engine secret that exposes relevant information to the application as environment variables. For now, create a temporary file located on your local workstation called “oauth2-proxy.properties“ that contains the following content:</li></ul><pre>OAUTH2_PROXY_COOKIE_SECRET=&lt;see-next-steps&gt;<br>OAUTH2_PROXY_CLIENT_ID=&lt;see-next-steps&gt;<br>OAUTH2_PROXY_CLIENT_SECRET=&lt;see-next-steps&gt;<br>OAUTH2_PROXY_PROVIDER=github<br>OAUTH2_PROXY_EMAIL_DOMAINS=*</pre><p>As the value for the property OAUTH2_PROXY_COOKIE_SECRET, we’ll generate an base64 encoded sequence which is used as a seed string for secure cookies (see <a href="https://oauth2-proxy.github.io/oauth2-proxy/configuration/overview#cookie-options">seed string for secure cookies</a> for further details). The value must either comprise of 16, 24, or 32 bytes to create an AES cipher. The following command can be used to generate and encryption key from your terminal window:</p><pre>dd if=/dev/urandom bs=32 count=1 2&gt;/dev/null | base64 | tr -d - &#39;\n&#39; | tr - &#39;+/&#39; &#39;-_&#39; ; echo</pre><p><strong>OIDC_CLIENT_ID &amp; OIDC_CLIENT_SECRET</strong></p><p>Before registering a new GitHub OAuth app, we’ll need to determine the homepage and callback URLs of our application. In principal both URL pattern starts with: “<a href="https://&lt;oauth2-proxy-app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud/oauth2/callback”.">https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud”.</a></p><p>The &lt;app-name&gt; should correspond to the public facing name that you want to surface. Assuming, you’ll want to expose your app with the name “my-app“, the run the following command in your local terminal to craft the base URL:</p><pre>echo &quot;https://my-app.$(ibmcloud ce project current - o json|jq -r .kube_config_context).$(ibmcloud ce project current - o json|jq -r .region_id).codeengine.appdomain.cloud&quot;</pre><p>Register a new OAuth app in GitHub.com</p><ol><li>On github.com, navigate to Settings &gt; Developer Settings <a href="https://github.com/settings/applications/new">https://github.com/settings/applications/new</a></li><li>Provide an application name; e.g. “my-oauth2-proxy-sample”</li><li>Put in the application URL as Homepage URL; e.g. “<a href="https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud/”">https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud/”</a></li><li>As “Authorization callback URL”, use the value of the Homepage URL and append the route “/oauth2/callback“; e.g. “<a href="https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud/”">https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud/oauth2/callback”</a></li><li>Complete this step by clicking “Register application“</li><li>On the next page, GitHub.com provides necessary meta information and credentials necessary to establish the trust relation with the application that initiates the OIDC flow<br>a) Copy the Client ID and paste into the “oauth2-proxy.properties“ as value for the property OAUTH2_PROXY_CLIENT_ID<br>b) Click “Generate a new client secret“, to obtain a new client secret. Use the value as property OAUTH2_PROXY_COOKIE_SECRET</li></ol><p>Now that we have all configuration values at hand, let us create the Code Engine secret:</p><pre>ibmcloud ce secret create -name oauth2-proxy-credentials -from-env-file oauth2-proxy.properties</pre><p>Finally, we’ll create OAuth2 Proxy app and attach the secret that contains the GitHub OAuth credentials</p><pre>ibmcloud ce app create -name my-app \<br> -image quay.io/oauth2-proxy/oauth2-proxy:latest-amd64 \<br> -port 4180 \<br> -memory 0.5G \<br> -cpu 0.25 \<br> -env-from-secret oauth2-proxy-credentials \<br> -env OAUTH2_PROXY_REVERSE_PROXY=true \<br> -env OAUTH2_PROXY_UPSTREAMS=$ORIGIN_APP_URL \<br> -env OAUTH2_PROXY_SKIP_PROVIDER_BUTTON=true \<br> -env OAUTH2_PROXY_SSL_UPSTREAM_INSECURE_SKIP_VERIFY=true \<br> -env OAUTH2_PROXY_PASS_HOST_HEADER=false \<br> -env OAUTH2_PROXY_PROXY_WEBSOCKETS=true \<br> -scale-down-delay 300</pre><p>Once the application has been deployed, open the browser and enter the public URL of the app.</p><p>You’ll be redirected to GitHub.com, once you’ve passed the authentication you’ll be asked you to authorize the OAuth app “my-oauth2-proxy-sample”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*YOmcxHeVC4W307ssMIK3Iw.png" /></figure><p>Once, that is done, you’ll see a rendered page within the content rendered by the origin application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*L4Bx9r9cAstsFLS1fgd4RQ.png" /></figure><p>Precisely, the OAuth2 Proxy does not only take care of authentication and authorization, but also forwards useful information to the origin app, such as the username of the authenticated user. To explore the available headers, we’ll make use of the debug endpoint provided by Code Engine hello app. As you can see the X-Forwarded-Email, X-Forwarded-User corresponds to the GitHub user that had been authenticated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLYXIb8Ijyx1F7RakUQ8Hg.png" /></figure><h3>Summary and Outlook</h3><p>In this article, we demonstrated a second method for securing access to your Code Engine application: using an OAuth2 Proxy with GitHub as the external OIDC provider. There are, however, many ways to further strengthen and extend this setup. We recommend exploring the full range of configuration options available in OAuth2 Proxy, documented here: <a href="https://oauth2-proxy.github.io/oauth2-proxy/configuration/overview">https://oauth2-proxy.github.io/oauth2-proxy/configuration/overview</a>.</p><p>For example, you may prefer not to use GitHub as your OIDC/OAuth2 provider. OAuth2 Proxy supports a wide variety of alternative identity providers — including Google, Apple, and many others — which you can review here: <a href="https://oauth2-proxy.github.io/oauth2-proxy/configuration/providers/">https://oauth2-proxy.github.io/oauth2-proxy/configuration/providers/</a>.</p><p>Finally, in <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-3-d97de417fc2f"><strong>Part 3</strong></a> of this series, we’ll show even more advanced scenarios — we’ll be looking at a more real world application that e.g. utilises web sockets — something that the OAuth2 Proxy might be struggling with</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4940b41483a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IBM Cloud Code Engine Authentication with OIDC]]></title>
            <link>https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-f098c819a32b?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/f098c819a32b</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[ibm-cloud]]></category>
            <category><![CDATA[oidc]]></category>
            <category><![CDATA[code-engine]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Mon, 01 Dec 2025 20:17:22 GMT</pubDate>
            <atom:updated>2025-12-04T10:16:00.701Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 1: Add OIDC Authentication To Your Code Engine App</h3><p><strong>Written by</strong></p><p>Simon Daniel Moser (smoser@de.ibm.com)<br>Distinguished Engineer for Containers @ IBM Cloud</p><p>Enrico Regge (reggeenr@de.ibm.com)<br>Software Architect @ IBM Cloud</p><p>Anyone who has used IBM Cloud Code Engine knows that, by default, any deployed application or function becomes accessible through a public, internet-facing URL — unless you explicitly configure private endpoints. While this design supports the platform’s goal of providing a quick and seamless deployment experience, many users eventually need to restrict access and introduce a login mechanism to their applications.</p><p>A common and standardized approach for securing access is <strong>OpenID Connect (OIDC)</strong>. OIDC is an authentication layer built on top of OAuth 2.0 that enables applications to verify a user’s identity by exchanging standardized tokens, primarily the ID token (a signed JSON Web Token).</p><p>This article is the first in a series of blogposts, where we will eventually demonstrate several patterns to add authentication mechanisms to protect your workload. In Part 1, we’ll walk you through how to extend your application’s source code on Code Engine to integrate with an OIDC provider. For our examples, we’ll use GitHub as the OIDC provider. By the end of the tutorial, you’ll be able to protect your application and allow users to log in using their existing GitHub identity.</p><p>A detailed description of the OIDC authentication flow can be found at <a href="https://openid.net/specs/openid-connect-core-1_0.html#Overview">https://openid.net/specs/openid-connect-core-1_0.html#Overview</a>. For the remainder of this article, we assume you already have a basic understanding of that flow. Figure 1 illustrates the first integration pattern — one you’ve likely encountered many times when logging into a website using e.g. your Google, Apple or Facebook account instead of creating a dedicated login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*O9ux3uOa82Zqqh2CU_SaFQ.png" /></figure><ol><li>The flow begins when a user accesses your application’s URL without presenting any authentication token (such as a header, cookie, or session identifier).</li><li>Your application detects the absence of valid authentication and immediately redirects the user to the configured OIDC provider.</li><li>At this point, the user logs in with the OIDC provider. Once authentication is successful, the provider redirects the user back to your application’s original URL, this time including the necessary authorization code or token required to complete the login.</li></ol><p>Although there are additional technical steps involved behind the scenes, the figure and description above provide a high-level overview of the process. To put this into practice, we’ll walk you through a step-by-step example showing how to protect your application using this approach. As a first step, we’ll deploy the sample application on Code Engine using the IBM Cloud CLI, which we’ll rely on throughout this blog post to perform all relevant operations.</p><h3>Setup and Configuration</h3><p>In this section we will setup the example.</p><ol><li>As described in the <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-cecli-getstart">Code Engine documentation</a><br>a) Install the IBM Cloud CLI including the Code Engine plugin <br>b) Perform all necessary login steps to IBM Cloud<br>c) Create or select the Code Engine project of your choice; e.g.</li></ol><pre>ibmcloud ce project create -name oidc-sample OR <br>ibmcloud ce project select -name &lt;yourProjectName&gt;</pre><p>2. Create an application by pointing it to the sample source code provided in <a href="https://github.com/IBM/CodeEngine">https://github.com/IBM/CodeEngine</a></p><pre>ibmcloud ce app create -name my-oidc-sample -src https://github.com/IBM/CodeEngine -build-context-dir auth-oidc/node</pre><p>3. Open the application URL by copying the URL rendered in the command line output. The authentication error shown in the screenshot below is expected, as we did not take care of any configuration, yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*Gku2pXh0uBZwaZl1e-AIug.png" /></figure><p>To provide necessary configuration information, we’ll eventually create a Code Engine secret that exposes relevant information to the application as environment variables.</p><p>For now, let us use a temporary file located on your local workstation, called oidc.properties that contains the following content:</p><pre>COOKIE_ENCRYPTION_KEY=&lt;see-next-steps&gt;<br><br>OIDC_REDIRECT_URL=&lt;see-next-steps&gt;<br><br>OIDC_CLIENT_ID=&lt;see-next-steps&gt;<br><br>OIDC_CLIENT_SECRET=&lt;see-next-steps&gt;<br><br>OIDC_PROVIDER_AUTHORIZATION_ENDPOINT=https://github.com/login/oauth/authorize<br><br>OIDC_PROVIDER_TOKEN_ENDPOINT=https://github.com/login/oauth/access_token<br><br>OIDC_PROVIDER_USERINFO_ENDPOINT=https://api.github.com/user</pre><p><strong>COOKIE_ENCRYPTION_KEY</strong></p><p>As the value for the property COOKIE_ENCRYPTION_KEY, we’ll generate an base64 encoded sequence of random bytes.</p><p>In order to make sure that the authentication flow will only be performed once per user session, the app will use a cookie that stores the authentication context. To protect those sensitive information from malicious actors, it is encrypted using symmetric encryption method and by applying AES 256 CBC as encryption algorithm that utilizes the provided key. If you have the openssl tool installed on your machine, the following command can be used to generate and encryption key from your terminal window:</p><pre>openssl rand -base64 32</pre><p><strong>OIDC_REDIRECT_URL</strong></p><p>As a value for the property OIDC_REDIRECT_URL property, we’ll point to the fully-qualified domain name (FQDN) of the endpoint “/auth/callback“. The URL pattern looks as follows: https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud/auth/callback.To obtain the public endpoint of the app using the CLI, you can use the following command:</p><pre>ibmcloud ce app get -name my-oidc-sample -output url</pre><p>The OIDC_REDIRECT_URL value that corresponds to the public URL of the app that we just deployed is https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud/auth/callback</p><p><strong>OIDC_CLIENT_ID &amp; OIDC_CLIENT_SECRET</strong></p><p>Register a new OAuth app in GitHub.com</p><ol><li>On github.com, navigate to Settings &gt; Developer Settings <a href="https://github.com/settings/applications/new">https://github.com/settings/applications/new</a></li><li>Provide an application name; e.g. “my-oidc-sample”</li><li>Put in the application URL as Homepage URL; e.g. https://&lt;app-name&gt;.&lt;proj-namespace&gt;.&lt;code-engine-region&gt;.codeengine.appdomain.cloud</li><li>As “Authorization callback URL”, use the value of the OIDC_REDIRECT_URL</li><li>Complete this step by clicking “Register application“</li><li>On the next page, GitHub.com provides necessary meta information and credentials necessary to establish the trust relation with the application that initiates the OIDC flow<br>a) Copy the Client ID and paste into the “oidc.properties“ as value for the property OIDC_CLIENT_ID<br>b) Click “Generate a new client secret“, to obtain a new client secret. Use the value as property OIDC_CLIENT_SECRET</li></ol><p>Now that we have all configuration values at hand, let us create the Code Engine secret, that will make sure to pass them along to the deployed app.</p><pre>ibmcloud ce secret create -name oidc-credentials -from-env-file oidc.properties</pre><p>Lastly, we’ll attach the secret to the application</p><pre>ibmcloud ce app update -name my-oidc-sample -env-from-secret oidc-credentials</pre><p>Once the application has been updated, open the browser and enter the public URL of the app. You’ll be redirected to GitHub.com, once you’ve passed the authentication you’ll be asked you to authorize the OAuth app my-iodc-sample</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWg-rWcfktkvg_yYhurwag.png" /></figure><p>Once, that is done, you’ll see a rendered page within the application that provides user context information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PL_oN0B1ZwXQDDCFlE9G7A.png" /></figure><p>Congratulations, that’s it 🎉</p><p>Next, let’s do a deep dive into some key aspects of the implementation and take a look into the actual source code to understand what needs to be in place to enable your workload for OIDC. In this section, we’ll highlight key elements of the source code. The entire example can be found here: <a href="https://github.com/IBM/CodeEngine/tree/main/auth-oidc">https://github.com/IBM/CodeEngine/tree/main/auth-oidc</a></p><p><strong>Routing</strong></p><p>The sample app is mainly based on <a href="https://www.npmjs.com/package/express">express</a>, a minimalist web framework for Node.js.</p><pre>import express from &quot;express&quot;;<br>…<br>const app = express();<br>…<br>// use router to bundle all routes to /<br>const router = express.Router();<br>app.use(&quot;/&quot;, router);<br>…<br>router.get(&quot;/&quot;, checkAuth, (req, res) =&gt; {<br>// handle the incoming request<br>});</pre><p>The source code above defines a router that handles all incoming traffic. Noteworthy in this snippet is a function called checkAuth, which intercepts each incoming request and checks whether the caller is authenticated. Following code shows the implementation of this function:</p><pre>async function checkAuth(req, res, next) {<br><br>  const encryptedSessionToken = req.cookies[SESSION_COOKIE];<br><br>  if (!encryptedSessionToken) {<br><br>    return res.redirect(&quot;/auth/login&quot;);<br><br>  }<br><br>  let sessionToken = // decrypt session token<br><br>  <br><br>  // use sessionToken as authentication towards the OIDC provider  const opts = {<br><br>    method: &quot;GET&quot;,<br><br>    headers: { Authorization: `Bearer ${sessionToken}`, },<br><br>   };<br><br>  // retrieve user information<br><br>  const response = await fetch(process.env.OIDC_PROVIDER_USERINFO_ENDPOINT, opts);<br><br>  if (!response.ok) {<br><br>    return res.redirect(&quot;/auth/failed&quot;);<br><br> }<br><br> // consider to cache user information, to avoid that the user call is being done on each individual request<br><br> // setting user into the request context<br><br> req.user = await response.json();<br><br> next();<br><br>}</pre><p>The authentication check starts with reading all cookies. If the cookie that contains the session token is not present, the code assumes the user is NOT logged in. In consequence, the user will be redirected to the login flow. In case the user is authenticated already, the code will decrypt the cookie value. With that value, an authentication check to the OIDC provider (GitHub in our example) is initiated to obtain user information. If the call succeeds, the request handling mechanism assumes that the user is authenticated properly. Before passing the request to the next handler, the user information is being stored in the request to enable any request handler to access user properties.</p><p>Once the login flow got initiated, the corresponding route handler will redirect the request to the authorization endpoint of the OIDC provider, as shown in the code snippet below</p><pre>router.get(&quot;/auth/login&quot;, (req, res) =&gt; {<br><br>  // redirect to the configured OIDC provider<br><br>  res.redirect(`${process.env.OIDC_PROVIDER_AUTHORIZATION_ENDPOINT}?client_id=${process.env.OIDC_CLIENT_ID}&amp;redirect_uri=${encodeURIComponent(process.env.OIDC_REDIRECT_URL)}&amp;response_type=code&amp;scope=openid+profile&amp;state=state`);<br><br>});</pre><p>The authorization request is specified in the OpenID Connect specification (see: <a href="https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest">https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest</a>). In a nutshell, the following parameters are most important:</p><ul><li>client_id — The client identifier granted by the Authorization server</li><li>scope: Specifies the requested access privileges, including openid to indicate an OIDC request, and potentially other scopes like profile, email, address, or phone to request specific user claims</li><li>redirect_uri— The URI to which the Authorization Server will redirect the user after authorization</li></ul><p>The route that handles the authorization callback request initiated by the authorization server is the last critical building block. The code snippet below shows the most important aspects:</p><pre>router.get(&quot;/auth/callback&quot;, async (req, res) =&gt; {<br><br>  const data = {<br><br>    code: req.query.code,<br><br>    redirect_uri: process.env.OIDC_REDIRECT_URL,<br><br>    grant_type: &quot;authorization_code&quot;,<br><br> };<br><br> // exchange authorization code for access token &amp; id_token<br><br> const response = await fetch(`${process.env.OIDC_PROVIDER_TOKEN_ENDPOINT}?${new URLSearchParams(data).toString()}`, {<br><br>   method: &quot;POST&quot;,<br><br>   headers: {<br><br>     &quot;Content-Type&quot;: &quot;application/x-www-form-urlencoded&quot;,<br><br>     Accept: &quot;application/json&quot;,<br><br>     Authorization: &quot;Basic &quot; + Buffer.from(process.env.OIDC_CLIENT_ID + &quot;:&quot; + process.env.OIDC_CLIENT_SECRET).toString(&quot;base64&quot;),<br><br>   },<br><br> });<br><br> if (!response.ok) {<br><br>   return res.redirect(&quot;/auth/failed&quot;);<br><br> }<br><br>  const accessTokenData = await response.json();<br><br>  // encrypt the access token<br><br>  const sessionCookieValue = encrypt(accessTokenData.access_token, ENCRYPTION_KEY, ENCRYPTION_IV);<br><br>  const maxAge = accessTokenData.expires_in ? 1000 * accessTokenData.expires_in : 600_000; // defaults to 10min<br><br>    // store the encrypted access token in a cookie<br><br>  res.cookie(SESSION_COOKIE, sessionCookieValue, {<br><br>    maxAge, httpOnly: true, path: &quot;/&quot;, secure: true,<br><br>  });<br><br>  return res.redirect(&quot;/&quot;);<br><br>});</pre><p>As part of the authorization callback, the OIDC Server provides an authorization code, a short-living credential that will be used to obtain an access token. Once the access token had been obtained it will encrypted and stored in a cookie. The lifetime of the cookie should adhere to the time-to-life of the authorization token.</p><h3>Summary / Outlook</h3><p>In this article, we demonstrated one approach to securing access to your Code Engine application using OIDC with GitHub identities. The flow follows the fundamentals of OpenID Connect: redirect the user to an identity provider, obtain an ID token, and establish a session.</p><p>Of course, there are many ways to strengthen and expand this solution. Leveraging just the OIDC technology, you can add more security, scalability, and flexibility. For a comprehensive overview of advanced OIDC concepts and best practices, see this excellent guide: <a href="https://medium.com/@udarasenarath875/openid-connect-advanced-concepts-and-best-practices-f2ee5dde2c65"><em>openid-connect-advanced-concepts-and-best-practices-f2ee5dde2c65</em></a>.</p><p>In <a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-2-f4940b41483a"><strong>Part 2</strong> </a>of this blog series, we’ll explore additional OIDC integration patterns and demonstrate how to use an OIDC proxy to protect your Code Engine applications — providing encrypted, battle-tested, community-governed authentication without requiring any changes to your source code.</p><p>Security, however, doesn’t end with authentication. Especially in enterprise environments, you’ll often complement identity-based protections with additional layers such as rate limiting, Web Application Firewall (WAF) rules, IP allowlists, and other firewall capabilities. If you’d like to explore how these controls can be implemented in Code Engine, take a look at this deep-dive: <a href="https://community.ibm.com/community/user/blogs/enrico-regge/2024/12/01/protect-code-engine-workload-with-cis-ip-firewall.">https://community.ibm.com/community/user/blogs/enrico-regge/2024/12/01/protect-code-engine-workload-with-cis-ip-firewall.</a></p><p>Finally, in<a href="https://medium.com/@sdmoser/ibm-cloud-code-engine-authentication-with-oidc-part-3-d97de417fc2f"> <strong>Part 3</strong></a> of this series, we’ll show how to extend OIDC beyond authentication into fine-grained authorization — allowing you to restrict specific parts of your application to users with defined roles or privileges.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f098c819a32b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The history and future of serverless containers — illustrated with IBM Cloud Code Engine]]></title>
            <link>https://medium.com/@sdmoser/the-history-and-future-of-serverless-containers-illustrated-with-ibm-cloud-code-engine-b4233bb42eff?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4233bb42eff</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[batch-processing]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[ibm-cloud]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Wed, 24 Jul 2024 20:06:24 GMT</pubDate>
            <atom:updated>2024-07-24T20:06:24.829Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>The history and future of s</strong>erverless containers —<strong> illustrated with IBM Cloud Code Engine</strong></h3><p><strong>From PaaS and Serverless to a generic Compute Platform. And Why.</strong></p><p>Remember 2016 ? Yes, that was long before the pandemic, and LLMs were not on the radar of many yet. What was on the radar instead were “serverless functions”, and those things were presented, as <a href="https://matduggan.com/serverless-functions-post-mortem/">Matt Dugan</a> puts it, “as the undeniable future of infrastructure” [1] in the tech industry. And indeed, every major cloud provider came out with his derivate of a function service — AWS Lambda, Google Cloud Functions, IBM Open Whisk, Microsoft Functions and so on and so forth.</p><p>To recap what serverless computing is, let’s look at the Wikipedia <a href="https://en.wikipedia.org/wiki/Serverless_computing">definition</a>: “Serverless computing is a cloud computing execution model in which the cloud provider allocates machine resources on demand, taking care of the servers on behalf of their customers” [2]. When, back in the day, I would have taken that definition and would have matched it against the service catalog of IBM Cloud, I would have gotten two matches: IBM Cloud Functions and IBM Cloud Foundry. Looking at them from higher up, they had quite some similarities — a developer pushed some code, somehow that code magically morphed into a container and that container was executed. Looking closer there were differences, of course — the scaling model, the pricing, the way how the container came into existence — but essentially, someone wanted to run some code, as a container, in a serverless way. As a senior technical leader for IBM Cloud, the question to ask was: Why do we build and maintain more than one service for that ?</p><p>Some time later, AI training scenarios became more present in the minds of people, product management came around and asked for a “serverless batch job as a service” capability. And that requirement made sense, because neither the characteristics of functions (short-running and memory constraint) nor of applications (long-running, http/s serving) were really a good fit for batch jobs which were potentially longer running, had high cpu and memory demands and are usually not http/s serving.</p><p>Table 1 summarises the various characteristics:</p><pre>|             | Duration | CPU demand  | Mem demand  | http | Capacity |<br>|-------------|----------|-------------|-------------|------|----------|<br>| Application | long     | medium/high | medium/high | Y    |          |<br>| Function    | short    | low         | low         | Y    |          |<br>| trad. Batch | long     | medium/high | medium/high | N    | medium   |<br>| LLM batch   | long     | high        | high        | N    | high     |<br>| HPC batch   | long     | high        | high        | N    | massive  |</pre><p>So in the minds of product management the conclusion was clear: Great, let’s build and operate a third service (that takes some code and runs it as a container). <br> <br>As you can imagine, I am telling you that story because in IBM Cloud we didn’t build that third service. In fact, we didn’t even want to have two services. We went back to the drawing board instead and said: Let’s create one service that can combine all three use-cases and potentially other, similar ones.</p><p>In March 2021, the first iteration of IBM Cloud Code Engine came to the market. At that time, it wasn’t even a replacement for the existing functions or cloud foundry services, but in fact it addressed a slightly orthogonal, third use-case: purely serverless containers. Imagine you have a container image built by yourself, and just want to push and run it without having to take care of e.g. a Kubernetes cluster. So for a short period of time, we did have a third serverless service (just to contradict my previous statement) — but only to create a landing zone for the users of the other two services, and with the clear goal to sunset the two other ones.</p><p>Up next, we had to implement the use case that was the value proposition of Cloud Foundry: “Here’s my code, run it on the cloud for me, I don’t care how” — to quote the official CF Haiku. We developed a smooth migration on-ramp for Cloud Foundry users to Code Engine, and even developed an equally simple equivalent of the popular “cf push” command called “ce app create”. All that was done done on a modern, Kubernetes-based technology stack, extended with open source CNCF/CDF projects like <a href="https://knative.dev/docs/">Knative</a> (to allow scale to zero), <a href="https://paketo.io/">Paketo Buildpacks</a> (to transform source code into containers) and <a href="https://shipwright.io/">Shipwright</a> (to oversee, orchestrate and execute container builds) and glued together with some custom code, e.g. to integrate the service into IBM Cloud IAM, billing, logging and monitoring solutions.</p><p>Once we had that, customers started to migrate over from Cloud Foundry to Code Engine, and we were in a position to tackle the next feature: The infamous “serverless batch job as a service” I spoke about earlier. We tagged along the Kubernetes Batch initiative, as it seemed like a good fit, and were pretty quickly able to run Batch Jobs and offer that as a feature of the Code Engine service. By then we could strike off two out of our three goals, and while we had delighted feedback from customers (“I had a solution where I had a web app that was periodically spawning batch job runs. I ran that on Bare Metal servers, on Cloud Foundry and other services, and now I can just have it all in Code Engine behind a single API, that is so cool!”), we also learned quickly that Kubernetes Batch is not up there yet with high-profile, HPC-like batch scheduling technologies. Keep that in mind for later …</p><p>Fast Forward to today: In the last couple of months, we were able to ship the last missing piece to complete the three-services-to-one transition: Functions support in Code Engine. That one was a bit trickier, as all people familiar with Kubernetes would understand that in K8s proper it is very hard if not even impossible to get to a container deployed, started and responding to a http request in a few hundred milliseconds, so a few tricks of the trade had to be applied to get to the desired outcome.</p><p>So far, so good — mission accomplished ?! And indeed, we are pretty proud that we have built the most complete and unified serverless container service that we know of, and are able to run that with extraordinary efficiency. But remember, in the beginning I said “LLMs were not on the radar of many yet” and “Let’s create one service that can combine all three use-cases and potentially other, similar ones”. Now, when you think about it, a lot of the recent AI/LLM use cases like model training are quite similar in nature to serious HPC scenarios. So where are the challenges ? First, HPC/AI workloads often have different infrastructure requirements than web apps or functions — they need special hardware, like GPUs, extraordinary big machines or high network bandwidth, and they either need no scheduler or a very fault tolerant scheduler, especially designed for these kind of workloads.</p><p>As you can see, more challenges ahead. But the design and architecture decisions we’ve been taken allow us to expand and grow our current generic container runtime platform. If we can think of ways how to address the use-cases from the previous paragraph with Code Engine (and yes, we have some ideas), we’ll be very close to a generic compute platform, instead of just a container platform. And then, only then, I’d call mission accomplished. So stay tuned on what’s next, I can promise you it will be very cool!</p><h4>References:</h4><p>(1) <a href="https://matduggan.com/serverless-functions-post-mortem/">https://matduggan.com/serverless-functions-post-mortem/</a></p><p>(2) <a href="https://en.wikipedia.org/wiki/Serverless_computing">https://en.wikipedia.org/wiki/Serverless_computing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4233bb42eff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting your IBM Cloud Code Engine applications to various backends using Satellite Connector]]></title>
            <link>https://medium.com/@sdmoser/connecting-your-ibm-cloud-code-engine-applications-to-various-backends-using-satellite-connector-072f4340b4c7?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/072f4340b4c7</guid>
            <category><![CDATA[private-network]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[network-connectivity]]></category>
            <category><![CDATA[code-engine]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Wed, 10 Apr 2024 13:08:25 GMT</pubDate>
            <atom:updated>2024-04-10T13:08:45.700Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.ibm.com/products/code-engine">Code Engine</a> is IBM Clouds premier Serverless Container Service, because it makes running a container in the cloud so easy and frees its users from much of the operational burden of maintaining and operating their own infrastructure.</p><p>But there is one feature that Code Engine customers have been constantly asking about, and that is connecting their Code Engine application, job or function to a “backend” that runs outside of code engine, and doing that over a private network connection.</p><p>Why is that a problem, you’re asking ? The technical explanation is that Code Engine is an IBM Cloud service that runs on IBMs Virtual Private Cloud Infrastructure, and because it is a managed service (otherwise, it would not be able to relief the customers from the burden of maintaining and operating their own infrastructure), the VPC network is owned and operated by the IBM Code Engine team. That means, usually if you want to connect from a VPC to (let’s say) another VPC, you’d define two VPE Gateways (one on the source VPC, and one on the target VPC), and you’d connect them up to let the data flow. But, given the Code Engine VPC is not owned by the customer who owns the application, and Code Engine cannot provide a way for a customer to define it’s own VPE in its VPC for security reason, a customer seems to be stuck when he wants to connect his app to someplace else. But is this really the case ? In this article, we’ll explain what you can do to overcome this issue.</p><h3>Connection Use Cases</h3><p>Before we dive into solutions, let’s take a step back and look at three distinct connection use-cases that the Code Engine team has been getting requests for:</p><ol><li>Connecting from Code Engine to e.g. a virtual machine in a different VPC (including using a direct link from that VPC to connect further on to an on-premise network or system)</li><li>Connecting from Code Engine directly to a system outside of IBM Cloud (e.g. directly to a on-premise system)</li><li>Connecting from Code Engine to a system in IBM Cloud classic infrastructure (e.g. a bare metal server)</li></ol><p>Each of those use cases requires can theoretically be solved with the solution we are about to describe, but you should keep in mind that for some scenarios there might be more elegant solutions on the horizon, although not fully available at the time of writing of this blog post.</p><h3>Solution</h3><p>Let’s assume we’ll want to expose an API backend, that requires specialized hardware and is therefore deployed on VPC virtual machines. Instead of exposing such an API directly, we’ll want to front it with an application deployed on Code Engine, which provides a secure and reliable HTTPs endpoint and adds advanced scaling and caching capabilities.</p><p>By default, Code Engine applications would not be able to reach the API backend, unless the backend is exposed to the public internet. Assuming we’ll only want to expose the API backend to some selected callers within the private IBM Cloud network, adding a <a href="https://cloud.ibm.com/docs/satellite?topic=satellite-understand-connectors">Satellite Connector</a> instance between the Code Engine component and the virtual machines is a viable solution. At a high-level, the request flow of such a setup looks as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dybx-ecZCaVfGGpzZL_eHw.png" /></figure><p>A Satellite what? <a href="https://www.ibm.com/products/satellite">IBM Cloud Satellite®</a> provides a distributed cloud architecture that brings the scalability and flexibility of public cloud services to the applications and data that run in your secure private cloud. As such, it offers Satellite Connectors, which provide a secure and private connection, through TLS tunneling, between applications that need to communicate with hybrid and multi-cloud environments. If you are interested in learning more about the concept of Satellite Connectors, you’ll find useful information in our documentation page “<a href="https://cloud.ibm.com/docs/satellite?topic=satellite-understand-connectors">Satellite Connector overview</a>”.</p><p>Instead of establishing an HTTP outbound connection to the virtual machine directly, the Code Engine component calls the Satellite Connector tunnel server, which is exposed on a shared, regional endpoint, like “<em>c-01.private.eu-de.link.satellite.cloud.ibm.com”</em>. Each connector instance allows to configure so called endpoints, which point to the FQDN, or the IP address and a specific port of the target destination, and tells the connector how to route traffic. Furthermore, each configured endpoint is represented by a unique port on the shared tunnel server endpoint, like “<em>c-01.private.eu-de.link.satellite.cloud.ibm.com:&lt;endpoint-specific-port&gt;</em>”.</p><p>Ok - So we just we just learned how an HTTP API backend can be connected. But does that work with a database backend that is exposed on TCP port XYZ? Yes, It does 🙂 Let’s take a look at the following high-level flow, which depicts the second concrete use case that we exploring in this post:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pda1P92Acus1k2yZVlQY4A.png" /></figure><p>Let’s assume you’ll want to crunch a large amount of data on a regular basis and also want to have some visualization through a web application on the results of such compute-intensive batch operation. <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-cebatchjobs">Code Engine jobs</a> are a perfect choice, if you require a large amount of capacity for some time, which will be released once the task is done, as you’ll only need to pay for the capacity and duration that you used it. Deploying a <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-ceapplications">Code Engine app</a> is a perfect choice, if you’ll want to run an HTTP server that automatically scales up or down (to zero) based on incoming requests. Enabling both, apps and jobs, to access backend services that are deployed in your virtual private cloud, is a great asset to many use cases.</p><p>Let’s see how this works in action 🚀</p><p>We prepared a little script in our sample repository (<a href="https://github.com/IBM/CodeEngine/tree/main/satellite-connector-to-vpc-vsi">https://github.com/IBM/CodeEngine/tree/main/satellite-connector-to-vpc-vsi</a>) that will provision all needed resources within your IBM Cloud account to provide an end-to-end sample solution that covers the two use cases depicted in the flow charts above.</p><p><strong>A word of warning: The script will create IBM Cloud resources that will cause usage and costs in your IBM Cloud account. The amount of the costs ultimately depends on the lifetime length of the example setup</strong>.</p><ul><li>Clone or download the IBM Cloud Code Engine Sample repository</li></ul><pre>git clone git@github.com:IBM/CodeEngine.git<br>cd CodeEngine/satellite-connector-to-vpc-vsi</pre><ul><li>Login to your IBM Cloud account using the IBM Cloud CLI, like described in <a href="https://cloud.ibm.com/docs/codeengine?topic=codeengine-install-cli">our documentation</a></li></ul><pre>ibmcloud login ...</pre><ul><li>Run the setup script, which will provision the entire setup</li></ul><pre>CLEANUP_ON_SUCCESS=false ./run</pre><p>The script execution can take a bit. While we are waiting let’s take a look on the resources that are being created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-7mvlpIRWTdzUlb8lRAsw.png" /></figure><p><strong>Code Engine components</strong></p><p>Mainly, the script provisions three different components, representing the different types of workload that IBM Cloud Code Engine supports today.</p><ul><li>Function — <em>ideal for short running use cases that require low latency</em> — acts as the HTTP proxy for the payload provided by the NGINX server (See <a href="https://github.com/IBM/CodeEngine/blob/main/satellite-connector-to-vpc-vsi/ce-function/index.js">Node.js source code</a>)</li><li>Job — <em>ideal for long-running, run-to-completion tasks that require a lot of resources for some time</em> — connects to the PostgreSQL database and insert a record per submitted instance (See <a href="https://github.com/IBM/CodeEngine/blob/main/satellite-connector-to-vpc-vsi/ce-job/job.mjs">Node.js source code</a>)</li><li>App — <em>the swiss knife, which is</em> <em>ideal for all sorts of HTTP server use cases that need to scale efficiently</em> — connects to the PostgreSQL database to query stored data and provide it as JSON payload on an HTTP endpoint (See <a href="https://github.com/IBM/CodeEngine/blob/main/satellite-connector-to-vpc-vsi/ce-app/main.go">Golang source code</a>)</li></ul><p><strong>Satellite Connector</strong></p><p>The Satellite Connector setup comprises of three components:</p><ul><li>Instance — the IBM Cloud resource that provides a secure connection between a specific remote location and IBM Cloud. The instance allows to manage endpoints and access control list rules</li><li>Endpoint — Endpoints are either the FQDNs or the IP addresses of the resources being made available across Satellite Connector. The script will create two endpoints. One for the NGINX server, and one for the PostgreSQL database. As a result, both backend destinations are targeted through different ports on the same generic Connector tunnel server domain (e.g. c-01.private.eu-de.link.satellite.cloud.ibm.com)</li><li>Agent — Running in the network of the destination to establish the connection. The script deploys the agent on a separate virtual machine within the same VPC subnet</li></ul><p><strong>VPC resources</strong></p><p>The provisioned VPC infrastructure components, such as network ACLs, subnet, public gateway, security group, are essential and well-known for any VPC-based solution. Furthermore, a virtual machine that provides the compute power to run workload, which is a NGINX server and a PostgreSQL database in this scenario, has been created.</p><p>Please note: Regardless of whether this solution pattern is being applied on IBM Cloud classic infrastructure or to connect your on-premise backends, the architecture and flow would look pretty similar. Basically, only the VPC portion would be replaced with corresponding infrastructure components, tailored to the needs of your backend.</p><p>Coming back to our script: Once it is has been finished, the output should look something like this and the following commands can be used to further play around with the sample setup:</p><p>1. Submit another job run:</p><pre>ibmcloud ce jobrun submit --job friendship-book-writer --array-size 10</pre><p>2. Invoke the function:</p><pre>curl https://http-proxy-function.&lt;your-id&gt;.&lt;region&gt;.codeengine.appdomain.cloud</pre><p>3. Invoke the app:</p><pre>curl https://friendship-book-api.&lt;your-id&gt;.&lt;region&gt;.codeengine.appdomain.cloud&#39;</pre><p>4. Inspect the Satellite Connector configuration</p><pre>https://cloud.ibm.com/satellite/connectors/&lt;some-unique-id&gt;</pre><p>5. Inspect the Code Engine project setup</p><pre>https://cloud.ibm.com/codeengine/project/&lt;region&gt;/&lt;some-unique-id&gt;/overview</pre><p>6. Tear down the sample setup:</p><pre> ./run clean<br><br>==========================================<br> SUCCESS<br>==========================================</pre><p>The Code Engine project details page, provides an overview on the running resources and their configuration. It can be found in the IBM Cloud console using following URL <a href="https://cloud.ibm.com/codeengine/projects">https://cloud.ibm.com/codeengine/projects</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bhr81ohLyIrVPHySs_M6WA.png" /></figure><p>The details page of each configured Connector endpoint provides information of the current traffic consumption, allowing operators to get sense on the utilization of a specific endpoint. Satellite Connector details can be found in the IBM Cloud console using following URL <a href="https://cloud.ibm.com/satellite/connectors">https://cloud.ibm.com/satellite/connectors</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuTTYfglkeTRskUCd1Kl_Q.png" /></figure><p>Well, this is all that we’ve prepared for you as part of this blog post. We hope that it helps you to get an idea whether this solution applicable for your use cases. For further explorations, we suggest to take a look at the operational aspects (e.g. HA support) of <a href="https://cloud.ibm.com/docs/satellite?topic=satellite-run-agent-swarm&amp;interface=ui">hosting a Connector agent</a> and to explore how <a href="https://cloud.ibm.com/docs/satellite?topic=satellite-connector-create-endpoints&amp;interface=ui#create-connector-rule-console">ACL rules on the Connector endpoints</a> can help to tighten the security aspects of the overall setup.</p><p>Before wrapping it up, please make sure to properly tear down the sample solution using the command shown below, to avoid unwanted costs in your account:</p><pre>./run clean</pre><h3>Conclusion and outlook</h3><p>That is it 🎉 🙌</p><p>In this blog post, we explored and verified a solution that uses <a href="https://cloud.ibm.com/docs/satellite?topic=satellite-understand-connectors">Satellite Connectors</a> to enable workload deployed on <a href="https://www.ibm.com/products/code-engine">IBM Cloud Code Engine</a> to connect to backends located within network segments that would otherwise hardly be reachable by Code Engine. While our concrete sample focusses on backends hosted on IBM Cloud VPC infrastructure, the same solution is applicable for IBM Cloud classic infrastructure and your on-premise environment, too.</p><p>To give you an outlook on what else is coming: Specifically for connections into the IBM Cloud VPC, we are looking into how the upcoming <a href="https://cloud.ibm.com/docs/vpc?topic=vpc-private-path-service-intro">Private Path services</a> can be adopted by Code Engine to further simplify the user experience… we’ll tell you more about it, soon 🙂</p><p>If you have feedback, suggestions, or questions about this post, please reach out to us on LinkedIn (<a href="https://www.linkedin.com/in/simonmoser/">https://www.linkedin.com/in/simonmoser/</a>, <a href="https://www.linkedin.com/in/jeremias-werner/">https://www.linkedin.com/in/jeremias-werner/</a>, or <a href="https://www.linkedin.com/in/enrico-regge/">https://www.linkedin.com/in/enrico-regge/</a>), or on <a href="https://stackoverflow.com/">StackOverflow</a> by using one of the following tags “<a href="https://stackoverflow.com/questions/tagged/ibm-cloud">ibm-cloud</a>” or “<a href="https://stackoverflow.com/questions/tagged/ibm-cloud-code-engine">ibm-cloud-code-engine</a>“.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=072f4340b4c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Highly available applications using IBMs Cloud Foundry PaaS — Part 2: In practice]]></title>
            <link>https://medium.com/highly-available-applications-using-ibms-cloud/highly-available-applications-using-ibms-cloud-foundry-paas-part-2-in-practice-f96ee27a267e?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/f96ee27a267e</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[ibm]]></category>
            <category><![CDATA[cloudflare]]></category>
            <category><![CDATA[cloud-foundry]]></category>
            <category><![CDATA[high-availability]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Tue, 21 Aug 2018 09:20:09 GMT</pubDate>
            <atom:updated>2018-08-23T03:34:43.849Z</atom:updated>
            <content:encoded><![CDATA[<h4>By Simon Moser, Richard Johnson and Fred Tucci</h4><p>So … you read <a href="https://medium.com/p/b35a92360114/">part 1</a> of this story and are curious enough to try it out.</p><p><strong>Note</strong>: <em>You will need your own domain in order to complete this tutorial, i.e. a domain you have control over such you can (temporarily) delegate DNS. If you already own a domain that you can delegate DNS, just proceed, otherwise go and get one at a service like godaddy.com.</em></p><p>First thing you need is an account on IBM Cloud so go to <a href="https://console.bluemix.net/">https://console.bluemix.net/</a> and sign up for a free account if you don’t already have one. Be sure to also obtain the ibmcloud command line tool from <a href="https://console.bluemix.net/docs/cli/reference/bluemix_cli/download_cli.html#install_use">here</a></p><p>As we will be using US-East and EU-DE as our regions, make sure that you are connected to US-East after your login. So in a console window, type</p><p>ibmcloud login -a mccp.us-east.bluemix.net<br>ibmcloud target --cf</p><p>You should now see something similar to this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9uEWXuK-zag2_JKAvYDIA.jpeg" /></figure><p>In case you don’t, you might have to create a space first (by executing ibmcloud cf create-space dev, in order to create a space called dev)</p><h4>Let’s push an application!</h4><p>By now we should be all ready to Rock’n’Roll! Next we need an application to push. For this example, we’ll use an asset from the open source Cloud Foundry acceptance test suite as our example. Open a terminal window, and execute</p><p>git clone <a href="https://github.com/cloudfoundry/cf-acceptance-tests.git">https://github.com/cloudfoundry/cf-acceptance-tests.git</a></p><p>This will download the acceptance test suite onto your laptop, and then change directory into the cf-acceptance-tests folder and descend into assets/dora. “Dora the Explorer” is not only <a href="https://www.youtube.com/watch?v=OK03o3BHafk">a popular TV show</a>, but also the name of a <em>Hello World</em> style test application (that has a set of useful parameters, see <a href="https://github.com/cloudfoundry/cf-acceptance-tests/tree/master/assets/dora">here</a> for a documentation of all the endpoints). Next, we’ll actually push the dora application. In your terminal, whilst located in the assets/dora directory, type</p><p>ibmcloud cf push dora_wdc_20180729sm -m 256M</p><p>Note that dora_wdc_20180729sm can be any name you choose — we just used a suffix with date and name initials. After a little while, you’ll see something like this on your screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wQCYNib0-vAZ3SdC2KrNQ.jpeg" /></figure><p>As you can see, the app is now available under the URL dora-wdc-20180729sm.us-east.mybluemix.net. So type your own app’s URL into your browser, or in the terminal window type your equivalent of</p><p>curl dorawdc20180729sm.us-east.mybluemix.net</p><p>The app will respond with Hi, I&#39;m dora.</p><h4>Let’s scale it to three instances in that region!</h4><p>Going back to part one of the series, you might remember that we have only 1 instance now, therefore we are located in one AZ only. In order to get better resiliency, let’s scale it to 3 instances. It’s literally as easy as typing</p><p>ibmcloud cf scale dora_wdc_20180729sm -i 3</p><p>Now, remember we told you that each instance has its own id, and that within a region you’d get a built in load balancer that sprays the requests across the instances. So if we could make dora reply with its instance ID, we could prove the load balancer is working. Luckily, we can :-) Just type your equivalent of</p><p>curl dorawdc20180729sm.us-east.mybluemix.net/id</p><p>a few times, and like in the screenshot below you’ll see it responding — our instances have the IDs <strong>732a7e10-e4df-4913–6fa9–2a8f</strong>, <strong>133bd88e-8ccc-448a-6c1d-881a</strong> and <strong>d0598b3a-3885–4255–55ea-106b</strong>, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5Smh8dIHq4ZTU12krn6oA.jpeg" /></figure><h4>Let’s push &amp; scale the application again in another datacenter !</h4><p>OK, now we are going to do the exact same steps in another region — EU-DE. For brevity, just follow the commands (again you can use your own app name):</p><pre>ibmcloud login -a mccp.eu-de.bluemix.net<br>ibmcloud target --cf <br>ibmcloud cf push dora_fra_20180729sm -m 256M<br>ibmcloud cf scale dora_fra_20180729sm -i 3</pre><p>So let’s summarise where we are: We have a dora app deployed with three instances in US-EAST, and it is reachable under something like <em>dora-wdc-20180729sm.us-east.mybluemix.net</em>, and we have three more instances in EU-DE, reachable under something like <em>dora-fra-20180729sm.eu-de.mybluemix.net</em>.</p><h4>Let’s add a GLB using IBM Cloud Internet Services</h4><p>So now we need a global load balancer to spray the requests over the two regions. In order to do so, go back to the IBM Cloud Console UI (<a href="https://console.bluemix.net/">https://console.bluemix.net/</a>), and browse the catalog for a service called “Internet Services”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1TLu3Sc-Ot2JAFwGJdX9yA.png" /></figure><p>Click on it, and give it a name (we chose “Simons GLB Service”, but anything will do). Make sure you pick the <em>Free Trial</em> plan.</p><p><strong>Note</strong>: <em>Once you have the instance created with a `free trial` plan, you will be stuck with it, as every user can only create one `free trial` instance ever, which unfortunately means if you delete it you will not be able to re-create one.</em></p><p>Now, click “create”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cVeHxysbg-z7s_DbqRxI_g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rl-9YdPOGjWDOG0H3Fmvnw.jpeg" /></figure><p>After a few seconds, the GLB Service is provisioned and now we have to configure it.</p><p>Follow the five steps in the “Welcome to IBM Cloud Internet Services” section. After getting started, <em>Step 2</em> will ask you for a domain where we can hook things up to — i.e. a domain that you own and that you want the applications to be running under. In this example, we went to <a href="http://www.godaddy.com/">GoDaddy</a> and got ourselves a domain called “multizone-ibmcf.com” — but of course you can use any domain you have already. So in <em>Step 2 of </em>the Internet Service configuration panel, enter your domain and click “<em>Connect and Continue</em>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IsLL3sp1dU996SA1Lbk_UQ.jpeg" /></figure><p>The next step (<em>Step 3- DNS</em>) you can skip, but <em>Step</em> <em>4 Delegate Domain Mangement</em> is very important: For the domain that you have chosen, you have to delegate the name server (NS) records to the Cloud Internet Services Service. In our case, we had to copy the two NS records from this page (e.g. ns011.name.cloud.ibm.com and ns014.name.cloud.ibm.com) and actually insert them into our domain registrar. In our case, we have to log in to godaddy.com and find a section titled “custom DNS” or “DNS server settings” (the section’s title varies from provider to provider). When there, copy both of the new NS records into your provider and save changes.</p><p>Returning to the IBM Cloud UI, click on “Check name servers”, as now that test should be working. Once you’ve confirmed it does, in the left navigation menu go to <em>Reliability-&gt;Global Load Balancer</em>. There, we create a GLB and named it “<strong>dora</strong>.multizone-ibmcf.com”, so do something equivalent for your domain. Be sure to turn the proxy button on too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OTRwfXiVIV69DgYs2KhZKA.jpeg" /></figure><p>Next, under “default origin pools”, click “Add Pool” and set that up similar to what’s shown here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*Xp490eWmzPfPSfmwNSrIfQ.jpeg" /></figure><p>The key here is the “origins” section — as you can see, we defined two origins and pointed them to our two regional URLs — dorawdc20180729sm.us-east.mybluemix.net and dorafra20180729sm.eu-de.mybluemix.net. Next, click “Add” to add the pool and then <strong>provision the GLB resource</strong> (Click on “Provision 1 Resource” in the main page).</p><p>After the GLB provisioning is done, in the main page under “Default Origin Pools”, click on “view details” and verify it looks equivalent to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ygu7urjpdPnWXdgXztlI1w.jpeg" /></figure><p>Now, we should be able to curl our domain (<strong>dora</strong>.multizone-ibmcf.com in our case), and it should forward the requests to our two backends, right? Let’s try it:</p><p>curl dora.multizone-ibmcf.com</p><p>Sadly, not working. So what are we missing? Well, in order to make this work properly, we have to register custom domains and routes to Cloud Foundry as well because otherwise it won’t recognize what to do with traffic from the custom domain. So for EU-DE, we have to</p><pre>ibmcloud login -a mccp.eu-de.bluemix.net<br>ibmcloud target --cf<br>ibmcloud cf create-domain smoser@xx.ibm.com multizone-ibmcf.com<br>(ibmcloud cf create-domain ORG DOMAIN)<br>ibmcloud cf create-route dev multizone-ibmcf.com dora<br>(ibmcloud cf create-route SPACE DOMAIN Balancer HOSTNAME)<br>ibmcloud cf map-route dora_fra_20180729sm multizone-ibmcf.com --hostname dora<br>(ibmcloud cf map-route APP_NAME DOMAIN HOSTNAME)<br>ibmcloud cf restart dora_fra_20180729sm</pre><p>and then repeat the same steps for US-East</p><pre>ibmcloud login -a mccp.us-east.bluemix.net<br>ibmcloud target --cf<br>ibmcloud cf create-domain smoser@xx.ibm.com multizone-ibmcf.com <br>(ibmcloud cf create-domain ORG DOMAIN)<br>ibmcloud cf create-route dev multizone-ibmcf.com dora <br>(ibmcloud cf create-route SPACE DOMAIN Balancer HOSTNAME)<br>ibmcloud cf map-route dora_wdc_20180729sm multizone-ibmcf.com --hostname dora<br>(ibmcloud cf map-route APP_NAME DOMAIN HOSTNAME)<br>ibmcloud cf restart dora_wdc_20180729sm</pre><p>In the end, our setup looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-FGA0jzndDNgi0dIJuzRPQ.jpeg" /></figure><h4>Basic testing</h4><p>We now have configured <a href="http://dora.multizone-ibmcf.com/">https://dora.multizone-ibmcf.com/</a> as our GLB domain and pointed it to our two apps in US-East and EU-DE. If we now execute</p><p>curl https://dora.multizone-ibmcf.com/id</p><p>we expect that all 6 app IDs respond (in no particular order, as we don’t know which region the GLB will choose to routes the request too, and inside a region we don’t know which instance it will get routed to). So let’s test if our assumptions hold true…</p><p>First, we need to get the current IDs for Washington. Execute your equivalent tocurl https://dorawdc20180729sm.us-east.mybluemix.net/id few times until you get three IDs (<strong>3c38f8f1-e9c9–4959–5582–9462</strong>, <strong>fd81e61d-2de1–4bcc-671a-0235</strong> and <strong>4137f0dd-4545–4c6d-69e1-ce72 for our example</strong>)</p><p>Next, execute your equivalent tocurl https://dorafra20180729sm.eu-de.mybluemix.net/ida few times until you get three IDs there, too (<strong>0ecdd52b-afe9–4baf-78ee-dcd9</strong>, <br><strong>42a14ade-15c1–4813–6ec9-c104</strong> and <strong>19bea1bd-2eb5–4d5e-4b96–341c for our example</strong>)</p><p>Then, finally execute curl <a href="https://dora.multizone-ibmcf.com/id">https://dora.multizone-ibmcf.com/id</a> and observe that now all 6 instances from US-East and EU-DE reply to the request happily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*q-Bvo7vnRCGqp41amVgAUA.jpeg" /></figure><h4>Resiliency testing</h4><p>Next, lets simulate to take down a region. We cannot really simulate taking down an “AZ”, as this means we’d have to stop a single app instance, which isn’t possible as Clouod Foundry will automatically restart it! So we’ll stop the entire app (all instances) in one region and then we can expect that curl <a href="https://dora.multizone-ibmcf.com/id">https://dora.multizone-ibmcf.com/id</a> will only reply with the IDs from the other region</p><pre>ibmcloud login -a mccp.eu-de.bluemix.net<br>ibmcloud target --cf<br>ibmcloud cf stop app dora_fra_20180729sm</pre><p>We can verify that now our EU-DE instances are stopped, curl <a href="https://dora.multizone-ibmcf.com/id">https://dora.multizone-ibmcf.com/id</a> will only reply with <strong>3c38f8f1-e9c9–4959–5582–9462</strong>, <strong>fd81e61d-2de1–4bcc-671a-0235</strong> and <strong>4137f0dd-4545–4c6d-69e1-ce72</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*XCHD1yOJeSTWMbvP_Vc56g.jpeg" /></figure><p>The latin “quod erat demonstrandum” seems an appropriate phrase at this point in time :-)</p><h4>But wasn’t there a database ? You tried to trick us again!</h4><p>Remember, in the first part of the series, we said</p><blockquote>assume you have an application that has a two-tier architecture, i.e. a web application that is backed by a database</blockquote><p>but then we never used a DB in the example. And the reason is that our nice little Dora example above just doesn’t use a database. But we can easily demonstrate how this would work with a Cloudant database, and you could easily use it for your real-world use-case — here are the high-level steps how to get that attached:</p><ul><li>Go to <a href="https://console.bluemix.net/catalog/services/cloudant">https://console.bluemix.net/catalog/services/cloudant</a></li><li>In the “Choose a region” dropdown select “US-East”</li><li>As a name, call it “MyCloudant_us_east”</li><li>Select the lite plan, click “create”</li><li>Repeat the above steps, exchanging “us_east” with “Germany” in both the drop down and the name</li></ul><p>Now you have two instances of the database. For the next steps, we’ll just quote from an article available <a href="https://www.ibm.com/developerworks/cloud/library/cl-multi-region-bluemix-apps-with-cloudant-and-dyn-trs/index.html">here</a></p><blockquote>To synchronize the application data across regions, configure each Cloudant database to continuously replicate from the database in each of the other regions.</blockquote><blockquote>This can be accomplished manually from the Cloudant dashboard according to the steps below, or it can be automated through the use of <a href="https://github.com/ibmjstart/bluemix-cloudant-replicator">this command-line utililty</a> created by the IBM jStart team.</blockquote><p><strong>Note</strong>: <em>Configuring continuous replication as described in this article will result in frequent API calls between the configured regions. With the default (“Shared”) plan on Bluemix, these calls will count toward the totals on your monthly bill. Consider setting </em><a href="https://console.ng.bluemix.net/docs/pricing/index.html#notifications"><em>Spending notifications</em></a><em> to avoid unexpected charges. Alternatively, consider upgrading to an Enterprise plan that is better suited for the continuous replication feature.</em></p><blockquote>From the Bluemix console, in each region, expand the Show Credentials section of your Cloudant NoSQL DB service tile, and note the usernames and passwords for your each Cloudant account.</blockquote><blockquote>After noting the password, click the tile itself and then LAUNCH the Cloudant Dashboard. Each region’s Cloudant instance should have a single database with the name my_sample_db.</blockquote><blockquote>In each Cloudant dashboard, open the Permissions view for the my_sample_db database. Grant Replicator permissions for the Cloudant user names in each of the other regions, or use the Generate API key button to create a key/pass combo for each of the other regions to use.</blockquote><blockquote>Next, open the Replication section for each region, and configure a continuous replication task from each of the other regions:</blockquote><blockquote>This should create a new database in each region with the name “_replicator” and a single document per replication task.</blockquote><p><a href="https://www.ibm.com/developerworks/cloud/library/cl-multi-region-bluemix-apps-with-cloudant-and-dyn-trs/index.html">Lee’s article</a> also has a section on testing the database replication that you might want to check out.</p><p>With that, we’re at the end of our article, and we’d like to finish up with a little outlook how this might evolve: Currently, the Cloud Foundry community is reworking their routing layer and basing it on top of <a href="https://istio.io/">ISTIO</a>, and once that is available you would be able to create a cross-regional service mesh that would add a bunch of really nice features like A/B testing and circuit breaking patterns into the mix. So stay tuned and watch out for further updates on the subject.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f96ee27a267e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/highly-available-applications-using-ibms-cloud/highly-available-applications-using-ibms-cloud-foundry-paas-part-2-in-practice-f96ee27a267e">Highly available applications using IBMs Cloud Foundry PaaS — Part 2: In practice</a> was originally published in <a href="https://medium.com/highly-available-applications-using-ibms-cloud">Highly available applications using IBMs Cloud Foundry PaaS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Highly available applications using IBMs Cloud Foundry PaaS — Part 1: The underpinnings]]></title>
            <link>https://medium.com/highly-available-applications-using-ibms-cloud/highly-available-applications-using-ibms-cloud-foundry-paas-part-1-the-underpinnings-b35a92360114?source=rss-bd5f78cde561------2</link>
            <guid isPermaLink="false">https://medium.com/p/b35a92360114</guid>
            <category><![CDATA[cloud-foundry]]></category>
            <category><![CDATA[high-availability]]></category>
            <category><![CDATA[ibm-bluemix]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[ibm]]></category>
            <dc:creator><![CDATA[Simon Moser]]></dc:creator>
            <pubDate>Sat, 11 Aug 2018 11:49:50 GMT</pubDate>
            <atom:updated>2018-08-21T09:21:07.412Z</atom:updated>
            <content:encoded><![CDATA[<h4>(Almost) seven nines availability on IBM Cloud for (less than) $18<br>By Simon Moser, Richard Johnson and Carl Swanson</h4><p>Clearly, applications hosted on a cloud can be a critical part of your business and organisation. One of the reasons why to choose a cloud over other hosting solutions is that the uptime for those applications is what really matters — low availability is not acceptable and it needs to approach that elusive 100% availability. Is it reachable? On the IBM multi-region cloud foundry compute offering the answer is “absolutely“! In this two-part series, the first part will explain the <em>what</em> and <em>why, w</em>hereas part 2 focusses on the<em> how</em>.</p><h4>Old School Legacy Hosting</h4><p>Let’s start with a little time travel: Assume it’s 2000, you have an application that has a two-tier architecture (i.e. a web application that is backed by a database), and you get asked to bring this application to production in a highly available, scalable way.</p><p>Back then you got yourself a few server machines in your datacenter and deployed the application there, and you worked with your DB team to get an HA-setup for the database, and you worked with your Network team to bring the network latencies down as much as possible, and you went to production. Life was good as you had a great setup and it worked. At least until you needed to scale this solution or you needed to deploy this solution to another geography — be it for business or for resiliency reasons. By then, the issues started: in the best case, you “just” had to rinse and repeat all of the steps (get some machines on your oversea datacenter, work with the DB team to get the same DB setup, etc.). In the worse case you didn’t have an overseas datacenter, so you had to either start building one or finding a parter that let you in his, often accompanied with a skill and culture mismatch — ok, let me stop here, as y’all probably know that story …</p><h4>Getting a little cloudy: IaaS</h4><p>But then “Infrastructure as a service” (IaaS) offerings came to the market, and it solved some of these problems. All of the sudden, your trusted IT team could start to spin up these servers all around the globe by themselves — no need for building oversea datacenters, no need for searching for partners, no skill mismatches, no cultural clashes — YAY! Problem solved!</p><p>Really? Partially yes, but you still needed to run all these servers, all the databases, having to take care of backups and recovery, security patching, etc. Also, scaling was still a semi-automatic process in many cases — even if you could automatically scale your servers with your application, you needed to take care of of things like connection management to the databases, as twice as many application servers potentially eat up twice as many database connections, and if the DB couldn’t handle this … ok, let me stop here again, as y’all probably know that story also.</p><h4>The new school: PaaS (or Serverless)</h4><p>So let’s take a look at how we would solve such a scenario today with a PaaS like Cloud Foundry on the IBM Cloud. To most easily accomplish this, it would be good if a few architectural prerequisites would be met</p><ol><li>Your application should be stateless. That means that all the data that needs to be stored from your app should be stored in the backend database or in other external services like logging services, but not “on the local hard drive” (assume you don’t have one)</li><li>Ideally, your application design follows the 12-factor principle — see 12 Factor Apps [<a href="https://12factor.net/">https://12factor.net</a>]. They are important indicators of a modern refactored application with the latest application design thinking.</li></ol><p>Even if you cannot guarantee 1 and 2 that doesn’t mean “game over” — you could still package everything up in a container and attach a persistent volume to it (then it can have state) — but then you have to manage this again, so life won’t be as great.</p><p>So let’s assume we have some nice born-on-the-cloud 12-factor application source code, and we require a database for persistence. Next, you sign-up and login into IBM cloud, and you’ll get placed into a region close to your current location — that is, being US-based you get placed into “US-SOUTH” or “US-EAST”, being EU-based you get placed into “EU-DE” (Germany) or “EU-GB” (United Kingdom), etc. This location that you are placed in is the location where your application will become available after you deploy. Needless to say, you can change the location as you like, as there are 5 <em>regional hubs</em> at the time of writing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7OtrpcO9R1TKQ0eXqpsVKQ.jpeg" /><figcaption>Green circles represent the regional hubs where IBM Cloud Foundry is delivered from (from left to right): US-SOUTH, US-EAST, EU-GB, EU-DE and AU-SYD</figcaption></figure><h4>PaaS feature: Auto-spreading across Availability Zones</h4><p>So what makes a <em>regional</em> <em>hub</em> a <em>regional hub</em>, and why is this important: A <em>regional hub </em>is a place that consists of at least three “Availability Zones” (AZ), realised through <em>independent datacenters</em> — i.e. separate buildings with separate power supplies and a certain distance between them. US-SOUTH consists of e.g. 10 AZ at the time of writing, where IBMs Cloud Foundry service is currently leveraging 4 of them. That might not be true for all <em>regional</em> <em>hubs</em>, but IBM Cloud Foundry uses at least 3 Availability Zones in every hub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yZTT-B4XDxyldfAyPG4kkg.png" /><figcaption>Two regional hubs with three Availability Zones each</figcaption></figure><p>One thing to note here is that IBM Cloud Foundry — unlike other services — does not expose Availability Zones to you as a user, but it will <em>automatically</em> use these AZ for you and — if you have multiple instances of your application —evenly distribute instances across each AZ automatically. The general idea here is that you as an application owner should not have to care about that placement — you should care about your code, and let the PaaS handle the rest (you’re understanding now where the term <em>serverless</em> originally comes from, do you?) .</p><p>But why have multiple instances of an application anyhow ? The answers are resiliency and performance. If you have just one instance of your application, it gets placed in one AZ. That in itself isn’t a problem, but at least it isn’t an ideal setup for a production app — even if that AZ is the most stable place on earth, your code might have an intermittent problem, the container in which your code is running might have a problem, or something else, and the result is always the same: Your application is not responding, and you are having an outage. Vice versa, even if your code is the most stable, an unforeseen event - although unlikely - can take down an entire AZ. Such unforeseen events might be power outages or a strike of nature. In order to protect your business, it is recommended to scale your application to more than one instance, and FWIW you’d only get a guaranteed SLA if you run at least two instances anyway.</p><p>But be careful —there are two types of scaling:<em> </em><strong><em>vertical </em></strong>and <strong><em>horizontal scaling</em></strong>. In the (pre)IaaS days, vertical scaling was the thing:</p><ul><li>Vertical scaling means increasing the amount of memory or CPU that the application can use. Factors such as user load, or the number and nature of tasks performed by an application, can change the disk space and memory the application requires. For many applications, increasing the available disk space or memory can improve overall performance. Obviously, vertical scaling is bound by the VM that the application is hosted on.</li></ul><p>While this is still something to consider, e.g. in order to achieve better response times and better performance per instance, it surely doesn’t help with protecting against outages. So lately people are more looking into horizontal scaling:</p><ul><li>Horizontal scaling means running additional instances of an application that can allow the application to handle increases in user load and concurrent requests as well, and in addition will protect against outages.</li></ul><p>Running multiple instances of your application is actually much easier if don’t have to worry about state (remember 12-factor from above? Stay away from that state!)</p><h4>So: How to scale horizontally ?</h4><p>Given that we assume a stateless, 12-factor app this is super easy to accomplish. In Cloud Foundry, it is literally one command :</p><p>cf scale -i 5 myApplication</p><p>Furthermore, you don’t even have to take care of spreading the traffic across all the instances that you have, as Cloud Foundry has a built-in load balancer (one LB group per <em>regional hub</em>) that will make sure all incoming requests to your application are automatically balanced across all instances of your application, and each instance handles tasks in parallel with every other instance. Adding more instances allows your application to handle increased traffic and demand. This is the primary way to manage your applications scale and performance.</p><p>But so far, what we explained you could do with basically any Cloud Foundry out there on the market. So why IBM cloud ?</p><h4>IBM Cloud Foundry: A multi-region Cloud Foundry</h4><p>To the best we know, IBM is the only provider of a public, multi-region Cloud Foundry service. For application availability, it means that all that we said above is true for all the five <em>regional hubs</em> that are supported. So — if you want to really really protect yourself or, going back to the initial example, you need to expand your business to other regions — you can deploy the same resilient multi instance setup to multiple <em>regional hubs</em>. N Availability Zones per region, spread over M <em>regional hubs</em>, what does that me mean in numbers ? Let’s do the math: IBM gives a<em> 99.95</em> availability SLA in one region — that is the SLA across all the Availability Zones in the <em>regional hub</em> given you have at least two instances running. So that application in that region would have a guaranteed availability of<em> 99.95</em>% — that means a potential downtime of 4.38 hours per year. OK’ish, but not great. So now let’s also add at least two instances in a second <em>regional hub</em> which has also a <em>99.95%</em> availability, and let’s furthermore add a custom Global Load Balancer (GLB) for your applications in front of the two regions (spanning across the regional LBs that Cloud Foundry brings). Then the combined availability becomes</p><p>1-(1–0.9995)² = 99.999975%.</p><p>Now that’s <a href="https://en.wikipedia.org/wiki/High_availability">6 nines (and three quarters of a seventh nine)</a>, which means an application downtime of <em>7.884 seconds</em> per year. So having an application scaled that way might not only help you with performance, but really with resiliency. In other words, it can handle almost any user load, and can achieve near perfect up-time capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ld_iVV8pxa3THTIolBLCdg.png" /><figcaption>A layout example with three instances per region, automatically placed, and a global load balancer in front of it. Even in case where an entire Region (Region 2) would be offline, and one AZ in region 1 would have issues there would still be two instances that would serve.</figcaption></figure><p>We’re confident <em>7.884 seconds</em> potential downtime per year is cool for most use-cases. But we’re also sure that the next question from anyone that has already tried to achieve that level of uptime is: how much does that cost ? For the financial example, we’ll use a node.js app. A node.js based app costs $0.07 USD/GB-Hour, that is 7 cents per GB of allocated memory per hour. So a node.js instance that uses 1GB memory costs 7 cents per hour. Two instances in one region of a 512MB app would then be 7 cents per hour, too, or $42.66 per month or 511.98$ per year. Consequently, for two regions that’s 1023.96$ — that’s pretty neat for almost 7 nines, isn’t it? Even if you go with 3 instances per region (to make sure you utilise all three AZ per region), the cost would only be 1535.94$ / year for 2 regions. Compare that to the old school costs trying to get that same availability.</p><h4>But wasn’t there a database ? How is that coming in ?</h4><p>As a thorough reader, you probably realised already that we were simplifying things a bit so far. Remember, in the beginning we said</p><blockquote>assume you have an application that has a two-tier architecture, i.e. a web application that is backed by a database</blockquote><p>but then we never talked about that DB again. So let’s fix that and think about the datastore for a bit: A database can be deployed the same way as the application can — i.e. you co-locate the database in the same <em>regional hub</em> where your application is running. There might be good reasons for doing that: Think about a European company that has to support GDPR and therefore has to place their DB in Europe, too. FWIW, that doesn’t literally mean “in the same <em>regional hub</em>” — a french customer for example that wants his DB that hosts its data in Paris could use a <em>regional spoke</em> datacenter in Paris, but still place his application in the central European <em>hub</em> in Germany.</p><p>However, now a new component comes into the equation, so lets look at how that affects availability. Our application, spread out across 3 AZ in a region and deployed across 2 regions with a GLB in front has an availability of 99.999975%. Let’s assume the database comes with a 99,95% SLA in one region, then the overall solution total availability becomes</p><p>99.999975% * 99.95% = 99,94999%</p><p>Mmh ... we’re back to three nines, that’s not what we wanted. So we need to raise the availability of the DB, too. But DB’s have state, and replicating state has always been the big issue, so we haven’t really gained anything, right ?</p><p>No! Because, instead of doing that yourself, you could use a database service like IBM Cloudant. It allows to synchronise data across regions, by configuring each Cloudant database to continuously replicate from the databases in each of the other regions. That way, your database SLA now also becomes 99.999975% and therefore the overall combined SLA is also 99.999975%. Prices would vary depending which DB plan you’re going for, but with a standard plan and 50GB of Storage, 200 Lookups/s, 100 Writes/s and 10 Queries/second are 2400 $ per instance per year, so two instances is 4800 $ per year for 2 regions.</p><h4>So I get almost 7 nines all automatic ? That would be black magic!</h4><p>True. And in fact it’s not totally “all automatic” — as mentioned there are two manual things to do: You have to set up your global load balancer service yourself and you have to enable the database replication. In <a href="https://medium.com/highly-available-applications-using-ibms-cloud/highly-available-applications-using-ibms-cloud-foundry-paas-part-2-in-practice-f96ee27a267e">Part 2</a> of this series, we’ll walk you step-by-step through the details of how to do that (and no worries, we’ll use an example that’s for free :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b35a92360114" width="1" height="1" alt=""><hr><p><a href="https://medium.com/highly-available-applications-using-ibms-cloud/highly-available-applications-using-ibms-cloud-foundry-paas-part-1-the-underpinnings-b35a92360114">Highly available applications using IBMs Cloud Foundry PaaS — Part 1: The underpinnings</a> was originally published in <a href="https://medium.com/highly-available-applications-using-ibms-cloud">Highly available applications using IBMs Cloud Foundry PaaS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>