Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_secedit module: adds ability to mod local security policies #22775

Closed
wants to merge 6 commits into from
Closed

win_secedit module: adds ability to mod local security policies #22775

wants to merge 6 commits into from

Conversation

rndmh3ro
Copy link
Contributor

ISSUE TYPE

Feature Pull Request

COMPONENT NAME

win_secedit

ANSIBLE VERSION
ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides
SUMMARY

Allows users to modify local security policies via the secedit utility for example:

    - name: Set local password age policy to 14 days
      win_secedit:
        category: System Access
        key: MaximumPasswordAge
        value: 14

@rndmh3ro
Copy link
Contributor Author

Migrated from ansible/ansible-modules-extras#3214 by rndmh3ro (not original author)

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 community_review In order to be merged, this PR must follow the community review workflow. feature_pull_request module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. windows Windows community labels Mar 19, 2017
@ansibot
Copy link
Contributor

ansibot commented Mar 19, 2017

The test ansible-test sanity --test pep8 failed with the following errors:

lib/ansible/modules/windows/win_secedit.py:4:30: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:34:161: E501 line too long (243 > 160 characters)
lib/ansible/modules/windows/win_secedit.py:34:244: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:39:161: E501 line too long (318 > 160 characters)
lib/ansible/modules/windows/win_secedit.py:44:40: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:48:37: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:52:161: E501 line too long (235 > 160 characters)
lib/ansible/modules/windows/win_secedit.py:56:71: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:57:35: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:61:12: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:63:48: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:64:41: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:66:24: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:67:25: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:68:11: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:73:52: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:75:17: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:76:24: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:78:39: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:81:24: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:83:54: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:86:30: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:88:38: W291 trailing whitespace
lib/ansible/modules/windows/win_secedit.py:91:14: W291 trailing whitespace

The test ansible-test sanity --test validate-modules failed with the following errors:

lib/ansible/modules/windows/win_secedit.py:0:0: E307 version_added should be 2.4. Currently 2.3
lib/ansible/modules/windows/win_secedit.py:0:0: E311 EXAMPLES is not valid YAML. Line 58 column 1
lib/ansible/modules/windows/win_secedit.py:0:0: E314 No ANSIBLE_METADATA provided

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Mar 19, 2017
@ansibot
Copy link
Contributor

ansibot commented Mar 20, 2017

The test ansible-test sanity --test ansible-doc --python 2.6 failed with the following error:

Command "ansible-doc win_secedit" returned exit status 1.
>>> Standard Error
[ERROR]: unable to parse
/root/src/github.com/ansible/ansible/lib/ansible/modules/windows/win_secedit.py
ERROR! module win_secedit missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 2.7 failed with the following error:

Command "ansible-doc win_secedit" returned exit status 1.
>>> Standard Error
[ERROR]: unable to parse
/root/src/github.com/ansible/ansible/lib/ansible/modules/windows/win_secedit.py
ERROR! module win_secedit missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 3.5 failed with the following error:

Command "ansible-doc win_secedit" returned exit status 1.
>>> Standard Error
[ERROR]: unable to parse
/root/src/github.com/ansible/ansible/lib/ansible/modules/windows/win_secedit.py
ERROR! module win_secedit missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 3.6 failed with the following error:

Command "ansible-doc win_secedit" returned exit status 1.
>>> Standard Error
[ERROR]: unable to parse
/root/src/github.com/ansible/ansible/lib/ansible/modules/windows/win_secedit.py
ERROR! module win_secedit missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test validate-modules failed with the following errors:

lib/ansible/modules/windows/win_secedit.py:0:0: E302 DOCUMENTATION is not valid YAML. Line 40 column 5
lib/ansible/modules/windows/win_secedit.py:0:0: E316 ANSIBLE_METADATA.metadata_version: required key not provided @ data['metadata_version']. Got None
lib/ansible/modules/windows/win_secedit.py:0:0: E316 ANSIBLE_METADATA.version: extra keys not allowed @ data['version']. Got '1.0'

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Mar 20, 2017

The test ansible-test sanity --test pep8 failed with the following errors:

lib/ansible/modules/windows/win_secedit.py:38:161: E501 line too long (243 > 160 characters)
lib/ansible/modules/windows/win_secedit.py:43:161: E501 line too long (318 > 160 characters)
lib/ansible/modules/windows/win_secedit.py:56:161: E501 line too long (235 > 160 characters)

click here for bot help

@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Mar 20, 2017
@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label Mar 20, 2017
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 21, 2017
@jborean93
Copy link
Contributor

Hey @rndmh3ro and @defionscode I'll try and get to looking at this sometime soon, looks like a good module to have, I know I've written a once off script to do this before. There are a few things in there from a brief look that would need to be made more standard to our other Windows module and I'll add some comments for a first round look.

