<?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[Ecliptical Software Inc. - Medium]]></title>
        <description><![CDATA[Solving real-world problems using Rust, Kubernetes, and other Cloud-Native technologies. - Medium]]></description>
        <link>https://medium.com/ecliptical-software-inc?source=rss----a1e1a9ae03e7---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Ecliptical Software Inc. - Medium</title>
            <link>https://medium.com/ecliptical-software-inc?source=rss----a1e1a9ae03e7---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:24:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/ecliptical-software-inc" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create a Custom GitHub Action in Rust]]></title>
            <link>https://medium.com/ecliptical-software-inc/create-a-custom-github-action-in-rust-dec1b80df954?source=rss----a1e1a9ae03e7---4</link>
            <guid isPermaLink="false">https://medium.com/p/dec1b80df954</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Peter Nehrer]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 00:18:23 GMT</pubDate>
            <atom:updated>2024-04-29T04:44:39.526Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Generated using DALL-E." src="https://cdn-images-1.medium.com/max/1024/1*kkAKUhgs1g2RoIEcjZ9ETw.png" /></figure><p>Anyone who gets into serious software development quickly realizes that the path to productivity leads through automation. This applies to both individuals as well as entire teams. When you automate repetitive development tasks, not only do you save time for your future self, but you also reduce human error, foster repeatability, and eliminate the bus factor.</p><p>Of course, there’s a fine balance between automating too little and too much — you probably don’t want to spend way more time automating your tasks than it would actually take to perform them manually! This is where your tools and platforms come into play. While some tasks are “standard practices” that apply to every project of a certain type, and may be set up right at the start, high-value projects tend to evolve in unique ways that eventually require a great deal of customization.</p><h3><strong>What are GitHub Actions?</strong></h3><p>If you’ve used GitHub while working on a software project, chances are you’ve seen <a href="https://docs.github.com/en/actions">GitHub Actions</a> being utilized for automating tasks such as enforcing code formatting, running unit tests, checking code quality, or even packaging and publishing the final software product.</p><p>As an integral part of the GitHub platform, GitHub Actions are tightly integrated into your software development life-cycle, right where your code lives, and where much of your daily product development and collaboration happens. They are quite intuitive and easy to grasp; they use <a href="https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#the-components-of-github-actions">domain language</a> that you’re likely familiar with, such as workflows, jobs, and steps. Your workflows are described in YAML files that are stored in Git along with the rest of your code. Best of all, they are free to use, and GitHub even provides <a href="https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration">free compute infrastructure</a> to run your workflows!</p><p>In addition to a set of commonly required actions provided directly by the platform itself, GitHub supports a rich <a href="https://github.com/marketplace?type=actions">marketplace</a> of third-party actions that seem to cover any engineering need under the sun. However, GitHub also allows you to create your own custom actions suitable for your project’s specific needs. Of course, if you feel that your custom GitHub Action can be useful to others, you may even publish it to GitHub Marketplace!</p><p>There are a number of reasons you may find yourself in need of a custom GitHub Action. For instance, your software project workflow may require some specific tasks that aren’t already available. You may also want to optimize your workflow, reducing the wait time or resources needed to perform the tasks. Or you may need to integrate with external systems that are internal to your team or company. Finally, you may want to develop and offer custom GitHub Actions for profit.</p><h3><strong>Custom GitHub Actions</strong></h3><p>While it’s possible to build custom GitHub Actions in JavaScript, this approach imposes limits on what they can do. For example, they run directly on the runner and can only use binaries that are part of the runner image. The language itself may be a less-than-ideal choice for non-JavaScript developers.</p><p>You can also create composite actions, which consist of steps that use other actions, including shell scripts. However, if you prefer to write your action in any other language, GitHub allows you to supply the implementation as a <a href="https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action">Docker container image</a>; when used in a job step, the runner will execute the action in its own Docker container.</p><p>For best results, you should place your custom action in its own GitHub repository. This will make it easier to share and evolve as its own project.</p><p>What defines a custom GitHub Action is a YAML descriptor file named <a href="https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions">action.yaml</a>, which must reside in the root of the action’s repository. It contains both required and optional pieces of data, such as the action’s name, description, and how it runs — essentially its type.</p><p>Docker-based actions require a <a href="https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions">Dockerfile</a> to build the action’s executable and package it into an image. In your action’s descriptor, you can supply the path to your Dockerfile or the full Docker image URI. As you get started with developing your action, it may be convenient to specify the path to the Dockerfile; however, when you actually use your action in production, you’ll benefit from building the image ahead of time and publishing it to a Docker registry (e.g., GitHub’s own <a href="https://ghcr.io/">Container Registry</a>).</p><p>There are several mechanisms that your Docker-based action can use to <a href="https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions">interact with the platform</a>. For instance, the platform will set up your container with environment variables that point to shared files for your action’s output parameters, job summary, and even environment variables to set up for subsequent steps.</p><p>Custom GitHub Actions may utilize <a href="https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs">input parameters</a> that the user can provide when calling the action in a job step. These parameters are passed to your container as command-line arguments. This is the easiest way to parameterize your action. Your action’s descriptor file must define any input parameters that you wish to support, including their name, type, default value, and whether they’re required.</p><h3><strong>Custom GitHub Actions in Rust</strong></h3><p>If you haven’t dipped your touch-typing fingers into Rust yet, you really owe it to yourself. <a href="https://www.rust-lang.org/">Rust</a> is a modern programming language with features that make it suitable not only for systems programming — its original purpose, but just about any other environment, too; there are frameworks that let your build web services, <a href="https://www.arewewebyet.org/">web applications</a> including user interfaces, software for embedded devices, <a href="https://www.arewelearningyet.com/">machine learning</a> solutions, and of course, command-line tools. Since a custom GitHub Action is essentially a command-line tool that interacts with the system through files and environment variables, Rust is perfectly suited for that as well.</p><p>Rust has a <a href="https://crates.io/">rich ecosystem</a> of frameworks and libraries that let you read, parse, and manipulate text files, interact with cloud services and databases, and perform any other job that your project’s development workflow may require. And because of its strong typing and tight memory management, you are much less likely to write programs that behave unexpectedly in production.</p><p>It is also quite easy to build a Rust program that links all of its dependencies into a single executable file. When you also <a href="https://doc.rust-lang.org/cargo/reference/profiles.html#opt-level">optimize your release build for size</a>, you end up with a small Docker container image that is quick to load and takes very little memory to do its job.</p><h3><strong>Tips for building custom GitHub Actions in Rust</strong></h3><p>As you get started, consider the following tips to help you along:</p><p><strong>1. Use the `act` tool to test-run your action</strong></p><p>To speed up your development cycle, install and use the <a href="https://github.com/nektos/act">act</a> tool to test-run your action directly in your development environment. This tool lets you invoke a GitHub workflow right on your local machine and will save you the round-trips of pushing each change to GitHub to see if it works.</p><p><strong>2. Use debug messages</strong></p><p>GitHub supports a <a href="https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging">debug mode</a> when executing workflows. This will cause any <a href="https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-debug-message">debug message</a> output to show up in the action’s logs. This feature gives your users the ability to debug their workflows in a uniform manner.</p><p><strong>3. Make your code easily testable</strong></p><p>Write lots of unit tests, and use libraries that help you test filesystem operations, such as <a href="https://crates.io/crates/assert_fs">assert_fs</a>, as well as your command-line parsing, such as <a href="https://crates.io/crates/assert_cmd">assert_cmd</a>. This will save you a lot of headaches with regression bugs as you build out your action’s functionality.</p><p><strong>4. Keep command-line argument parsing simple</strong></p><p>Fancy command-line argument parsing simply isn’t necessary when building a custom GitHub Action. All input parameters are described and fed statically into your executable’s command-line arguments. That means that all parameters will always be supplied in the order you define in <em>action.yaml</em>, regardless of their values, so ensure that your code knows how to handle empty strings and defaults.</p><p><strong>5. Use GitHub Actions to automate your own development process</strong></p><p>Not surprisingly, you can invoke your own action as part of your action’s automated workflow! In addition to your regular Rust-based project workflow, add one that calls your action with a set of resources that you can use to test its functionality.</p><p><strong>6. Build and publish your Docker image to ghcr.io for free</strong></p><p>Take full advantage of what GitHub has to offer, for free:</p><p>1. Build and package your action as a Docker container image as part of your release workflow.</p><p>2. Publish it to GitHub’s <a href="https://ghcr.io/">Container Registry</a>, which you can set up for your action’s repository.</p><p>3. Update your action’s descriptor to use the desired version of your pre-built Docker image, which will greatly speed up its execution!</p><p><strong>7. Use Alpine-based Rust builder for statically-linked executables</strong></p><p>For the smallest possible Docker container images, build your action using an <a href="https://hub.docker.com/_/rust/tags?page=1&amp;name=alpine">Alpine Linux-based Rust builder</a>. This image configures your Rust toolchain for static linking using the <a href="https://musl.libc.org/">musl library</a>, which produces single-file executables without any dynamic library dependencies. With this approach, your final Docker container image can consist of <a href="https://hub.docker.com/_/scratch/">your executable alone</a>, with no other files needed!</p><h3><strong>Next steps</strong></h3><p>To learn more, sign up for this interactive project on how to <a href="https://www.educative.io/projects/build-custom-github-actions-in-rust">Build Custom GitHub Actions in Rust</a> at Educative.io, which will take you step by step through creating your own custom GitHub Action in Rust!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dec1b80df954" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ecliptical-software-inc/create-a-custom-github-action-in-rust-dec1b80df954">Create a Custom GitHub Action in Rust</a> was originally published in <a href="https://medium.com/ecliptical-software-inc">Ecliptical Software Inc.</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s your crate’s Minimum Supported Rust Version?]]></title>
            <link>https://medium.com/ecliptical-software-inc/whats-your-crate-s-minimum-supported-rust-version-f5036248efd9?source=rss----a1e1a9ae03e7---4</link>
            <guid isPermaLink="false">https://medium.com/p/f5036248efd9</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cargo]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Peter Nehrer]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 05:34:16 GMT</pubDate>
            <atom:updated>2023-01-22T04:13:07.272Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*_yG8UYpxzgnz8EujkpSIJw.png" /></figure><p>You worked hard to build your Rust library. You followed best practices, took advantage of those expressive yet concise language constructs, pulled in rock-solid dependencies instead of reinventing the wheel…</p><p>Your library is useful; its API lean and to the point, generic where it makes sense. Even your unit test coverage is decent!</p><p>You’re ready to publish it for the world to enjoy.</p><p>But what version of Rust does it really require?</p><p>Maybe you’re one of those fearless explorers who live on <em>nightly</em>. Or maybe you use the latest <em>stable</em> but keep it up-to-date as soon as a new release comes out so you can take take advantage of those sweet-sweet goodies that just about every new version delivers!</p><p>Before Rust 1.56, you’d have to informally document the version that you <em>thought</em> was required; for example, the one that you used to build your crate, or retroactively determined by installing older versions of Rust. Your users would then have to follow this advice.</p><p>However, starting with version 1.56 Rust allows crate authors to specify their <a href="https://github.com/rust-lang/rfcs/blob/master/text/2495-min-rust-version.md">Minimum Supported Rust Version</a> as <a href="https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field">rust-version in Cargo.toml</a>.</p><p>Nice! Yet the original problem persists — what version should you enter into that field?</p><p>If you go with the version that you’re currently on, then it’s possible you’re unnecessarily forcing your users to that version or newer.</p><p>On the other hand, constraining yourself to an older version doesn’t bring much joy (unless of course you have a specific audience in mind).</p><p>Ready to dive into shell and whip up a for-loop to install every possible Rust version to see which one breaks the build?</p><p>Before getting overcome by despair, have a look at <a href="https://github.com/foresterre/cargo-msrv">cargo-msrv</a> — this little gem of a tool figures it all out for you!</p><p>First, install it like you would any other cargo subcommand; e.g.:</p><pre>cargo install cargo-msrv</pre><p>Then, let it determine which Rust version your crate <em>actually</em> requires based on your code <em>as well as</em> your dependencies:</p><pre>cargo msrv</pre><p>Et violà:</p><pre>Determining the Minimum Supported Rust Version (MSRV) for toolchain aarch64-apple-darwin<br>Using check command cargo check<br>Check for toolchain &#39;1.61.0-aarch64-apple-darwin&#39; succeeded<br>Check for toolchain &#39;1.58.1-aarch64-apple-darwin&#39; succeeded<br>Check for toolchain &#39;1.57.0-aarch64-apple-darwin&#39; succeeded<br>Check for toolchain &#39;1.56.1-aarch64-apple-darwin&#39; succeeded<br>   Finished The MSRV is: 1.56.1   ██████████████████████████████████████████████████████████████████████████████████████████████████████████ 00:00:45</pre><p>Not only that; it’ll also tell you <em>why</em> an earlier version would break the build! That way, you can decide if this is something that you can change or work around in order to support an older Rust version, thus potentially reaching a wider audience.</p><p>Once you’ve set your Cargo.toml’s rust-version to the recommended value, you can verify that it still holds as you continue developing your crate:</p><pre>cargo msrv verify</pre><p>The tool offers a lot more <a href="https://foresterre.github.io/cargo-msrv/">helpful features</a>.</p><p>Kudos to the <a href="https://github.com/foresterre">author</a> and thanks to all those who <a href="https://github.com/foresterre/cargo-msrv/graphs/contributors">contributed</a>; I was delighted to have discovered this very useful tool!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5036248efd9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ecliptical-software-inc/whats-your-crate-s-minimum-supported-rust-version-f5036248efd9">What’s your crate’s Minimum Supported Rust Version?</a> was originally published in <a href="https://medium.com/ecliptical-software-inc">Ecliptical Software Inc.</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Story of Rusty Containers, Queues, and the Role of Assumed Identity]]></title>
            <link>https://medium.com/ecliptical-software-inc/a-story-of-rusty-containers-queues-and-the-role-of-assumed-identity-3102a9ca4a3f?source=rss----a1e1a9ae03e7---4</link>
            <guid isPermaLink="false">https://medium.com/p/3102a9ca4a3f</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Peter Nehrer]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 05:33:58 GMT</pubDate>
            <atom:updated>2020-08-28T14:03:02.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*X3PP2t5rB6GKCVm2.jpg" /></figure><h3>How to access Amazon Web Services from Rust-based Kubernetes applications using Rusoto and IAM Roles for Service Accounts</h3><p>I made acquaintance with <a href="https://github.com/rusoto/rusoto">Rusoto</a> only recently, while building a Rust service that consumed messages from Amazon SQS. I was instantly impressed with this <em>AWS SDK for Rust</em> — well designed, modular, thoroughly documented, and even more comprehensive than typical AWS SDKs for other languages.</p><p>In order to set up my application to use SQS, all I had to do was add <a href="https://crates.io/crates/rusoto_core">rusoto_core</a> and <a href="https://crates.io/crates/rusoto_sqs">rusoto_sqs</a> crates to my Cargo.toml and create an instance of <a href="https://docs.rs/rusoto_sqs/0.45.0/rusoto_sqs/struct.SqsClient.html">SqsClient</a> for my target region. Even better, I could set it up with the <a href="https://docs.rs/rusoto_core/0.45.0/rusoto_core/enum.Region.html#default">default region</a>, which causes it to look for the configured region in the usual environment variables or profile configuration files:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22bcaff7844c380488bb9907e3b729d6/href">https://medium.com/media/22bcaff7844c380488bb9907e3b729d6/href</a></iframe><p>For my containerized application this was ideal, since in Kubernetes it would get its static configuration through environment variables anyway, and I could easily supply them when running locally:</p><pre>RUST_LOG=debug AWS_REGION=ca-central-1 QUEUE_URL=https://sqs.ca-central-1.amazonaws.com/1234567890/rusoto-sqs-k8s-demo cargo run</pre><h3>Supplying AWS credentials</h3><p>Similar to how it determines the desired service region, the default Rusoto client uses a <a href="https://rusoto.github.io/rusoto/rusoto_credential/struct.ChainProvider.html">discovery algorithm</a> to obtain its AWS credentials; it checks the environment variables, profile configuration files, and even the IAM instance profile if running on an EC2 instance.</p><p>If any of the supplied credentials are configured to expire periodically, this provider would even refresh them as needed!</p><p>As expected, running my code locally was a breeze, since the client used my default AWS profile credentials, which were granted access to the SQS queue that I had set up for testing. I tried sending a test message to my queue using AWS CLI:</p><pre>aws sqs send-message --queue-url https://sqs.ca-central-1.amazonaws.com/1234567890/rusoto-sqs-k8s-demo --message-body &#39;Hello world!&#39;</pre><p>Success! As my application’s debug log indicated, it was able to receive and process the message:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe18a73b5782fc250056d5f65d5c6552/href">https://medium.com/media/fe18a73b5782fc250056d5f65d5c6552/href</a></iframe><blockquote><em>In order to demonstrate the approach outlined in this article, I created a small </em><a href="https://github.com/ecliptical/rusoto-sqs-k8s-demo"><em>demonstration project</em></a><em> that’s available on GitHub. Most of the code snippets and log outputs in this article are taken from this project. Please note that it is very minimalistic, focusing on the subject at hand and glossing over other important aspects, such as error handling, testing, and deployment. It could even use a more efficient Docker build! Perhaps more on that in another article…</em></blockquote><h3>Detour: Kubernetizing your application</h3><p>Applications running in Kubernetes differ from typical CLI-based programs in a number of ways. For instance, they have different configuration and logging needs. Furthermore, they must support readiness and liveness probes, and gracefully shut down in response to the TERM signal. Finally, they must run in a Docker container.</p><h3>Logging</h3><p>Granted, log entries like the one shown earlier aren’t as human-readable as those generated by e.g., the <a href="https://crates.io/crates/pretty_env_logger">pretty_env_logger</a> crate; however, because they are JSON, they are easily consumable by various application monitoring tools.</p><p>For Kubernetes applications that use <a href="https://crates.io/crates/tokio">tokio</a> to implement asynchronous servers I typically reach for the <a href="https://crates.io/crates/tracing">tracing</a> and <a href="https://crates.io/crates/tracing-subscriber">tracing-subscriber</a> crates. This pair gives me the ability to use the <a href="https://crates.io/crates/log">log</a> crate as I normally would — for logging — as well as async-aware tracing, should the need arise. As a bonus, it provides JSON-formatted log output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/174e9517613fe4bf4cddd49f5353e2b2/href">https://medium.com/media/174e9517613fe4bf4cddd49f5353e2b2/href</a></iframe><h3>Configuration</h3><p>For better user experience with a CLI-based application, I would normally utilize a crate such as <a href="https://crates.io/crates/gumdrop">gumdrop</a> in order to support argument-based configuration. However, there is no need for that in Kubernetes as the application primarily receives its configuration through environment variables passed down to it through Docker, config maps mounted as files on filesystem volumes, or dynamically through an external service (e.g., Consul).</p><p>The <a href="https://crates.io/crates/config">config</a> create does the trick here — it supports these types of configuration sources while allowing me to read configuration values into a typed struct:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fc660dd3721dd2e9048d55b93f8ca39/href">https://medium.com/media/8fc660dd3721dd2e9048d55b93f8ca39/href</a></iframe><h3>Build info</h3><p>For easier debugging, I like to have the application log its current version at startup. This can be easily accomplished with the help of the <a href="https://crates.io/crates/built">built</a> crate, which projects various build-time data, such as the current git hash, into constants, which can in turn be used to create the version string:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4d0a3eee0ea460593beb42ee7d3caf5/href">https://medium.com/media/c4d0a3eee0ea460593beb42ee7d3caf5/href</a></iframe><h3>Readiness and liveness probes</h3><p>Kubernetes must be able to determine the health of each container in order to replace it in case the application runs into some unexpected trouble. To do that, the container can be configured with a readiness (checked upon startup) and a liveness probe (checked periodically), which tells Kubernetes when the container is ready to receive traffic as well as alive and healthy, respectively.</p><p>For the demo application, I chose a simple TCP connection probe — as long as the application accepts the controller’s connection request on the specified port, the probe is deemed successful:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f41da1351c7a791f4d7416ef9d0935c/href">https://medium.com/media/7f41da1351c7a791f4d7416ef9d0935c/href</a></iframe><h3>Signals</h3><p>It’s a good practice to have your application handle POSIX signals, especially the TERM signal, which the container host sends to the application upon graceful shutdown. The application should use that opportunity to finish processing any outstanding requests and clean up any open resources:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a48b96af80a390ea0439c7a72ae24e18/href">https://medium.com/media/a48b96af80a390ea0439c7a72ae24e18/href</a></iframe><h3>Docker build</h3><p>In order to run in Kubernetes, the application must be packaged as a Docker image. One of the easiest way to accomplish this is to create a multi-stage Dockerfile using <a href="https://github.com/emk/rust-musl-builder">Rust MUSL Builder</a> to build the application and <a href="https://www.alpinelinux.org/">Alpine Linux</a> as the base of the target image.</p><p>Rust MUSL Builder comes pre-installed with the desired Rust toolchain. Furthermore, it produces statically-linked builds, which comes in handy when running the binaries in Alpine Linux.</p><p>After verifying the formatting, running clippy, unit tests, and finally the release build (with the desired maximum logging level), the target binary is copied into Alpine Linux:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77d47bfcfa391d432c5ff30cda7dcca3/href">https://medium.com/media/77d47bfcfa391d432c5ff30cda7dcca3/href</a></iframe><p>Lastly, for better process handling, I recommend installing <a href="https://github.com/krallin/tini">tini</a> and having it spawn the actual application process:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/167dd80d130e4fdf1d8f26cd938562e5/href">https://medium.com/media/167dd80d130e4fdf1d8f26cd938562e5/href</a></iframe><p>Finally, running the build takes a good while:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed466d5c0c885ba38da7f9f471d19fd9/href">https://medium.com/media/ed466d5c0c885ba38da7f9f471d19fd9/href</a></iframe><h3>Deploying into Kubernetes</h3><p>After the resounding success of the application’s trial run on my laptop, I was ready to press ahead and deploy it into Kubernetes!</p><p>Your organization’s approach for deploying applications into Kubernetes will likely vary. For instance, one might use the Amazon Elastic Container Registry (ECR) to host the Docker images, and <a href="https://helm.sh/">Helm</a> to simplify the various deployment descriptors and the actual roll-out procedures. However, for demonstration purposes a <a href="https://github.com/features/packages">GitHub Package Registry</a> and plain Kubernetes deployment descriptors applied using kubectl will suffice.</p><h3>Docker registry</h3><p>To allow Kubernetes to deploy a Docker container, it must be able to download the specified image from a Docker registry. For the demo project, I set up a GitHub Package Registry at docker.pkg.github.com/ecliptical/rusoto-sqs-k8s-demo and pushed the tagged build into it:</p><pre>docker tag ecliptical/rusoto-sqs-k8s-demo docker.pkg.github.com/ecliptical/rusoto-sqs-k8s-demo/rusoto-sqs-k8s-demo:v1 docker push docker.pkg.github.com/ecliptical/rusoto-sqs-k8s-demo/rusoto-sqs-k8s-demo:v1</pre><p>Hopefully, your organization’s CI/CD system takes care of running the build and pushing it to the Docker registry!</p><h3>Deployment descriptor</h3><p>In order to deploy the application into Kubernetes, kubectl needs a deployment.yaml file that describes the various aspects of the deployment, including the containers and their configuration. This is where you supply static values for the various environment variables either directly or as secrets. In practice, these are often managed by the SRE team or other authorized personnel:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d90a840c543f50c050891b9c7fbc972/href">https://medium.com/media/2d90a840c543f50c050891b9c7fbc972/href</a></iframe><h3>Secrets</h3><p>For the above deployment descriptor to work, there must a be a special regsecret and a generic rusoto-sqs-k8s-demo-secrets secret set up in the target namespace. For the demo, you can create the former like so (after replacing your GitHub credentials):</p><pre>AUTH=$(echo -n YOUR_GITHUB_USERNAME:YOUR_GITHUB_API_TOKEN | base64)</pre><pre>echo &#39;{&quot;auths&quot;:{&quot;docker.pkg.github.com&quot;:{&quot;auth&quot;:&quot;&#39;${AUTH}&#39;&quot;}}}&#39; | kubectl create secret -n demo generic regsecret --type=kubernetes.io/dockerconfigjson --from-file=.dockerconfigjson=/dev/stdin</pre><p>And the latter (partially):</p><pre>kubectl -n demo create secret generic rusoto-sqs-k8s-demo-secrets --from-literal=queue_url=https://sqs.ca-central-1.amazonaws.com/1234567890/rusoto-sqs-k8s-demo</pre><p>For the actual application I asked the Operations Team to kindly set up the registry secret and issue a new set of AWS credentials for my new-fangled application with relevant permissions for the SQS queue in question…</p><h3>Not so fast!</h3><p>It turns out that issuing static AWS credentials (that is, the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY pair) to Kubernetes applications isn&#39;t a great idea! The preferred way is to have the application assume a designated IAM role, which can then be granted various permissions as needed. In contrast to access-key based credentials, which are issued to a user, IAM roles may be scoped specifically to the set of permissions that the application needs, thus improving your system&#39;s security posture through the principle of least privilege.</p><p>For “classic” applications running in EC2, this can be done through IAM instance profiles.</p><p>But what about Kubernetes?</p><h3>Fine-grained IAM Roles for Service Accounts</h3><p>Luckily, Kubernetes applications can take advantage of <a href="https://aws.amazon.com/id/blogs/opensource/introducing-fine-grained-iam-roles-service-accounts/">fine-grained IAM roles for service accounts</a>. This approach combines Kubernetes’ Role-Based Access Control (RBAC) with Amazon’s Identity and Access Management (IAM). The details of this mechanism are somewhat involved — it takes advantage of the fact that Kubernetes can issue <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#service-account-token-volume-projection">projected service account tokens</a> for pods. Since these are valid OIDC JWTs, Amazon’s Secure Token Service (STS) can use them for authentication thanks to its support for <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html">OIDC federation</a>. Thus, a Kubernetes pod with a specific service account may be linked to an IAM role through STS. This ends up being relatively straightforward particularly in Amazon’s Elastic Kubernetes Service (EKS), since its control plane takes care of automatically provisioning, injecting, and periodically updating the necessary environment variables and projected filesystem volume. However, the same web-hook based mechanism can be implemented in other environments.</p><p>The bottom line — with a little bit of additional Kubernetes configuration, my application can get access to automatically managed, periodically refreshed AWS credentials.</p><h3>Creating IAM role</h3><p>Your organization’s policies will likely determine how to go about provisioning an IAM role for your application. For this demo, you can just use the AWS CLI:</p><pre>aws iam create-policy --policy-name RusotoSQSK8sDemoConsumer --policy-document &#39;{&quot;Version&quot;: &quot;2012-10-17&quot;, &quot;Statement&quot;: [{&quot;Effect&quot;: &quot;Allow&quot;, &quot;Action&quot;: [&quot;sqs:DeleteMessage&quot;, &quot;sqs:GetQueueUrl&quot;, &quot;sqs:ChangeMessageVisibility&quot;, &quot;sqs:DeleteMessageBatch&quot;, &quot;sqs:ReceiveMessage&quot;, &quot;sqs:GetQueueAttributes&quot;, &quot;sqs:ChangeMessageVisibilityBatch&quot;], &quot;Resource&quot;: [&quot;arn:aws:sqs:*:1234567890:*&quot;]}]}&#39;</pre><p>This creates a RusotoSQSK8sDemoConsumer role with enough permissions to receive and process messages in any SQS queue in the given account.</p><h3>OIDC provider setup</h3><p>Depending on your particular environment, the steps for setting up an Open ID Connect provider for your Kubernetes cluster will vary. If using EKS, you can create the provider and configure your cluster to use it in one step with the help of <a href="https://eksctl.io/">eksctl</a>:</p><pre>eksctl utils associate-iam-oidc-provider --cluster rusoto-sqs-demo --approve<br>[ℹ] eksctl version 0.26.0<br>[ℹ] using region ca-central-1<br>[ℹ] will create IAM Open ID Connect provider for cluster &quot;rusoto-sqs-demo&quot; in &quot;ca-central-1&quot;<br>[✔] created</pre><h3>Kubernetes service account</h3><p>Next, you need a Kubernetes service account annotated with the ARN of the previously provisioned IAM role, which you can then assign to your application pods.</p><p>Here again, eksctl makes this process a one-step operation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c305ee44dd334f026dee3cdf083f1321/href">https://medium.com/media/c305ee44dd334f026dee3cdf083f1321/href</a></iframe><h3>Deployment descriptor changes</h3><p>Finally, you can incorporate the required changes into your pods’ deployment descriptor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ca0e865a95e87468e2c74fef5a0f169/href">https://medium.com/media/9ca0e865a95e87468e2c74fef5a0f169/href</a></iframe><p>Two sets of changes stand out:</p><ol><li>You no longer need the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables -- they&#39;ve been removed.</li><li>The serviceAccountName property has been added specifying the desired service account name, and a securityContext section with the fsGroup property -- this instructs Kubernetes to mount filesystem volumes with user nobody as their owner (id 65534 in Linux), thus allowing the unprivileged application process to read the automatically injected web token file.</li></ol><p>All in all, when the pod is deployed, the EKS control plane will automatically inject two new environment variables and mount a new filesystem volume containing the periodically refreshed OIDC JWT:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b47810569dae7e8da561e7df48385609/href">https://medium.com/media/b47810569dae7e8da561e7df48385609/href</a></iframe><h3>Rusoto credentials, revisited</h3><p>One outstanding issue remained — how is the application going to find and use these injected credentials?</p><p>Rusoto is quite flexible — the <a href="https://crates.io/crates/rusoto_credential">rusoto_credential</a> crate allows me to implement my own credential providers, which could obtain and refresh my application’s AWS credentials from an arbitrary external source. With this in mind I set out to investigate what it would take to read the injected AWS_WEB_IDENTITY_TOKEN_FILE and call STS&#39;s AssumeRoleWithWebIdentity to exchange the OIDC JWT for AWS role credentials. Whew!</p><p>Invariably, the trail of breadcrumbs lead me to the <a href="https://crates.io/crates/rusoto_sts">rusoto_sts</a> crate, which exposes the Amazon STS API. As I said before, Rusoto is modular and doesn’t force you to package code that you won’t need. After perusing the documentation for a bit in order to devise my plan of attack, there — sitting unassumingly at the end of the list of exported structs — I found the <a href="https://docs.rs/rusoto_sts/0.45.0/rusoto_sts/struct.WebIdentityProvider.html">WebIdentityProvider</a>.</p><p>I couldn’t believe my luck!</p><p>With a <a href="https://docs.rs/rusoto_sts/0.45.0/rusoto_sts/struct.WebIdentityProvider.html#method.from_k8s_env">single method call</a> I could simply instantiate a different kind of credentials provider that would read the injected environment variables and files and make the appropriate STS calls to authenticate my AWS API calls:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9ed5c46a8b64963ae85145d2a59ed39/href">https://medium.com/media/a9ed5c46a8b64963ae85145d2a59ed39/href</a></iframe><h3>Onward into Kubernetes, this time for real</h3><p>With all required changes finally in place, and the Docker image rebuilt and pushed into the registry, I was finally able to deploy the application. For the demo application, the equivalent procedure would simply be:</p><pre>kubectl apply -f deployment.yaml deployment.apps/rusoto-sqs-k8s-demo created</pre><p>After receiving similarly positive yet rather anti-climactic output, I tailed the pods’ logs to see if another test message sent to the target SQS queue would be picked up:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5ddbd669f40fcc67d302f2f53210a41/href">https://medium.com/media/d5ddbd669f40fcc67d302f2f53210a41/href</a></iframe><p>Sweet victory!</p><h3>Have your token-based identity and eat it, too</h3><p>Ultimately, I decided to support both injected and static AWS credentials in order to make it easier to run the app locally. If the injected credentials are available, then let’s use those:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7c389f25b9ac4b82c13f1f07575bebf/href">https://medium.com/media/a7c389f25b9ac4b82c13f1f07575bebf/href</a></iframe><h3>Conclusion</h3><p>Even with Kubernetes at the helm, navigating the cloudy skies can become an arduous endeavor, especially when faced with complex, sensitive issues such as application security and controlling access to AWS resources.</p><p>Thankfully, Rusoto provides an easy way to tap into Amazon’s support for IAM roles for Kubernetes service accounts, which bridge the Kubernetes and AWS worlds in terms of security and access control.</p><p>I am grateful for and continue to be amazed by all the generous contributions of the open-source Rust community, which make it possible for me and many others to build applications using this powerful, modern language platform.</p><p>To follow the examples in this article please see the <a href="https://github.com/ecliptical/rusoto-sqs-k8s-demo">accompanying project on GitHub</a>.</p><p>Splash photo by <a href="https://unsplash.com/@nessa_rin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Rinson Chory</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><p><em>Originally published at </em><a href="https://dev.to/pnehrer/a-story-of-rusty-containers-queues-and-the-role-of-assumed-identity-kl2"><em>https://dev.to</em></a><em> on August 26, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3102a9ca4a3f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ecliptical-software-inc/a-story-of-rusty-containers-queues-and-the-role-of-assumed-identity-3102a9ca4a3f">A Story of Rusty Containers, Queues, and the Role of Assumed Identity</a> was originally published in <a href="https://medium.com/ecliptical-software-inc">Ecliptical Software Inc.</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Curious Tale of Rust TLS and Postgres in the Cloud]]></title>
            <link>https://medium.com/ecliptical-software-inc/a-curious-tale-of-rust-tls-and-postgres-in-the-cloud-969a4d2bea9?source=rss----a1e1a9ae03e7---4</link>
            <guid isPermaLink="false">https://medium.com/p/969a4d2bea9</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[tokio]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Peter Nehrer]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 05:33:25 GMT</pubDate>
            <atom:updated>2020-08-03T01:02:12.405Z</atom:updated>
            <content:encoded><![CDATA[<p>How to Connect Securely to Amazon RDS for PostgreSQL using Tokio and Rustls</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NPjvgSAg4rBzSKOl" /><figcaption>Photo by <a href="https://unsplash.com/@pawel_czerwinski?utm_source=medium&amp;utm_medium=referral">Paweł Czerwiński</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Recently I ran into a curious problem while working on a piece of asynchronous database code for a micro-service written in Rust — it looked something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f3bf86ef8cafbe070d754cfe7d87d03/href">https://medium.com/media/6f3bf86ef8cafbe070d754cfe7d87d03/href</a></iframe><p>This particular module used <a href="https://crates.io/crates/tokio-postgres">Tokio Postgres</a> along with <a href="https://crates.io/crates/deadpool-postgres">Deadpool Postgres</a> — part of my favorite Rust stack — to interact with an AWS RDS for PostgreSQL database. Of course, everything worked great when I ran it against a Postgres instance deployed in my local Docker container — the Deadpool documentation contains <a href="https://docs.rs/deadpool-postgres/0.5.6/deadpool_postgres/index.html#example-with-config-and-dotenv-crate">easy-to-follow examples</a> that can get you going in minutes.</p><p>I knew I’d have to support connecting to the database securely in order to deploy the code to production — the deployment policy requires (as it should!) that all connections to RDS instances use TLS. By default, the Tokio Postgres crate supports plain-text connections to help you get started, but luckily also outlines <a href="https://docs.rs/tokio-postgres/0.5.5/tokio_postgres/index.html#ssltls-support">steps to enable TLS</a>.</p><p>To be honest, I was a bit crestfallen when I didn’t see <a href="https://crates.io/crates/rustls">Rustls</a> listed as one of the supported methods; only (effectively) OpenSSL. After all, there are <a href="https://www.zdnet.com/article/a-rust-based-tls-library-outperformed-openssl-in-almost-every-category/">many good reasons</a> to use Rustls, in addition to the fact that it was already part of my stack (e.g., both <a href="https://crates.io/crates/reqwest">Reqwest</a> and <a href="https://crates.io/crates/warp">Warp</a> support it) and would allow me to crank out <a href="https://github.com/emk/rust-musl-builder">statically linked binaries</a> more easily.</p><p>Never fear — the amazing Rust community has your back! A quick search through <a href="https://crates.io/">crates.io</a> produced the <a href="https://crates.io/crates/tokio-postgres-rustls">tokio-postgres-rustls</a> crate, which was exactly what I needed; after a small addition to my configuration and database connection pool setup, I was on my way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59cda883dc0c1996043eb81148b41b01/href">https://medium.com/media/59cda883dc0c1996043eb81148b41b01/href</a></iframe><h3>Reality Bites</h3><p>As luck would have it, after pointing my Postgres client configuration to the RDS instance, I was met with the unpleasant surprise I had mentioned earlier — <strong>BadCertificate</strong> error! Wha… wha… whad’ya MEAN??</p><p>I must admit — in all my excitement I only skimmed through tokio-postgres-rustls documentation, and didn’t even peek at rustls, since the basic configuration example happened to compile just fine (yikes!). After a stern mental self-admonishment I carefully scanned Rustls’s <a href="https://docs.rs/rustls/0.18.0/rustls/index.html#getting-started">Getting Started</a> example and sure enough, I discovered that I may have missed a step:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6f896d1cc8a1d04ba87e7d85130ed02/href">https://medium.com/media/c6f896d1cc8a1d04ba87e7d85130ed02/href</a></iframe><p>Of course! Rustls (probably) doesn’t come with any pre-configured root certificates! That would make sense — Rust libraries tend to defer use-case-specific decisions to the user — why include files/bytes that may not even be needed?</p><h3>Take Two</h3><p>Ok — new dependency included, Mozilla’s trusted root certificates added. That must have been the problem! Alas, the same error:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f3bf86ef8cafbe070d754cfe7d87d03/href">https://medium.com/media/6f3bf86ef8cafbe070d754cfe7d87d03/href</a></iframe><p>“This means war!”, I thought to myself. Rather, it meant that I had to read the documentation more carefully — a little bit of sleuthing revealed that AWS utilized their own/separate <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html">root certificates</a> for their RDS instances. This, it turns out, is also helpfully indicated in the database instance details in RDS console — if you know what to look for!</p><figure><img alt="Certificate authority rds-ca-2019" src="https://cdn-images-1.medium.com/max/600/1*AwxObkCxLq-hCEyHKwc03w.png" /><figcaption>Clipping of the Connectivity &amp; security section</figcaption></figure><h3>Third Time’s a Charm</h3><p>After downloading the <a href="https://s3.amazonaws.com/rds-downloads/rds-ca-2019-root.pem">requisite root certificate</a> and adding it to my database pool’s TLS configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ffc6da781e40e06073890e7cd391d4c/href">https://medium.com/media/6ffc6da781e40e06073890e7cd391d4c/href</a></iframe><p>Success!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2249ec1624f522abdb94ac90a0d2b65c/href">https://medium.com/media/2249ec1624f522abdb94ac90a0d2b65c/href</a></iframe><h3>Conclusion</h3><p>There are many great libraries that help you build modern micro-services and native cloud applications in Rust. If you ever find yourself working with PostgreSQL, use Tokio Postgres with Deadpool to build responsive, scalable applications with Rust’s powerful asynchronous constructs.</p><p>To secure your client connection, use Rustls; however, make sure it is configured properly either with <a href="https://crates.io/crates/webpki-roots">Mozilla’s trusted root certificates</a> or your service provider’s own root certificates!</p><p>To try the approach outlined in this article, check out the demo project <a href="https://github.com/ecliptical/tokio-postgres-rustls-rds-demo">hosted on GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=969a4d2bea9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ecliptical-software-inc/a-curious-tale-of-rust-tls-and-postgres-in-the-cloud-969a4d2bea9">A Curious Tale of Rust TLS and Postgres in the Cloud</a> was originally published in <a href="https://medium.com/ecliptical-software-inc">Ecliptical Software Inc.</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>