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

Upgrade ossec to v3.0.0 #3724

Merged
merged 5 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ ip_info:
local_deb_packages:
- "securedrop-keyring-0.1.2+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-config-0.1.1+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-ossec-agent-2.8.2+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-ossec-agent-3.0.0+{{ securedrop_app_code_version }}-amd64.deb"
- "{{ securedrop_app_code_deb }}.deb"
- "ossec-agent-2.8.2-amd64.deb"
- "ossec-agent-3.0.0-amd64.deb"

# Configuring the tor hidden services
tor_instances:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ ip_info:
local_deb_packages:
- "securedrop-keyring-0.1.2+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-config-0.1.1+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-ossec-server-2.8.2+{{ securedrop_app_code_version }}-amd64.deb"
- ossec-server-2.8.2-amd64.deb
- "securedrop-ossec-server-3.0.0+{{ securedrop_app_code_version }}-amd64.deb"
- ossec-server-3.0.0-amd64.deb

# Configure the tor hidden services. The Monitor server has only one,
# for SSH, since no web interfaces.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build_ossec_deb_pkg_dependencies: []

ossec_server_hostname: ossec-server
ossec_version: 2.8.2
ossec_version: 3.0.0
# Parent directory for performing build operations. All files related
# to build, including source tarball, will be created inside this dir.
build_path: /tmp/build
Expand All @@ -21,3 +21,5 @@ ossec_build_rsync_generic_opts:
# See explanation from b291059d556d6cdb11c8ab8d68eab96436cb9f69
ossec_build_rsync_ansible_hack_opt:
- "--rsync-path='sudo rsync'"

ossec_source_checksum: sha256:a271d665ed502b3df4ff055a177159dfc0bc8a69dd44eab1f7c57fe8fff42a98
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2