Copy link
Contributor

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably enough comments for a first round check. Three major things that would need to be done would be to;

  • Add check mode to the module
  • Add some tests
  • More of a question for us to answer in the next WUG around how do we want to handle pipelining and indenting in powershell modules. I'll raise an agenda item.

Please feel free to ask me questions around any of my comments or if you need guidance around check mode/testing.

########


Set-StrictMode -Version Latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually set StrictMode to 2 when running a module automatically, this should be needed


function Get-IniFile {
param (
[parameter(mandatory=$true, position=0, valuefrompipelinebypropertyname=$true, valuefrompipeline=$true)][string]$FilePath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to just move this to function Get-IniFile($FilePath) to make it more python like

{
"^\[(?<Section>.*)\]"
{
$ini.Add($curSectionName, $currentSection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to remove an indent for these lines so they match up in each case statement

}
default
{
throw "Unidentified: $_" # should not happen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to Fail-Json @{} "Error Message here" and change the error to be a bit more descriptive

throw "Unidentified: $_" # should not happen
}
}
if ($ini.Keys -notcontains $curSectionName) { $ini.Add($curSectionName, $currentSection) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the if body to a new line


$params = Parse-Args $args;

$result = New-Object psobject @{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$result = @{

changed = $false
};

$category = Get-Attr $params "category" -failifempty $true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a look at Get-AnsibleParam which can be seen in other modules like win_tempfile. This way you can specify the object type and other options.

};

$category = Get-Attr $params "category" -failifempty $true
$key = Get-Attr $params "key" -failifempty $true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to Get-AnsibleParam as above


$category = Get-Attr $params "category" -failifempty $true
$key = Get-Attr $params "key" -failifempty $true
$value = Get-Attr $params "value" -failifempty $true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to Get-AnsibleParam as above

$sepath = "$home\sec_edit_dump.inf"

If ((Get-WmiObject Win32_ComputerSystem).PartOfDomain) {
Fail-Json $result "This host is joined to a Domain Controller, you'll need to modify GPO directly instead of secedit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be here, in some GPO policies I've seen set definitely allowed me to change certain entries just not others. This should probably be a warning in the python document.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Apr 2, 2017
- The category you wish to modify a value under. This can things like System Access, Event Audit, etc.
If you supply an invalid category the module will error out and let you know what the valid categories are for that particular system.
required: true
default: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If parameter is required, there is no default.

For example, under the System Access category there is a key MinimumPasswordAge that could be targeted.
Just like with category, if an invalid key is specified, the module will error out and show what the valid keys for the given category are.
required: true
default: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

description:
- The value to assign to the key.
required: true
default: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 11, 2017
@jborean93
Copy link
Contributor

@rndmh3ro are you still willing to look into getting this merged in. I'm happy to take it on if you don't have the time as I think this would be good to have in Ansible.

@rndmh3ro
Copy link
Contributor Author

@jborean93, feel free to take this on!

@jhawkesworth
Copy link
Contributor

@jborean93 - sorry I couldn't make the WWG meeting.
I'd prefer to avoid pipelining in ansible powershell modules just because I think its another thing to understand.
I think splitting into 2 modules is valid - perhaps win_user_privilege and win_audit_event - I think the first one would be much more useful than the second one. I'm less concerned about common code at the moment - eventually we will be able to share code between modules - but there's also the issue of 'findability'. I don't think we have the ability to do a redirect in the documentation, but perhaps we could have a 'stub' win_secedit or win_secpol module which just has documentation links to win_user_privilege and win_audit_event. If stub modules aren't acceptable, maybe just mentioning secpol and 'security policy' in the short module description is enough.

@jborean93
Copy link
Contributor

No worries time zones can be quite annoying, the general consensus was to split it up into separate modules mostly focusing on the user right stuff and one to do what this PR focuses on. This is similar to how win_path and win_environment fit together.

@ansibot ansibot added needs_repo This PR no longer has an associated branch as it was removed by the submitter. support:community This issue/PR relates to code supported by the Ansible community. labels Jun 29, 2017
@juliedavila
Copy link
Contributor

Given where this has gone, should we close this particular pr?

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed module This issue/PR relates to a module. new_module This PR includes a new module. labels Jul 7, 2017
@rndmh3ro
Copy link
Contributor Author

rndmh3ro commented Jul 7, 2017

Yes, #26332 superseeds this.

@rndmh3ro rndmh3ro closed this Jul 7, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 4, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 feature This issue/PR relates to a feature request. needs_repo This PR no longer has an associated branch as it was removed by the submitter. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants