Table of contents
1.
Introduction
2.
Actions
3.
Properties
3.1.
change_password_at_next_logon 
3.2.
group_name_for_expired_passwords 
3.3.
group_name_for_password_never_expires 
3.4.
maximum_password_age  
3.5.
minimum_password_length 
3.6.
password_never_expires 
3.7.
require_complex_passwords
4.
Common Resource Functionality
4.1.
Common properties
4.1.1.
compile_time
4.1.2.
ignore_failure
4.1.3.
retries
4.1.4.
retry_delay
4.1.5.
sensitive
4.2.
Notifications
4.3.
Guards
4.3.1.
Properties
5.
Examples
6.
Frequently Asked Questions 
6.1.
What do you mean by Action?
6.2.
What is the default password length? 
6.3.
What is the default notification? 
6.4.
What is the default value for group_name_for_expired_passwords?
6.5.
What are the properties that define the guard?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

CHEF RESOURCES -windows_password_policy Resource

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

Introduction

Chef resources signify a piece of the operating system at the required state. It is a configuration policy statement that describes the desired state for a configuration item and declares the necessary steps taken to achieve that state.

Introduction Image

The windows_password_policy Resource is used to handle passwords and password lengths in Chef.

An appropriate syntax for CHEF- RESOURCES -windows_password_policy Resource is-

windows_password_policy 'name' do
  change_password_at_next_logon              true, false # default value: false
  group_name_for_expired_passwords           String # default value: "Users"
  group_name_for_password_never_expires      String # default value: "Administrators"
  maximum_password_age                       Integer # default value: 365
  minimum_password_length                    Integer # default value: 12
  password_never_expires                     true, false
  require_complex_passwords                  true, false # default value: true
  action                                     Symbol # defaults to: set if not specified
  end

Actions

The windows_password_policy performs the following actions-

: nothing

As the name signifies, it doesn’t act until and unless it is notified by some other resource to take action. As soon as it gets the notification, it acts immediately or queues up to run at the end of the Chef Infra Client run.

: set 

: set uses properties to determine the password policy.

Properties

The following properties are present in windows_password_policy Resource-

change_password_at_next_logon 

It strictly instructs the users in the local user group to change the value of the password at the next logon.

group_name_for_expired_passwords 

The group whose passwords have to get changed at the next login 

group_name_for_password_never_expires 

password_never_expires rules apply to these groups. Its default is Admins.

maximum_password_age  

It defines the maximum age in days before which the user must alter a password. The default value for the same is set to 365 days.

minimum_password_length 

It specifies the minimum password length. The default value for the same is 12 characters.

password_never_expires 

It sets the value to true and false to never expire the passwords. The value is true by default.

require_complex_passwords

It sets the value to true or false depending on the requirement of special characters, lower or upper in passwords.

Common Resource Functionality

Common properties

These properties are common to every resource that is running.

compile_time

This property comes to play when the resource is being run. The value is true when the resource is being built. When the chef infra client configures the node, the value is false.

ignore_failure

As the name suggests, it allows running a recipe regardless of resource failures.

retries

This property specifies the number of attempts made to retry when an exception occurs.

retry_delay

The gap of seconds between the trial and retrial attempts is retry_delay.

sensitive

This property ensures that sensitive information is not exposed to the chef infra client.

Notifications

notifies

In this case, a resource notifies another resource to perform a specific action on state change. The: timer governs if you want to tell more than one resource; use the ‘notifies’ statement for each resource to be informed.

If the mentioned resource is not available, an error arises. The following: timers are present -

: before

It instructs that before the processing of the resource block. the system should act on the resource

: delayed

Delayed is the default timer. It instructs to queue up and perform the execution at the end of the chef infra client run.

:immediate

It directs the resource to implement urgently.

The syntax for notifies is-

notifies :action, 'resource[name]', :timer

subscribes

A resource usually listens to another resource. The action is taken if the resource's state is exposed to changes. First, the resource name is given, and then the action and timer are in that order.

The following: timers are present -

: before

It instructs the user to act on the resource before processing the resource block.

: delayed

This is the default timer. It instructs to queue up and perform the execution at the end of the chef infra client run.

: immediate

It directs the resource to implement urgently.

The syntax of subscribes is-

subscribes :action, 'resource[name]', :timer

Guards

A guard's property determines whether the execution should be continued or stopped. It examines the node's state during the execution phase of the chef-client run. This property accepts string and ruby block values.

  • A string is considered a shell command. If the return value is 0, the guard is applied. In case the value is other than 0, the guard is not used.
  • A block is a ruby code that returns either true or false. If the return value is actual, the guard is applied, and in the case of false, the guard value is not used.

The Guard property is vitally important as it ensures that the resource is tested for the desired state. If the required conditions are fulfilled, the chef infra client does nothing.

Properties

The following properties are the basis of defining guard during the execution of chef infra client.

not_if

When the condition returns true, it prevents the resource from execution.

only_if

Only if the condition returns true it permits the resource for execution.

Examples

The following code snippet is an instance of how windows_password_policy Resource works when put into action.

This code snippet shows how we configure the local password policy.

windows_password_policy 'Settings for password complexity, length, and duration' do
  require_complex_passwords true
  minimum_password_length 12
  maximum_password_age 365
  action :set
end

Frequently Asked Questions 

What do you mean by Action?

Action decides the set of activities that Chef Client Run will perform to bring the node to its desired state.

What is the default password length? 

The default minimum password length is 12 characters.

What is the default notification? 

: delayed is the default notification.

What is the default value for group_name_for_expired_passwords?

“Users” is the default value for group_name_for_expired_passwords.

What are the properties that define the guard?

not_if and only_if properties define the guard.

Conclusion

In this article, we studied CHEF- RESOURCES -windows_password_policy Resource. The reader can carry out a thorough understanding of the topic by referring to the Official Documentation. For more information on Chef and DevOps, Refer-

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass