Skip to content

Commit

Permalink
Add support for Windows (#12)
Browse files Browse the repository at this point in the history
* Add initial Windows support. Remove apt/yumrepo_core hard dependencies.

* Update checkout action to v3

* Update checkout action to v4
  • Loading branch information
gibbs authored Jan 26, 2024
1 parent 422e12a commit 53fdf8a
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 17 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
fixtures:
repositories:
apt: https://github.com/puppetlabs/puppetlabs-apt.git
chocolatey: https://github.com/puppetlabs/puppetlabs-chocolatey.git
facts: https://github.com/puppetlabs/puppetlabs-facts.git
provision: https://github.com/puppetlabs/provision.git
puppet_agent: https://github.com/puppetlabs/puppetlabs-puppet_agent.git
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }}
github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup ruby
uses: ruby/setup-ruby@v1
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}}
name: Spec Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }})
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup ruby
uses: ruby/setup-ruby@v1
Expand All @@ -62,7 +62,7 @@ jobs:
BOLT_GEM: true
CI: true
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-20.04
if: github.repository_owner == 'gibbs'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,21 @@ osquery::settings:
query: SELECT * FROM suid_bins;
interval: 3600
```
## Dependencies
The following modules are soft dependencies that are required
depending on the OS family used.
### Debian Family
- `puppetlabs/apt` >= 9.1.0

### RedHat Family

- `puppetlabs/yumrepo_core` >= 1.2.0

### Windows Family

- `puppetlabs/chocolatey` >= 8.0.0

29 changes: 28 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The following parameters are available in the `osquery` class:
* [`config_group`](#-osquery--config_group)
* [`package_name`](#-osquery--package_name)
* [`package_ensure`](#-osquery--package_ensure)
* [`package_provider`](#-osquery--package_provider)
* [`package_install_options`](#-osquery--package_install_options)
* [`service_name`](#-osquery--service_name)
* [`service_enable`](#-osquery--service_enable)
* [`service_ensure`](#-osquery--service_ensure)
Expand All @@ -39,6 +41,7 @@ The following parameters are available in the `osquery` class:
* [`repo_key_id`](#-osquery--repo_key_id)
* [`repo_key_server`](#-osquery--repo_key_server)
* [`settings`](#-osquery--settings)
* [`validate_cmd`](#-osquery--validate_cmd)

##### <a name="-osquery--config_path"></a>`config_path`

Expand Down Expand Up @@ -80,6 +83,22 @@ The osquery package ensure state

Default value: `'installed'`

##### <a name="-osquery--package_provider"></a>`package_provider`

Data type: `Optional[String]`

The package provider to use (Windows)

Default value: `undef`

##### <a name="-osquery--package_install_options"></a>`package_install_options`

Data type: `Optional[Array]`

The install_options to provide when using Chocolatey (Windows)

Default value: `undef`

##### <a name="-osquery--service_name"></a>`service_name`

Data type: `String[1]`
Expand Down Expand Up @@ -114,7 +133,7 @@ Default value: `true`

##### <a name="-osquery--repo_url"></a>`repo_url`

Data type: `String`
Data type: `Optional[String]`

The osquery repository URL to use

Expand Down Expand Up @@ -144,3 +163,11 @@ A hash of settings to set in the osquery configuration file

Default value: `{}`

##### <a name="-osquery--validate_cmd"></a>`validate_cmd`

Data type: `String`

The command to validate osquery.conf format changes

Default value: `'/usr/bin/osqueryi --config_path % --config_check'`

1 change: 1 addition & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ osquery::service_ensure: running
osquery::config_path: /etc/osquery/osquery.conf
osquery::config_owner: 0
osquery::config_group: 0
osquery::validate_cmd: '/usr/bin/osqueryi --config_path % --config_check'

osquery::settings:
options:
Expand Down
11 changes: 11 additions & 0 deletions data/windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
osquery::config_path: 'C:/Program Files/osquery/osquery.conf'
osquery::config_group: Administrator
osquery::config_owner: Administrator
osquery::package_provider: chocolatey
osquery::package_install_options:
- -params
- /InstallService
osquery::service_name: osqueryd
osquery::settings: ~
osquery::validate_cmd: 'C:/Program Files/osquery/osqueryi --config_path "%" --config_check'
4 changes: 2 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
owner => $osquery::config_owner,
group => $osquery::config_group,
mode => '0640',
content => to_json_pretty($osquery::settings),
content => stdlib::to_json_pretty($osquery::settings),
notify => Service[$osquery::service_name],
require => Package[$osquery::package_name],
validate_cmd => '/usr/bin/osqueryi --config_path % --config_check',
validate_cmd => $osquery::validate_cmd,
}
}
14 changes: 13 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
# @param package_ensure
# The osquery package ensure state
#
# @param package_provider
# The package provider to use (Windows)
#
# @param package_install_options
# The install_options to provide when using Chocolatey (Windows)
#
# @param service_name
# The osquery service name
#
Expand All @@ -39,6 +45,9 @@
# @param settings
# A hash of settings to set in the osquery configuration file
#
# @param validate_cmd
# The command to validate osquery.conf format changes
#
# @author Dan Gibbs <[email protected]>
#
class osquery (
Expand All @@ -47,14 +56,17 @@
Variant[Integer[0], String[1]] $config_group = 0,
String[1] $package_name = 'osquery',
String $package_ensure = 'installed',
Optional[String] $package_provider = undef,
Optional[Array] $package_install_options = undef,
String[1] $service_name = 'osqueryd',
Boolean $service_enable = true,
Stdlib::Ensure::Service $service_ensure = 'running',
Boolean $manage_repo = true,
String $repo_url = undef,
Optional[String] $repo_url = undef,
Optional[String] $repo_key_id = undef,
Optional[String] $repo_key_server = undef,
Hash $settings = {},
String $validate_cmd = '/usr/bin/osqueryi --config_path % --config_check',
) {
contain osquery::package
contain osquery::config
Expand Down
11 changes: 11 additions & 0 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
require => Yumrepo['osquery-s3-rpm'],
}
}
'windows': {
Package<|title == $osquery::package_name|> {
provider => $osquery::package_provider,
}

if $osquery::package_provider == 'chocolatey' {
Package<|title == $osquery::package_name|> {
install_options => $osquery::package_install_options,
}
}
}
default: {
fail("Repository for ${facts[os][family]} is not supported.")
}
Expand Down
18 changes: 10 additions & 8 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 5.0.0 < 10.0.0"
},
{
"name": "puppetlabs/apt",
"version_requirement": ">= 6.0.0 < 10.0.0"
},
{
"name": "puppetlabs/yumrepo_core",
"version_requirement": ">= 1.0.0 < 3.0.0"
}
],
"operatingsystem_support": [
Expand Down Expand Up @@ -52,6 +44,16 @@
"22.04",
"20.04"
]
},
{
"operatingsystem": "Windows",
"operatingsystemrelease": [
"11",
"10",
"2012",
"2019",
"2022"
]
}
],
"requirements": [
Expand Down
9 changes: 8 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@
it { is_expected.to contain_yumrepo('osquery-s3-rpm') }
end

if ['Debian', 'Redhat'].include? facts[:os]['family']
it { is_expected.to contain_file('/etc/osquery/osquery.conf') }
end

if facts[:os]['family'] == 'windows'
it { is_expected.to contain_file('C:/Program Files/osquery/osquery.conf') }
end

it { is_expected.to contain_package('osquery') }
it { is_expected.to contain_service('osqueryd') }
it { is_expected.to contain_file('/etc/osquery/osquery.conf') }
end
end
end
Expand Down

0 comments on commit 53fdf8a

Please sign in to comment.