mQINBE15UXUBEAChQfKBpWvjFhqplrnqHNqUuk5hubtcsn95ftpYlj8p8n8mFzn/
a62yhRV28sT76+ZCrcxYfcZJtiGEXbU0nkzKPh9WOpmG46kyX24dcsVFe/BJ1FrE
7XGJrr56g1BdrM6rvblFEjF//No9MmNxVt8fJRNMqbLgRjsvUCRJ10nN1KwSgusk
AyPSTn2KuI1opRf+9chxvtk2zFSFbUo6NFZREis3Aib5oxpddzxO2c93JuDSJKYb
6zitesjptfT4lIo7+1xU+XVDe7upXbl+OX56RyHLSV+HIA9k7wkcBsXoAnqN5C4N
/yhZzFK7sEzWbPjiFSpKInv+DnFI+Mua/Img3++dhgtCeVj9XL23vSIqDFOnanoa
iSwRNr5eiZJfkYIbbb0r1azCZ3+Cx07OLRFn4PjbqnPpsZTRTRJy7qoRLUrpeREn
I5YlRHeWE+vJYHFTDcpd7GDtghhx5ZDpq0E1obpbOpdio0M8pdU4X0V+RvOFqbbw
oysfw2ZkNdfS1z9TpYJfPgPrcPMZo1Ar6oucEXvvbHSsmcR7f3LNo/Z8KK7FpLXi
V37tNcoXfnDkLNe8ZmeIRO/oUI0FS7fjnNOThkm5yQAK5elfnHCsvPsOCu0+dwZs
5Nl3yMnZHoEq+xxDMHJ1nxCVdVCmQk/4I7jKixCmKDPyi6+Ts/7Oahmg8wARAQAB
tCRTY290dCBSLiBTaGlubiA8c2NvdHRAYXRvbWljb3JwLmNvbT6JAjgEEwECACIF
Ak15UXUCGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEO4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8tQ
-----END PGP PUBLIC KEY BLOCK-----
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ossec_version:
description:
- version number of release to download
default: "2.8.2"
default: "3.0.0"
required: no
notes:
- The OSSEC version to download is hardcoded to avoid surprises.
Expand All @@ -23,76 +23,54 @@
'''
EXAMPLES = '''
- ossec_urls:
ossec_version: "2.8.2"
ossec_version: "3.0.0"
'''

import re # noqa: E402
import re # noqa: F401


HAS_REQUESTS = True
try:
import requests
import requests # noqa: F401
except ImportError:
HAS_REQUESTS = False


class OSSECURLs():

def __init__(self, ossec_version):
self.REPO_URL = "https://github.com/ossec/ossec-hids"
self.ossec_version = ossec_version

checksums = self.parse_checksums()

self.ansible_facts = dict(
ossec_version=self.ossec_version,
ossec_tarball_filename=self.ossec_tarball_filename,
ossec_tarball_url=self.ossec_tarball_url,
ossec_checksum_filename=self.ossec_checksum_filename,
ossec_checksum_url=self.ossec_checksum_url,
ossec_signature_filename=self.ossec_signature_filename,
ossec_signature_url=self.ossec_signature_url,
)

self.ansible_facts.update(checksums)

@property
def ossec_tarball_filename(self):
return "ossec-hids-{}.tar.gz".format(self.ossec_version)

@property
def ossec_tarball_url(self):
return "https://github.com/ossec/ossec-hids/archive/{}.tar.gz".format(
self.ossec_version)
return self.REPO_URL + "/archive/{}.tar.gz".format(self.ossec_version)

@property
def ossec_checksum_url(self):
return "https://github.com/ossec/ossec-hids/releases/download/{}/{}".format( # noqa: E501
self.ossec_version, self.ossec_checksum_filename)
def ossec_signature_url(self):
return self.REPO_URL + "/releases/download/{}/{}".format(
self.ossec_version, self.ossec_signature_filename)

@property
def ossec_checksum_filename(self):
return "{}-checksum.txt".format(self.ossec_tarball_filename)

def parse_checksums(self):
r = requests.get(self.ossec_checksum_url)
checksum_regex = re.compile(r'''
^MD5\(
'''
+ re.escape(self.ossec_tarball_filename) +
r'''\)=\s+(?P<ossec_md5_checksum>[0-9a-f]{32})\s+
SHA1\(
'''
+ re.escape(self.ossec_tarball_filename) +
r'''\)=\s+(?P<ossec_sha1_checksum>[0-9a-f]{40})$
''', re.VERBOSE | re.MULTILINE
)
checksum_list = r.content.rstrip()
results = re.match(checksum_regex, checksum_list).groupdict()
return results
def ossec_signature_filename(self):
return "ossec-hids-{}.tar.gz.asc".format(self.ossec_version)


def main():
module = AnsibleModule( # noqa: F405
argument_spec=dict(
ossec_version=dict(default="2.8.2"),
ossec_version=dict(default="3.0.0"),
),
supports_check_mode=False
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,23 @@
get_url:
url: "{{ ossec_tarball_url }}"
dest: "{{ build_path }}/{{ ossec_tarball_filename }}"
checksum: "{{ ossec_source_checksum }}"

- name: Gather checksum info for downloaded tarball.
stat:
path: "{{ build_path }}/{{ ossec_tarball_filename }}"
get_md5: yes
register: ossec_download

- name: Fail if MD5 and SHA1 checksums for tarball are not correct.
fail:
msg: >
The checksums for {{ ossec_tarball_filename }} do not match.
Both MD5 and SHA1 checksums were inspected. The checksums
used for the inspection where:
MD5: {{ ossec_md5_checksum }}
SHA1: {{ ossec_sha1_checksum }}

The checksums found were:
MD5: {{ ossec_download.stat.md5 }}
SHA1: {{ ossec_download.stat.checksum }}

Try rerunning the playbook to download the files again.
when: not (ossec_download.stat.exists and
ossec_download.stat.md5 == "{{ ossec_md5_checksum }}" and
ossec_download.stat.checksum == "{{ ossec_sha1_checksum }}")
- name: Download OSSEC signature.
get_url:
url: "{{ ossec_signature_url }}"
dest: "{{ build_path }}/{{ ossec_signature_filename }}"

- name: Copy OSSEC archive GPG key.
copy: src=../files/OSSEC-ARCHIVE-KEY.asc dest=/tmp/OSSEC-ARCHIVE-KEY.asc

- name: Import OSSEC archive GPG key.
shell: "gpg --import /tmp/OSSEC-ARCHIVE-KEY.asc"

- name: Verify signature of OSSEC tarball.
shell: "gpg --verify {{ build_path }}/{{ ossec_signature_filename }}"
register: ossec_verification_return_code
failed_when: ossec_verification_return_code.rc != 0

- name: Install apt dependencies for building OSSEC packages.
apt:
Expand Down Expand Up @@ -91,13 +84,18 @@
- "{{ ossec_build_dir }}"
- "{{ ossec_build_dir }}/var"

- name: Remove client.keys to avoid overwriting existing client.keys
file:
state: absent
dest: /var/ossec/etc/client.keys

- name: Copy /var/ossec/ to OSSEC build directory.
command: cp -R /var/ossec {{ ossec_build_dir }}/var/

- name: Copy OSSEC DEBIAN package scripts to build directory.
command: cp -R {{ repo_src_path }}/DEBIAN {{ ossec_build_dir }}

- name: Copy OSEC DEBIAN/control template to build directory.
- name: Copy OSSEC DEBIAN/control template to build directory.
template:
src: "{{ purpose }}_control.j2"
dest: "{{ ossec_build_dir }}/DEBIAN/control"
Expand Down Expand Up @@ -126,6 +124,7 @@
# config testing after the build is completed.
# - "{{ ossec_build_dir }}"
- /var/ossec
- /tmp/OSSEC-ARCHIVE-KEY.asc

- name: Fetch newly built Debian packages back to localhost.
fetch:
Expand Down
30 changes: 29 additions & 1 deletion install_files/ansible-base/roles/ossec/tasks/register.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@
- ossec_is_client
- not ossec_agent_already_registered

# Ossec 3.0 now defaults to requiring a shared secret for agent authentication.
# Disabling authentication is broken for authd in ossec 3.0. Registering agents
# requires a 32 hex character password with a line feed appended to the
# password file (see: https://github.com/ossec/ossec-hids/issues/1472)
- name: Generate authd shared secret
set_fact :
ossec_registration_secret: "{{ lookup('pipe', 'head -c 32 /dev/urandom | md5sum | tr -d \" -\" | sed \"$d\"') }}"
delegate_to: localhost
delegate_facts: True
when:
- not ossec_agent_already_registered

- name: Copy authd shared secret
copy:
content: "{{ hostvars['localhost']['ossec_registration_secret'] }}"
dest: /var/ossec/etc/authd.pass
mode: 440
when:
- not ossec_agent_already_registered

- name: Append carriage return to auth file
command: sed -ie 's/$/\n/' /var/ossec/etc/authd.pass
when:
- not ossec_agent_already_registered

- name: Start authd.
shell: /var/ossec/bin/ossec-authd -i {{ app_ip }} -p 1515 >/dev/null 2>&1 &
async: 0
Expand All @@ -86,11 +111,14 @@
with_items: "{{ authd_iprules }}"
when: not ossec_agent_already_registered

# agent-auth now returns 0 if registration fails (https://github.com/ossec/ossec-hids/issues/1491)
- name: Register OSSEC agent.
command: /var/ossec/bin/agent-auth -m {{ monitor_ip }} -p 1515 -A {{ app_hostname }}
command: /var/ossec/bin/agent-auth -m {{ monitor_ip }} -p 1515 -A {{ app_hostname }} -P /var/ossec/etc/authd.pass
register: ossec_agent_registration_result
when:
- ossec_is_client
- not ossec_agent_already_registered
failed_when: "'INFO: Valid key created. Finished.' not in ossec_agent_registration_result.stdout"

# If the OSSEC agent auth iptable rule exemptions are in place remove them and
# restart OSSEC. This order does matter. The app server's
Expand Down
4 changes: 2 additions & 2 deletions install_files/ossec-agent/etc/ossec-init.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DIRECTORY="/var/ossec"
VERSION="v2.8.2"
DATE="Thu Jun 11 11:39:25 PDT 2015"
VERSION="v3.0.0"
DATE="Tue Aug 21 10:52:11 PDT 2018"
TYPE="agent"
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
ossec-agent (3.0.0) unstable; urgency=low

[ SecureDrop Team ]
* Release Notes https://github.com/ossec/ossec-hids/releases/tag/3.0.0

-- SecureDrop Team <[email protected]> Tue, 21 Aug 2018 10:43:47 -0700

ossec-agent (2.8.2) unstable; urgency=low

[ SecureDrop Team ]
Expand All @@ -8,6 +15,6 @@ ossec-agent (2.8.2) unstable; urgency=low
ossec-agent (2.8.1) unstable; urgency=low

[ James Dolan ]
* Initial release
* Initial release

-- James Dolan <[email protected]> Fri, 14 Mar 2014 15:46:57 -0700
4 changes: 2 additions & 2 deletions install_files/ossec-server/etc/ossec-init.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DIRECTORY="/var/ossec"
VERSION="v2.8.2"
DATE="Thu Jun 11 11:39:25 PDT 2015"
VERSION="v3.0.0"
DATE="Tue Aug 21 10:52:11 PDT 2018"
TYPE="server"
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
ossec-server (3.0.0) unstable; urgency=low

[ SecureDrop Team ]
* Release Notes https://github.com/ossec/ossec-hids/releases/tag/3.0.0

-- SecureDrop Team <[email protected]> Tue, 21 Aug 2018 10:43:47 -0700

ossec-server (2.8.2) unstable; urgency=low

[ SecureDrop Team ]
Expand Down
2 changes: 1 addition & 1 deletion install_files/securedrop-ossec-agent/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Priority: optional
Maintainer: SecureDrop Team <[email protected]>
Homepage: https://securedrop.org
Package: securedrop-ossec-agent
Version: 2.8.2+0.10.0~rc1
Version: 3.0.0+0.10.0~rc1
Architecture: amd64
Depends: ossec-agent,securedrop-keyring,securedrop-config
Replaces: ossec-agent
Expand Down
7 changes: 6 additions & 1 deletion install_files/securedrop-ossec-agent/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ set -e

case "$1" in
configure)
service ossec restart
# Replace monitor server domain name by ip address due to
# https://github.com/ossec/ossec-hids/issues/1145
mon_ip=$(grep -oP "^\\d+\.\\d+\.\\d+\.\\d+(?=.*securedrop-monitor-server-alias)" /etc/hosts)
sed -i -e "s/<server-hostname>securedrop-monitor-server-alias<\/server-hostname>/<server-ip>$mon_ip<\/server-ip>/g" /var/ossec/etc/ossec.conf
service ossec restart
;;

abort-upgrade|abort-remove|abort-deconfigure)
Expand All @@ -28,6 +32,7 @@ case "$1" in
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;

esac

# dh_installdeb will replace this with shell code automatically
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
securedrop-ossec-agent (3.0.0) unstable; urgency=low

* Upgrade to ossec 3.0

-- SecureDrop Team <[email protected]> Tue, 21 Aug 2018 11:43:47 -0700

securedrop-ossec-agent (2.8.1) unstable; urgency=low

* Initial release
* Initial release

-- James Dolan <[email protected]> Fri, 14 Mar 2014 15:46:57 -0700
Loading