-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new role: logon policy for ad user
Lists hosts where Active Directory users have been granted log on permission.
- Loading branch information
Showing
21 changed files
with
1,037 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
|
||
- hosts: all | ||
gather_facts: false | ||
|
||
# The variables you would most likely want/need to override have been included | ||
vars: | ||
|
||
# Report parameters | ||
logon_policy_for_ad_user_user_name: '' | ||
|
||
# Facts | ||
logon_policy_for_ad_user_facts_generate: true | ||
|
||
# Reports | ||
logon_policy_for_ad_user_reports_generate: true | ||
logon_policy_for_ad_user_reports_backup: false | ||
|
||
roles: | ||
- name: oneidentity.authentication_services.logon_policy_for_ad_user | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2022, One Identity LLC | ||
# File: logon_policy_for_ad_user_filters.py | ||
# Desc: Ansible filters for logon_policy_for_ad_user role | ||
# Auth: Laszlo Nagy | ||
# Note: | ||
# ------------------------------------------------------------------------------ | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
# Imports | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Future module imports for consistency across Python versions | ||
from __future__ import absolute_import, division, print_function | ||
|
||
# Want classes to be new type for consistency across Python versions | ||
__metaclass__ = type | ||
|
||
from ansible.errors import AnsibleFilterError | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
# Helper functions | ||
# ------------------------------------------------------------------------------ | ||
|
||
# ------------------------------------------------------------------------------ | ||
def get_logon_policy_for_ad_user(logon_policy_for_unix_hosts): | ||
""" | ||
Example of logon_policy_for_unix_hosts: | ||
{ | ||
"192.168.56.101": [ | ||
[ | ||
"QASDEV\\eripley", | ||
"VAS", | ||
"1003", | ||
"10001", | ||
"Ellen Ripley", | ||
"/home/eripley", | ||
"/bin/bash" | ||
], | ||
[ | ||
"QASDEV\\smartbela", | ||
"VAS", | ||
"1371126438", | ||
"1000", | ||
"Bela Smart", | ||
"/home/smartbela", | ||
"/bin/bash" | ||
] | ||
], | ||
"192.168.56.103": [ | ||
[ | ||
"QASDEV\\eripley", | ||
"VAS", | ||
"1003", | ||
"10001", | ||
"Ellen Ripley", | ||
"/home/eripley", | ||
"/bin/bash" | ||
], | ||
[ | ||
"QASDEV\\senior", | ||
"VAS", | ||
"1234567", | ||
"1000", | ||
"Senior", | ||
"/home/Senior", | ||
"/bin/bash" | ||
] | ||
] | ||
} | ||
""" | ||
|
||
users = {} | ||
for host in logon_policy_for_unix_hosts: | ||
users_allowed = logon_policy_for_unix_hosts[host] | ||
for user in users_allowed: | ||
if user[0] not in users: | ||
users.update({user[0]: {'user': user, 'hosts': [host]} }) | ||
else: | ||
users[user[0]]['hosts'].append(host) | ||
|
||
return users | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
# Classes | ||
# ------------------------------------------------------------------------------ | ||
|
||
# ------------------------------------------------------------------------------ | ||
class FilterModule(object): | ||
""" | ||
logon_policy_for_ad_user role jinja2 filters | ||
""" | ||
|
||
def filters(self): | ||
filters = { | ||
'logonpolicyforaduser': get_logon_policy_for_ad_user | ||
} | ||
return filters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# `logon_policy_for_ad_user` Role | ||
|
||
The `logon_policy_for_ad_user` role creates CSV and HTML reports that list the hosts where Active Directory users have been granted log on permission. | ||
|
||
## Variables | ||
|
||
All of the variables shown below have a default value but can be overridden to suit your environment. Variable overriding can be done in playbooks, inventories, from the command line using the `-e` switch with the `ansible-playbook` command, or from Ansible Tower and AWX. See [Ansbile documentation](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html) for further information. | ||
|
||
### Report parameters | ||
|
||
* `logon_policy_for_ad_user_user_name`: An Active Directory user can be specified in the following format: DOMAIN\SamAccountName. For example: EXAMPLE\jason. Reports will be generated for the specified user. If no user is specified then the reports will be generated for all Active Directory users who have been granted log on permission. | ||
|
||
Default value is: | ||
```yaml | ||
logon_policy_for_ad_user_user_name: '' | ||
``` | ||
### Facts generation | ||
Facts generation variable defaults for all roles are set by variables in the [`common`](../common/README.md) role and can be overriden for all roles by setting the appropriate [`common`](../common/README.md) role variable. See [common role facts generation variables](../common/README.md#facts-generation) in the [`common`](../common/README.md) role. | ||
|
||
* `logon_policy_for_ad_user_facts_generate` enables facts generation. Implicitely enabled if `logon_policy_for_ad_user_reports_generate` is set. | ||
|
||
Default value is: | ||
```yaml | ||
logon_policy_for_ad_user_facts_generate: "{{ facts_generate }}" | ||
``` | ||
|
||
### Report generation | ||
|
||
Report generation variable defaults for all roles are set by variables in the [`common`](../common/README.md) role and can be overriden for all roles by setting the appropriate [`common`](../common/README.md) role variable. See [common role report generation variables](../common/README.md#report-generation) in the [`common`](../common/README.md) role. | ||
|
||
* `logon_policy_for_ad_user_reports_generate` enables report generation. Reports are generated at the end of a `logon_policy_for_ad_user` run for all hosts. | ||
|
||
Default value is: | ||
```yaml | ||
logon_policy_for_ad_user_reports_generate: "{{ reports_generate }}" | ||
``` | ||
|
||
* `logon_policy_for_ad_user_reports_backup` enables backup of prior reports by renaming them with the date and time they were generated so that the latest reports do not override the previous reports. | ||
|
||
Default value is: | ||
```yaml | ||
logon_policy_for_ad_user_reports_backup: "{{ reports_backup }}" | ||
``` | ||
|
||
* `logon_policy_for_ad_user_reports_host` sets the host on which the reports should be generated. | ||
|
||
Default value is: | ||
```yaml | ||
logon_policy_for_ad_user_reports_host: "{{ reports_host }}" | ||
``` | ||
|
||
* `logon_policy_for_ad_user_reports` is a list of dictionaries that define the reports to be generated. The default value creates a CSV and HTML report using the templates included with the `logon_policy_for_ad_user` role. | ||
|
||
Default value is: | ||
```yaml | ||
logon_policy_for_ad_user_reports: | ||
- src: logon_policy_for_ad_user_report.csv.j2 | ||
dest: logon_policy_for_ad_user_report.csv | ||
- src: logon_policy_for_ad_user_report.html.j2 | ||
dest: logon_policy_for_ad_user_report.html | ||
``` | ||
|
||
The `src` key for each list entry is the report template file on the Ansible control node. With a relative path Ansible will look in the `logon_policy_for_ad_user` role `template` directory. Use a absolute path to speciy templates located elsewhere on the Ansible control node. | ||
|
||
The `dest` key for each list entry is the report file on the machine specified in `logon_policy_for_ad_user_reports_host`. If `logon_policy_for_ad_user_reports_host` is set to the Ansible control node a relative path can be used and it will be relative to the directory from which the playbook is run. For other hosts, an absolute path must be used. In either case the containing directory must exist. | ||
|
||
## Usage | ||
|
||
Below is a sample playbook using the `logon_policy_for_ad_user` role. | ||
|
||
```yaml | ||
--- | ||
- hosts: all | ||
gather_facts: false | ||
# The variables you would most likely want/need to override have been included | ||
vars: | ||
# Report parameters | ||
logon_policy_for_ad_user_user_name: '' | ||
# Facts | ||
logon_policy_for_ad_user_facts_generate: true | ||
# Reports | ||
logon_policy_for_ad_user_reports_generate: true | ||
logon_policy_for_ad_user_reports_backup: false | ||
roles: | ||
- name: oneidentity.authentication_services.logon_policy_for_ad_user | ||
``` | ||
|
||
For a copy of this and other sample playbooks see [examples](../../examples/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
|
||
# Report parameters | ||
# ------------------------------------------------------------------------------ | ||
|
||
logon_policy_for_ad_user_user_name: '' | ||
|
||
|
||
# Facts settings | ||
# ------------------------------------------------------------------------------ | ||
|
||
logon_policy_for_ad_user_facts_generate: "{{ facts_generate }}" | ||
|
||
|
||
# Reports settings | ||
# ------------------------------------------------------------------------------ | ||
|
||
logon_policy_for_ad_user_reports_generate: "{{ reports_generate }}" | ||
logon_policy_for_ad_user_reports_backup: "{{ reports_backup }}" | ||
|
||
# On which host should the reports be generated. | ||
# TODO: This has only been tested on the Ansible control node (127.0.0.1) | ||
logon_policy_for_ad_user_reports_host: "{{ reports_host }}" | ||
|
||
# List of reports to generate | ||
# src: Is the report template file on the Ansible control node. | ||
# With no or relative path Ansible will look in the logon_policy_for_ad_user role template directory. | ||
# Full path to find the template files elsewhere on the Ansible control node. | ||
# dest: Is the destination file on the host (logon_policy_for_ad_user_reports_host.) | ||
# With no or relative path when the destination is the Ansible control node. | ||
# (logon_policy_for_ad_user_reports_host = 127.0.0.1) relative to the playbook directory. | ||
# Full path for other locations or on other hosts. | ||
# In either case the directory must already exist. | ||
logon_policy_for_ad_user_reports: | ||
- src: logon_policy_for_ad_user_report.csv.j2 | ||
dest: logon_policy_for_ad_user_report.csv | ||
- src: logon_policy_for_ad_user_report.html.j2 | ||
dest: logon_policy_for_ad_user_report.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
|
||
galaxy_info: | ||
|
||
author: Laszlo Nagy <[email protected]> | ||
|
||
company: One Identity | ||
|
||
description: > | ||
Identifies the hosts where Active Directory users have been granted log on permission. | ||
issue_tracker_url: https://github.com/OneIdentity/ansible-authentication-services/issues | ||
|
||
license: Apache-2.0 | ||
|
||
min_ansible_version: 2.9 | ||
|
||
# | ||
# To view available platforms and versions (or releases), visit: | ||
# https://galaxy.ansible.com/api/v1/platforms/ | ||
# | ||
platforms: | ||
- name: Amazon | ||
versions: | ||
- all | ||
- name: MacOSX | ||
versions: | ||
- 10.12 | ||
- 10.13 | ||
- 10.14 | ||
- 10.15 | ||
- name: EL | ||
versions: | ||
- all | ||
- name: Debian | ||
versions: | ||
- all | ||
- name: Fedora | ||
versions: | ||
- all | ||
- name: FreeBSD | ||
versions: | ||
- all | ||
- name: AIX | ||
versions: | ||
- 7.1 | ||
- 7.2 | ||
- name: opensuse | ||
versions: | ||
- all | ||
- name: Solaris | ||
versions: | ||
- all | ||
- name: SLES | ||
versions: | ||
- 11 | ||
- 12 | ||
- 15 | ||
- name: Ubuntu | ||
versions: | ||
- all | ||
|
||
# galaxy_tags: [] | ||
|
||
dependencies: | ||
- role: common |
Oops, something went wrong.