<?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 Alex Collier on Medium]]></title>
        <description><![CDATA[Stories by Alex Collier on Medium]]></description>
        <link>https://medium.com/@devopsdropin?source=rss-d93ec337be4d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Alex Collier on Medium</title>
            <link>https://medium.com/@devopsdropin?source=rss-d93ec337be4d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:18:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devopsdropin/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[Transitioning to AWS CDK]]></title>
            <link>https://medium.com/version-1/transitioning-to-aws-cdk-305a5a27f59a?source=rss-d93ec337be4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/305a5a27f59a</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cdk]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Alex Collier]]></dc:creator>
            <pubDate>Wed, 11 May 2022 14:24:21 GMT</pubDate>
            <atom:updated>2022-05-31T09:57:28.923Z</atom:updated>
            <content:encoded><![CDATA[<p>It is often said that</p><blockquote>It is the journey, not the destination that matters</blockquote><p>but to my mind, this expression overlooks the question of where the journey <em>starts</em>. When we talk of a transition similarly, the focus is often on the endpoint. Start typing ‘transitioning’ into a Google search, and matches like ‘… to grey hair’ or ‘… baby to own room’ appear near the top of the suggestions — the starting point is assumed, self-evident or, possibly, irrelevant. So when we talk of transitioning to CDK, where might we suppose we started our journey?</p><figure><img alt="narrow path through dark forest" src="https://cdn-images-1.medium.com/max/412/1*lnyJseg5aeo-rawJ9Cp43w.png" /></figure><p>My own DevOps path had emerged from the shady forests of Bourne Shell scripting and JumpStart deployments on Solaris into the sunny uplands of RedHat Enterprise Linux and its open-source stablemates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/0*cssdS5NL5wa7ahx8" /></figure><p>RedHat were actively promoting Ansible at this point and as an avid fan of automation and scripting I set about seeing what it could do. I gradually fell in love with Ansible’s simplicity, power and flexibility, applying it to more and more infrastructure components at the hosting provider where I then worked, a task made easier by the availability of a vast array of technology-specific extensions, found either in the core modules or from community-contributed content.</p><blockquote>Want a summary of the port utilisation across network gear from three different vendors? <em>Ansible and jinja2 will see you right.</em></blockquote><blockquote>Want to run a Proof of Concept of a clustered application on VMWare then deploy the application and its pre-requisites <em>in exactly the same way</em> on physical hardware? <em>Ansible roles will do it for you.</em></blockquote><p>It was not until I turned Ansible’s attention in the direction of the Public Cloud (AWS in this case) that I started to see that there may be gaps in its capabilities. It is great at making and managing individual components, but it struggles to cope as the scale and complexity of the managed estate start to rise. The inventory is one of the key facets of Ansible — it tells Ansible what it is managing, how to log into it and what sub-groupings exist within it. When you enter a world where you can launch a thousand virtual instances at a keystroke, control of your inventory becomes crucial, but this is something that Ansible did not manage smoothly. Run a playbook to launch ten EC2 instances, and it will happily do it. Re-run the same playbook with the instance count set to 15 and you get <em>another</em> 15 instances. This is because there is no state management and no recording of the individual unique identifiers (ARNs, UUIDs and so on) of the components which get deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*7FwNLhOnekAY65pT" /></figure><p>As I stood there ankle-deep in the squelchy bogland at the borders of Ansible and Public Cloud, I spied in the near distance the welcoming landscape of the realm of Terraform. This was to be my next stopping off point and during my 12-month stay, I came to truly appreciate the benefits of a provisioning tool over a configuration management tool when it came to deploying Public Cloud infrastructure (AWS again). With Ansible, you specified a set of states that you wanted to exist and to achieve that state things were created, destroyed or changed <em>in the order specified</em>.</p><p>As I alluded to previously, Terraform does <em>provisioning</em> and in that respect sits alongside tools such as CloudFormation and OpenStack. You specify a state that you wish your infrastructure to attain using Terraform’s own declarative language. Terraform then figures out what it needs to change to make that state a reality. It interrogates and stores the state of the infrastructure, compares that with the state defined in the code base, forms a plan of any required changes and then applies them. If there is no solution, or an error occurs, it digs in its heels and no plan is produced. No plan, no changes.</p><p>Terraform shares with Ansible the facility of using parameters or variables to define important, recurring values. It is this approach that enables us to guarantee that the same inbound TCP port is consistently open on the Network Access Control List, the Security Group, the host firewall and the web server listener. Terraform is very focused on reusability and the concept of keeping code “DRY” (<strong>D</strong>on’t <strong>R</strong>epeat <strong>Y</strong>ourself), and parameters figure largely here also. Code is written as modules and generally forms one repo; different sets of parameters, stored in the separate “live” repo, can then be fed to the same modules to produce separate but similar infrastructure — Dev/QA/Production, or Customer A, B &amp; C for example — all from one code base. Modules can be invoked from a central repository at the Terraform Registry, allowing control of most current Cloud providers. Bespoke modules stored in a version-controlled repository, allow different versions to be deployed to specific environments based on Git tags or Semantic Versioning. Terraform can be paired up with Terragrunt to help with the management of the configuration or “live” code tree and to assist in assembling and running all the required modules in one place.</p><p>If you want to do lower-level configuration, such as setting EC2 user-data, then there is a mechanism available, but it is essentially limited to crafting a multi-line string variable with placeholders for your parameters and squirting this into the EC2 deployment configuration. This contrasts with what you can do with Ansible, which has a whole arsenal of operating systems and application configuration options at its disposal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/0*il8N_eJcjI6-yj1f.png" /></figure><p>Now, glittering on the horizon I spy AWS CDK, a land of novelty and promise. Many languages are used in CDK, but they are familiar, everyday languages used by developers the world over. If you are fortunate enough to be strong in one of these languages, that is a big help. I had none of them to any degree and plunged in with TypeScript, a strongly-typed reworking of JavaScript. The joy of using a programming language as the basis for your provisioning is that it is very powerful, but it conversely means that you are limited by any lack in your own knowledge of that language. Many IDEs help out with TypeScript — Atom and VS Code, to name but two, have good error correction and auto-complete functionality.</p><p>The CDK approach is similar to Terraform, but you describe the infrastructure you want in the language of your choice using pre-defined building blocks called constructs and all configuration and control have to be done via AWS CloudFormation. A package manifest (package.json) defines which packages are needed for development and deployment and there are mechanisms to go and fetch them automatically from a repository. CDK sits on top of Node.js, which does all the package management using Node Package Manager (npm), so an understanding of that technology and JavaScript generally is useful. Under the covers, your code is <em>transpiled </em>into JavaScript and a plan is constructed that will produce your desired configuration. There are handy sub-commands that allow you to see how your desired state differs from reality and what the CloudFormation change set will look like. As with Terraform, user-data configuration is a concept, but the mechanism is similarly simplistic.</p><p>All the heavy lifting around state management is done inside CloudFormation, so as a developer you just need access to the code repo and the NPM library. Once your code is deployed, in a pipeline for example, NPM can go and fetch the required dependencies, so you don’t need to amass a vast code blob in your workspace, as can be the case with Terraform, especially when it has its friend Terragrunt round to play. Unlike Terraform, CDK does not appear to keep track of the unique identifiers of the resources that it deploys. If you change the name of a resource in your code, for example, it does not rename the existing resource, but rather pops out a new resource with the new name, the original resource becoming detached.</p><p>Getting started with coding for CDK is pretty straightforward. Running <strong>cdk init</strong> will lay out a directory structure for your chosen language and will even install a sample application to show you the true path. An application defines one or more stacks; each stack references one or more constructs and the constructs roll out the resources. Built-in classes and constructs can be extended and adapted to make your own, reusable components, helping to keep your code D.R.Y.</p><p>Whilst you can create everything in one <em>.ts</em> file, the typical layout, as exemplified in CDK’s sample app, encourages a modular design, with a <em>lib </em>directory containing your resource definitions and a top-level stack definition file that imports the CDK constructs that you need (<em>aws-s3, aws-lambda</em> etc) as well as any of your own sub-components. Self-contained components such as blobs of Lambda or file assets can be stashed in a <em>resources </em>or <em>lambda </em>directory for referencing elsewhere in the codebase. Your application is launched from an “executable” in the <em>bin </em>directory, which assembles application inputs from the environment, the command line arguments and configuration files and launches the application, as transpiled JavaScript, via the top-level stack file.</p><p>An interesting feature of CDK is its ability to test itself on whether the code fulfils the brief, i.e. whether the synthesized stack will contain the required components. This functionality leverages the <em>jest </em>JavaScript testing tool, so can be very complex if required. It is set up via the <em>test </em>directory and will typically be used for tests such as verifying that the right number of DynamoDB tables will be deployed, or that specific configuration parameters will be passed to your stack. Running the tests does not require the installation of any external tools, such as might be the case with Terraform and Terratest — it is done simply by running <strong>npm run test.</strong></p><p>So is CDK worth the upskilling effort involved? If you are competent in one of its configuration languages, it is certainly worth exploring. Even if you are not, AWS are pushing CDK pretty hard since it featured at re:Invent 2020 and TypeScript is now starting to work its way up the popularity charts [<a href="https://pypl.github.io/PYPL.html">PYPL PopularitY of Programming Language index</a>].</p><p>If you fancy giving CDK a try, there is a great starter resource at <a href="https://cdkworkshop.com/">cdkworkshop.com</a>. It may be the thing for you, so drop by and have a wander around. As Lao Tzu puts it:</p><blockquote>A journey of a thousand miles starts with a single step</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*4MRay5OEvTqx8VJ7uwJ4Tg.png" /></figure><p><a href="https://quoteinvestigator.com/2012/08/31/life-journey/">https://quoteinvestigator.com/2012/08/31/life-journey/</a></p><p><strong>About the Author:<br></strong>Alex is an AWS DevOps Engineer here at Version 1.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=305a5a27f59a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/version-1/transitioning-to-aws-cdk-305a5a27f59a">Transitioning to AWS CDK</a> was originally published in <a href="https://medium.com/version-1">Version 1</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[EC2 Metadata — Evil or Genius]]></title>
            <link>https://medium.com/version-1/ec2-metadata-evil-or-genius-1abf73525d80?source=rss-d93ec337be4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1abf73525d80</guid>
            <category><![CDATA[aws-ec2]]></category>
            <dc:creator><![CDATA[Alex Collier]]></dc:creator>
            <pubDate>Mon, 12 Jul 2021 17:30:10 GMT</pubDate>
            <atom:updated>2021-07-29T08:36:53.963Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>EC2 Metadata — Evil or Genius</strong></h3><p>Regular listeners to BBC Radio 4 may be familiar with the “Evil Genius” series, in which Russell Kane, assisted by a panel of expert and celebrity guests, weighs iconic figures in the balance to establish whether they were truly evil or truly genius.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*f6HjiH2CJvItz7G4Y-6Jmw.jpeg" /><figcaption>Evil Genius, courtesy of the BBC</figcaption></figure><p>I would like to pick up that idea and run with it for a while, but apply it to something a little closer to home for your run-of-the-mill IT folk — the metadata available in an AWS EC2 instance.</p><p>Before delving into the technical ins and outs of EC2 metadata, let us first look at what metadata is, in general terms. The prefix ‘meta-‘ is derived from the Greek word meaning ‘after’ or ‘beyond’, and came to prominence in terms such as ‘metamathematics’ and ‘metaphysics’ to denote a field of study of the underlying base subject. <em>Meta-</em> has sprawled impressively into many parts of the English language to mean anything that is ‘about’ something else, giving us meta-<em>rules</em> (rules about the application of rules), meta<em>programming</em> (where programs feed on other programs), but not Metaxa, which is a half-decent Greek brandy. Meta<em>data</em> then, is data about data; the author and date of publication of a book, for example, with the contents of the book being the data itself, or is that <em>themselves</em> what with <em>data</em> being a plural? Hello, fellow nit-pickers.</p><p>Enough of these <em>amuse-bouches</em>, let us get our teeth into the main course — EC2 metadata, what is it, what can we use it for and most importantly, is it evil or genius?</p><h4>What is it?</h4><p>It’s data <em>about</em> your EC2 instances (of course, we guessed that from the long-winded explication above, right?), accessible inside each instance and provided by the instance metadata service (IMDS). You can access the metadata by “browsing” to <a href="http://169.254.169.254/latest/metadata/">http://169.254.169.254/latest/metadata/</a> from within your instance. This will return a list of categories that you can drill down into to reveal all sorts of interesting stuff about your instance that is not immediately available from within the operating system itself. With that in mind let us move on to look at…</p><h4>What can we do with it?</h4><p>Want to know the public IP address of your instance without looking it up on the console?</p><blockquote>curl <a href="http://169.254.169.254/latest/metadata/public-ipv4">http://169.254.169.254/latest/metadata/public-ipv4</a> will tell you what you want to know.</blockquote><p>What AMI did I use to launch this instance?</p><blockquote>curl <a href="http://169.254.169.254/latest/metadata/ami-id">http://169.254.169.254/latest/metadata/ami-id</a> is your friend.</blockquote><p>Did I really launch my instance in Bahrain?!</p><blockquote>curl <a href="http://169.254.169.254/latest/metadata/placement/availability-zone">http://169.254.169.254/latest/metadata/placement/availability-zone</a> will set your mind at rest.</blockquote><p>“That seems like a lot of information to have lying around”, I hear you say. “Is it secure?”. Well the answer is yes and no, which might have been anticipated from the tone of this post.</p><h4>Evil or Genius?</h4><p>It might be assumed that a URL that is only accessible on a private, local address would be secure, however, if we imagine a scenario where the instance is running a service which is presented to the outside world, things become a little less clear-cut. Enter … <em>Server-Side Request Forgery</em>, or SSRF for short. SSRF is a means of forcing an application to make a call to a system or service that it was not designed to, usually with undesirable consequences. It is often exploited in connection with a web application carrying out import or export operations, such as sending a printable report in PDF or uploading an image. If the application does not carry out sufficient checks on the type and endpoint of such transfers, then they can be exploited to retrieve information that should not normally be visible.</p><p>In mid-2019, just such an exploit was carried out against Capital One, resulting in the leakage of personal details for 100 million existing customers and prospective cardholders. The attacker, who had a bona fide Capital One online account, noticed that the process to upload and preview a custom image for printing to your new credit card made use of an AWS S3 bucket, the URL of which was specified as a sub-component of the upload-image URL. By crafting a new “sub-URL” which pointed instead to the application instance’s metadata source, she was able to syphon off the instance’s IAM Role access keys and then use these to access and scan a large number of S3 buckets, downloading personal information on millions of people. This breach has been modelled by Kontra as an instructional exercise: <a href="https://application.security/free-application-security-training/server-side-request-forgery-in-capital-one">Capital One SSRF | Kontra</a>, allowing you to step into the shoes of the hacker responsible and gain a better understanding of how the vulnerability was discovered and exploited.</p><p>In and of itself then, Instance Metadata seems reasonably secure and is demonstrably useful. Add a sloppily-constructed application into the mix, one which does not check its inputs and outputs thoroughly, and suddenly metadata is sliding into a dark place.</p><p>Depending on how secure you want things to be, a number of options present themselves.</p><p>At the most extreme, the instance metadata service can be simply disabled.</p><p>If you still have a requirement for metadata, a newer, more secure flavour, cunningly called IMDSv2 is available. Using it allows you to block access to the older, less secure version and use a time-bound, token-based access method. Essentially you ‘unlock’ an instance metadata session for a fixed period of time (between one second and six hours), do what you need to do, and IMDS access stops working when the token expires. For details, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#configuring-instance-metadata-options">Configure the instance metadata service — Amazon Elastic Compute Cloud</a></p><p>Or stick with good old IMDSv1 and use an application with no security flaws. Simple.</p><p><strong>About the Author</strong></p><p><em>Alex Collier is currently a </em>DevOps Cloud Engineer<em> at Version 1.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*IPtCfrozo28XPE1IfovYeQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1abf73525d80" width="1" height="1" alt=""><hr><p><a href="https://medium.com/version-1/ec2-metadata-evil-or-genius-1abf73525d80">EC2 Metadata — Evil or Genius</a> was originally published in <a href="https://medium.com/version-1">Version 1</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>