<?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 Rhyno van der Sluijs on Medium]]></title>
        <description><![CDATA[Stories by Rhyno van der Sluijs on Medium]]></description>
        <link>https://medium.com/@rhyno-vds?source=rss-9a46b540b99e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ip_5WaUZzrqa-BZAZJd1Rg.png</url>
            <title>Stories by Rhyno van der Sluijs on Medium</title>
            <link>https://medium.com/@rhyno-vds?source=rss-9a46b540b99e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:21:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rhyno-vds/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[The Secret Power of CloudFormation]]></title>
            <link>https://rhyno-vds.medium.com/the-secret-power-of-cloudformation-78c93ed9e5ec?source=rss-9a46b540b99e------2</link>
            <guid isPermaLink="false">https://medium.com/p/78c93ed9e5ec</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Rhyno van der Sluijs]]></dc:creator>
            <pubDate>Fri, 15 Jan 2021 05:25:18 GMT</pubDate>
            <atom:updated>2021-01-26T21:13:20.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lmx4zqmtq118HcahwGuJCw.jpeg" /></figure><h3>CloudFormation’s Secret Powers</h3><p>Terraform vs CloudFormation articles are everywhere. Most seem to highlight Terraforms dominance over CloudFormation. It’s easy to see why. Terraform has a far superior syntax and is much more versatile. However, CloudFormation has features that are not mentioned in any of these articles which in some cases dwarves the advantages that you get from Terraform. Depending on your circumstance, these secret powers could actually sway you to use CloudFormation over Terraform.</p><p>In this article we will look at common problems that organisations face and how using CloudFormation can solve them.</p><h3>Problem: Multi Account/Region Deployments</h3><p>Most organisations that use AWS require mandatory IAM roles, S3 Buckets, or Cloud infrastructure to be deployed across all of their AWS accounts. They may also want to deploy an application to multiple accounts or regions for users. When organisations have many AWS accounts, this can be tedious to manage. No native approach exists in Terraform. Engineers must create pipelines to execute their code in multiple AWS accounts.</p><h3>Solution: StackSets</h3><p>CloudFormation has a useful feature called StackSets. This allows engineers to create a single CloudFormation stack which is then deployed to multiple different AWS accounts or regions. This greatly simplifies provisioning and updating infrastructure across an AWS environment. Engineers can deploy and update a single CloudFormation stack which is subsequently pushed out to all required regions and accounts. Subsequent updates are done in parallel which in itself is a challenge to recreate in Terraform.</p><figure><img alt="Engineers target a StackSet to update multiple instances" src="https://cdn-images-1.medium.com/max/352/1*kV8dGBNlr4HRYjuVr2Mk5g.png" /><figcaption>Engineers target a single StackSet to update multiple stack instances</figcaption></figure><p>StackSets have the ability to define different parameters for different accounts and regions. Therefore dev, test and production environments can be deployed through a single StackSet. When applying an update, it is possible to target which accounts are updated by a StackSet. This means that dev and test environments can be updated before deploying to production. All of these features are ready to use without needing engineers to build it out themselves.</p><p>One challenge with administrating multiple AWS accounts is setting up the required IAM roles in child accounts so that a parent account can provision resources in those accounts. AWS have recently allowed StackSets to automatically create and manage the required IAM roles on your behalf making it even easier to use. When an AWS account is removed from an organisation, a StackSet resources can be configured to automatically delete provisioned resources.</p><h3>Problem: Platform Engineering</h3><p>Large organisations that have many AWS accounts and teams often create a platform engineering team. This team is tasked to standardise monitoring, alerting and infrastructure provisioning across all AWS accounts.</p><p>Let’s suppose that a platform engineer team uses Terraform to define a fully compliant Kubernetes cluster with all monitoring and alerting baked in. Teams will be able to provision this whenever they need a cluster. After completing their scripts, they run into a problem: How do they allow teams to provision a cluster on demand? How do they make updates and force all instances of the cluster to be updated? How can they regulate their AWS accounts to enforce the use of the standardised cluster? Then there are the technical questions such as managing Terraform state and concurrency.</p><h3>Solution: AWS Service Catalogues</h3><p>To solve this problem, CloudFormation natively integrates with AWS Service Catalogues. This service allows us to define a CloudFormation template which is published as a Catalogue Item to targeted AWS account. User’s can then provision the required resources by executing the Service Catalogue item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*j7e-B3T14NW7etJPFcwPbA.jpeg" /><figcaption>Platform Engineers create a service catalogue and publish it to AWS accounts</figcaption></figure><p>With this tool, platform engineers can define their standardised infrastructure. Publishing, updating, and provisioning this infrastructure is solved saving countless months to implement themselves.</p><h3>Problem: Logging, Auditing &amp; Notification</h3><p>Organisations want all changes that are made by their tools to be tracked and audited. In some cases they also want engineers to be notified when changes occur to their environment whether it is in a pipeline or outside of a pipeline.</p><h3>Solution: Stacks &amp; AWS Config</h3><p>When deploying a CloudFormation template, a Stack entity is created representing an instance of that template. This entity shows historical details such as when the stack was created, updated or deleted. Stacks that have been removed still have metadata that exist and can be reviewed.</p><p>AWS Config can be utilised to detect when a Stack set has changed. Notifications can be sent to certain individuals based on rules. It can also be configured to assess CloudFormation stack against agreed upon standard. Stack parameters can be inspected as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*L6gVg8Gdpa1nWBeOJ4Aa7g.jpeg" /><figcaption>Engineers update a CloudFormation stack containing a log of changes. AWS Config audits and alerts on any changes.</figcaption></figure><h3><strong>Other Terraform Challenges</strong></h3><p>In this section we will look at some challenges that exist in Terraform which do not exist in CloudFormation.</p><h4>Parallel Deployments</h4><p>I recently encountered this problem with Terraform. In the environment I was working in, we had an application deployed in many locations globally. When it came to updating all of these instances concurrently, Terraform does not natively support this.</p><p>The reason why is that it operates in a directory which must be initialised. If there are multiple instances of a terraform template in an environment, each of these would be a separately initialised which changes the local terraform state file that is generated. This is particularly challenging in large environments. When using CloudFormation, a user can push their updates and it will concurrently apply the changes.</p><h4><strong>State Management</strong></h4><p>Articles comparing Terraform to CloudFormation almost always have this as a win for CloudFormation. In my opinion, this is understated especially when you have a large AWS environment. State management can be tedious. Location, security, access and concurrency need to be managed. It is possible for state file storage to get disorganised. Teams need to agree and commit to a location / naming conventions for storing state files.</p><h3>Building these features in Terraform</h3><p>Most of these problems can be solved with Terraform. I have successfully solved these myself. “Let’s create a Jenkins pipeline that executes the Terraform code!” … but it is never as straight forward as that. How do we manage multiple different Terraform instances across different AWS accounts and regions whilst ensuring that they are updated when the platform team makes changes? Then there is the concurrency issue. How do we plan on concurrently updating many instances of a template in Terraform?</p><p>Yes, all of these problems can be solved. But now the platform team has to manage the Terraform code and a complex custom Jenkins deployment pipeline. This overhead can not be underestimated when stretched across many AWS accounts. When using CloudFormation, all of these powerful features exist out of the box ready to go.</p><h3>Conclusion</h3><p>CloudFormation is more than an IaC tool. It attempts to solve the management of provisioning and updating resources across an entire organisation. This is a massive win for organisations that have many AWS accounts. Terraform, in itself, does not attempt to do this. It is purely an IaC tool. Other services need to be either created or purchased. Building that kind of capability for terraform must not be underestimated.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78c93ed9e5ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easily restrict Kubernetes access to CloudFront]]></title>
            <link>https://rhyno-vds.medium.com/easily-restrict-kubernetes-access-to-cloudfront-3c26c0654224?source=rss-9a46b540b99e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c26c0654224</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[cloudfront]]></category>
            <dc:creator><![CDATA[Rhyno van der Sluijs]]></dc:creator>
            <pubDate>Wed, 25 Nov 2020 06:48:46 GMT</pubDate>
            <atom:updated>2020-11-25T06:48:46.039Z</atom:updated>
            <content:encoded><![CDATA[<p>CloudFront is an easy to use CDN that can be placed in front of an Elastic Load Balancer (ELB). However, placing CloudFront in front of an ELB does not guarantee that all traffic will go through CloudFront. It is possible to bypass it completely and go straight to the ELB which poses a security concern when relying on restrictions implemented on CloudFront including AWS WAF.</p><p>CloudFront allows you to send a custom header and value to an origin. This feature can be used to validate that requests have originated from CloudFront. When using Kubernetes and an Nginx controller, it is possible to configure Nginx to check for incoming headers. If the custom header exists with a valid shared token, then the request is valid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*c6LldkIH8NT-EodvtdKyDQ.png" /><figcaption>Request goes through CloudFront which adds header and passes Nginx check</figcaption></figure><p>If the request does not contain the custom header, the request will be dropped. Therefore, all requests going directly to the load balancer will not have the custom header and will be dropped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*gAKtzLXn7VQTTnfQqi10HQ.png" /><figcaption>Request goes directly through ELB and fails Nginx check</figcaption></figure><h3>Step 1: Configuring CloudFront</h3><p>To lockdown CloudFront to Kubernetes, we need to make CloudFront add a custom header on every request to the origin. This can be done by adding a new header and value to the section <strong>Origin Custom Headers</strong>.<strong> </strong>We will look at two methods of configuring this.</p><p><strong>Option 1: Configuring through UI</strong></p><p>For an existing distribution, the configuration location can be found by navigating to:</p><p>Selected Distribution -&gt; Origins and Origin Groups -&gt; Edit Origin</p><p>The <strong>Origin Custom Header </strong>can be found at the bottom of the edit screen as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*lI29RvxQdixQv2jAnLo72g.png" /><figcaption>Create a new header with a random value</figcaption></figure><p><strong>Option 2: Configuring with CloudFormation</strong></p><p>It is possible to use CloudFormation or Terraform to configure the <strong>Origin Custom Header</strong>. The following is a simple CloudFormation template that shows how to add the custom headers to an origin:</p><pre>AWSTemplateFormatVersion: 2010-09-09<br>Parameters: <br>  OriginDomain: <br>    Type: String<br>  CloudfrontToken: <br>    Type: String<br>  OriginRequestPolicyId:<br>    Type: String<br>    Default: 216adef6-5c7f-47e4-b989-5492eafa07d3<br>  CachePolicyId:<br>    Type: String<br>    Default: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad</pre><pre>Resources:<br>  CloudfrontDistributionWithToken:<br>    Type: AWS::CloudFront::Distribution<br>    Properties:<br>      DistributionConfig:<br>        DefaultCacheBehavior:<br>          TargetOriginId: !Ref OriginDomain <br>          ViewerProtocolPolicy: allow-all<br>          OriginRequestPolicyId: !Ref OriginRequestPolicyId<br>          CachePolicyId: !Ref CachePolicyId<br>        Enabled: True<br>        Origins:<br>          - Id: !Ref OriginDomain<br>            DomainName: !Ref OriginDomain<br>            <strong>OriginCustomHeaders:<br>              - HeaderName: cf-token<br>                HeaderValue: !Ref CloudfrontToken</strong><br>            CustomOriginConfig:<br>              HTTPPort: 80<br>              HTTPSPort: 443<br>              OriginProtocolPolicy: match-viewer</pre><h3>Step 2: Configuring Nginx Controller</h3><p>In order to make Nginx check for incoming headers, a small script will need to be added. This can be done by updating the Nginx controller configmap. We will look at updating the configmap directly as well as updating it through the nginx-controller helm chart.</p><p><strong>Option 1: Updating configmap directly</strong></p><p>On your kubernetes cluster, locate the configmap used by the nginx controller. This is usually called <strong>ingress-nginx-controller </strong>in the <strong>ingress-nginx</strong> namespace.</p><p>Within the configmap, update the data variable and add the following lines:</p><pre>location-snippet: |<br>  if ($http_cf_token != &#39;random_value&#39;) {</pre><pre>   return 403;<br>  }</pre><p>This small script will check whether or not the header <strong>cf-token</strong> is equal to the specified value. Remember to set <strong>random_value</strong> to your token value. Your configmap should look something like this:</p><pre>apiVersion: v1<br>kind: ConfigMap<br>data:<br><strong>  location-snippet: |<br>  if ($http_cf_token != &#39;random_value&#39;) {<br>   return 403;<br>  }</strong><br></pre><p><strong>Option 2: Updating helm chart</strong></p><p>If you are using helm chart for your Nginx controller deployment, you can add the <strong>config</strong> variable to your values.yaml file as shown below and update your helm release.</p><pre>controller:<br>  config:<br>  <strong> location-snippet: |<br>     if ($http_cf_token != ‘${cf_token}’) {<br>      return 403;<br>     }</strong></pre><h3>Automation Ideas</h3><p>All of the mentioned steps can be automated using infrastructure as code tools such as Terraform and CloudFormation. For example, it is possible to generate random value in Terraform and CloudFormation which is used as the shared token between CloudFront and the Nginx controller</p><p>With terraform, this can be done by using the <a href="https://registry.terraform.io/providers/hashicorp/random/latest/docs">random provider</a>. With CloudFormation, it is a bit more difficult but a range of options are available which you can search online. I have used the <a href="https://stackoverflow.com/questions/54897459/how-to-set-semi-random-name-for-s3-bucket-using-cloud-formation">Stack ID</a> approach before where a random value is retrieved from the Stack ID.</p><h3>Summary</h3><p>It is possible to restrict Kubernetes access to CloudFront by making CloudFront add a Custom header on each request. This header is then checked by the Nginx controller. With these changes, all requests to Kubernetes will be validated to ensure that requests come from CloudFront. This ensures that no one can bypass and potentially evade restrictions implemented on CloudFront.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c26c0654224" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>