Table of contents
1.
Introduction
2.
Chef InSpec Profiles
2.1.
Profile Dependencies
2.2.
Using Resources from an Included Profile
3.
Chef InSpec Inputs
3.1.
Working with Inputs in Control Code
3.2.
Input Options Reference
4.
Common Terms related to Chef InSpec
5.
Chef Workstation
5.1.
Chef Workstation Tools
5.2.
Installing Chef Workstation
5.3.
Setting Up Chef Workstation
5.3.1.
Configure Ruby Environment
5.3.2.
Setting up the Chef Repo
5.3.3.
Setting up Chef Credentials
6.
Frequently Asked Questions
6.1.
What is Chef Security?
6.2.
What Distinguishes a Recipe from a Cookbook?
6.3.
What Purpose Does the Starter Kit Serve?
7.
Conclusion
Last Updated: Mar 27, 2024

Common Terms related to Chef InSpec

Author Shivani Singh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Chef InSpec is an open-source testing framework for infrastructure. It uses a machine- and human-readable language to express compliance, security, and policy requirements.

In 2020, it was purchased and combined to form Progress Chef. Current Chief Technology Officers Adam Jacob, Jesse Robbins, Barry Steinglass, and Nathan Haneysmith established the business as Opscode in 2008.

Chef InSpec

Adam Jacob developed Chef as a tool for his consulting business, which specialized in developing end-to-end server/deployment solutions. Jesse Robbins, who oversaw operations at Amazon, was introduced to Chef by Jacob and immediately realized its potential.

An open-source framework, Chef InSpec is used to test and audit your infrastructure and apps. Chef InSpec compares the state of your system as it is with the state you specify in simple-to-read and simple-to-write Chef InSpec code. Chef InSpec finds infractions and presents findings in a report, but you are in charge of fixing them.

Chef InSpec Profiles

Chef InSpec Profiles

Complex test and compliance profiles can be created with Chef InSpec, which organizes controls to assist dependency management and code reuse. With its own distribution and execution flow, each profile stands alone as an independent structure. A profile should be organized as follows:

examples/profile
├── README.md
├── controls
│   ├── example.rb
│   └── control_etc.rb
├── libraries
│   └── extension.rb
|── files
│   └── extras.conf
└── inspec.yml

The profile can be verified using the InSpec check command. 

Profile Dependencies

Controls and unique resources from one Chef InSpec profile can be added to another. A profile can also skip or change the included controls when inheriting controls from another profile. The to-be-included profile must be defined in the relies section of the including profile's inspec.yml file before a profile can use controls from another profile. 

Gem Dependencies

The gem dependencies settings in the inspec.yml metadata file can be used to specify any profile that has Ruby gem dependencies that must be installed.

Vendoring Dependencies

The inspec.yml file will be read to source any profile dependencies when you run a local profile. The dependencies will then be locally cached, and an inspec.lock file will be created.

Dependencies may be re-vendored and the lock file updated using inspec vendor —overwrite if you add or modify dependencies in inspec.yml.

Using Resources from an Included Profile

By default, your profile has access to every custom resource from a stated dependency. You can use the require_resource DSL method to distinguish between two resources if they are provided by two of your dependents and have the same name:

require_resource(profile: 'my_dep', resource: 'my_res',
                  as: 'my_res2')

Chef InSpec Inputs

The "knobs" you can turn to alter how Chef InSpec profiles behave are called inputs. If a profile accepts inputs, you have the flexibility to specify the inputs in a number of different ways. A multi-layered approach to profile configuration is made possible by the ability of profiles that include other profiles to adjust inputs in the included profile.

There are numerous ways to set inputs in Chef InSpec:

  1. Directly within the control code using the syntax input("input name", 42).
  2. Metadata files in the profile inspec.yml
  3. Reading directly from the command line using the CLI option --input name1=value1 name2=value2…
  4. Reading inputs from files using the CLI option --input-file somefile.yaml
  5. Using the verifier/inputs settings in kitchen inspection

Working with Inputs in Control Code

The scope is input everywhere. All areas of the InSpec profile DSL accept inputs. They can be utilized in any place. 

For setting inputs in the control DSL, You can set an input value in the DSL by writing input('some_name', value: 'some_value'). A new value will be set as a result of the value: option being present.

Input Options Reference

Name 

Required String. This option identifies the input.

Description 

Optional String. Human-meaningful explanation of the input.

Value 

Optional, any Ruby or YAML type.

Type 

Optional, String. This value must be one of String, Numeric, Regexp, Array, Hash, Boolean, or Any. 

Required 

Optional, true or false. If true, control using the input will be failed if it reads the value when none has been set.

Priority 

Optional, Integer, 0-100. Higher values make this assignment have higher precedence. This is an advanced feature.

Profile 

Optional, String. Allows you to set input in another profile from your profile.

Sensitive 

Optional, true or false.

Common Terms related to Chef InSpec

