avatarTeri Radichel

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3886

Abstract

2SL Job Execution Framework Job</h2><p id="e21f">Two files are required in our job repository (besides the README and the license.) You might have a job that requires other files but this is the minimum.</p><p id="6605"><i>Dockerfile</i> — builds the container with whatever tools the job needs to execute its actions.</p><p id="e2fb"><i>execute.sh </i>— the job specific actions.</p><p id="7fb3">As explained in a prior post the build process for the container pulls in files from both the job execution framework and the job-specific container.</p><figure id="ec4c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*SfkDmMlex9bcPaqP4YU34Q.png"><figcaption></figcaption></figure><p id="2a62"><i>init.sh — </i>Because we are running this job from AWS CloudShell, we are also going to have an init.sh script that obtains the credentials from CloudShell and passes them to the container. This file currently also upgrades buildx and builds the container but ideally we wouldn’t even need that. Hopefully AWS will update buildx in CloudShell soon and I’ll have another option for you in the future if all goes according to plan.</p><p id="f881">The steps to add the container, build and execute the job steps are essentially the same as the last job (2sl-job-awsorginit) so I copied the files from that job into this repository and made the following changes.</p><h2 id="2a0e">Repository</h2><p id="06ab">First I create a new repository and add a README:</p><div id="d015" class="link-block"> <a href="https://github.com/tradichel/2sl-job-awsenvinit"> <div> <div> <h2>GitHub - tradichel/2sl-job-awsenvinit: Initialize a 2nd Sight Lab Job Execution Framework…</h2> <div><h3>undefined</h3></div> <div><p>undefined</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*K17OqOA1N6trIky9)"></div> </div> </div> </a> </div><p id="10da">I cloned the repository and copied and pasted the files from 2sl-job-awsorginit into this repository.</p><h2 id="7c9f">README</h2><p id="9ef8">The instructions are pretty much the same as the last job, except that there’s a prerequisite (the last job) so I add that to the readme and update the job name.</p><h2 id="81a2">Init.sh</h2><p id="706f">I did a search and replace, changing “org” to “env” in the init script.</p><p id="cd19">I also changed the comments:</p><figure id="5d2d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*CQLy13zfhGlTkiD617yu1g.png"><figcaption></figcaption></figure><p id="89b7">I also changed the profile to root-admin.</p><figure id="6ef0"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*dWVMvkYNUdIK5o5v8g_RkQ.png"><figcaption></figcaption></figure><h2 id="ab81">Dockerfile</h2><p id="ee7b">The only thing I had to change in the Dockerfile was the name in the comments and the description.</p><figure id="3372"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*99xCwTyoB4jw38uXa0ff3A.png"><figcaption></figcaption></figure><p id="6420">See this post for more on how the Docker container works in AWS CloudShell and the subsequent post in the link at the bottom:</p><div id="48ff" class="link-block"> <a href="https://readmedium.com/a-docker-container-in-cloudshell-c46b87798b04"> <div> <div> <h2>A Docker Container In CloudShell</h2> <div><h3>ACM.435 Building and running containers in AWS CloudShell</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*yIZ0XTaRocwjfsRYUnq-Ew.png)"></div> </div> </d

Options

iv> </a> </div><h2 id="7be7">execute.sh</h2><p id="81dd">I replace the job-specific code in execute.sh with the following:</p><figure id="ec67"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*tDDrEzPNiqzD9pPwHYX0BQ.png"><figcaption></figcaption></figure><p id="f774">To test what I have working so far I did the following:</p><ul><li>Login as the <i>aws-root</i> user created with my last job in my management account.</li><li>Copy init.sh into CloudShell from the 2sl-job-initawsenv git repository</li><li>Change the permissions</li></ul><div id="948e"><pre><span class="hljs-attribute">chmod</span> <span class="hljs-number">700</span> init.sh</pre></div><ul><li>Execute init.sh</li></ul><div id="aa6e"><pre>./init.sh</pre></div><ul><li>If you get an out of space error, restart CloudShell as explained before and run init.sh again.</li></ul><p id="bd73">I get the expected output, so we’re good to go onto the next step:</p><figure id="6636"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*eJB5pVg9GgQOVKzPbNIq3g.png"><figcaption></figcaption></figure><p id="6148">At this point, if youre job doesn’t require any parameters and just runs a series of steps, you can replace execute.sh with whatever you want and run it like I did in the prior job. But for this job I need to pass in the environment name (or a list of names) to build out. So I need an SSM parameter for this job and I’m going to add that in the next post.</p><p id="4bc3">Next step:</p><div id="e4c3" class="link-block"> <a href="https://readmedium.com/adding-a-batch-job-configuration-ssm-parameter-for-the-2sl-job-execution-framework-aa926d676b0a"> <div> <div> <h2>Adding a Batch Job Configuration SSM Parameter For The 2SL Job Execution Framework</h2> <div><h3>ACM.439 Deploy a 2SL Job Execution Environment — Step 2— Adding a job configuration parameter to deploy a single…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*w1MDES-L6KGpH3cWCQSY-A.png)"></div> </div> </div> </a> </div><p id="f723">Follow for updates.</p><p id="4a3a">Teri Radichel | <i>© <a href="https://2ndsightlab.com/?source=post_page---------------------------">2nd Sight Lab</a> 2024</i></p><div id="8b5f"><pre><span class="hljs-section">About Teri Radichel:

