<?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 drew jess on Medium]]></title>
        <description><![CDATA[Stories by drew jess on Medium]]></description>
        <link>https://medium.com/@hybby?source=rss-5dc4be744d5f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*24WViRhaSMx-0KasoQh3DA.jpeg</url>
            <title>Stories by drew jess on Medium</title>
            <link>https://medium.com/@hybby?source=rss-5dc4be744d5f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:43:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hybby/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[AWS AutoScalingPlans, RollingUpdates and CloudFormation]]></title>
            <link>https://medium.com/@hybby/aws-autoscalingplans-rollingupdates-and-cloudformation-49f56c153fcb?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/49f56c153fcb</guid>
            <category><![CDATA[rolling-updates]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[asg]]></category>
            <category><![CDATA[scaling-plans]]></category>
            <category><![CDATA[autoscaling]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Mon, 18 May 2020 19:06:00 GMT</pubDate>
            <atom:updated>2020-05-18T19:06:00.984Z</atom:updated>
            <content:encoded><![CDATA[<p>We’ve been exploring the world of <a href="https://docs.aws.amazon.com/autoscaling/plans/userguide/auto-scaling-getting-started.html">AWS AutoScaling Plans</a> recently. Being captivated by the tasty-looking <a href="https://aws.amazon.com/blogs/aws/new-predictive-scaling-for-ec2-powered-by-machine-learning/">Predictive Scaling for EC2</a>, we were wooed into replacing all of our <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-policy.html">AWS::AutoScaling::ScalingPolicy</a> resources for equivalent, shiny new <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-autoscalingplans-scalingplan.html">AWS::AutoScalingPlans::ScalingPlan</a> resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*LhVLJgp4dW9bthMikSq68w.png" /><figcaption>“There’s scaling,” says Jeff Barr, “all under one roof!”</figcaption></figure><p>These seemed great at first, but we ended up hitting a lot of gotchas with how AutoScalingPlans interact with AutoScalingGroups, particularly where CloudFormation was concerned.</p><h3>TL;DR</h3><p>This article will interest you if you’re considering moving to <strong>ScalingPlans</strong> and are a heavy user of <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html">AWS AutoScaling RollingUpdates</a>. And hopefully save you some time and heartache.</p><p>You may also have ended up here because you’ve seen any of the below error messages as part of a CloudFormation update:</p><pre>UPDATE_ROLLBACK_IN_PROGRESS<br>The following resource(s) failed to update: [AutoScalingPlan].</pre><pre>UPDATE_FAILED<br>Scaling  plan has been updated but failed to be applied to all resources.  Problems were encountered for 1 resource. See scaling plan resources for  the failure details.</pre><p>And subsequently maybe also the following in the <strong>AWS AutoScaling</strong> console:</p><pre>ActiveWithProblems<br>The resource was not updated because it was found to have different min/max capacity than what the scaling instruction indicates</pre><p>Read on to find out more. Spoiler alert: <em>there’s no happy ending</em>.</p><h3>Getting Started</h3><p>On the face of it, moving to <strong>ScalingPlans</strong> seemed simple. We aren’t super-complicated people; we’d implemented <strong>TargetTracking</strong> policies on some of our services to track and add/remove instances in accordance with our AutoScalingGroup’s <strong>ASGTotalCPUUtilization</strong> metric. This old policy mapped perfectly to an equivalent <strong>ScalingInstruction</strong> <strong>TargetTrackingConfiguration</strong> property in the new resource. So we had feature-parity immediately.</p><p>Setting the <strong>PredictiveScalingMode</strong> to <strong>ForecastOnly</strong> allowed AWS Auto Scaling start to generate pretty looking graphs using <strong>Machine Learning™</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OLs4NHB5MW8IwNKH1G7gJg.png" /><figcaption>You too might be able to be as efficient as AWS suggest you can be!</figcaption></figure><p>So, we set the <strong>PredictiveScalingMode </strong>to <strong>ForecastAndScale</strong>, basking in wonder at the <em>dozens</em> of <strong>AutoScaling ScheduledActions</strong> that were implemented on our <strong>AutoScalingGroup</strong>. Wow! Every hour, the size of the <strong>AutoScalingGroup</strong> would be enforced! You could even use the <strong>ScheduledActionBufferTime </strong>property to scale a set amount of time before the hour, in case you usually get really busy when the clock strikes 12, just like we do! Amazing!</p><p>For one reason or another, we went back to <strong>ForecastOnly</strong>. Our services are frequently victims to short, sudden, bursts of traffic. So the reality was that the capacity levels that AWS suggested was fine for regular traffic, but not enough if we saw an unexpected, unpredictable spike of traffic.</p><p>We just ended up setting our <strong>MinCapacity</strong> ever-higher until we were overprovisioned enough to deal with these spikes. This led to some ugly <strong>PredictiveScaling</strong> graphs — the blue line in the image above was continually flatlined above the orange line. A constant reminder of “wasted” compute.</p><p>So yeah, we turned predictive scaling off, thinking that we’d maybe enable it again sometime. We kept the new resources, because they were newer (hence better) and we still had the TargetTracking policies set up, so had feature parity, right? This was true, but we encountered some unexpected gotchas...</p><h3>Changing AutoScalingGroup Capacity</h3><p>We frequently want to change the size of our <strong>AutoScalingGroup</strong>s. In production, we might scale up for a once-off event where we expect greater traffic. In our performance testing environments, we want to scale down at the end of the day to save money.</p><p>We also try to be good systems engineers. That means keeping our AWS infrastructure definitions within CloudFormation templates, for all the good reasons that entails (maintainability, reviewability, recreatability, etc).</p><p>So when implementing the new ScalingPlans, we did so by removing our old <strong>AWS::AutoScaling::ScalingPolicy</strong> CloudFormation resources and replacing them with <strong>AWS::AutoScalingPlans::ScalingPlan</strong> resources. The latter requires that you provide a <strong>MinCapacity</strong> and a <strong>MaxCapacity</strong> for the ScalingPlan to enforce upon the AutoScalingGroup:</p><pre>&quot;AutoScalingPlan&quot;: {<br>      &quot;Type&quot; : &quot;AWS::AutoScalingPlans::ScalingPlan&quot;,<br>      &quot;Properties&quot; : {<br>        &lt;...snip...&gt;<br>        &quot;ScalingInstructions&quot; : [ {<br>          &quot;DisableDynamicScaling&quot; : false,<br>          &quot;MaxCapacity&quot; : &lt;Integer&gt;,<br>          &quot;MinCapacity&quot; : &lt;Integer&gt;,<br>        &lt;...snip...&gt;<br>}</pre><p>This looked familiar, as we also set <strong>MinSize</strong> and <strong>MaxSize</strong> on our AutoScalingGroup resource using a couple of CloudFormation Parameters:</p><pre>&quot;AutoScalingGroup&quot;: {<br>      &quot;Type&quot;: &quot;AWS::AutoScaling::AutoScalingGroup&quot;,<br>      &quot;Properties&quot;: {<br>        &lt;...snip...&gt;<br>        &quot;MinSize&quot;: { &quot;Ref&quot;: &quot;MinSize&quot; },<br>        &quot;MaxSize&quot;: { &quot;Ref&quot;: &quot;MaxSize&quot; },<br>        &lt;...snip...&gt;<br>}</pre><p>We could just reuse those, implementing as so:</p><pre>&quot;AutoScalingPlan&quot;: {<br>      &quot;Type&quot; : &quot;AWS::AutoScalingPlans::ScalingPlan&quot;,<br>      &quot;Properties&quot; : {<br>        &lt;...snip...&gt;<br>        &quot;ScalingInstructions&quot; : [ {<br>          &quot;DisableDynamicScaling&quot; : false,<br>          &quot;MaxCapacity&quot; : { &quot;Ref&quot;: &quot;MinSize&quot; },<br>          &quot;MinCapacity&quot; : { &quot;Ref&quot;: &quot;MaxSize&quot; },<br>        &lt;...snip...&gt;<br>}</pre><p>Now, to change the number of instances running, it should be as simple as adjusting the value of <strong>MinSize</strong> and <strong>MaxSize</strong> CloudFormation Parameters. Let’s do it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*Kg3FcWRua3FNwhKdCb7W7A.png" /><figcaption>Wait, what? At least… it’s… not.. red?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAuUxXNY4qdR347TdYJ5GA.png" /><figcaption>I think CloudFormation just told me what it really thinks of me.</figcaption></figure><p>The above images show result of adjusting either of the shared <strong>MinSize</strong> or <strong>MaxSize</strong> CloudFormation parameter values and then performing a CloudFormation update. What happens seems to be the following:</p><ol><li>The <strong>AutoScalingPlan</strong> resource transitions into <strong>UPDATE_IN_PROGRESS</strong>.</li><li>In the AWS AutoScaling console, the <strong>ScalingPlan</strong> reports that it is: <br><strong><em>ActiveWithProblems </em></strong><em>— The resource was not updated because it was found to have different min/max capacity than what the scaling instruction indicates.</em></li><li>The <strong>AutoScalingPlan</strong> resource transitions into <strong>UPDATE_FAILED</strong> and the CloudFormation Stack begins to roll back.</li><li>When the stack enters <strong>ROLLBACK_COMPLETE</strong>, the <strong>MinSize</strong>/<strong>MaxSize</strong> parameter you changed is set back to its original value. The size of the <strong>AutoScalingGroup</strong> also hasn’t changed.</li></ol><p>This is not great — let’s see what AWS has to say on the matter in the <strong>Other Considerations</strong> in the <a href="https://docs.aws.amazon.com/autoscaling/plans/userguide/gs-best-practices.html#gs-considerations">Best Practices for AWS Auto Scaling Plans</a> documentation…</p><blockquote>Your customized settings for minimum and maximum capacity, along with other settings used for dynamic scaling, show up in other consoles. However, we recommend that after you create a scaling plan, you <strong>do not modify these settings from other consoles </strong>because your scaling plan does not receive the updates from other consoles.</blockquote><p>Emphasis mine. If we go back to our <strong>CloudFormation Events </strong>above we can see that the <strong>AutoScalingGroup</strong> resource was updated by CloudFormation before the <strong>AutoScalingPlan</strong> resource was. That’ll be a modification from an<em> “other console”</em>, then.</p><h3>Sound of Separation</h3><p>OK, fine. It’s a bit messy, but we can use seperate CloudFormation parameters:</p><ul><li><strong>AutoScalingGroupMinSize</strong>: MinSize of the AutoScalingGroup resource</li><li><strong>AutoScalingGroupMaxSize</strong>: MaxSize of the AutoScalingGroup resource</li><li><strong>AutoScalingPlanMinSize</strong>: MinCapacity of the AutoScalingPlan resource</li><li><strong>AutoScalingPlanMaxSize</strong>: MinCapacity of the AutoScalingPlan resource</li></ul><p>We can’t omit any; <strong>MinSize</strong> and <strong>MaxSize</strong> are <strong>Required</strong> according to the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html">AWS::AutoScaling::AutoScalingGroup</a> documentation. Same deal for <strong>MinCapacity</strong> and <strong>MaxCapacity</strong> of <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-autoscalingplans-scalingplan-scalinginstruction.html">AWS::AutoScalingPlans::ScalingPlan </a>ScalingInstructions.</p><p>We’ll just set <strong>AutoScalingGroupMinSize</strong> and <strong>AutoScalingGroupMaxSize</strong> to 0, then scale up our service by adjusting <strong>AutoScalingPlanMinSize</strong> and <strong>AutoScalingPlanMaxSize</strong>. That works just fine.</p><p>At face value, this has fixed our issue. We can now adjust <strong>AutoScalingPlanMinSize </strong>and<strong> AutoScalingPlanMaxSize</strong> freely. This updates the size of the <strong>AutoScalingGroup</strong> without adjusting it via CloudFormation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*ZnMEp36fIYGFuab_JuZ-BA.png" /><figcaption>Aww yiss.</figcaption></figure><p><em>“And they all lived happily ever after”</em>, right? Here’s where I tell you the follow-up story of how we’re <em>heavy</em> users of <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html">AWS AutoScaling RollingUpdates</a>. When we deploy a new version of a service, it looks like this:</p><ul><li>We create a new <strong>Amazon Machine Image (AMI)</strong> which contains a new version of our application.</li><li>We update our <strong>AWS::AutoScaling::LaunchConfiguration</strong> resource with this new AMI ID as part of a CloudFormation stack update. This forces a recreation of the <strong>LaunchConfiguration</strong> resource which in turn cascades an update to the <strong>AutoScalingGroup</strong> resource.</li><li>Our <strong>AutoScalingGroup</strong> has an <strong>UpdatePolicy</strong> configured to perform <strong>RollingUpdates</strong>. Replacing the <strong>LaunchConfiguration</strong> triggers the replacement of each one of the <strong>AutoScalingGroup</strong>’s running instances, replacing the old instances with new instances. When the <strong>RollingUpdate </strong>is complete, so is our deployment.</li></ul><p><strong>RollingUpdates</strong> and <strong>ScalingPlans</strong> appear to co-exist, in that you won’t see a <strong>RollingUpdate</strong> fail. It’ll succeed just fine. Then, when next you come to adjust the size of your <strong>AutoScalingGroup </strong>via the <strong>AutoScalingPlanMinSize</strong> and <strong>AutoScalingPlanMaxSize </strong>parameters, CloudFormation will scream at you:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pj29VS42QtL2EPxbHE85bg.png" /><figcaption>Why do you hate me, ScalingPlan?</figcaption></figure><blockquote><strong>UPDATE_FAILED</strong><br>Scaling plan has been updated but failed to be applied to all resources. Problems were encountered for 1 resource. See scaling plan resources for the failure details.</blockquote><p>It’ll rollback immediately. If you’re quick, you’ll see the same status messages in the <strong>AWS AutoScaling</strong> console from when we tried using the shared <strong>MinSize</strong>/<strong>MaxSize</strong> parameters:</p><blockquote><strong>ActiveWithProblems </strong><em>— </em>The resource was not updated because it was found to have different min/max capacity than what the scaling instruction indicates.</blockquote><p>What happened here? Well, during the first stack update where we performed the<strong> RollingUpdate</strong>, I observed the following:</p><ul><li>Before doing anything, Note the size of your <strong>AutoScalingGroup</strong>. It should match <strong>AutoScalingPlanMinSize </strong>and<strong> AutoScalingPlanMaxSize</strong>.</li><li>Start a CloudFormation update that triggers a <strong>RollingUpdate </strong>(e.g. alter the AMI ID of the <strong>LaunchConfiguration</strong>). Watch it succeed.</li><li>Note the size of your <strong>AutoScalingGroup</strong> at this point. You’ll notice that it has changed to match <strong>AutoScalingGroupMinSize</strong> and <strong>AutoScalingGroupMaxSize</strong>.</li></ul><p>This is unexpected. And confirms that a <strong>RollingUpdate</strong> will reapply whatever properties your CloudFormation template’s <strong>AutoScalingGroup</strong> has set.</p><p>The next time you come along to adjust the capacity of your <strong>AutoScalingGroup </strong>(be that in five minutes or in five months) by adjusting <strong>AutoScalingPlanMinSize</strong> or <strong>AutoScalingPlanMaxSize</strong>, you’ll be set up to fail from the get-go.</p><p>As far as the <strong>AutoScalingPlan</strong> is concerned, your <strong>AutoScalingGroup</strong> has changed from underneath it. From an “<em>other console”</em>, as the <a href="https://docs.aws.amazon.com/autoscaling/plans/userguide/gs-best-practices.html#gs-considerations">Best Practices for AWS Auto Scaling Plans</a> liked to put it.</p><p>The <strong>AutoScalingPlan</strong> is never updated about this change, and will never automatically fix itself. In practice, the only way to fix this is to either:</p><ul><li>Manually adjust the size of the <strong>AutoScalingGroup</strong> back to the same values as the last known adjustment that the <strong>AutoScalingPlan</strong> made.</li></ul><p>or</p><ul><li>Delete and recreate the <strong>ScalingPlan</strong> resource. <br>(Note: when you do this, your <strong>AutoScalingGroup</strong> size will revert to <strong>AutoScalingGroupMinSize</strong> and <strong>AutoScalingGroupMaxSize. <br></strong>Sure hope you hadn’t configured those as 0…)</li></ul><p>Speaking as a guy who’s deleted a few dozen <strong>ScalingPlans</strong> to fix these issues, let me tell you that deleting them is what you’ll be doing most often.</p><p>Why? Well, while you <em>can</em> determine what the current size of an <strong>AutoScalingGroup</strong> is, and while you <em>can</em> determine what the current capacities of an <strong>AutoScalingPlan</strong> are, you <em>cannot</em> determine what an <strong>AutoScalingPlan</strong> <em>thinks</em> that the <strong>AutoScalingGroup</strong> should be set to. That information is not exposed to us mere mortals.</p><h3>Conclusions</h3><p>It’s a tale as old as time — new AWS services, existing AWS services and CloudFormation don’t always mix or fit tightly enough together. In this case, there’s a lack of integration between <strong>AutoScalingGroups</strong> and <strong>AutoScalingPlans</strong>, and an unreasonable expectation that <strong>AutoScalingPlans </strong>should be the only resources permitted to change the size of an <strong>AutoScalingGroup</strong>.</p><p>The root cause of our problem is that CloudFormation always rolls back. In reality, all we’d need to fix our issue is one additional property named <strong>ForceCurrentCapacity</strong> on an <strong>AWS::AutoScalingPlans::ScalingPlan ScalingInstruction</strong> resource. When true, the <strong>AutoScalingPlan</strong> could say: “yeah, I’m gonna enforce whatever my <strong>MinCapacity</strong> and <strong>MaxCapacity</strong> are on the <strong>AutoScalingGroup</strong>, regardless or not whether they seem to have changed”.</p><p>But we don’t have that. And instead, due to continued rollbacks while trying to adjust the size of our <strong>AutoScalingGroup</strong> resources following service deployments, we reluctantly went back to <strong>AutoScaling::ScalingPolicy </strong>resources. Although they’re not as fancy, they work without any real fuss and scale our services when we need it.</p><p>And while we don’t have the option of turning <strong>PredictiveScaling</strong> back on or seeing the pretty graphs that the <strong>AWS Auto Scaling</strong> console provides, I’ll take working deployments and predictable CloudFormation updates any day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49f56c153fcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Declarative Jenkinsfiles: Dynamic Parallel Stages]]></title>
            <link>https://medium.com/@hybby/declarative-jenkinsfiles-dynamic-parallel-stages-1b9538b0eabb?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b9538b0eabb</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[groovy]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[declarative-pipeline]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Wed, 29 Apr 2020 18:31:00 GMT</pubDate>
            <atom:updated>2020-04-29T18:31:00.982Z</atom:updated>
            <content:encoded><![CDATA[<p>Been working on replacing a crusty old Jenkins job recently that’s used for scaling up a load-testing environment. Currently, it’s a good ol’ handcranked freestyle job with a 300-line bash script pasted into the <strong>Execute Shell</strong> field. When it needs debugged or changed it’s fun for all the family.</p><p>I’ve wanted to rewrite this for a while. Right now, the script has a bunch of configuration at the top of the file which dictates how many instances to launch, what sizes of instances to use, etc. And it’s pretty repetitive:</p><pre># config for standard load tests<br>SERVICEONE_NORMALLOAD_INSTANCETYPE=c5.xlarge<br>SERVICEONE_NORMALLOAD_MINSIZE=3<br>SERVICEONE_NORMALLOAD_MAXSIZE=3<br>SERVICETWO_NORMALLOAD_INSTANCETYPE=c5.large<br>SERVICETWO_NORMALLOAD_MINSIZE=6<br>SERVICETWO_NORMALLOAD_MAXSIZE=6</pre><pre># config for high load tests<br>SERVICEONE_HIGHLOAD_INSTANCETYPE=c5.xlarge<br>SERVICEONE_HIGHLOAD_MINSIZE=6<br>SERVICEONE_HIGHLOAD_MAXSIZE=6<br>SERVICETWO_HIGHLOAD_INSTANCETYPE=c5.large<br>SERVICETWO_HIGHLOAD_MINSIZE=9<br>SERVICETWO_HIGHLOAD_MAXSIZE=9</pre><pre>if [[ $SCALING_LEVEL = &#39;NORMAL&#39; ]] ; then<br>    # perform scaling actions with the first set of config...<br>    ...</pre><pre>elif [[ $SCALING_LEVEL = &#39;HIGH&#39; ]] ; then<br>    # perform scaling actions with the second set of config...<br>    ...</pre><pre>fi</pre><p>We don’t have just two services, of course. Or just two load settings. So you can see how this script gets pretty gnarly, pretty quickly. Adding a new service? Sure hope you got all the variable names right. Something not working? Better step through every single command to see what’s not as you expected.</p><p>Additionally, this script works through every service sequentially. This increases the time to scale the environment drastically if you have a bunch of services. The total time taken is the product of the number of services you have, and how long it takes to scale a service. Worse if one takes longer than another. There are no actions performed in parallel.</p><p>How could I make this better? For config, I envisioned something like this:</p><pre>def SERVICES = [<br>    &quot;service-1&quot;: [<br>        &quot;NORMAL&quot;: [ <br>            &quot;InstanceType&quot;: &quot;c5.xlarge&quot;, <br>            &quot;MinSize&quot;: 3, <br>            &quot;MaxSize&quot;: 3<br>        ],<br>        &quot;HIGH&quot;: [<br>            &quot;InstanceType&quot;: &quot;c5.xlarge&quot;, <br>            &quot;MinSize&quot;: 6, <br>            &quot;MaxSize&quot;: 6<br>        ]<br>    ],<br>    &quot;service-2&quot;: [<br>        &quot;NORMAL&quot;: [ <br>            &quot;InstanceType&quot;: &quot;c5.large&quot;, <br>            &quot;MinSize&quot;: 6, <br>            &quot;MaxSize&quot;: 6<br>        ],<br>        &quot;HIGH&quot;: [<br>            &quot;InstanceType&quot;: &quot;c5.large&quot;, <br>            &quot;MinSize&quot;: 9, <br>            &quot;MaxSize&quot;: 9<br>        ]<br>    ]<br>]</pre><p>Should be achievable in a <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjW_Z-4iI7pAhWPiFwKHbNbCyAQFjAAegQIAxAB&amp;url=https%3A%2F%2Fjenkins.io%2Fdoc%2Fbook%2Fpipeline%2Fsyntax%2F&amp;usg=AOvVaw0RQhrSz2PNbCo-OvxK9F54">Jenkins Declarative Pipeline</a>, right? It’s easy enough to define a list of nested maps. By doing this, I can set all of my configuration values at the top of my Jenkinsfile, once per service. And people can come along and easily see what’s set to what. Great.</p><p>It got me thinking though. Every service scales up in the same way. We update a <strong>Launch Configuration</strong> and an <strong>Autoscaling Group</strong> resource in a <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=11&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwj-39LOiI7pAhXCQkEAHbGHDRkQFjAKegQIBBAB&amp;url=https%3A%2F%2Fdocs.aws.amazon.com%2FAWSCloudFormation%2Flatest%2FUserGuide%2Fcfn-whatis-concepts.html&amp;usg=AOvVaw2__8bW_fGKshP2eE9eajkD">CloudFormation Stack</a>. Do we have to do this sequentially? Can we kick off each service’s scaling job in parallel to save time?</p><p>I ended up doing just this, implementing the parallelism with <a href="https://www.jenkins.io/blog/2017/09/25/declarative-1/">Parallel Stages</a> in my Jenkinsfile. However, instead of writing out each stage individually, I wrote a function that generated one stage per item in my configuration map. Then, I could use the parallel directive to kick off every stage at once, at the same time.</p><p>My Jenkinsfile looked something like this:</p><pre>// set up a config map as per the above snippet<br>def SERVICES = [ ...see above... ] </pre><pre>// generate a pipeline stage for each item in the config map<br>def parallelStagesMap = SERVICES.collectEntries {<br>    [ &quot;${it}&quot;: generateStage(it) ]<br>}</pre><pre>// here&#39;s how we generate identical stages<br>def generateStage(service) {<br>    def service_name = service.key<br>    return {<br>        stage(&quot;Service: ${service_name}&quot;) {<br>            size = service.value[env.LEVEL][&#39;InstanceType&#39;]<br>            max = service.value[env.LEVEL][&#39;MaxSize&#39;]<br>            min = service.value[env.LEVEL][&#39;MinSize&#39;]</pre><pre>            // insert your scaling commands in here<br>            sh( script: &quot;&quot;&quot;<br>                    echo &quot;Action: ${env.LEVEL}&quot;    &amp;&amp; \<br>                    echo &quot;Service: ${service_name}&quot; &amp;&amp; \<br>                    echo &quot;InstanceType: ${size}&quot; &amp;&amp; \<br>                    echo &quot;MaxSize: ${max}&quot; &amp;&amp; \<br>                    echo &quot;MinSize: ${min}&quot;<br>                &quot;&quot;&quot;<br>            )<br>        }<br>    }<br>}</pre><pre>pipeline {<br>    agent any</pre><pre>    parameters {<br>        choice(<br>            name: &#39;LEVEL&#39;,<br>            description: &#39;What level do you want to scale to?&#39;,<br>            choices: [<br>                &#39;NORMAL&#39;,<br>                &#39;HIGH&#39;<br>            ]<br>        )<br>    }<br>    stages {<br>        stage(&#39;Scale services&#39;) {<br>            steps {<br>                script {<br>                    // kick off all the stages we generated<br>                    parallel parallelStagesMap<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>When we run the job, it works and looks great:</p><figure><img alt="One stage per configuration item" src="https://cdn-images-1.medium.com/max/772/1*R73-1zTz7aJHnMCn4xhxZw.png" /><figcaption>Each item in our configuration hash has its own stage, executed in parallel.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*WOFmpBFykmBHYiImVcLy9A.png" /><figcaption>Or if you prefer the fancier BlueOcean pipeline view…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*C6FoqGsAlnlaFxgu2sMgkA.png" /><figcaption>The logs for each stage are pretty useful too.</figcaption></figure><p>This method is especially useful if one particular service has a problem scaling up — the error will show clearly on the stage related to that service, not halfway down a shell script somewhere that you have to dig into the logs of.</p><p>The configuration hash at the top also serves as self-documentation for our scaling levels. How many levels do we scale to? Oh, there’s two levels defined in the hash. How many services do we scale? They’re all there, unobscured and easy to see. No hidden settings, or secret numbers.</p><p>When our scaling levels change due to a projected increase in traffic or otherwise, we’re now one Pull Request away from having the updated levels ready-to-go — peer reviewed, merged once. New service launched? Cool, raise a PR. No more need to hunt through multiple Jenkins jobs, wondering which one is live and which one isn’t. The next run of the job will pull in the latest Jenkinsfile, along with the latest config.</p><p>This also opens us up to being able to schedule the scaling up and scaling down of our load testing environment using the <a href="https://github.com/jenkinsci/parameterized-scheduler-plugin">Parameterized Scheduler Plugin</a> and the ubiquitous cron syntax. In the pipeline section of our Jenkinsfile, we can set something like this:</p><pre>triggers {<br>    parameterizedCron(&#39;&#39;&#39;<br>        # scale up in the morning, scale down at night (weekdays)<br>        H 6 * * 1-5 % LEVEL=NORMAL        <br>        H 18 * * 1-5 % LEVEL=ZERO<br>       &#39;&#39;&#39;)<br>    }</pre><p>This takes the legwork out of manually making sure the environment is available each morning and ensures we’re saving as much as we can on instance costs during evenings and weekends. We also don’t have to mess around with AutoScalingGroup ScheduledActions, which is nice.</p><p>You can see some extremely abstract versions of Jenkinsfiles I’ve been working on recently at my <a href="https://github.com/hybby/jenkinsfiles">GitHub</a>, recorded because I realise it’s probably not the last time I’ll need to write something like this.</p><p>Happy Jenkinsfile-ing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b9538b0eabb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Macs, Control Characters, and iTerm2]]></title>
            <link>https://medium.com/@hybby/macs-control-characters-and-iterm2-8a0335f7a8d2?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a0335f7a8d2</guid>
            <category><![CDATA[new-laptop]]></category>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[iterm2]]></category>
            <category><![CDATA[keyboard]]></category>
            <category><![CDATA[character-control]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Tue, 31 Mar 2020 21:05:29 GMT</pubDate>
            <atom:updated>2020-05-15T13:34:57.044Z</atom:updated>
            <content:encoded><![CDATA[<p>I always forget how to do this. And I always lose <a href="http://eosrei.net/articles/2011/07/ascii-control-characters-escape-sequences-iterm">Brad Erickson’s excellent article</a> that taught me how to fix it. So here it is, for posterity.</p><p>Whenever I switch to a new Mac, be that through replacement of machine or job, I tend to wrestle with my laptop for a while. Mostly, this is due to Mac systems using the <strong>Command </strong>(⌘) key for shortcuts (copy, paste, etc.) while my favoured terminal emulator, <strong>iTerm2</strong>, sensibly uses <strong>Ctrl (^)</strong> as the modifier key for sending control characters (<strong>^C</strong>, etc).</p><p>I’m also a stubborn critic of modern laptop keyboard layouts in general. I don’t <em>want</em> the bottom-left key on my laptop to be <strong>Fn</strong>. I want it to be <strong>Ctrl</strong>, like how it was when I grew up, dammit! So of course, I use an external keyboard which has everything laid out the way I like it.</p><p>So, in summary, I want my keyboard to do the following, for example:</p><ul><li>Use <strong>Ctrl + c </strong>to copy in most applications.</li><li>Use <strong>Ctrl + c </strong>to send control characters in iTerm2.</li></ul><p>This presents a small challenge, because these are different things. One uses by default, <strong>Command </strong>(⌘). The other uses<strong> Ctrl (^)</strong>.</p><h4>Fix one thing, break another</h4><p>When I first connect my external keyboard to a new Mac, copying, pasting, etc. requires that I use <strong>Super (“Windows”) + c</strong> for copy, for example. But <strong>iTerm2</strong> works perfectly as I expect it to. No good.</p><p>I know what you’re thinking. Just go to <strong>System Preferences</strong> → <strong>Keyboard</strong> → <strong>Modifier Keys</strong>… and make sure you select the correct keyboard from the drop-down box, then swap the keys around like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*Z2hyvqZ-nZ9QKWjSU2PS2Q.png" /><figcaption>This should work, right?</figcaption></figure><p>This fixes my first requirement. I can now copy, paste, etc. with what my keyboard considers <strong>Ctrl</strong>. But it’s broken the second one! Now I need to use Super <strong>(“Windows”) + c</strong> to send a control character via <strong>iTerm2</strong>. Oh no!</p><h4>Is there a setting for that?</h4><p>How about the <strong>iTerm2</strong> → <strong>Preferences</strong> → <strong>Keys </strong>→ <strong>Remap Modifiers</strong> menu?</p><p>As soon as you start playing with this, <strong>iTerm2</strong> asks for <strong>Accessibility Access (Events)</strong> privileges on your laptop.</p><figure><img alt="Image showing iTerm2 requesting permission to control this computer using accessibility features" src="https://cdn-images-1.medium.com/max/573/1*0uZljmoxSbsNJo2Sl5lF8g.png" /><figcaption>Okay.</figcaption></figure><p>If you grant this, you’re presented with a menu that looks suspiciously familiar to the one that we messed around with earlier:</p><figure><img alt="The iTerm2 → Preferences → Keys → Remap Modifiers window" src="https://cdn-images-1.medium.com/max/672/1*UMtXj9tHGVmgnZ53VxId0Q.png" /><figcaption>This looks promising, but ultimately proves futile.</figcaption></figure><p>For one, this is a bit of a mind-melter for me. What if I’ve adjusted the <strong>System Preferences</strong> menu from earlier? Does this override those? Perform another remap on top? Something else? My brain hurts just thinking about it.</p><p>For two, no matter what I adjust here, it doesn’t actually <em>do</em> anything to my external keyboard. I’m left to assume that this menu is hard-coded to adjust settings for the laptop’s built-in keyboard, as it seems to be lacking the <strong>Select keyboard</strong> drop-down box from the earlier menu.</p><p>Let’s not mess around with this, and let’s find another solution.</p><h4>iTerm2 Key Bindings to the rescue!</h4><p>Brad Erickson seems to be the only other person on the entire Internet that this behaviour frustrates, and he wrote a <a href="http://eosrei.net/articles/2011/07/ascii-control-characters-escape-sequences-iterm">great article</a> on how to fix it using <strong>iTerm2</strong>‘s <strong>Key Bindings</strong> configuration.</p><p>Here’s how I got it working to my liking:</p><p>Hit up <strong>iTerm2</strong> → <strong>Preferences</strong> → <strong>Keys</strong>. The default tab in this window is <strong>Key Bindings. </strong>In the bottom left corner, press the small <strong>plus sign (+) </strong>to add a new binding. That’ll bring up a menu asking you for a shortcut and an action.</p><p>Here’s where I press <strong>Ctrl + c</strong>, which now shows up as<strong> Command + c </strong>(<strong>⌘c</strong>) after my previous adventures in <strong>System Preferences</strong>. As for an action, I want to <strong>Send Hex Code</strong>. Then, I can use Wikipedia’s handy <a href="https://en.wikipedia.org/wiki/ASCII#Control_characters">ASCII Control Characters</a> table to select the hex code that represents the control character that I want to send. I want <strong>^C</strong>, which has a hex code of <strong>03</strong>, formatted properly as <strong>0x3</strong> as far as <strong>iTerm2</strong> is concerned. Turns out this control character is actually called the <strong>End-of-Text</strong> character. TIL.</p><figure><img alt="Configuring a Key Binding to send the ^C control character in iTerm2" src="https://cdn-images-1.medium.com/max/734/1*KqXYKKXFIW8AlmGvwqufzw.png" /><figcaption>Configuring a Key Binding to send the ^C control character in iTerm2</figcaption></figure><p>As soon as the <strong>OK</strong> button is pressed, my shell’s behaviour is as I expect.</p><h4>How about other control characters?</h4><p>You can use the same mechanism to add the control characters that you send most often. Over a year and half, I’ve found that I only commonly use these:</p><ul><li><strong>^C (0x3)</strong>: Ctrl + c (End-of-Text, or “send interrupt”)</li><li><strong>^D (0x4)</strong>: Ctrl + d (End-of-Transmission, or “logout”)</li><li><strong>^Z (0x1a)</strong>: Ctrl + z (Substitute, or “background job”)</li><li><strong>^] (0x1d)</strong>: Ctrl + ] (Group Separator, or “exit telnet”)</li></ul><p>I’ll be the first to admit that setting these up manually isn’t ideal, but given the infrequency with which I move machines, I’m happy to take the hit since it’s truly a “set and forget” solution.</p><p>Hopefully this will help someone out there. And hopefully now you can <em>control</em> your terminal properly and <em>escape</em> any stress that this situation was putting you under!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a0335f7a8d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Timeouts Loading Data from S3 to Aurora]]></title>
            <link>https://medium.com/@hybby/timeouts-loading-data-from-s3-to-aurora-baa3d561f805?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/baa3d561f805</guid>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aurora]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Fri, 20 Apr 2018 11:45:07 GMT</pubDate>
            <atom:updated>2018-04-20T11:50:09.969Z</atom:updated>
            <content:encoded><![CDATA[<p>Been working on a data migration recently which involves loading a pretty big tab-separated file into an Amazon Aurora (MySQL) database and hit an interesting issue in one of our sub-accounts.</p><p>We’d gone through the documented steps of creating an IAM Role, associating its ARN with the cluster using aws rds add-role-to-db-cluster and adding its ARN as the value of the aurora_load_from_s3_role DB cluster parameter.</p><p>We’d added the s3:GetObject and s3:ListBucket permissions to the bucket policy of the data source, using the IAM Role’s ARN as the principal (we decided to use a bucket policy for ease of clean-up after the migration had been completed).</p><p>But still, no matter what we tried, our LOAD DATA FROM S3 FILE query would <em>always</em> hang for approximately five minutes and then throw us an error:</p><pre>ERROR 1815 (HY000): Internal error: Unable to initialize S3Stream</pre><p>What was going on? It felt like a timeout, due to the severe hang before the command bombed out. Checking our tables afterwards verified that no data had been written by the query, either.</p><p>An extra-strange thing is that the query worked just fine in our main AWS account (using a different S3 bucket and Role ARN, but with otherwise functionally identical configuration).</p><p>We only experienced the issue when trying to run the query from one of our sub-accounts, which we use for performance testing.</p><p>Double and triple checking our S3 and IAM setups didn’t flag up anything obvious. So we delved into the <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraMySQL.Integrating.LoadFromS3.html">documentation</a>, and the most interesting thing appeared to be the fifth point:</p><blockquote>Configure your Aurora MySQL DB cluster to allow outbound connections to Amazon S3.</blockquote><p>Checking the page page linked to in this section implied that our cluster was likely to be misconfigured if we encountered an error like so:</p><pre>ERROR 1873 (HY000): Lambda API returned error: Network Connection. Unable to connect to endpoint</pre><p>However, this didn’t seem to be the case for us. We weren’t seeing this error. Still, my instinct was that we were hitting some sort of network problem so I decided to check our our VPC Endpoint configuration in the console, accessed via <em>VPC -&gt; Endpoints</em>.</p><p>Sure enough, I didn’t have a VPC Endpoint configured for the S3 service in this account. Checking our main account showed that we <em>did</em> have an S3 endpoint, which gave another hint as to why it worked there.</p><p>A<em> VPC Endpoint </em>is a resource within AWS that allows you to privately connect a VPC to a particular AWS service. This means that services which are normally hosted in private subnets, like database clusters can be permitted to communicate with AWS services that expect to be communicated with via the Internet, like Amazon S3. Configuring a VPC Endpoint inserts a statement into Routing Tables that you specify, meaning you can control exactly what subnets you are granting this access to.</p><p>I created a new endpoint, selecting com.amazonaws.us-east-1.s3 as the Service Name. I provided the VPC ID where my Amazon Aurora cluster was located. Finally, I provided the Route Table IDs that contained the subnets used by my Amazon Aurora cluster, and decided to use the default policy that was provided.</p><p>After creating the endpoint I reran the LOAD DATA FROM S3 query. Our query hit five minutes and didn’t bomb out like before. The anticipation started to build — our datafile was rather large (approximately 13m rows), so we expected it to take a bit of time. Then, finally:</p><pre>Query OK, 12537768 rows affected (10 min 50.39 sec)<br>Records: 12537768 Deleted: 0 Skipped: 0 Warnings: 0</pre><p>It worked! And it was pretty damn fast, too.</p><p>Lesson learnt: even if you <em>really, really</em> hope the problem isn’t your VPC configuration, sometimes it is. That, and sometimes you need to use a bit of imagination with AWS’s documentation.</p><p>Hopefully I’ll get to write a bit more about my experiences performing data migrations in AWS soon; in particular we’ve been having fun exporting data from Amazon Redshift to S3, where we then import that data into an Amazon Aurora cluster. I’ve been really impressed with the simplicity and speed that can be achieved and hope never have to load data from anywhere else ever again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=baa3d561f805" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Puppet CA Host Certificate Expiry]]></title>
            <link>https://medium.com/@hybby/puppet-ca-host-certificate-expiry-36923facfd75?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/36923facfd75</guid>
            <category><![CDATA[puppet]]></category>
            <category><![CDATA[certificate-authority]]></category>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[ssl]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Wed, 25 Oct 2017 17:23:57 GMT</pubDate>
            <atom:updated>2018-06-25T22:11:07.736Z</atom:updated>
            <content:encoded><![CDATA[<p>So you read the title and thought <em>“Hey, I just read that article!”</em>, right? Nah, here’s another article about Puppet CA Server certificates. Similar, but different. I’m just being cheeky by submitting them a couple of hours apart.</p><h3>CA certs… Host certs… What?!</h3><p>So, when a normal node runs Puppet for the first time, it contacts its Puppet CA server for a certificate that proves it’s allowed to be a client of that master. A detailed step through of what happens is:</p><ol><li>It generates a new SSL keypair ($::hostprivkey and $::hostpubkey)</li><li>Using its newly generated $::hostprivkey, it generates a certificate signing request ($::hostcsr) for a certificate and sends that off to whatever’s configured as its Puppet CA server ($::ca_server). No catalog is compiled at this point, because the node isn’t considered a trusted client of the Puppet master.</li><li>The CSR from the node ends up in the $::csrdir of the Puppet CA server. If the Puppet CA server is configured to allow auto-signing of the node that made the request, it signs it with its CA certificate ($::cacert) and pops the signed cert into $::signeddir. The CSR gets deleted.</li><li>On the node’s next Puppet run, it gets a copy of the signed certificate from the Puppet CA server and is allowed to continue with its run. It gets a catalog and nice things happen to it for the rest of its little life. Or for five years. Which is how long the signed certs are valid for, by default.</li></ol><p>So we’ve described a situation where a node requests what I’ll call a <em>host certificate</em> from the CA, which gives one back signed by its <em>CA cert</em>.</p><h3>Okay, okay. But what about the CA?</h3><p>You might already know this, but the Puppet CA server is usually a client of itself.</p><p>So when it was first spun up, the Puppet CA generated itself an SSL keypair ($::cakey and $::capub) and a CA certificate ($::cacert). This certificate is self-signed, and is marked as a CA cert, meaning it’s allowed to sign other certificate requests.</p><p>That’s on the master side. But Puppet masters also run the Puppet agent.</p><p>When the Puppet CA ran puppet agent -t for the first time, it went through the steps we went discussed above. Generated itself a new keypair ($::hostprivkey and $::hostpubkey)… Looked to see who its CA server was… (itself!) and submitted a CSR to them ($::hostcsr) and waited until it got a response back (from itself!).</p><p>So yeah, the upshot is that the Puppet CA server has two sets of certs. Its CA certs, and its host certs. We can illustrate that clearly here:</p><pre># puppet config print hostcert hostprivkey hostpubkey cacert cakey capub | awk &#39;{print $NF}&#39; | xargs md5sum<br>63c251f890893690df65f79d36eb5d62  /var/lib/puppet/ssl/certs/puppetca.example.com.pem<br>e2c7e9bb4b5a68c812989c2da702b971  /var/lib/puppet/ssl/private_keys/puppetca.example.com.pem<br>3b8874ae570cecb3470384b1fc307503  /var/lib/puppet/ssl/public_keys/puppetca.example.com.pem<br>f4288c68efa8a4f9bd07d0bac62710a6  /var/lib/puppet/ssl/ca/ca_crt.pem<br>af2f94391cefa3e8d296d0648ebeb5d5  /var/lib/puppet/ssl/ca/ca_key.pem<br>7c17a8d5cc920b1d923f4b18deefea51  /var/lib/puppet/ssl/ca/ca_pub.pem</pre><p>In the vast majority of cases, these certificates will have been generated at roughly the same time (usually the same day, almost certainly the same week). That means that they also <em>expire</em> at roughly the same time. But be warned, the content of the two certs is <em>completely</em> different, as the checksums above show!</p><p>So you might have went through the steps from my previous post, renewed your CA certs, managed to get everything working just nicely, perform your first Puppet run after the big scary change and be faced with this redness:</p><pre>Warning: Certificate &#39;puppetca.example.com&#39; will expire on 2017-11-22T22:08:37UTC</pre><p>Believe it or not, this is referring to the <em>host cert</em> of your Puppet CA cert. Check out the expiry of it if you don’t believe me:</p><pre># openssl x509 -noout -text -in $(puppet config print hostcert) | grep -A2 Valid<br>        Validity<br>            Not Before: Nov 22 22:08:37 2017 GMT<br>            Not After : Nov 22 22:08:37 2022 GMT</pre><p>Fine, sounds legit. What’s the impact?</p><p>Honestly? Not much. It means that once the “Not After” date has expired, the client cert used by your Puppet agent won’t be accepted by the CA any more. That means no catalogues. Boo.</p><p>On nodes that aren’t important, fixing this is a cinch. But not only is it a little bit embarrassing when your most important Puppet server can’t be an agent of itself, it comes with some additional configurations. You can’t just nuke $::ssldir and walk away like you usually would.</p><h3>What’s the big deal, then?</h3><p>Usually when you want to regenerate a Puppet client’s certs you’ll do this:</p><pre>root@client# rm -rf $(puppet config print ssldir)</pre><pre>root@puppetca# puppet cert clean client</pre><pre>root@client# puppet agent -t<br>&lt;keys regen&gt;<br>&lt;csr created&gt;<br>&lt;puppet ca signs&gt;<br>&lt;new cert recieved&gt;<br>&lt;puppet run continues&gt;</pre><p>This is a bad idea to run on your Puppet CA. Like, a <em>really</em> bad idea.</p><ol><li>It’ll delete the entirety of your Puppet CA’s SSL directory. That means your CA certs, CA keys and all of your estate’s signed certificates gone, up in smoke. (Have I mentioned that it’s a good idea to back this up?)</li><li>It’s not so bad if you’ve already deleted all of your SSL data, but if you were to run puppet cert clean puppetca when you still had all of your certs, you’d revoke both your host certs <em>and </em>your CA certs. They’d get appended to your CA’s CRL and none of the nodes in your estate would be able to check in with your Puppet masters any more. This is because your Puppet CA would not believe its own certs are valid any more.</li></ol><p>So yeah, don’t do any of that.</p><p>Instead, we can perform a bit of surgery on your Puppet CA’s SSL directory and only remove the keys and certs that we mean to. We can even make it so that we can revert things if we mess it up, somehow! Let’s go.</p><h3>Alternative DNS Names</h3><p>First up, let’s see what your CA thinks about its own certs:</p><pre>root@puppetca# puppet cert list --all | grep $(uname -n)<br>+ &quot;puppetca.example.com&quot;                                         (SHA256) A8:7A:68:3E:E9:61:CB:7A:FF:E9:42:48:FC:57:04:F8:BF:2E:05:8C:4D:EA:AF:F7:E5:3C:D6:5B:EF:8C:E1:6C (alt names: &quot;DNS:puppet&quot;, &quot;DNS:puppet-1.example.com&quot;, &quot;DNS:puppet.example.com&quot;)</pre><p>The alt names section tells me that the cert that’s already issued has <a href="https://en.wikipedia.org/wiki/Subject_Alternative_Name">X.509 Subject Alternative Name</a> extensions baked in. This is a list of alternative DNS names that are also valid for the cert that’s been signed. It’s used so that your clients could hit, for example, a friendly CNAME DNS record that references your Puppet CA instead of the CA’s FQDN itself.</p><p>We’re gonna make sure that these are configured on your Puppet agent, too. Just so that we’re replacing like-with-like.</p><pre>root@puppetca# puppet config print dns_alt_names</pre><pre>root@puppetca#</pre><p>If, like above, you don’t have any output, you’re missing a bit of config. dns_alt_names is be configured in /etc/puppet/puppet.conf under the [main] section. So add something appropriate like this:</p><pre>dns_alt_names=puppet,puppet-1.example.com,puppet.example.com</pre><p>Re-running puppet config print dns_alt_names should have more success now.</p><h3>Back it up, back it up!</h3><p>Make sure and CYA by backing up everything you touch. And maybe even some stuff you don’t. I went a bit overboard:</p><pre># create backup directories<br>mkdir -p $(puppet config print ssldir)/backup/{host,ca,signed}<br><br># back up our ca certs and crls (local and ca) because we&#39;re paranoid<br>cp $(puppet config print cacert) $(puppet config print ssldir)/backup/ca/cacert.pem<br>cp $(puppet config print cacrl) $(puppet config print ssldir)/backup/ca/cacrl.pem<br>cp $(puppet config print localcacert) $(puppet config print ssldir)/backup/ca/localcacert.pem<br>cp $(puppet config print hostcrl) $(puppet config print ssldir)/backup/ca/hostcrl.pem<br><br># back up our agent-side certs<br>cp $(puppet config print hostcert) $(puppet config print ssldir)/backup/host/hostcert.pem<br>cp $(puppet config print hostprivkey) $(puppet config print ssldir)/backup/host/hostprivkey.pem<br>cp $(puppet config print hostpubkey) $(puppet config print ssldir)/backup/host/hostpubkey.pem<br><br># remove up our ca-side signed cert, backing it up ofc<br>cp $(puppet config print signeddir)/$(hostname -f).pem $(puppet config print ssldir)/backup/signed/signed.pem<br><br># make sure they&#39;re there<br>find $(puppet config print ssldir)/backup | xargs ls -ld</pre><p>Now you should have a pretty list of files backed up in `$(puppet config print ssldir)/backup, should the worst happen.</p><h3>Precision cut</h3><p>Now for the action. For the avoidance of doubt, all of this is performed on your Puppet CA server.</p><pre># 1. stop puppet agent<br>service puppet stop </pre><pre># 2. move the host certs that Puppet Agent knows about<br>mv $(puppet config print hostcert) /tmp/hostcert.pem<br>mv $(puppet config print hostprivkey) /tmp/hostprivkey.pem<br>mv $(puppet config print hostpubkey) /tmp/hostpubkey.pem</pre><pre># 3. move the signed version of the ca&#39;s host cert<br>mv $(puppet config print signeddir)/$(hostname -f).pem /tmp</pre><pre># 4. regenerate our host ssl keypair, create csr and submit to ca<br>puppet agent -t</pre><pre># 5. get the ca to sign our csr<br>puppet cert sign $(hostname -f)</pre><pre># 6. get the agent to retrieve the signed cert and perform a run<br>puppet agent -t</pre><pre># 7. restart puppet agent<br>service puppet start</pre><p>All going well, you should have new host certs on your Puppet CA server, with the actual CA certs themselves being left well alone!</p><p>Now, you can check the validity of your new host cert.</p><pre># openssl x509 -noout -text -in $(puppet config print hostcert) | grep -A2 Valid<br>        Validity<br>            Not Before: Oct 18 11:55:40 2017 GMT<br>            Not After : Oct 18 11:55:40 2022 GMT</pre><p>Compare it to the validity dates of your CA cert if you want to. They’ll differ:</p><pre># openssl x509 -noout -text -in $(puppet config print cacert) | grep -A2 Valid<br>        Validity<br>            Not Before: Oct 18 10:22:30 2017 GMT<br>            Not After : Oct 18 10:22:30 2022 GMT</pre><p>Now we can hopefully put this sorry affair behind us. And get on with some real work wrangling some clouds, eh?</p><p>See you in five years!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36923facfd75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Puppet CA Certificate Expiry]]></title>
            <link>https://medium.com/@hybby/puppet-ca-certificate-expiry-d3e2ac50bc63?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3e2ac50bc63</guid>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[certificate-authority]]></category>
            <category><![CDATA[puppet]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Wed, 25 Oct 2017 14:16:27 GMT</pubDate>
            <atom:updated>2017-10-25T17:23:39.386Z</atom:updated>
            <content:encoded><![CDATA[<p>Hard to believe it, but it’s coming up on five years since our company stood up its first <a href="https://puppet.com/">Puppet</a> master. No cake here. Instead, all we get is a lousy old CA certificate expiry.</p><p>At first, I inhaled sharply and mentally prepared myself for the impending chaos of our client certificates becoming invalid.</p><p>Instead, I was pleasantly surprised when I stumbled across <a href="https://forge.puppet.com/puppetlabs/certregen">puppetlabs/certregen</a> which promised to make the whole sorry affair disappear painlessly. It‘s even Puppet 3 compatible!</p><p>The secret-sauce is all around the use of a clever <a href="https://puppet.com/blog/puppet-faces-what-heck-are-faces">Puppet Face</a> to provide the puppet certgen command on your CA server. This simplifies the regeneration of your master’s CA cert to one command, creating a replacement from the exact same key used to create your expiring cert. The new cert’s effectively a drop-in replacement!</p><p>The other piece of magic is a simple, super-portable class that manages the contents of $::localcacert on your client nodes to be the same as whatever’s in your master’s $settings::cacert file. It does this by calling the file()function on the Puppet master on catalog compilation, grabbing what the master believes its CA cert to be. So, we update the CA cert on the master and then the nodes take care of themselves!</p><p>Of course, because the replacement CA certificate is generated from the same keys as your expiring CA cert, this tool is <em>not suitable for use when your CA’s keys have been compromised</em>.</p><p>So how does it work in practice? The module’s <a href="https://github.com/puppetlabs/puppetlabs-certregen/blob/master/README.markdown">README</a> is pretty hot at explaining everything, but for the sake of completeness, here’s the process I used. It assumes that your CA cert <em>hasn’t expired yet</em>.</p><h3>Install the module</h3><p>We use Puppetfile, so I added the following to ours:</p><pre>mod &#39;puppetlabs-certregen&#39;, &#39;0.2.0&#39;</pre><h3>Get the expiring cert’s serial</h3><p>Running puppet certregen ca won’t do anything off the bat — it’ll error and spit out something like so:</p><pre>$ sudo puppet certregen ca<br>Error: The serial number of the CA certificate to rotate must be provided. If you are sure that you want to rotate the CA certificate, rerun this command with --ca_serial 01</pre><h3>Actually regenerate the CA certificate</h3><p>When you’re <em>for-reals</em> ready to regenerate your Puppet master’s CA cert, re-run the above command providing the serial number you gleaned previously:</p><pre>$ sudo puppet certregen ca --ca_serial 01<br>Notice: Backing up current CA certificate to /var/lib/puppet/ssl/ca/ca_crt.1508247754.pem<br>Notice: Signed certificate request for ca<br>CA expiration is now 2022-10-16 13:42:34 UTC<br>CRL next update is now 2022-10-16 13:42:34 UTC</pre><p>As you can see, this backs up the current (expiring) CA cert, just in case. Then it spits out the new expiration date of its replacement. Great!</p><p>To be clear — your CA server now has a new certificate, but all of the nodes in your Puppet deployment still have the old, expiring version. Let’s fix that!</p><h3>Enforce node management of CA cert</h3><p>Now we’ve gotta get some mechanism in place where your nodes can get the updated CA certificate. This is where the certregen::client class comes into play. It defines a File resource that manages each node’s CA certificate (whose path is determined by consulting the $::localcacert variable).</p><p>We use Roles &amp; Profiles, so I added the following to our base profile:</p><pre>include certregen::client</pre><p>The important thing is that all of your nodes get this into their catalogs somehow, so you can use the main manifest or whatever.</p><p>This change needs to make its way into <em>all of the Puppet directory environments that you care about</em>. In my case, I made the change to our production environment and retroactively applied it to a handful of static environments that we care about. I consider pretty much every other environment as disposable.</p><h3>Update compile masters</h3><p>Got any non-CA, compile-only Puppet masters? Get them to complete a Puppet run against your CA as a priority. This’ll update the CA used by these masters to the new one, along with the associated CRL.</p><pre>drew@pmaster-1 $ sudo puppet agent -t --server puppetca.example.com<br>...<br>Notice: /Stage[main]/Certregen::Client/File[/var/lib/puppet/ssl/certs/ca.pem]/content: content changed &#39;{md5}35d987adf79eaaed26780cd0e69f7d52&#39; to &#39;{md5}ed6cb1e53b7ad78ac41629fb8e3e2c38&#39;<br>Notice: /Stage[main]/Certregen::Client/File[/var/lib/puppet/ssl/crl.pem]/content: content changed &#39;{md5}910a663110f54bf974a26b750c3a8a90&#39; to &#39;{md5}a774a54175b68251b11d0b2e264eec37&#39;<br>...</pre><pre>Notice: Finished catalog run in 6.42 seconds</pre><p>If you don’t do this first, any nodes that compile catalogs using these Puppet masters will get the CA cert that the compile master believes to be current — in this case, the old, expiring one! And that’s no good!</p><p>Don’t have any compile masters? Then you’re good.</p><h3>Update CA cert on client nodes</h3><p>As the nodes across your deployment check in with your Puppet masters, you’ll notice their CA certificate and associated CRL update to the new one:</p><pre>drew@host1 $ sudo grep &#39;content changed&#39; /var/log/syslog | grep &#39;Certregen::Client&#39;<br>Oct 17 04:06:59 host1 puppet-agent[6556]: (/Stage[main]/Certregen::Client/File[/var/lib/puppet/ssl/certs/ca.pem]/content) content changed &#39;{md5}35d987adf79eaaed26780cd0e69f7d52&#39; to &#39;{md5}ed6cb1e53b7ad78ac41629fb8e3e2c38&#39;<br>Oct 17 04:06:59 host1 puppet-agent[6556]: (/Stage[main]/Certregen::Client/File[/var/lib/puppet/ssl/crl.pem]/content) content changed &#39;{md5}910a663110f54bf974a26b750c3a8a90&#39; to &#39;{md5}a774a54175b68251b11d0b2e264eec37&#39;</pre><p>If in doubt, you can check that the CA certificate serials of your Puppet CA and your client nodess match!</p><pre>root<a href="/service/mailto:root@puppet-test.east.fdbox.net">@</a>puppetca # openssl x509 -in $(puppet config print cacert) -noout -text | grep Serial<br>        Serial Number: 7 (0x7)</pre><pre>root@node1 # openssl x509 -in $(puppet config print localcacert) -noout -text | grep Serial<br>        Serial Number: 7 (0x7)</pre><p>And whew, you’ve just avoided what could have been a major problem. Just like that. Thanks, Puppet!</p><h3>Things to remember (or is it “things I found out”?)</h3><p>After including the ::certregen::client class, the content of each node’s$::localcacert and $::hostcrl files will be managed by Puppet, and kept up to date with the most recent versions located on your Puppetmasters.</p><p>That means that if a certificate is revoked on your CA, an entry will be added to its CRL. And that new version of the CRL will subsequently be pushed out across all of the nodes with the ::certregen::client class included in their manifests.</p><p>More importantly, consider whether ::certregen::client is going to affect your Puppet CA’s <em>own catalog</em>. Consider where your Puppet CA gets <em>its</em> catalog from.</p><p>Is it itself? Then you’re good.</p><p>Is it a different master or a load balancer containing a number of compile masters? If so, things could get messy.</p><p>If your Puppet CA hits another master for its catalog, it may receive an older version of the CRL than it has itself. In reality, this just means that $::cacert and $::localcacert will differ on your Puppet CA (as will $::cacrl and $::hostcrl), which may add some confusion if you start inspecting certs.</p><p>For me, I had a rouge $::cacert living on one of my compile masters, which really added some spice into the mix. It all worked out in the end, though.</p><p>To avoid any of these potential issues, I’d make sure the value of server in /etc/puppet/puppet.conf for your Puppet CA is itself. Probably worth making sure your compile masters point at your Puppet CA for their catalogs, too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3e2ac50bc63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting the dots with `scp`]]></title>
            <link>https://medium.com/@hybby/today-one-of-my-colleagues-was-having-trouble-copying-some-files-between-linux-boxes-4d43f497f716?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d43f497f716</guid>
            <category><![CDATA[scp]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Fri, 18 Nov 2016 16:54:17 GMT</pubDate>
            <atom:updated>2016-11-18T16:57:21.576Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, one of my colleagues was having trouble copying some files between Linux boxes. As a result, I learnt something about scp that I didn’t know before — by default, using scp between two <em>remote</em> hosts from a third party host means that SSH connections “leapfrog” through the box where the source file is located.</p><p>Let me set the scene — imagine three hosts:</p><ul><li>A host calledbastionthat scp copies are initiated from.</li><li>A host called sourcebox that has a file you want to copy (/tmp/source_file).</li><li>A host called destbox that has a place you want to copy the file to (/tmp/destfile).</li></ul><p>Imagine that our private key (~/.ssh/id_rsa) is physically present on bastion, but not on either sourcebox or destbox.</p><p>Our corresponding public key (~/.ssh/id_rsa.pub) is configured in the~/.ssh/authorized_keys file of all three hosts. We can therefore authenticate to each of these three boxes via ssh by using our private key.</p><p>Our /tmp/source_file exists on sourcebox and is accessible from bastion.</p><pre>drew@bastion:~$ ssh -i ~/.ssh/id_rsa sourcebox &#39;cat /tmp/source_file&#39;<br>content of my file</pre><p>Likewise, we can tell that there’s no file called /tmp/dest_file on destbox.</p><pre>drew@bastion:~$ ssh -i ~/.ssh/id_rsa destbox &#39;ls -ld /tmp/dest_file&#39;<br>ls: cannot access /tmp/dest_file: No such file or directory</pre><p>Okay, let’s try and copy our file by using scp from bastion:</p><pre>drew@bastion:~$ scp -i ~/.ssh/id_rsa sourcebox:/tmp/source_file sourcebox:/tmp/dest_file<br>Host key verification failed.<br>lost connection</pre><p>Huh? But… ssh worked before between bastion and both of our other hosts... What gives? Both of these hosts are located in the ~/.ssh/known_hosts file of bastion, too…</p><pre>drew@bastion:~$ ssh-keygen -F sourcebox | grep found<br># Host sourcebox found: line 3 type ECDSA</pre><pre>drew@bastion:~$ ssh-keygen -F destbox | grep found<br># Host destbox found: line 4 type ECDSA</pre><p>Let’s dig a bit deeper with a bit of ssh&#39;s -vvv option… (I’ve omitted a lot of the noise with ellipsis to make it easier to read)</p><pre>drew@bastion:~$ scp -vvv -i ~/.ssh/id_rsa sourcebox:/tmp/source_file destbox:/tmp/dest_file<br>...<br>debug1: Host &#39;sourcebox&#39; is known and matches the ECDSA host key.<br>...<br>debug1: Authentication succeeded (publickey).<br>Authenticated to sourcebox ([192.168.10.12]:22).<br>...<br>debug1: Connecting to destbox [192.168.10.13] port 22.<br>...<br>debug1: Sending command: scp -v /tmp/source_file destbox:/tmp/dest_file<br>...<br>Host key verification failed.<br>lost connection</pre><p>So, it seems like when we invoke scp from bastion, we first connect to sourcebox and then initiate a connection <em>from there</em> to destbox.</p><p>As it stands, sourcebox doesn’t know about destbox, so we can fix that by adding destbox&#39;s host keys…</p><pre>drew@sourcebox:~$ ssh-keyscan destbox &gt;&gt; ~/.ssh/known_hosts<br># destbox SSH-2.0-OpenSSH_6.6p1 Ubuntu-2ubuntu1<br># destbox SSH-2.0-OpenSSH_6.6p1 Ubuntu-2ubuntu1</pre><pre>drew@sourcebox:~$ ssh-keygen -F destbox | grep found<br># Host destbox found: line 1 type RSA<br># Host destbox found: line 2 type ECDSA</pre><p>Let’s try again and see where we stand…</p><pre>drew@bastion:~$ scp -i ~/.ssh/id_rsa sourcebox:/tmp/source_file destbox:/tmp/dest_file<br>Permission denied, please try again.<br>Permission denied, please try again.<br>Permission denied (publickey,password).<br>lost connection</pre><p>Our host key problem is now resolved. Our sourcebox host now successfully validates the host key of destbox. But we have another problem…</p><p>Now we’re getting authentication failure messages. Basically, the private key that we’re using from bastion isn’t present on sourcebox, so we’re effectively trying to authenticate to destbox from sourceboxwithout a password, an attempt which is swiftly rebuffed by destbox.</p><p>You can fix this from bastion by using a feature of ssh called AgentForwarding. First, you load your private key into ssh-agentand tell scpto forward it by using -o ForwardAgent=yes...</p><pre>drew@bastion:~$ eval $(ssh-agent)<br>Agent pid 3117</pre><pre>drew@bastion:~$ ssh-add<br>Identity added: /home/drew/.ssh/id_rsa (/home/drew/.ssh/id_rsa)</pre><pre>drew@bastion:~$ scp -o ForwardAgent=true sourcebox:/tmp/source_file destbox:/tmp/dest_file</pre><pre>drew@bastion:~$ ssh destbox &#39;cat /tmp/dest_file&#39;<br>content of my file</pre><p>Another way around this without using ssh-agent <em>or </em>having to configure anything on sourcebox would be to use the -3 option that comes with scp. From scp(1):</p><blockquote>-3 Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. Note that this option disables the progress meter.</blockquote><p>This would change the connections that are made by scp from this:</p><pre>bastion -&gt; sourcebox    # initiate connection to sourcebox<br>sourcebox -&gt; destbox    # copy from sourcebox to destbox</pre><p>to this:</p><pre>bastion -&gt; sourcebox    # copy from sourcebox to bastion<br>bastion -&gt; destbox      # copy from bastion to destbox</pre><p>Both of these are a bit more convenient than manually setting up SSH tunnels or anything like that. And both options help to reduce the number of places you have to plonk your private key, which is always good.</p><p>I’ve been using these tools for a long time now, but for some reason in my head I always assumed that connections were made from <em>the place that the command was invoked</em>. TIL, I guess.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d43f497f716" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deleting EBS Volumes While Snapshotting]]></title>
            <link>https://medium.com/@hybby/deleting-ebs-volumes-while-snapshotting-271ca0518380?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/271ca0518380</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Tue, 26 Jul 2016 09:16:58 GMT</pubDate>
            <atom:updated>2016-07-26T09:16:58.259Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been working with AWS quite heavily recently. A lot of the time, I find myself thinking, <em>“I wonder what happens if I do this…”</em></p><p>Sometimes, I can find the answer in Amazon’s fairly extensive documentation library. But sometimes, I want to perform events in a certain order where the consequences aren’t described clearly.</p><p>For example, <em>“What happens if I delete an EBS volume while a snapshot operation is taking place?”</em>. Advice that I could find implied that snapshots were asynchronous operations and that volumes were safe to use after the snapshot was initiated (incurring a performance penalty, of course). However, nothing was said about deletions.</p><p>I tested it out. Turns out that if you delete a volume while a snapshot’s being taken, the volume remains in a <em>Deleting</em> state until the snapshot’s completed. Once the snapshot is finished, the volume is fully deleted.</p><p>This makes sense. I’m glad it happens this way and we don’t end up with failed snapshots or anything silly like that. +1 for sensibility, AWS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=271ca0518380" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shimming a disk into a VxVM disk group]]></title>
            <link>https://medium.com/@hybby/shimming-a-disk-into-a-vxvm-disk-group-14d41aa6d49c?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/14d41aa6d49c</guid>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[vxvm]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Fri, 25 Sep 2015 10:34:19 GMT</pubDate>
            <atom:updated>2015-09-28T21:21:41.673Z</atom:updated>
            <content:encoded><![CDATA[<p>We had a problem with an Oracle database on a four node <em>Veritas Cluster Server (VCS)</em> cluster<em> </em>recently. The symptom of our problem was that the database had been brought down with <em>VCS</em> and just <em>wouldn’t</em> come back up again. The problem was ultimately traced down to the <em>Veritas Volume Manager (VxVM) </em>disk group level.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7578dd3492f7524fe161e7fddf53a91a/href">https://medium.com/media/7578dd3492f7524fe161e7fddf53a91a/href</a></iframe><h4>Initial analysis</h4><p>The original diagnosis was that a SAN disk (LUN) had been accidentally unmapped from the host and put back hurriedly, resulting in it disappearing from the host. Volume migrations on our <em>IBM XIV</em> arrays have caused things like this in the past, and regular SCSI bus scans don’t result in the LUN coming back in.</p><p>So, we thought we’d take an outage, reboot and see if the LUN would come back in. It’d been up for a couple of years and <em>did</em> have a lot of SAN storage presented to it (subject to relatively frequent change). Maybe the host’s SCSI subsystem was being funky. We could patch while we were at it, too.</p><p>One reboot later and still no dice — the missing LUN was nowhere to be found. I had a closer look at the disk group’s configuration. Our missing LUN was only used in one of the <em>VxVM</em> volumes. It was a 256GB sub-disk tacked neatly onto the end of a healthy 1.4TB sub-disk.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/331c7310e8fcffd11e53d3d278e0e773/href">https://medium.com/media/331c7310e8fcffd11e53d3d278e0e773/href</a></iframe><p>There was only one data plex, so no mirroring in place. There’d be no way to recover any data that was on this disk if the disk group was deemed to be borked.</p><p>So, to the immediate question: <em>“Where is the disk?”</em></p><p>If we could find it, reattaching it and recovering the volume would be a simple enough task. Through sheer luck, I found a text file containing a list of all LUNs configured visible from the host from a couple of months back. Searching for the DA name <strong>`xiv1_1234`</strong> threw up the LUN’s human-friendly name (as configured on the array) along with its size and serial number.</p><p>Next stop was the array. I queried the array for a LUN of the same name. Nothing. Same size? Nothing. Serial number? Nothing.</p><p>There were only a few possibilities at this point:</p><ol><li>The LUN has been renamed and unmapped from the host.</li><li>The LUN has been deleted.</li></ol><p>At this stage, I turned to our storage guys. I gave them all of the details I had gathered. Turns out that the LUN had been deleted erroneously as part of a decommission of a completely different database <em>some months earlier</em>! And as it was a development database, there were no full backups to speak of.</p><p>However, I did think it was strange that our database hadn’t noticed that one of its LUNs had disappeared! It had been running merrily for the past four months, oblivious. The cluster software had shut down it cleanly and deported its disks without a problem. It was only when trying to bring its storage back in again did we encounter our problem.</p><p>I speculated that since the database <em>had</em> been running fine before it was shut down, it must not have had any of its data located on the deleted LUN. If the database <em>had </em>tried to issue any read or write operations to the deleted LUN, there’d have been I/O errors everywhere.</p><p><em>VxVM</em> usually writes sequentially to its volumes. Our deleted LUN had been right at the end of our impacted volume. A colleague&#39;s <strong>`df`</strong> output increased my confidence in this, although it was a <em>pretty close call!</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82fde4821c7f11fd253dc4d3b8f66851/href">https://medium.com/media/82fde4821c7f11fd253dc4d3b8f66851/href</a></iframe><p>Given all of this information, I wondered — what if i grabbed a blank LUN of the same size and tried to fool <em>VxVM</em> into importing the disk group by using it as a shim? Worth a shot, right? So, I had the storage guys present a new LUN and take a snapshot of the surviving disk (in case i royally borked stuff up) and got to work.</p><h4>You’ve gotta destroy to rebuild…</h4><p>Because our volume had only one plex, it would be impossible for <em>VxVM</em> to rebuild any data that it thought was on our failed sub-disk. Therefore, standard disk recovery commands such as <strong>`vxrecover`</strong> wouldn’t help us.</p><p>However, Symantec <a href="http://www.symantec.com/connect/downloads/script-change-group-id-veritas-disk-group">describe a method of destroying and recreating a disk group in place</a> for the purposes of changing its unique disk group ID (DGID). We could use this method to recreate our disk group, too! Of course, we’d be making a few adjustments…</p><p><em>VxVM</em> stores a lot of metadata to describe the layout of its disk groups and volumes. For example, the sub-disk configuration contains the path to the block device of the multipath device that it’s stored on, which <em>Veritas Dynamic Multipather (VxDMP)</em> then distributes I/O to the storage paths. The metadata <em>completely </em>represents these data structures — if you have all of the metadata, it’s possible to recreate a disk group that’s been destroyed, as long as nothing’s damaged them.</p><p>Because I was able to partially import the disk group, I was able to dump the configuration of that disk group (we had one good LUN, remember?).</p><pre># vxprint -g datadb_DEV -hmvps &gt;&gt; /var/tmp/datadb_DEV.layout</pre><p>Even if I wasn’t able to do this, there’d be a good chance that <strong>`vxbackupd`</strong> would have stored some backup configuration copies from some point in <strong>`/etc/vx/cbr/bk`</strong>.</p><p>My troublesome volume was made up of two sub-disks. What a lucky situation — since I had one <em>good</em> sub-disk and one <em>bad </em>sub-disk, I was able to compare the metadata information and figure out what I had to change to make my bad sub-disk look good again…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*-JoLknwjzimY_e8Ga2wAQA.png" /></figure><p>Great! I know what I need to add, and I know what I need to change to make a good sub-disk. I just needed a few more pieces of information, first.</p><p>One thing that I didn’t have available to me already was the <strong>`dev`</strong> string for my newly assigned shim disk. I also needed the unique <strong>`guid`</strong> for the disk, too. These were easy to find, but I needed to temporarily configure the disk to find it out:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/324910f64b08a8e2a1aeaed4f2ce77b1/href">https://medium.com/media/324910f64b08a8e2a1aeaed4f2ce77b1/href</a></iframe><p>I also needed what <em>VxVM</em> believed to be the correct associations between <em>Disk Access (DA)</em> or <em>Dynamic Multipath (DMP)</em> names — the multipath block device — and DM names — a name assigned by humans to each disk.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7da118846935d0e1f87fa23cd91607a/href">https://medium.com/media/f7da118846935d0e1f87fa23cd91607a/href</a></iframe><p>Finally, I needed the public and private region offsets for each LUN in the disk group. These are required so that when we reinitialise our disks, we can tell <em>VxVM</em> where its disk header (private region) is, and where the data starts (the public region). Without these exact values, we run the risk of overwriting areas that used to contain data with new headers, instantly corrupting the disk. For good.</p><p>These values were simple to get from the healthy LUN (<strong>`vxdisk list`</strong>). However, for the failed LUN, I had to go through a bunch of old configuration copy backups located in <strong>`/etc/vx/cbr/bk`</strong> and hope that I’d find config for my failed disk. It was my lucky day, again.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57067716e6b4a50d9e2449ab406ad7f2/href">https://medium.com/media/57067716e6b4a50d9e2449ab406ad7f2/href</a></iframe><p>With my information in hand, I edited the following fields within my <strong>`/var/tmp/datadb_DEV.layout`</strong> file to match my newly assigned LUN. Here are the fields that I changed or added to my file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01bc5780cd439f3428195e1125914013/href">https://medium.com/media/01bc5780cd439f3428195e1125914013/href</a></iframe><p>I now had everything I needed to destroy and recreate my diskgroup.</p><h4>Put it all together and what do you get?</h4><ol><li>Ensure the disk group is deported</li><li>Reinitialise all disks with the correct public and private region offsets</li><li>Use our updated metadata to recreate our disk group</li><li>Activate our <em>VxVM</em> volumes and <strong>`fsck`</strong> them</li><li>Mount our filesystems</li><li>???</li><li>Profit!</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1aa9eaa734d0e1386881b5d66f7153e/href">https://medium.com/media/c1aa9eaa734d0e1386881b5d66f7153e/href</a></iframe><p>After this, the troublesome volume was marked as ENABLED. The filesystem checks returned okay. Everything mounted successfully. I asked a couple of our database guys to have a look and try to open the database instance.</p><p>The database opened! So, the shim worked! <em>VxVM</em> had no idea that the disk had been swapped out from under it!</p><p>I have to concede that in this situation, I was extremely lucky. What were the chances of an unused (but configured) disk being deleted from an array? And what were the chances of the database not trying to write to that disk for a number of months afterwards? Most amazingly, what were the chances of being able pulling off some brazen disk butchery without a hitch?</p><p>Time for a beer!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14d41aa6d49c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using dlpiping to test VCS heartbeats]]></title>
            <link>https://medium.com/@hybby/dlpiping-to-test-vcs-heartbeats-1250f8d9dd18?source=rss-5dc4be744d5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1250f8d9dd18</guid>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[vc]]></category>
            <dc:creator><![CDATA[drew jess]]></dc:creator>
            <pubDate>Wed, 16 Sep 2015 14:19:58 GMT</pubDate>
            <atom:updated>2015-09-28T20:51:34.928Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine you have a couple of hosts with <em>Veritas Cluster Server (VCS)</em> installed, configured with the recommended two heartbeat interfaces. Only, you’re not sure whether they’re able to communicate or not!</p><p>In the normal TCP/IP world, you’d just <strong>`ping`</strong> the hosts via the relevant network interfaces. However, <em>VCS</em> heartbeats run over the <em>Low Latency Transport (LLT)</em> protocol, which operates at layer 2 of the OSI model. Therefore, its interfaces don’t require IP addresses to be configured on them. Enter <strong>`dlpiping`</strong>! A utility that allows us to test connectivity using the <em>LLT</em> protocol!</p><p>The <strong>`VRTSllt`</strong> package installs the <strong>`dlipiping`</strong> command in <strong>`/opt/VRTSllt`</strong>, so it requires that you’ve gone through the VCS installation process.</p><p>First, decide the host that you want to test connectivity <em>to</em>. Identify one of your heartbeat interfaces. In my case, we’re using <strong>`eth5`</strong>. Grab the hardware address of the interface. Let’s imagine that’s <strong>`01:23:45:67:89:ab`</strong> in our case.</p><p>Now, execute <strong>`dlpiping`</strong> in <em>server mode</em>.</p><pre>root@host1# /opt/VRTSllt/dlpiping -vs eth5<br>using packet size = 78<br>dlpiping: binding ping SAP 0xf00e</pre><p>Now, on the host you want to test connectivity <em>from</em>, send a request!</p><pre>root@host2# /opt/VRTSllt/dlpiping -vc eth5 01:23:45:67:89:ab<br>using packet size = 78<br>dlpiping: sent a request to 01:23:45:67:89:ab<br>dlpiping: received a packet from 01:23:45:67:89:ab<br>01:23:45:67:89:ab is alive</pre><p>Hooray! On your first host, you’ll see a response pop up, too.</p><pre>dlpiping: sent a response</pre><p>This is an invaluable tool in troubleshooting those times when your cluster just won’t come up, no matter what you do! This will give you reassurance that at least your network is working. Or alternatively, confirmation that you’ve got lower level issues!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1250f8d9dd18" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>