Common Terms related to Chef InSpec
  • Attribute: Deprecated name for input.
     
  • Control Block: Declaring a control block requires the usage of the control keyword. The term "control" in this context refers to a "regulatory control, guideline, or demand" rather than a construct used in software engineering.
     
  • Core Resource: A resource that's part of InSpec
     
  • Custom Resource: An external source that is not part of InSpec.
     
  • Describe Block: To refer to a Chef InSpec resource, use the describe keyword together with a describe block. To include related tests that pertain to a resource, use the describe keyword together with the resource's name.
     
  • Domain Specific Language, or DSL, is an abbreviation. It alludes to the language extensions that Chef InSpec offers to make it simpler to author resources and controls.
     
  • Expected Result: The value that a matcher will compare to the property being accessed is the expected outcome when employing a matcher.
     
  • Filter Statement: A filter statement is utilized when employing a plural resource to choose particular test subjects based on filter criteria.
     
  • Input: Chef InSpec can obtain input from a variety of sources, including the command line, profile metadata, or the control file DSL itself.
     
  • It: It declares a single test that is run directly against the resource inside of a described block.
     
  • Its: Its declares a single test against a resource attribute inside a described block.
     
  • Matcher: A matcher really makes claims about resources or resource attributes. A true/false value is always returned by matchers.
     
  • Plural resources: A resource that performs searches and represents various instances of the resource on the target platform is referred to as a plural resource.
     
  • Profile: A profile is a group of connected controls that can be distributed.
     
  • Target: The OS or API that Chef InSpec is using to conduct audits is the target.
     
  • Test: A test is a specific claim made regarding the condition of the resource or one of its attributes.

Chef Workstation

Everything you need to get started with Chef is included in the simple-to-install Chef Workstation package, including ad hoc remote execution, remote scanning, setup tasks, cookbook writing tools, and reliable dependency and testing software.

Chef Workstation

Everything else required to create recipes and submit them to the Chef Infra Server is included in the Chef Workstation, along with Chef Infra Client, Chef InSpec, Chef Habitat, chef and knife command line tools, and testing tools like Test Kitchen and Cookstyle.

Ad-hoc task support and the new Chef Workstation desktop application are only two of the new features that replace ChefDK in the Chef Workstation.

Chef Workstation Tools

All the tools needed to succeed with Chef Infra and InSpec are included in Chef Workstation. For popular operating systems, these utilities are packaged together with all the prerequisites you need to get started.

  1. Chef CLI, a tool for Chef Infra's workflow.
     
  2. Knife: A system administration tool for the Chef Infra Server.
     
  3. The agent who uses Chef Infra as a client.
     
  4. Chef InSpec: This tool for compliance as code may also be used to evaluate Chef Infra cookbooks.
     
  5. Cookstyle: A linting tool that finds and automatically fixes style, grammar, and logic errors in your code to help you produce better Chef Infra cookbooks.

Installing Chef Workstation

Installing Chef Workstation requires running as a privileged user.

On macOS, Linux, and Windows, Chef Workstation is installed at C:opscodechef-workstation and /opt/chef-workstation, respectively.

macOS Install

  1. Go to the Chef Workstation downloads page and choose the package that corresponds to the macOS version that you are using. The Download button should be chosen.
  2. Comply with the instructions to install the Chef Workstation after accepting the license.

Install Chef Workstation alternatively by using the Homebrew package manager: brew install --cask chef-workstation

Windows Install

  1. Go to the Chef Workstation downloads page and choose the package that corresponds to your Windows version. On the Download button, click.
  2. Comply with the instructions to install the Chef Workstation after accepting the license. The installer uses the C:opscodechef-workstation directory by default, but you will have the option to alter it.

Install Chef Workstation alternatively by using the Chocolatey package manager: choco install chef-workstation

Verifying the Installation

To verify the installation, run: chef -v

Setting Up Chef Workstation

Setting Up Chef Workstation

Configure Ruby Environment

Step 1: Run the command echo $SHELL to find out your default shell.

Step 2: Add the content for Workstation initialization to the relevant shell rc file.

Step 3: Launch a fresh shell window and enter: which ruby
 

Setting up the Chef Repo

Everything you require to define your infrastructure using Chef Infra is kept in the chef-repo directory on your computer. To upload data from the chef-repo directory to the Chef Infra Server, use the chef and knife commands. Create your Chef Infra repository using the chef generate repo command.
 

Setting up Chef Credentials

You must manage users using the Chef Infra Server CLI or the Manage UI if you're configuring Chef Workstation as an administrator of the Chef Infra Server.

You must configure your special client private key, which corresponds to a client on the Chef Infra Server that your server administrator generates for you if you're setting up Chef Workstation as a Chef user.

To verify that Chef Workstation can connect to the Chef Infra Server, run the following command: knife client list

Frequently Asked Questions

What is Chef Security?

Chef Secure teaches you hacking and cybersecurity, in order to prevent data breaches brought on by bad code.

What Distinguishes a Recipe from a Cookbook?

A recipe is a group of resources that, in most cases, configures a piece of infrastructure or a software program. A cookbook organizes recipes and other information in a more comprehensible way than merely having recipes.

What Purpose Does the Starter Kit Serve?

You can securely communicate with the Chef server using certificates and other files that are included in the Starter Kit.

Conclusion

To conclude this blog, we discussed the basics of Chef InSpec, its profile, and its inputs. We saw some common terms regarding Chef InSpec. We also discussed the Chef workstation, its tools, installation, and setup. In setting up, we discussed configuring the ruby environment, setting up the Chef repo, and setting up Chef credentials.  

For more content, Refer to our guided paths on Coding Ninjas Studio to upskill yourself.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Thankyou
Live masterclass