⭐️ Author: Cybersecurity Books
⭐️ Presentations: Presentations by Teri Radichel
⭐️ Recognition: SANS Award, AWS Security Hero, IANS Faculty
⭐️ Certifications: SANS ~ GSE 240
⭐️ Education: BA Business, Master of Software Engineering, Master of Infosec
⭐️ Company: Penetration Tests, Assessments, Phone Consulting ~ 2nd Sight Lab</pre></div><div id="caae"><pre><span class="hljs-section">Need Help With Cybersecurity, Cloud, or Application Security?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span>
🔒 Request a penetration test or security assessment
🔒 Schedule a consulting call
🔒 Cybersecurity Speaker for Presentation</pre></div><div id="5a42"><pre>Follow <span class="hljs-keyword">for</span> more stories like <span class="hljs-keyword">this</span>:

❤️ Sign Up my Medium Email List ❤️ Twitter: <span class="hljs-meta">@teriradichel</span> ❤️ LinkedIn: https:<span class="hljs-comment">//www.linkedin.com/in/teriradichel</span> ❤️ Mastodon: <span class="hljs-meta">@teriradichel</span><span class="hljs-meta">@infosec</span>.exchange ❤️ Facebook: 2nd Sight Lab ❤️ YouTube: @2ndsightlab</pre></div><figure id="faf5"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*H9Ew1KCl-29nZiPR.jpeg"><figcaption></figcaption></figure></article></body>

Creating a New Batch Job Type For The 2SL Job Execution Framework

ACM.438 Deploy a 2SL Job Execution Environment — Step 1 — The job container and a script to run it

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

⚙️ Part of my series on Automating Cybersecurity Metrics. The Code.

🔒 Related Stories: AWS Security | Application Security | Batch Jobs

💻 Free Content on Jobs in Cybersecurity | ✉️ Sign up for the Email List

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In the last post, I explained what a job execution environment is for the 2nd Sight Lab Job Execution Framework.

In the next series of posts I’m going to build out that environment piece by piece. In the end you’ll have a job that you can execute using the 2nd Sight Lab Job Execution Framework to create a new environment for future jobs.

The difference with this job is that we haven’t yet created our job execution environment, so the job will pull credentials from CloudShell. As mentioned I don’t recommend using CloudShell for the reasons outlined in a prior post, but I don’t want to deploy secrets with credentials or AWS developer access keys in the root management account for our organization.

Besides the difference of where the credentials come from the job will essentially work the same as a job run via a test script from the execution environment we are creating.

Create a new Repository

The first step is to create a repository for our job and build a container that can run the job.

I explained the separate repositories used by the framework here:

We will create a new repository for this job named 2sl-job-awsenvinit.

Files required for a new 2SL Job Execution Framework Job

Two files are required in our job repository (besides the README and the license.) You might have a job that requires other files but this is the minimum.

Dockerfile — builds the container with whatever tools the job needs to execute its actions.

execute.sh — the job specific actions.

As explained in a prior post the build process for the container pulls in files from both the job execution framework and the job-specific container.

init.sh — Because we are running this job from AWS CloudShell, we are also going to have an init.sh script that obtains the credentials from CloudShell and passes them to the container. This file currently also upgrades buildx and builds the container but ideally we wouldn’t even need that. Hopefully AWS will update buildx in CloudShell soon and I’ll have another option for you in the future if all goes according to plan.

The steps to add the container, build and execute the job steps are essentially the same as the last job (2sl-job-awsorginit) so I copied the files from that job into this repository and made the following changes.

Repository

First I create a new repository and add a README:

I cloned the repository and copied and pasted the files from 2sl-job-awsorginit into this repository.

README

The instructions are pretty much the same as the last job, except that there’s a prerequisite (the last job) so I add that to the readme and update the job name.

Init.sh

I did a search and replace, changing “org” to “env” in the init script.

I also changed the comments:

I also changed the profile to root-admin.

Dockerfile

The only thing I had to change in the Dockerfile was the name in the comments and the description.

See this post for more on how the Docker container works in AWS CloudShell and the subsequent post in the link at the bottom:

execute.sh

I replace the job-specific code in execute.sh with the following:

To test what I have working so far I did the following:

  • Login as the aws-root user created with my last job in my management account.
  • Copy init.sh into CloudShell from the 2sl-job-initawsenv git repository
  • Change the permissions
chmod 700 init.sh
  • Execute init.sh
./init.sh
  • If you get an out of space error, restart CloudShell as explained before and run init.sh again.

I get the expected output, so we’re good to go onto the next step:

At this point, if youre job doesn’t require any parameters and just runs a series of steps, you can replace execute.sh with whatever you want and run it like I did in the prior job. But for this job I need to pass in the environment name (or a list of names) to build out. So I need an SSM parameter for this job and I’m going to add that in the next post.

Next step:

Follow for updates.

Teri Radichel | © 2nd Sight Lab 2024

About Teri Radichel:
~~~~~~~~~~~~~~~~~~~~
⭐️ Author: Cybersecurity Books
⭐️ Presentations: Presentations by Teri Radichel
⭐️ Recognition: SANS Award, AWS Security Hero, IANS Faculty
⭐️ Certifications: SANS ~ GSE 240
⭐️ Education: BA Business, Master of Software Engineering, Master of Infosec
⭐️ Company: Penetration Tests, Assessments, Phone Consulting ~ 2nd Sight Lab
Need Help With Cybersecurity, Cloud, or Application Security?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
🔒 Request a penetration test or security assessment
🔒 Schedule a consulting call
🔒 Cybersecurity Speaker for Presentation
Follow for more stories like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
❤️ Sign Up my Medium Email List
❤️ Twitter: @teriradichel
❤️ LinkedIn: https://www.linkedin.com/in/teriradichel
❤️ Mastodon: @teriradichel@infosec.exchange
❤️ Facebook: 2nd Sight Lab
❤️ YouTube: @2ndsightlab
Batch
Job
Security
Cloud
AWS
Recommended from ReadMedium