Tuesday, September 6, 2022
HomeCyber SecurityRefactoring Current Code to Use IAM Naming Conventions: Half 2 | by...

Refactoring Current Code to Use IAM Naming Conventions: Half 2 | by Teri Radichel | Cloud Safety | Sep, 2022


ACM.42 Simplifying Consumer and Group creation with reusable templates and capabilities

This can be a continuation of my sequence on Automating Cybersecurity Metrics.

I’ve been writing about naming conventions and now I’m attempting to rearrange my code into extra concise parts that observe my outlined naming conference.

A typical perform to deploy CloudFormation stacks

Within the final put up I confirmed you easy methods to use a typical perform for repetitive code. You possibly can create a typical perform to deploy a CloudFormation stack to make it simpler to deploy a stack and implement a typical naming customary.

That perform can be utilized all through our code, however I’m going to begin with our iam folder. I created a folder known as “stacks” and transfer the file with the widespread perform into the stacks folder:

In an effort to use this widespread perform in one other template in the identical listing you would come with this line of code in your bash file:

supply "stack_functions.sh"

Then you may name the perform in that file:

deploy_iam_stack $profile $username $rtype $template $parameters

Widespread templates for customers and teams

One of many issues I additionally realized was repetitive whereas my code was the creation of customers and teams which each use quite simple templates that don’t actually range. All I have to do is cross in a reputation.

I did need to take away the task of a bunch to make this work but it surely makes extra sense to assign customers to group individually anyway. You may need to change a bunch task with out redeploying a person or a bunch. There’s a CloudFormation assemble we will use to affiliate customers and teams:

Right here’s our person generic person template:

Our group template:

Add customers to a bunch:

Notice that I initially examined the above template including one person and I’ve but to check out the template with an inventory of customers however I’ll earlier than I examine within the above code to the listing.

Limitations when utilizing CloudFormation to deploy customers

Whether or not I’m creating an IAM administrator, KMS administrator, or developer I can use the identical Consumer template. This works or me as a result of I’ve a small group. In case you have a really giant group pay attention to stack limits in CloudFormation:

You possibly can enhance the stack restrict however I’ve additionally seen that CloudFormation tends to decelerate when you may have numerous stacks. I’m unsure if that drawback nonetheless exists as a result of I haven’t pushed the boundaries recently.

Additionally, in case you transfer your person creation to an account that’s solely used to create customers you’ll have extra out there stacks. You may additionally have a separate person creation account for every line of enterprise. These are simply concepts. As an architect it’s essential to take into consideration easy methods to clear up issues with the capability out there to you no matter what kind of expertise you utilize.

A typical perform to deploy our person template

Subsequent I can create a typical perform to deploy the person template. We solely want the person identify and a CLI profile. See prior posts for details about utilizing CLI profiles.

Discover under that I’m together with the road of code I defined above utilizing the supply command that permits me to name the perform within the stack_functions.sh file. Since that file is one listing up I add “../” in entrance of the file identify to create a relative path to the file. I’m calling the validate_param and the deploy_iam_stack capabilities from the stack_functions.sh file.

Discover I’m calling the validate_param perform I added to the stack_functions.sh so I don’t have to write down this code block time and again.

Subsequent I can alter my deployment script to create any variety of customers:

Usually in a company your customers can be names like: tradichel, mjordan, wgretzky, sbird, or no matter your naming conventions are for people. I’m simply utilizing names like IAMAdmin or KMSAdmin to make it simpler to observe together with what I’m doing.

Create related capabilities for teams and including customers to teams

You possibly can observe the identical course of as above to create capabilities to deploy teams and customers of teams. When you may have a singular template identify that’s particular to a stack equivalent to an IAM Coverage, you may name the generic perform in stack_functions.sh to deploy a selected distinctive template.

The tip result’s generally named assets and it must be simpler to search out your code.

In the event you add the repository and template to the highest of your CloudFormation information it is possible for you to to click on on a stack, then Template, and simply discover the stack that deployed the code. In case you are relying on the knowledge under to be appropriate, be sure to add it to the guidelines of issues your QA workforce checks earlier than code will get deployed to manufacturing.

As soon as you understand what code deployed a stack you may examine for drift — when one thing in manufacturing or another setting doesn’t match what’s in supply management as a result of somebody made a change exterior your regular deployment course of.

Notice that I’m unsure I’m completed making adjustments to this code so observe alongside as I clear up a bit extra and get again to what I used to be doing — creating the remainder of my batch job course of. Ultimately, I’d find yourself transferring all of this into batch jobs but it surely’s best to begin with CLI instructions. I can probably translate my capabilities and into batch jobs. Comply with alongside to see the way it seems.

Teri Radichel

In the event you preferred this story please clap and observe:

Medium: Teri Radichel or Electronic mail Checklist: Teri Radichel
Twitter: @teriradichel or @2ndSightLab
Requests companies by way of LinkedIn: Teri Radichel or IANS Analysis

© 2nd Sight Lab 2022

All of the posts on this sequence:

____________________________________________

Writer:

Cybersecurity for Executives within the Age of Cloud on Amazon

Want Cloud Safety Coaching? 2nd Sight Lab Cloud Safety Coaching

Is your cloud safe? Rent 2nd Sight Lab for a penetration take a look at or safety evaluation.

Have a Cybersecurity or Cloud Safety Query? Ask Teri Radichel by scheduling a name with IANS Analysis.

Cybersecurity & Cloud Safety Assets by Teri Radichel: Cybersecurity and Cloud safety courses, articles, white papers, displays, and podcasts



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments