<?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 Felipe Costa on Medium]]></title>
        <description><![CDATA[Stories by Felipe Costa on Medium]]></description>
        <link>https://medium.com/@devsecguy?source=rss-7ffb4dc1debb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XE2q8rRVtbhO8gp7rMRWRQ.jpeg</url>
            <title>Stories by Felipe Costa on Medium</title>
            <link>https://medium.com/@devsecguy?source=rss-7ffb4dc1debb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 30 May 2026 17:38:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devsecguy/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[Creating Lambda Custom Packages]]></title>
            <link>https://towardsaws.com/creating-lambda-custom-packages-bb36e78c4ae6?source=rss-7ffb4dc1debb------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb36e78c4ae6</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[dependencies]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[Felipe Costa]]></dc:creator>
            <pubDate>Tue, 13 Aug 2024 04:48:12 GMT</pubDate>
            <atom:updated>2024-08-13T05:20:30.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OOx-XeCL6Mpi-ZoreITI-Q.png" /></figure><p>Serverless applications are becoming more and more popular and they are the barebones of event-driven architectures. The fact that we don’t need to manage infrastructure and we can just run code as a service is pretty awesome, it’s like orchestrating a symphony without knowing where the musicians sit, relying on invisible, ephemeral orchestrators that appear and disappear based on demand.</p><p>Back in 2014, AWS introduced <a href="https://aws.amazon.com/lambda/">Lambda</a>, a serverless computing service that fits perfectly into this new paradigm, and it has been a game changer ever since. Lambda can run code on demand and has great integration with other AWS services, making it a perfect candidate for building serverless applications.</p><p>We can run so many languages such as NodeJS, Go, Python, Java, and many others. Some of the key components Lambda has are the following:</p><ul><li><strong>Function Code:</strong> A block of code that runs in response to an event. It can be triggered by HTTP requests, changes in data, or even a schedule.</li><li><strong>Handler:</strong> The entry point of a Lambda function. It’s the function that Lambda calls when the function is invoked.</li><li><strong>Execution Role:</strong> An IAM role that grants permissions to the Lambda function. It defines what the function can do and what resources it can access.</li><li><strong>Configuration:</strong> The settings that define how the function behaves. It includes the function name, runtime, memory size, timeout, and other settings.</li></ul><p>With these components, you can create a Lambda function that runs your code in response to events. You can deploy manually or using an Infrastructure as Code (IaC) tool like <a href="https://www.terraform.io/">Terraform</a> or <a href="https://aws.amazon.com/cloudformation/">CloudFormation</a>.</p><p>One of the main challenges of building serverless applications is managing dependencies. Lambda already comes with some pre-installed packages, but if your code requires additional packages, you need to install them yourself. You can include these libraries by packaging them with your function code. I’m not a developer, but when I was learning about Lambda, I found that the process of packaging dependencies with the function code can be complicated, it took me some time to get it right and the documentation at the time didn’t seem clear enough to me, that’s why I decided to write this article — you can thank me later. ✌️</p><p>There are 2 main ways to package dependencies with your Lambda function code:</p><ul><li><strong>Lambda Layers</strong>: You can create a Lambda Layer that contains the dependencies and attach it to the function. This is useful when you have common dependencies shared across multiple functions.</li><li><strong>Custom Packages</strong>: You can package the dependencies in a separate directory and include them with the function code. This is useful for large dependencies or when you have a lot of dependencies.</li></ul><p>I’ll show you how to package custom dependencies with your Lambda function code using both methods in this article. I’ll use a simple code example to demonstrate the process, with a step-by-step guide that you can follow to package your dependencies.</p><p>I will use Python, but the same principles apply to other runtimes. Let’s say you have a Lambda function that uses the <em>requests</em> library to make HTTP requests. The <em>requests</em> library is not available by default in Lambda, so you need to include it with your function code.</p><p>Here’s how you can package the <em>requests</em> library with your Lambda function code:</p><p>1. Create a directory for your Lambda function code. You can name the directory <strong>lambda_function</strong>.</p><p>2. Create a <strong>requirements.txt</strong> file in the <strong>lambda_function</strong> directory. Add the following line to the <strong>requirements.txt</strong> file:</p><pre>requests==2.31.0</pre><p>3. Create a <em>handler.py</em> file in the <strong>lambda_function</strong> directory. Add the following code to the <em>handler.py</em> file:</p><pre>import requests<br><br>def lambda_handler(event, context):<br>    response = requests.get(&#39;https://dog.ceo/api/breeds/list/all&#39;)<br>    return response.json()</pre><p>This code accesses an API endpoint that provides a list of all dog breeds. When you make a GET request to this endpoint, it returns a JSON object containing a comprehensive list of all dog breeds, organized by their breed names. Each breed name may include sub-breeds as well. We are using the <em>requests </em>package to query this API.</p><p>The next step will be to install the requests package and create a zip:</p><pre># Install Requests<br>pip3 install -r requirements.txt -t .<br><br># Create the Zip<br>zip -r handler.zip .</pre><p>Now it’s time to deploy the Lambda function. This can be done manually using the AWS Management Console, or you can use an IaC tool like Terraform or CloudFormation to deploy the function.</p><p>When you deploy the function, you need to upload the <strong>lambda_function.zip</strong> file as the function code. The Lambda service will extract the contents of the zip file and run the function code.</p><p>Here’s an example with Terraform, if you want to know how to setup Terraform, check this tutorial <a href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started">here</a>.</p><pre>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}<br><br>resource &quot;aws_iam_role&quot; &quot;role&quot; {<br>  name = &quot;example&quot;<br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect = &quot;Allow&quot;<br>        Principal = {<br>          Service = &quot;lambda.amazonaws.com&quot;<br>        }<br>        Action = &quot;sts:AssumeRole&quot;<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_lambda_function&quot; &quot;lambda_custom_package&quot; {<br>  function_name = &quot;lambda_custom_package&quot;<br>  handler = &quot;handler.lambda_handler&quot;<br>  runtime = &quot;python3.9&quot;<br>  role = aws_iam_role.role.arn<br>  filename = &quot;handler.zip&quot;<br>}</pre><p>To deploy the Terraform code, just run:</p><pre>terraform init<br>terraform apply</pre><p>This is how your function should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyAbUvG24xMGVIq9T7F2sQ.png" /><figcaption>Lambda Function</figcaption></figure><p>If you invoke your function, you should get the result of the API call to the dog.ceo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*40d8aadf2SBYnZqe8FVETg.png" /><figcaption>Invoke Results</figcaption></figure><p>Another way to use custom packages is by creating a <a href="https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html">Lambda Layer</a>, which is a way to share code and dependencies across multiple functions. You can create a Layer that contains the <em>requests</em> package and attach it to your function. This way, you can reuse the same layer across multiple functions, reducing the size of the function code and making it easier to manage dependencies.</p><p>Here’s how you can create a Lambda Layer using the <em>requests</em> package:</p><p>1. Create a directory named <strong>python </strong>for your Lambda Layer.</p><p>2. Create a <em>requirements.txt</em> file in the directory and add the following line to the <em>requirements.txt</em> file:</p><pre>requests==2.31.0</pre><p>3. The next step will be to install the requests package and create a zip:</p><pre># Install Requests<br>pip3 install -r requirements.txt -t .<br><br># Create the Layer Zip<br>zip -r layer.zip python/<br><br># Create the Code Zip<br>zip -r code.zip handler.py</pre><p>Here’s the Terraform code with the Lambda layer, make sure to select the right Python version and also the architecture of your function:</p><pre><br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}<br><br>resource &quot;aws_iam_role&quot; &quot;layer_role&quot; {<br>  name = &quot;layer_role&quot;<br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect = &quot;Allow&quot;<br>        Principal = {<br>          Service = &quot;lambda.amazonaws.com&quot;<br>        }<br>        Action = &quot;sts:AssumeRole&quot;<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_lambda_layer_version&quot; &quot;lambda_layer&quot; {<br>  layer_name = &quot;requests_layer&quot;<br>  filename = &quot;layer.zip&quot;<br>  compatible_runtimes = [&quot;python3.9&quot;]<br>  compatible_architectures = [&quot;x86_64&quot;]<br>}<br><br>resource &quot;aws_lambda_function&quot; &quot;lambda_with_layer&quot; {<br>  function_name = &quot;lambda_with_layer&quot;<br>  handler = &quot;handler.lambda_handler&quot;<br>  runtime = &quot;python3.9&quot;<br>  architectures = [&quot;x86_64&quot;]<br>  role = aws_iam_role.layer_role.arn<br>  filename = &quot;code.zip&quot;<br>  layers = [aws_lambda_layer_version.lambda_layer.arn]<br>}</pre><p>To deploy the Terraform code, just run:</p><pre>terraform init<br>terraform apply</pre><p>This is how your function should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9fAUpfOlrSMt1ERipKlvw.png" /><figcaption>Function with Layer</figcaption></figure><p>There we go, now you know how to package custom dependencies with your Lambda function code. Everything we discussed here is available on my <a href="https://github.com/felipecosta09/lambda-custom-packages">GitHub</a>. This will help you manage dependencies more effectively and build serverless applications with ease.</p><p>I hope you found this article helpful, and I encourage you to explore Lambda further and experiment with different use cases. Serverless is a powerful tool that can help you build scalable, cost-effective applications, and Lambda is a key component of this paradigm. Happy coding! 🧑‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb36e78c4ae6" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/creating-lambda-custom-packages-bb36e78c4ae6">Creating Lambda Custom Packages</a> was originally published in <a href="https://towardsaws.com">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate AWS Secret Rotation]]></title>
            <link>https://towardsaws.com/automate-aws-secret-rotation-4f2411b038a8?source=rss-7ffb4dc1debb------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f2411b038a8</guid>
            <category><![CDATA[secrets]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Felipe Costa]]></dc:creator>
            <pubDate>Mon, 05 Aug 2024 05:09:11 GMT</pubDate>
            <atom:updated>2024-08-22T15:42:04.624Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automate AWS Secret Rotation with Lambda 🔐</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IKat6qgPZ4w79hZIQlBKRg.png" /></figure><p>Secrets are essential components of applications, including passwords, API keys, tokens, and certificates. If these secrets are compromised, your entire system could be at risk. That’s why it’s essential to apply the right security measures and to rotate them regularly.</p><p>In 2023, <a href="https://www.securityweek.com/major-organizations-using-hugging-face-ai-tools-put-at-risk-by-leaked-api-tokens/">AI cybersecurity startup Lasso discovered over 1,600 valid Hugging Face API tokens exposed in code repositories</a>, granting access to hundreds of organizations’ accounts. These tokens were exploited to access sensitive data and manipulate AI models, impacting organizations like Google, Meta, Microsoft, and VMware.</p><p>Consider your OpenAI API key. If exposed, unauthorized users could incur substantial charges by making requests on your behalf, manipulating your AI models, skewing data and outputs, or stealing sensitive information processed by your AI.</p><p>One of the main vectors of security breaches is the exposure of secrets. If a secret is leaked, it can be used to access sensitive data or perform unauthorized actions. To mitigate this risk, you should rotate your secrets regularly. This means generating new secrets and updating the applications that use them.</p><p>In this article, we’re diving into how you can rotate secrets on AWS using OpenTofu. For those not familiar, <a href="https://opentofu.org/">OpenTofu</a> is the open-source and free version of Terraform, it’s a great tool to manage your infrastructure as code and it’s very easy to use.</p><p>If you’re tired of manually updating passwords and API keys or just want to step up your security game, stick around. We’re about to make secret rotation a breeze!</p><p><a href="https://aws.amazon.com/secrets-manager/">AWS Secrets Manager</a> is a service that helps you to encrypt and centrally manage your secrets such as database credentials and API keys. With Secrets Manager, you can secure, audit, and manage secrets used to access your IT resources. By simply using Secrets Manager, you can avoid storing sensitive information in your code, and you can easily rotate secrets with built-in AWS Lambda functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKFzUqardeyjTt5zqo5hcg.png" /><figcaption>AWS Secret Manager</figcaption></figure><p>You can also use <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html">AWS SSM Parameter Store</a> to store secrets. However, AWS Secrets Manager provides additional features like automatic rotation, audit logs, and cross-account access. In this article, we’ll focus on AWS Secrets Manager.</p><p>By only using AWS Secret Manager you’re already taking a big step towards better security practices and meeting specific compliance requirements, frameworks such as ISO, SOC, and PCI among others, require managing secrets responsibly. But we can go even further by automating the rotation process. This way, you can ensure that your secrets are always up-to-date and that your applications are secure.</p><p>I will show you how to create a secret in AWS Secrets Manager and set up automatic rotation using Lambda, all deployed via <a href="https://opentofu.org/">OpenTofu</a>. We will create a secret with a random API key and configure it to rotate every 30 days (You can customize the rotation period for your needs). We will also create an IAM role that allows the Secret Manager to rotate the secret on our behalf. Finally, we will deploy a Lambda function that will be triggered by Secrets Manager to perform the rotation. I also added to the stack an SNS topic so a notification can be sent once the secret is rotated.</p><p>You can find the Tofu code for this infrastructure in this <a href="https://github.com/felipecosta09/aws-secret-rotation">GitHub repository</a>. Here’s how the architecture looks like once deployed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*W768dbGd6cBcEGn8NMLZiA.png" /><figcaption>Stack Architecture</figcaption></figure><p>Let’s dive into the <a href="https://opentofu.org/">OpenTofu</a> code that creates the infrastructure described above.</p><p>First, we need to create a secret in AWS Secrets Manager. I’m using a random API key as the secret value. I also create the rotation configuration for the secret, which specifies how often the secret should be rotated and the Lambda function that will perform the rotation.</p><pre># Create the Secret Manager<br>resource &quot;aws_secretsmanager_secret&quot; &quot;apikey&quot; {<br>  name = &quot;apikey-${random_string.random.id}&quot;<br>  description = &quot;My API key&quot;<br>  tags = {<br>    Name = &quot;poc-apikey-${random_string.random.id}&quot;<br>  }<br>}<br><br># Store the API key in the secret<br>resource &quot;aws_secretsmanager_secret_version&quot; &quot;apikey&quot; {<br>  secret_id     = aws_secretsmanager_secret.apikey.id<br>  secret_string = var.apikey<br>}<br><br># Create the Rotation Configuration<br>resource &quot;aws_secretsmanager_secret_rotation&quot; &quot;rotation&quot; {<br>  secret_id           = aws_secretsmanager_secret.apikey.id<br>  rotation_lambda_arn = aws_lambda_function.rotation_lambda.arn<br><br>  rotation_rules {<br>    automatically_after_days = 30<br>  }<br>}</pre><p>Now we need to create the Lambda function that rotates the secret, important details are the environment variable <strong><em>SECRET_NAME</em></strong> which is the name of the “secret” in Secrets Manager, and the role that allows the Lambda function to update the secret. I will not go into details about the IAM role and policy, but you can find the code in the <a href="https://github.com/felipecosta09/aws-secret-rotation">GitHub repository</a>.</p><p>The same Lambda function can be used to rotate multiple secrets, in different AWS accounts or regions, as long as the Lambda function has the necessary permissions to update those secrets. You can also create multiple Lambda functions to rotate different secrets, depending on your needs.</p><pre># Create the Lambda Function to Rotate the Secret<br>resource &quot;aws_lambda_function&quot; &quot;rotation_lambda&quot; {<br>  filename         = data.archive_file.rotation_lambda_zip.output_path<br>  function_name    = &quot;rotation-lambda-${random_string.random.id}&quot;<br>  description      = &quot;A lambda function to rotate the secret&quot;<br>  architectures    = [&quot;arm64&quot;]<br>  role             = aws_iam_role.rotation_lambda_role.arn<br>  handler          = &quot;handler.lambda_handler&quot;<br>  runtime          = &quot;python3.12&quot;<br>  timeout          = 30<br>  memory_size      = 128<br>  source_code_hash = data.archive_file.rotation_lambda_zip.output_base64sha256<br>  environment {<br>    variables = {<br>      SECRET_NAME = aws_secretsmanager_secret.apikey.name<br>      TOPIC_ARN   = aws_sns_topic.sns_topic.arn<br>    }<br>  }<br>}</pre><p>The Lambda function is written in Python and uses the AWS SDK to rotate the secret. It is a very simple code that generates a new API key and updates the secret in Secrets Manager, that should be enough to understand how it works. What you need to replace is the function <strong><em>create_secret </em></strong>(placeholder) for the code to pull/generate a new API key for your secret, once the Lambda function is triggered, we have in the handler the logic to update the secret in Secrets Manager.</p><pre>import boto3<br>import os<br>import json<br>import uuid<br>from botocore.exceptions import ClientError<br><br># Initialize the boto3 client<br>secret = boto3.client(&#39;secretsmanager&#39;)<br>sns = boto3.client(&#39;sns&#39;)<br><br># Get environment variables<br>secret_name = os.environ[&#39;SECRET_NAME&#39;]<br>topic_arn = os.environ[&#39;TOPIC_ARN&#39;]<br><br># Function to create a new secret value, replace by your own logic<br>def create_secret(secret_name):<br>    # Generate a new API key<br>    try:<br>        new_api_key = str(uuid.uuid4())<br>        secret = {<br>        &quot;api_key&quot;: new_api_key<br>        }<br>        return json.dumps(secret)<br>    except Exception as e:<br>        print(f&quot;Failed to generate a new secret value: {e}&quot;)<br><br># Function to format the message log<br>def format_response(secret_name, response):<br>    formatted_response = {<br>    &quot;RequestId&quot;: response[&#39;ResponseMetadata&#39;][&#39;RequestId&#39;],<br>    &quot;Date&quot;: response[&#39;ResponseMetadata&#39;][&#39;HTTPHeaders&#39;][&#39;date&#39;],<br>    &quot;SecretId&quot;: secret_name,<br>    &quot;Status&quot;: &quot;Success&quot; if response[&#39;ResponseMetadata&#39;][&#39;HTTPStatusCode&#39;] == 200 else &quot;Failed&quot;,<br>    &quot;HTTPStatusCode&quot;: response[&#39;ResponseMetadata&#39;][&#39;HTTPStatusCode&#39;],        <br>    }<br>    return formatted_response<br><br># Send a notification to the SNS topic<br>def send_notification(message):<br>    try:<br>        response = sns.publish(<br>            TopicArn=topic_arn,<br>            Message=json.dumps(message),<br>            Subject=&#39;Secret rotation completed&#39;<br>        )<br>        print(f&quot;Notification sent to {topic_arn}&quot;)<br>        return response<br>    except ClientError as e:<br>        print(f&quot;Failed to send notification to {topic_arn}: {e}&quot;)<br><br>def lambda_handler(event, context):<br><br>    # Create a new secret<br>    new_secret = create_secret(secret_name)<br><br>    # Update the secret value<br>    try:       <br>        response = secret.put_secret_value(SecretId=secret_name, SecretString=new_secret)<br>        formatted_response_json = format_response(secret_name, response)<br>        print(f&quot;Secret rotation completed&quot;)<br>        print(formatted_response_json)<br>        sns_notification = send_notification(formatted_response_json)<br>        print(sns_notification)<br>    except ClientError as e:<br>        print(f&quot;Failed to update secret {secret_name}: {e}&quot;)<br>        return {<br>            &quot;statusCode&quot;: 500,<br>            &quot;body&quot;: json.dumps(&quot;Secret rotation failed&quot;)<br>        }<br>    <br>    # Return a success message<br>    return {<br>        &quot;statusCode&quot;: 200,<br>        &quot;body&quot;: json.dumps(&quot;Secret rotation completed&quot;)<br>    }</pre><p>Although it’s possible also to use the <strong><em>update_secret</em></strong> method in AWS Secrets Manager to rotate the secret, I recommend using <strong><em>put_secret_value</em></strong> because it only updates the secret value and doesn’t touch the metadata, such as <em>SecretString</em>, <em>SecretBinary</em>, <em>Description</em>, <em>KmsKeyId</em>, and <em>Tags</em>. This way, you can keep the metadata intact and only rotate the secret value.</p><p>You can check the cloudwatch logs to see if the Lambda ran correctly and in the secret manager, you can retrieve the secret to know if it was changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pGKz28ogB-4fPlkbN5jJPA.png" /></figure><p>As you can see below you can also manually trigger the rotation in the secret manager, under Rotation &gt; Rotate secret immediately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*ncqzMD6nuxC2pLolXhqk0Q.png" /></figure><p>After rotating the secret, the Lambda will also publish a notification to an SNS topic. From the SNS you can subscribe to your email address or even other AWS resources, this will allow for a better monitoring of the rotation task:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0mjdqmb-T7GAY2zlseJkgA.png" /><figcaption>Email Notification</figcaption></figure><p>As easy as it looks, this is a very strong security practice that you can implement in your infrastructure. It’s a simple way to keep your secrets up-to-date and secure. By automating the rotation process, you can ensure that your applications are always using the latest secrets and that your system is protected from unauthorized access.</p><p>We have the habit of putting every security practice in security tools, but the tools only make it easier to implement these practices. You can buy a supercar, but it doesn’t do much if you don’t know how to drive. It’s crucial to understand the practice to use the tool properly and make the most of it.</p><p>As we saw in this article, it’s not hard to implement secret rotation and it’s a simple yet powerful way to improve the security of your applications.</p><p>I hope this article has been helpful to you. I would love to answer your questions and feedback, you’re welcome to leave a comment below.</p><h3>References:</h3><p><a href="https://www.securityweek.com/major-organizations-using-hugging-face-ai-tools-put-at-risk-by-leaked-api-tokens/">https://www.securityweek.com/major-organizations-using-hugging-face-ai-tools-put-at-risk-by-leaked-api-tokens/</a></p><p><a href="https://aws.amazon.com/secrets-manager/">https://aws.amazon.com/secrets-manager/</a></p><p><a href="https://opentofu.org/">https://opentofu.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f2411b038a8" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/automate-aws-secret-rotation-4f2411b038a8">Automate AWS Secret Rotation</a> was originally published in <a href="https://towardsaws.com">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cloud One Conformity Template Scanner ]]></title>
            <link>https://medium.com/@devsecguy/cloud-one-conformity-template-scanner-6859b801c596?source=rss-7ffb4dc1debb------2</link>
            <guid isPermaLink="false">https://medium.com/p/6859b801c596</guid>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[trend-micro]]></category>
            <category><![CDATA[misconfiguration]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[cspm]]></category>
            <dc:creator><![CDATA[Felipe Costa]]></dc:creator>
            <pubDate>Thu, 27 Aug 2020 14:58:19 GMT</pubDate>
            <atom:updated>2020-08-27T14:58:19.585Z</atom:updated>
            <content:encoded><![CDATA[<p>The Easiest Way to Scan your Cloud Formation Templates in your Pipeline by ⚡️<a href="https://medium.com/u/7ffb4dc1debb">Felipe Costa</a> and <a href="https://medium.com/u/94534226a645">Raphael Bottino</a>⚡️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DMskbn0YiNV2JZ-O" /><figcaption>Photo by <a href="https://unsplash.com/@markuswinkler?utm_source=medium&amp;utm_medium=referral">Markus Winkler</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Infrastructure-as-a-Code</strong> technology has been used as the <em>de facto</em> way to build infrastructure in the cloud, especially by CI/CD automation tools such as Jenkins, GitHub Actions and so many others. <strong>IaC </strong>allows us to make our applications more dynamic by giving the ability to deploy applications or “Stacks” multiple times per day.</p><p>I’ll link an article explaining deeper this concept here from my friend <a href="https://medium.com/u/e82bad47dcfb">Fernando Cardoso</a>:</p><p><a href="https://medium.com/swlh/putting-security-into-the-iac-pipeline-4de98f88ad24">Putting Security into The IaC Pipeline</a></p><p>There is no question that these tools provide great flexibility and resources to empower developers to make more with less, however…</p><blockquote><em>How to measure security in these configurations and what kind of baselines should we follow?</em></blockquote><p><strong><em>A: These are the concerns that </em></strong><a href="https://www.trendmicro.com/en_us/business/products/hybrid-cloud/cloud-one-conformity.html"><strong><em>Trend Micro Cloud One Conformity</em></strong></a><strong><em> is helping customers to solve.</em></strong></p><p><a href="https://www.trendmicro.com/en_us/business/products/hybrid-cloud/cloud-one-conformity.html"><strong>Trend Micro Cloud One Conformity</strong></a> is a great tool to help you avoid misconfiguration to be introduced in your cloud environment. The platform analyzes your cloud environment looking for misconfigurations/security risks and notifying when someone (Human) or something (CI/CD tools) introduces a new configuration out of best practices in different phases of your development cycle. Theses misconfigurations can be detected in the build phase when the team is changing the code by analyzing your IaC templates directly from the IDE (<a href="https://code.visualstudio.com/">VS Code</a>) or even during the build time by your CI/CD tool. At the runtime of the application, the platform monitors the cloud accounts for any manual intervention or new misconfiguration introduced directly to the cloud environment. Look the illustration below that describes where the platform fits in the DevOps cycle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vEfkrFEwIioA9XfxDstHBQ.png" /><figcaption>Cloud One Conformity in the Development Cycle</figcaption></figure><p>With the mission to make it easier for customers to scan their IaC templates, we&#39;ve decided to create this open-source project so every customer can have access to the code and use it on their own. The project is in GitHub and together with the code we also created a GitHub Action that is a CI/CD automation tool to make this scan be reproducible, you can get this Action on the GitHub Marketplace for <strong>FREE</strong> and use in any GitHub repository, check it out:</p><p><a href="https://github.com/marketplace/actions/cloud-one-conformity-pipeline-scanner">Cloud One Conformity Pipeline Scanner - GitHub Marketplace</a></p><p>The Action that we created in GitHub uses an NPM module to implement all the functionality that the Action needs.</p><p><a href="https://medium.com/u/94534226a645">Raphael Bottino</a> originally created the <a href="https://medium.com/u/96cd9a1fb56">Node.js</a> module that translates the Cloud One Conformity API&#39;s to make it easier to use in a pipeline and in the IDE to scan your <strong>IaC</strong> templates, you can check the <a href="https://www.npmjs.com/">NPM</a> module here and use in your own projects as well:</p><p><a href="https://www.npmjs.com/package/cloud-conformity">cloud-conformity</a></p><p>We&#39;re not going to cover the IDE integration in this article, but it&#39;s already well explored here in this another article below, we highly recommend you to read:</p><p><a href="https://medium.com/@raphabot/shift-well-architecture-left-by-extension-security-will-follow-9012168b56e8">Shift Well-Architecture Left. By Extension, Security Will Follow</a></p><p>The best way to demonstrate why all this tech is awesome is to get our hands dirty, so let&#39;s try out this Action!</p><p>I&#39;ve created a repository in GitHub to show you how this Action work, you can have access to the repository in this link below:</p><p><a href="https://github.com/felipecosta09/Demo-Cloud-One">felipecosta09/Demo-Cloud-One</a></p><p>I&#39;ve added a Cloud Formation template to this repository that simulates a real scenario of a customer getting an infrastructure deployed in AWS Cloud, this is the Cloud Formation <a href="https://github.com/felipecosta09/Demo-Cloud-One/blob/master/infrastructure.yaml">template</a>. We also created the pipeline file that GitHub Actions require to automate your build and every time that there is a new commit, your template will be scanned.</p><p>The Pipeline has only 2 actions, the first action will checkout the code from the repository and the second will scan the template, below is the pipeline file I commented the code also make it easier to read.</p><p>Under the Cloud Formation Action, you can see that there are some parameters that need to be passed, they&#39;re:</p><ul><li><strong>Conformity API Key - </strong>The form of authentication required to access the API, you can see how you generate the API Key <a href="https://www.cloudconformity.com/help/public-api/api-keys.html">here</a>;</li><li><strong>Triggers</strong> - How many misconfigurations are acceptable based on the severity (<em>maxExtreme, maxVeryHigh, maxHigh, maxMedium and maxLow</em>);</li><li><a href="https://github.com/cloudconformity/documentation-api#endpoints"><strong>Cloud Conformity Regions</strong></a><strong> - </strong>The region where your console is located;</li><li><strong>Template Path</strong> - The path of the template that you want to scan;</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca2cb7f8a1cc0f6627861d5a460ba4eb/href">https://medium.com/media/ca2cb7f8a1cc0f6627861d5a460ba4eb/href</a></iframe><p>Based on the &quot;severity triggers&quot; you pipeline will go through or fail, and there it is: you&#39;ll have a fully automated tool that can analyze IaC templates and help you shift-left security in your development cycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGARlDzUz2bQCw_x95KX-w.png" /><figcaption>Result of the Action directly in the Pipeline</figcaption></figure><p>It&#39;s amazing how using a simple tool can make such a great difference in how we approach security by helping developers to analyze their code directly in the current toolset. But we still have a gap here, because if you don&#39;t use GitHub actions and decide to use a different CI/CD tool such as Gitlab or even Jenkins, you won&#39;t be able to execute the steps that I just showed. That&#39;s why we&#39;ve decided to port this project to run inside a docker container, which makes it very portable and keeps the lightweight execution. We&#39;re always looking to provide as many options as we can for our customers to implement security controls. Take a look at the container that is published in <a href="https://hub.docker.com/r/raphabot/conformity-template-scanner-pipeline">Dockerhub</a>.</p><p>This is the command that you can use to scan your templates using a simple docker command:</p><pre>docker run -v /home/ec2-user/dynamotest.template:/app/dynamotest.template -e cc_apikey=$MYAPIKEY -e cc_region=$MYREGION -e maxExtreme=0 -e maxVeryHigh=0 -e maxHigh=0 -e maxMedium=0 -e maxLow=0 -e templatePath=infrastructure.yaml felipecosta09/conformity-template-scanner-pipeline:latest</pre><p><strong>PS.: To be able to scan a local template from a machine or inside a pipeline, the parameter “-v” is required in the docker run command, the example specifies a local file being copied to the container that will scan the Cloud Formation template </strong><strong>/home/ec2user/dynamotest.template:/app/infrastructure.yaml, where:</strong></p><ul><li><strong>/home/ec2-user/infrastructure.yaml</strong> — Represent the absolute path of the local Cloud Formation template file to be scanned;</li><li><strong>/app/infrastructure.yaml</strong> — The path where the file will be copied <strong>(ONLY CHANGE THE FILE NAME OF THE TEMPLATE)</strong>;</li></ul><p>You can also invoke the JS file within the implementation of the npm package to scan your templates, just clone the original <a href="https://github.com/raphabot/conformity-template-scanner-pipeline">GitHub Repo</a>, replace the variables and of course, you need nodejs to be installed, take a look:</p><pre>cc_apikey=$MYAPIKEY cc_region=$MYREGION maxExtreme=0 maxVeryHigh=0 maxHigh=0 maxMedium=0 maxLow=0 templatePath=infrastructure.yaml node scan.js</pre><p>We hope that these tools will help you in your journey to the cloud, application modernization, and to achieve operational excellence. All the work that we start a couple of months ago with this project was because we had so many feedbacks from customers and also in the open-source community, so if there is something that we&#39;re missing, please give your feedback so we can get even better. Our mission at the end of the day is to help with security challenges so you can be successful.</p><h3>References:</h3><p><a href="https://www.npmjs.com/package/cloud-conformity">https://www.npmjs.com/package/cloud-conformity</a></p><p><a href="https://github.com/raphabot/cloud-conformity-cloudformation-scanner">https://github.com/raphabot/cloud-conformity-cloudformation-scanner</a></p><p><a href="https://hub.docker.com/r/raphabot/conformity-template-scanner-pipeline">https://hub.docker.com/r/raphabot/conformity-template-scanner-pipeline</a></p><p><a href="https://github.com/raphabot/conformity-template-scanner-pipeline">https://github.com/raphabot/conformity-template-scanner-pipeline</a></p><p><a href="https://github.com/cloudconformity/documentation-api">https://github.com/cloudconformity/documentation-api</a></p><p><a href="https://www.cloudconformity.com/">https://www.cloudconformity.com/</a></p><p><a href="https://github.com/felipecosta09/Demo-Cloud-One">https://github.com/felipecosta09/Demo-Cloud-One</a></p><p><a href="https://medium.com/swlh/putting-security-into-the-iac-pipeline-4de98f88ad24">https://medium.com/swlh/putting-security-into-the-iac-pipeline-4de98f88ad24</a></p><p><a href="https://medium.com/@raphabot/shift-well-architecture-left-by-extension-security-will-follow-9012168b56e8">https://medium.com/@raphabot/shift-well-architecture-left-by-extension-security-will-follow-9012168b56e8</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6859b801c596" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trend Micro Container Security for CI/CD]]></title>
            <link>https://medium.com/@devsecguy/trend-micro-container-security-for-ci-cd-acbcedd61cae?source=rss-7ffb4dc1debb------2</link>
            <guid isPermaLink="false">https://medium.com/p/acbcedd61cae</guid>
            <category><![CDATA[cloud-one]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[trend-micro]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Felipe Costa]]></dc:creator>
            <pubDate>Tue, 23 Jun 2020 20:36:42 GMT</pubDate>
            <atom:updated>2023-03-24T15:21:30.519Z</atom:updated>
            <content:encoded><![CDATA[<p>How to Integrate Trend Micro Cloud One Container Security in your CI/CD using GitHub Actions ❤️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R3twLuvoH1VwG96f" /><figcaption><strong>Photo by </strong><a href="https://unsplash.com/@yancymin?utm_source=medium&amp;utm_medium=referral"><strong>Yancy Min</strong></a><strong> on </strong><a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral"><strong>Unsplash</strong></a></figcaption></figure><p>Nowadays the CI/CD process is essential to ensure business agility and therefore the success of many companies. DevOps teams have been changing their approach to application development, with a cloud-native and API-first mentality. As a result, teams can now use multiples tools and deploy applications in different environments. Changing deployment or adding more integrations is not a problem anymore and allows the application to take advantage of many services and/or resources that cloud providers have to offer.</p><p>Securing CI/CD pipelines is an obvious requirement since it is a top priority for DevOps teams today. Accomplishing that, however, is not a straightforward process. Implementing frictionless security early in the CI/CD workflow is the best approach to “shift-left” the responsibility for securing any application: the earlier your team can identify new weaknesses or vulnerabilities inside the applications, the easier it will be to fix them. Waiting until after the application is deployed to production — at runtime — makes it a lot more difficult to implement any changes.</p><p>The following tools will help your DevOps teams to have more visibility on the weakness in their code and help also to prioritize security vulnerabilities that matter the most, spending less time fixing non-critical bugs to reduce the overall risk of your applications.</p><p>Here is an article from my friend <a href="https://medium.com/u/e82bad47dcfb">Fernando Cardoso</a> that explains security tools for DevOps pipelines in-depth:</p><p><a href="https://medium.com/swlh/how-to-integrate-security-on-the-devops-pipeline-e36dea836d7b">How to integrate security on the DevOps pipeline?</a></p><p>The best way to understand how these concepts are applied in real life is to get your hands dirty, so let’s create some containers and scan them in pipeline time.</p><p>The architecture is pretty simple: we have a code repository, a CI/CD build system, a container registry, and a platform to deploy the application (I will not cover deployment in this article, maybe in a future one 🤞). We’ll build the container from scratch, push to a container registry, and scan this container to check how many security issues I or my team introduced to this new application.</p><p>For starters, I will use <a href="https://github.com/open-source"><strong>GitHub</strong></a> as my code repository and <a href="https://github.com/features/actions"><strong>GitHub Actions</strong></a> as my CI/CD system because it is integrated and so easy to use, and to scan my brand new container application I will use <a href="https://www.trendmicro.com/en_us/business/products/hybrid-cloud/cloud-one-container-image-security.html"><strong>Trend Micro Cloud One™Container Security</strong></a> (<em>Formerly Deep Security Smart Check</em>), as it allows me to make sure that before I deploy any application to my production environment, I can check for any Malware, Vulnerabilities, Secrets, and Compliance and block my pipeline to go further in case I find any issues with my code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKG1_cG02vtUrf-i2THR-w.png" /><figcaption><strong>Base Architecture of our CI/CD Pipeline</strong></figcaption></figure><blockquote>PS.: I’m also using <a href="https://aws.amazon.com/ecr/">AWS ECR</a> as my container register, but the same process applies to Microsoft® Azure, Google Cloud, and any other cloud provider with a Docker Register base or even local environment.<em> 👍</em></blockquote><p>I’ve created a public repository on my <a href="https://github.com/open-source"><strong>GitHub</strong></a><strong> </strong>called <a href="https://github.com/felipecosta09/Trend-Micro-Container-Security-for-CI-CD"><strong>Trend-Micro-Container-Security-for-CI-CD</strong></a><strong>. </strong>In this repository, I have a Dockerfile that I use to build my container and a few other files that I need for my application to work. I will start by using Github Action to run my first build:</p><p><a href="https://github.com/felipecosta09/Trend-Micro-Container-Security-for-CI-CD">felipecosta09/Trend-Micro-Container-Security-for-CI-CD</a></p><p>To create your first Github Actions pipeline you need to create a folder structure inside your repository in this format:</p><pre>My-Repo/.github/workflow/pipeline.yml</pre><p>Inside the workflow folder, you need to create a YML file that will represent your pipeline, I already created one in my repo:</p><p><em>PS.: You may have noticed that some of the environment variables are secrets, is just to make it more readable and secure to expose on the internet. </em><strong><em>You should always use secrets to expose your keys and secrets.</em></strong></p><p>The tasks to Build, Tag, and Push containers are already known by everyone working with CI/CD pipelines, but I want to focus on how you can scan these containers as soon as they’re ready. The last part of the pipeline is where we scan the container, is a simple GitHub Action that I’ve created and published to GitHub Marketplace so you can use to easily scan your containers without spending a lot of time creating code and most importantly, you can block the pipeline from going further in case it reaches the threshold defined by you. To use the Action, you just select from the Marketplace, input the information requested, and it’s done!</p><p>The mechanism to scan the container is based on a Docker container that the Trend Micro team has created to use Cloud One™ Container Security (Formerly Deep Security Smart Check) API to start and check the status of the scans. This means that you can scan containers in any pipeline, not only in GitHub Actions. I’ll leave the link to the Action in the marketplace, so you can learn how to use it, what kind of inputs you’ll need to provide, and what kind of results you should expect. I also created examples on how to use this Action with Azure and AWS container registries and even using a Docker command:</p><p><a href="https://github.com/marketplace/actions/deep-security-smart-check-scan-action">Deep Security Smart Check Scan Action - GitHub Marketplace</a></p><p>To add the Action to your pipeline you can copy the code example from the marketplace or you can edit your pipeline YML code directly from the GitHub website and you’ll be able to search for marketplace actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-L_c2HsdO8q4Cqi1ATmurg.png" /><figcaption><strong>Cloud One Container Security Scan Action Code</strong></figcaption></figure><p><a href="https://github.com/felipecosta09/Deep-Security-Smart-Check-Scan-Action">felipecosta09/Deep-Security-Smart-Check-Scan-Action</a></p><p>Back to our pipeline, as soon as you run the pipeline and provide the required information, the Action should start to Build, Tag, Push, and Scan the container. In our case, the second job “Container_Scan” failed the pipeline because after the container scan completed, we identified:</p><ul><li><strong>1 Malware Found (Malicious File)</strong></li><li><strong>1 Secret Exposed (Private key)</strong></li><li><strong>156 Vulnerabilities (Including OS packages and 3rd party packages)</strong></li><li><strong>13 Checklists (We failed to be compliant with PCI-DSS v3, HIPAA and NIST 800–190)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qn_fz8VqpDNCUyGKuNuF3g.png" /><figcaption><strong>GitHub Action Results in the Pipeline</strong></figcaption></figure><p>I detailed also the information that you can see in the Smart Check console, including the Overall Scan Details and each one of the layers in which Smart Check identified issues with our code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*48en0KYYSVPFqgV58NX3Eg.png" /><figcaption><strong>Scan Results in the Smart Check Console</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NI69S8UzB-vF2KzKydiLTg.png" /><figcaption><strong>Malware Found (Malicious File)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYH4SHPNEs579CbQ8nyvXw.png" /><figcaption><strong>Secret Exposed (Private key)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTGgV3zDIdC4KMLKtqEc0A.png" /><figcaption><strong>Vulnerabilities (Including OS packages and 3rd party packages)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQs-DPlBPfSDSlppMVNpwQ.png" /><figcaption><strong>Checklist PCI-DSS v3, HIPAA and NIST 800–190</strong></figcaption></figure><p>In case you’re running a Java container application you’ll also count with a dependency check, through a partnership with <a href="https://snyk.io/">Snyk</a>, which is the most advanced and accurate <strong>Open-Source</strong> vulnerability database. Below there is an example on how it will look like in Smart Check console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wei7KZSvtVacTWOzeCF1aw.png" /><figcaption><strong>Snyk Vulnerability Results</strong></figcaption></figure><p>You can easily go to <a href="https://snyk.io/vuln">Snyk KB</a> to check more about each one of the vulnerabilities and create Pull Request to each one of them.</p><p><a href="https://snyk.io/vuln/SNYK-JAVA-COMFASTERXMLJACKSONCORE-174736">Snyk - Deserialization of Untrusted Data in com.fasterxml.jackson.core:jackson-databind</a></p><p>Imagine how many vulnerabilities/weaknesses my team or I could introduce to a new or old application. Without using these tools, we would probably never know. The fact that we can detect and prevent these issues from being deployed to a production application is one of the best security practices that you can follow. The more you “shift-left” the security responsibilities, the more you’ll increase the reliability and decrease the overall security risk.</p><h3>References:</h3><p><a href="https://github.com/kubernetes/kops">https://www.github.com/deep-security/smartcheck-scan-action</a></p><p><a href="https://www.trendmicro.com/containers">https://www.trendmicro.com/containers</a></p><p><a href="https://calculator.aws/">https://www.github.com/felipecosta09/Deep-Security-Smart-Check-Scan-Action</a></p><p><a href="https://github.com/marketplace/actions/cloud-one-container-security-scan-action">https://github.com/marketplace/actions/cloud-one-container-security-scan-action</a></p><p><a href="https://snyk.io/">https://snyk.io/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acbcedd61cae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an Enterprise-Grade Kubernetes Cluster]]></title>
            <link>https://medium.com/@devsecguy/creating-an-enterprise-grade-kubernetes-cluster-4117d0a6988e?source=rss-7ffb4dc1debb------2</link>
            <guid isPermaLink="false">https://medium.com/p/4117d0a6988e</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Felipe Costa]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 18:37:14 GMT</pubDate>
            <atom:updated>2020-04-13T18:37:14.264Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using KOPS to make Kubernetes Cluster simple</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Dg4BmJWht1Y1Ilq_" /><figcaption>Photo by <a href="https://unsplash.com/@goran_ivos?utm_source=medium&amp;utm_medium=referral">Goran Ivos</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://github.com/kubernetes/kops">KOPS</a> (Kubernetes Operations) helps you to create, destroy, upgrade and maintain production-grade, highly available and scalable Kubernetes clusters from the command line. It is the easiest way to get a production Kubernetes cluster up and running.</p><p>This article is meant to help you create your self-managed K8s cluster, it’s long but very easy to follow. The official documentation for <strong>KOPS (Kubernetes Operations) </strong>can be found here:</p><p><a href="https://github.com/kubernetes/kops">GitHub - kubernetes/kops: Kubernetes Operations (kOps) - Production Grade k8s Installation, Upgrades and Management</a></p><p>I’m using AWS as a preferred cloud provider to run this cluster. This tool also supports Google Cloud, OpenStack, VMware vSphere in alpha, and other platforms planned.</p><p>KOPS will create several different resources in your AWS account to set up the K8s cluster, such as EC2 instances, Route 53 entries, Autoscaling Groups, and Load Balancers to provide high-availability and scalability to your cluster.</p><p>To start, we will need to have an EC2 instance that can be an instance — that you already own or you can set up a new one and assign the right permissions to this instance, to set up a new one, follow the manual below:</p><p><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html">Set up to use Amazon EC2</a></p><p>It is also required to have these IAM permissions below so the EC2 can set up your cluster:</p><blockquote><strong>AmazonEC2FullAccess<br>AmazonRoute53FullAccess<br>AmazonS3FullAccess<br>IAMFullAccess<br>AmazonVPCFullAccess</strong></blockquote><p>To set up these permissions you can create an IAM user, set up the permissions and use AWS CLI to configure the Access Key and Secret, so your EC2 instance can use KOPS to set up the cluster. You can check in the official KOPS manual to configure that:</p><p><a href="https://github.com/kubernetes/kops/blob/master/docs/getting_started/aws.md">kubernetes/kops</a></p><p>The other option is to use IAM Roles and attach these permissions to your EC2 instance — as I did — and you should have the same results either way. To create an IAM Role, follow this manual:</p><p><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#create-iam-role">IAM Roles for Amazon EC2</a></p><p>Next step will be to install the 2 required tools to set up your cluster:</p><h4>Install Kubectl:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cacb96fde573db126f3a95956b3aeb2d/href">https://medium.com/media/cacb96fde573db126f3a95956b3aeb2d/href</a></iframe><h4>Install KOPS:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb62b4402ccda25b63c47eaef79b8823/href">https://medium.com/media/bb62b4402ccda25b63c47eaef79b8823/href</a></iframe><p><em>PS.: You’ll also need the AWS CLI to be installed — since I’m using an Amazon Linux 2 machine, AWS CLI is already installed.</em></p><p>After installing the tools, we need to create an S3 bucket so can store the state of your cluster, to create the bucket follow the configurations below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14f59f389e45692ed55d00017b78af9c/href">https://medium.com/media/14f59f389e45692ed55d00017b78af9c/href</a></iframe><p><em>PS.: This is the most basic way to set up your S3 bucket. I also recommend you set up versioning your S3 bucket in case you ever need to revert or recover a previous state store and also default encryption to your bucket, but it’s optional</em></p><p>I’ll also set up some environment variables to make easier to execute commands in the future:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/901a56369d22aee25fa6962e6c13056a/href">https://medium.com/media/901a56369d22aee25fa6962e6c13056a/href</a></iframe><p><em>PS.: You can choose any name you want but the name </em><strong>MUST END<em> </em></strong><em>with “</em><strong><em>k8s.local</em></strong><em>” due to DNS configurations that the KOPS will execute during the process to create the cluster. Also, your S3 bucket name needs to be unique across the AWS Cloud.</em></p><p>You will need to choose which availabilities zones are available for your cluster to use. In this example, we will be deploying our cluster to the us-east-1 region, to check the availability zones to that region, just follow the options below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbc08bf00355757fcc0463634f7afc75/href">https://medium.com/media/bbc08bf00355757fcc0463634f7afc75/href</a></iframe><p>You can check out all the Regions and Availability codes in this link below:</p><p><a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html">Regions, Availability Zones, and Local Zones</a></p><p>In my case, I’m creating my nodes each one on a different availability zone (1 Master and 3 Worker Nodes). By executing the command below you’ll create the configuration in the S3 bucket so KOPS can read and deploy your cluster:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/088c4cfba1e1371dbfe3bd3dd4a3dd2d/href">https://medium.com/media/088c4cfba1e1371dbfe3bd3dd4a3dd2d/href</a></iframe><p>The above command will generate a cluster configuration, but not start building it yet. As per the message, you must set up an ssh public key and add this key to the cluster:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37e6bbc60bd06a0e0f21783605af64bf/href">https://medium.com/media/37e6bbc60bd06a0e0f21783605af64bf/href</a></iframe><p><em>PS.: Skip the passphrase configuration</em></p><p>I’ll run the cluster within the master default configuration, but if you want to modify the cluster set up configurations, you can use the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f4315ddee23ccec5aa9aee9c6fd8210/href">https://medium.com/media/1f4315ddee23ccec5aa9aee9c6fd8210/href</a></iframe><p>I modified the node’s configuration on the cluster so can scale more instances than the default, you can change instance type and minimum and maximum instances by using the following command and editing the variables:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddc4c088f4836aeb2612cf8cd28c0772/href">https://medium.com/media/ddc4c088f4836aeb2612cf8cd28c0772/href</a></iframe><p>If you want to double-check the configurations that KOPS will apply, you can use the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea79c6fd4b0f5bdb439fb03835a6a5c5/href">https://medium.com/media/ea79c6fd4b0f5bdb439fb03835a6a5c5/href</a></iframe><p>To apply all the configuration we’ve done so far, execute the command below to start creating your K8s cluster, based on the config files that we store in the S3 Bucket:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/193eb40c7cd1cbe3a19481355702c0da/href">https://medium.com/media/193eb40c7cd1cbe3a19481355702c0da/href</a></iframe><p>It will take time to create the cluster (usually from 10 to 15 minutes) so be patient. You can check the status of the cluster creation by executing the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/024775677f5761e47a641fb29eb746e6/href">https://medium.com/media/024775677f5761e47a641fb29eb746e6/href</a></iframe><p><em>PS.: The command above will show several errors during the process but don’t worry, this happens because the cluster is not ready yet.</em></p><p>After a couple of minutes when the cluster is 100% operational, you’ll be able to check your nodes and master by executing the same command as before:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a192fac79fb72c9045aae164eae8e73a/href">https://medium.com/media/a192fac79fb72c9045aae164eae8e73a/href</a></iframe><p><strong>Done!</strong> You have just created an enterprise-grade K8s cluster in the cloud.</p><p>If you’re worried about the cost of this setup, I made an estimation cost using AWS Pricing Calculator, generally speaking, this set up will cost you around 0.25USD per hour. You can check the full estimate cost in the link below:</p><p><a href="https://calculator.aws/#/estimate?id=806bcedd844ac67481c9e3407ef5003fec504e20">https://calculator.aws/#/estimate?id=806bcedd844ac67481c9e3407ef5003fec504e20</a></p><p>Remember to delete your cluster if you’re not using it, to delete your cluster, just execute the command below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6aab820c7ad92fc6f505c2d7526bb8d/href">https://medium.com/media/a6aab820c7ad92fc6f505c2d7526bb8d/href</a></iframe><h3>References:</h3><p><a href="https://github.com/kubernetes/kops">https://github.com/kubernetes/kops</a></p><p><a href="https://kubernetes.io/">https://kubernetes.io/</a></p><p><a href="https://calculator.aws/">https://calculator.aws/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4117d0a6988e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>