Skip to content

Commit

Permalink
Add installer signing
Browse files Browse the repository at this point in the history
  • Loading branch information
WStechura committed Sep 27, 2024
1 parent 150421e commit af05e0b
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 64 deletions.
9 changes: 6 additions & 3 deletions .github/actions/run-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ runs:
- name: Run sanity test
shell: bash
run: pushd ~/.ansible/collections/ansible_collections/dynatrace/oneagent && ansible-test sanity && popd
- name: Prepare component tests
id: prepare-component-tests
shell: bash
run: python -m virtualenv venv && source venv/bin/activate && cd roles/oneagent/tests/component &&
pip install -r resources/requirements.txt
- name: Run component tests
id: component-tests
shell: bash
run: python -m virtualenv venv && source venv/bin/activate && cd roles/oneagent/tests/component &&
pip install -r resources/requirements.txt && python run.py --linux_x86=localhost
run: python run.py --linux_x86=localhost
- name: Upload logs
if: failure() && steps.component-tests.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: component-tests-${{ github.sha }}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,5 @@ jobs:
uses: ./.github/actions/setup-build-environment
- name: Build the collection
uses: ./.github/actions/build-collection
- name: Debug
run: ls -alR
- name: Run tests
uses: ./.github/actions/run-tests
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dynatrace-oneagent-*
.idea/
**/.idea/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ In its current state, the collection consists of a single role that deploys Dyna
### General
* Ansible >= 2.15.0
### Windows
* pywinrm >= 0.4.3
* pywinrm >= 0.4.1

## Setup
`pip install -r requirements.txt`
Expand Down
4 changes: 2 additions & 2 deletions roles/oneagent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ For full list of suitable parameters, see [OneAgent configuration via command-li
The following variables are available in `defaults/main/` and can be overridden:

| Name | Default | Description
|------|-|-
|-|-|-
| `oneagent_environment_url` | `-` | The URL of the target Dynatrace environment (see [Direct download from your environment](#direct-download-from-your-environment)).
| `oneagent_paas_token` | `-` | The [PaaS Token] retrieved from the "Deploy Dynatrace" installer page.
| `oneagent_local_installer` | `-` | The Path to OneAgent installer stored on the main node.
Expand All @@ -53,7 +53,7 @@ The following variables are available in `defaults/main/` and can be overridden:
| `oneagent_package_state` | `present` | OneAgent package state; use `present` or `latest` to make sure it's installed, or `absent` in order to uninstall.
| `oneagent_reboot_host` | `false` | Reboot the secondary machine after OneAgent installation
| `oneagent_validate_certs` | `true` | If set to `false`, allows to download OneAgent from a server with insecure SSL certificate (expired, self-signed, etc).
| `oneagent_verify_signature` | `true` | Allows to skip verifying the installer's signature on UNIX platforms
| `oneagent_verify_signature` | `true` | Verifies installer's signature (available only on AIX/Linux platforms)
| `oneagent_reboot_timeout` | `3600` | Set the timeout for rebooting secondary machine in seconds

For more information, see customize OneAgent installation documentation for [Linux], [Windows], and [AIX].
Expand Down
1 change: 1 addition & 0 deletions roles/oneagent/tasks/gather-info/gather-info.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Gather installers info
ansible.builtin.include_tasks: tasks/gather-info/gather-info-{{ oneagent_system_family }}.yml

- name: Compare versions of installed OneAgent and uploaded installer
ansible.builtin.set_fact:
_oneagent_is_installation_possible: "{{ _oneagent_installed_agent_version.stdout | default('') < _oneagent_new_agent_version.stdout }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/oneagent/tasks/provide-installer/signature-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

- name: Validate installer signature
ansible.builtin.shell: >
( printf "%s\n" "{{ oneagent_certificate_verification_header }}";
( printf '%s\n' '{{ oneagent_certificate_verification_header }}';
printf '\n\n----SIGNED-INSTALLER\n'; cat "{{ oneagent_installer_path }}" ) |
openssl cms -verify -CAfile "{{ oneagent_ca_cert_dest_path }}" > /dev/null
no_log: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ parseParams() {
while [ $# -gt 0 ]; do
local param="${1}"
if [ "${param}" = "--version" ]; then
printf "%s" "${INSTALLER_VERSION}"
printf "%s\n" "${INSTALLER_VERSION}"
exit 0
elif [ "${param}" = "INSTALL_PATH" ]; then
INSTALL_DIR="$(printf "%s" "${param}" | cut -d "=" -f "2-")"
Expand Down Expand Up @@ -68,6 +68,7 @@ main() {
deployOneagentCtl
deployUninstallScript
applyConfig
exit 0
}

##################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFazCCA1OgAwIBAgIUYkKTxzGlL9GbWs+0yUpApwdKNq4wDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDA5MjAwNzAxMzZaFw0yNTA5
MjAwNzAxMzZaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggIiMA0GCSqGSIb3DQEB
AQUAA4ICDwAwggIKAoICAQC9mTJgc7MYM/KjZ90iF/omZEd1VCnj/nubAKkVSMdO
XAaYHRAszNUZh11fJ9wJEoY5CgeAQxWcy2YAh9Sb8MU/FmO7erXuK1h+315DI2Ao
owxQjb3rL7+mfD9EKZon9RJuMdzwBhZhNpATa+RXbI5IsJJLGW8sWH8k+/XXmpBj
qjVOpY8BYjU6wEFrTo+vvu17CyGnYFcX/LssgggBTCSV7bLWAuCML/Si2MwSz6Yn
s4jf0Av8cUpoQXbFF8Rh+ejtgDIBwydUD6MOtrnX0DClKdDe+A/GDNK79g4rfnOC
FV4VKIDaJ92GrRf03xCgxappQmFtpx00I9oNDUSQYE6LxVwYg56TGhoFeNoV0nBA
F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Y3Rg/uBxA8T3vbhWeC3djg79
LT+WQqRE6l4E7mNeb/vIPddt4nP8SvPmy+3ilLYPb6A2kwpItY1oVbsMPmo0NpU=
-----END CERTIFICATE-----
52 changes: 52 additions & 0 deletions roles/oneagent/tests/component/resources/installers/private.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQC9mTJgc7MYM/Kj
Z90iF/omZEd1VCnj/nubAKkVSMdOXAaYHRAszNUZh11fJ9wJEoY5CgeAQxWcy2YA
h9Sb8MU/FmO7erXuK1h+315DI2AoowxQjb3rL7+mfD9EKZon9RJuMdzwBhZhNpAT
a+RXbI5IsJJLGW8sWH8k+/XXmpBjqjVOpY8BYjU6wEFrTo+vvu17CyGnYFcX/Lss
gggBTCSV7bLWAuCML/Si2MwSz6Yns4jf0Av8cUpoQXbFF8Rh+ejtgDIBwydUD6MO
trnX0DClKdDe+A/GDNK79g4rfnOCFV4VKIDaJ92GrRf03xCgxappQmFtpx00I9oN
DUSQYE6LxVwYg56TGhoFeNoV0nBAFIoWOyVxSFpS4FXkhOAstHholMYjvE2QwUfO
4dFPqVD8cgRlB/rstP1guhFIxrRHKhD3Quj5c48EoC///mgHuc6BLj/16H3z3GpZ
FPexXFFxZEVvhgoZRGonLjOCpz8kwOQki96o2IZnejU/i/oYbmBBwMT2aw2X+O/U
W6cD9UBPjxzkxHbK0NACnMFkVt8U8RpILZ4kFWNZU7ANN3E0rTSXyUi5zDUuRefL
lsuqxAFSKNKiYe65RJSjERbFqq1M+FLatD7ms8Ax97WVIPOwvGD7swx6vVAW2kh2
pkPC1GTrbl/0bHCRZBiXfEc1PqvUbwIDAQABAoICAANowfgu5MKRm91n0ALRGtxQ
TR+YternxcNNfliqllosyqk3H1pKszbGebw1VbXOfK7alC7oJ0qjhJ0nkVN5ueW6
mP0EovtFX70f8NYlnAAqMSu2gic3FJWSI5aoRKyoIQ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+UZSXGZ3
+MhOk5PnCl7UNsYpjbvy5hG1KUJMDWs+/wwRbCCSv+PQKfYG+q94wiSsNGHCmPzD
4pk7UepX47XyPUEFFqXDbTov3muL6q3x9Co3yj0PAbX6B2WKfquXJbsi7jmDCxzQ
3xG8cvNVEwspZX75ptSaJV5PImJRRg==
-----END PRIVATE KEY-----
74 changes: 49 additions & 25 deletions roles/oneagent/tests/component/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
from pathlib import Path
from typing import Any
from scripts.util.test_data_types import DeploymentPlatform
from scripts.util.constants.common_constants import SIGNATURE_FILE_NAME

USER_KEY = "user"
PASS_KEY = "password"

BASE_DIR = Path(__file__).resolve().parent
TEST_DIR = BASE_DIR / "test_dir"
LOG_DIR = TEST_DIR / "logs"
INSTALLERS_DIR = TEST_DIR / "installers"
INSTALLERS_DEST_DIR = TEST_DIR / "installers"
INSTALLERS_RESOURCE_DIR = BASE_DIR / "resources" / "installers"
TEST_VARS = {"PYTHONPATH": "scripts/"}



class ServerWrapper(object):
def __init__(self, proc: subprocess.Popen):
self.proc = proc
Expand All @@ -30,7 +33,7 @@ def __enter__(self):

def __exit__(self, exc_type, exc_val, exc_tb):
self.proc.terminate()
save_log(self.proc.stdout, LOG_DIR / "server.log")
save_file(self.proc.stdout, LOG_DIR / "server.log")


def get_env_vars() -> dict[str, str]:
Expand All @@ -40,10 +43,9 @@ def get_env_vars() -> dict[str, str]:
return env_vars


def save_log(out, log_path: Path) -> None:
with log_path.open("w") as log:
for line in out:
log.write(line)
def save_file(data: list[str], path: Path) -> None:
with path.open("w") as log:
log.writelines(data)


def get_test_args(args: dict[str, Any]) -> list[str]:
Expand All @@ -59,7 +61,7 @@ def run_test(test: str, test_args: list[str]) -> bool:
logging.info(f"Test: {test_name}")
proc = subprocess.run(["pytest", test] + test_args, env=get_env_vars(), encoding="utf-8",
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
save_log(proc.stdout, LOG_DIR / f"{test_name}.log")
save_file(proc.stdout, LOG_DIR / f"{test_name}.log")
success = proc.returncode == 0
logging.info("PASSED" if success else "FAILED")
return success
Expand Down Expand Up @@ -95,46 +97,68 @@ def replace_tag(source: list[str], old: str, new: str) -> list[str]:
return [line.replace(old, new) for line in source]


def prepare_installers() -> None:
logging.info("Preparing installers...")
def sign_installer(installer: list[str]) -> list[str]:
cmd = ["openssl", "cms", "-sign",
"-signer", f"{INSTALLERS_RESOURCE_DIR / SIGNATURE_FILE_NAME}",
"-inkey", f"{INSTALLERS_RESOURCE_DIR / "private.key"}"]

oneagentctl_bin_name = "oneagentctl.sh"
uninstall_script_name = "uninstall.sh"
installer_partial_name = "Dynatrace-OneAgent-Linux"
proc = subprocess.run(cmd, input=f"{''.join(installer)}", encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if proc.returncode != 0:
logging.error(f"Failed to sign installer: {proc.stdout}")
sys.exit(1)

version_tag = "##VERSION##"
uninstall_code_tag = "##UNINSTALL_CODE##"
oneagentctl_code_tag = "##ONEAGENTCTL_CODE##"
signed_installer = proc.stdout.splitlines()
delimiter = next(l for l in signed_installer if l.startswith("----"))
index = signed_installer.index(delimiter)
signed_installer = signed_installer[index + 1:]

resource_dir = BASE_DIR / "resources" / "installers"
custom_delimiter = "----SIGNED_INSTALLER"
return [ f"{l}\n" if not l.startswith(delimiter) else f"{l.replace(delimiter, custom_delimiter)}\n" for l in signed_installer]

uninstall_template = get_file_content(resource_dir / uninstall_script_name)

def prepare_installers() -> None:
logging.info("Preparing installers...")

uninstall_template = get_file_content(INSTALLERS_RESOURCE_DIR / "uninstall.sh")
uninstall_code = replace_tag(uninstall_template, "$", r"\$")

oneagentctl_template = get_file_content(resource_dir / oneagentctl_bin_name)
oneagentctl_template = get_file_content(INSTALLERS_RESOURCE_DIR / "oneagentctl.sh")
oneagentctl_code = replace_tag(oneagentctl_template, "$", r"\$")

installer_template = get_file_content(resource_dir / f"{installer_partial_name}.sh")
installer_template = replace_tag(installer_template, uninstall_code_tag, "".join(uninstall_code))
installer_template = replace_tag(installer_template, oneagentctl_code_tag, "".join(oneagentctl_code))
installer_partial_name = "Dynatrace-OneAgent-Linux"
installer_template = get_file_content(INSTALLERS_RESOURCE_DIR / f"{installer_partial_name}.sh")
installer_template = replace_tag(installer_template, "##UNINSTALL_CODE##", "".join(uninstall_code))
installer_template = replace_tag(installer_template, "##ONEAGENTCTL_CODE##", "".join(oneagentctl_code))

timestamp = '{:%Y%m%d-%H%M%S}'.format(datetime.now())
# Minimal supported version is 1.199
for version in ["1.199.0", "1.300.0"]:
full_version = f"{version}.{timestamp}"
installer_code = replace_tag(installer_template, version_tag, full_version)
with open(INSTALLERS_DIR / f"{installer_partial_name}-{full_version}.sh", "w") as f:
f.writelines(installer_code)
installer_code = replace_tag(installer_template, "##VERSION##", full_version)
installer_code = sign_installer(installer_code)

save_file(installer_code, INSTALLERS_DEST_DIR / f"{installer_partial_name}-{full_version}.sh")


def assign_localhost_to_ca_provider() -> None:
with open("/etc/hosts", "a+") as f:
if any(SIGNATURE_FILE_NAME in line for line in f.read()):
return
f.write("\n# For orchestration tests purposes\n")
f.write(f"127.0.0.1\t{SIGNATURE_FILE_NAME}\n")


def prepare_environment() -> None:
logging.basicConfig(
format="%(asctime)s [server] %(levelname)s: %(message)s", datefmt="%H:%M:%S", level=logging.INFO
)
shutil.rmtree(TEST_DIR, ignore_errors=True)
os.makedirs(INSTALLERS_DIR, exist_ok=True)
os.makedirs(INSTALLERS_DEST_DIR, exist_ok=True)
os.makedirs(LOG_DIR, exist_ok=True)
shutil.copyfile(INSTALLERS_RESOURCE_DIR / SIGNATURE_FILE_NAME, INSTALLERS_DEST_DIR / SIGNATURE_FILE_NAME)

prepare_installers()
assign_localhost_to_ca_provider()


def parse_args() -> dict[str, Any]:
Expand Down
10 changes: 9 additions & 1 deletion roles/oneagent/tests/component/scripts/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from flask import Blueprint, Flask, request, send_file

from util.common_utils import get_installers
from util.constants.common_constants import HOST_SERVER_PORT
from util.constants.common_constants import HOST_SERVER_PORT, INSTALLERS_DIRECTORY, SIGNATURE_FILE_NAME

APPLICATION_ROOT = "/api/v1/deployment/installer/agent"

Expand All @@ -30,6 +30,14 @@ def get_installer(system: str, arch: str, version: str) -> TransferResult:
return msg, HTTPStatus.NOT_FOUND


@bp.route(f"/{SIGNATURE_FILE_NAME}")
def get_ca_certificate() -> TransferResult:
cert_file = INSTALLERS_DIRECTORY / SIGNATURE_FILE_NAME
if not cert_file.exists():
return f"{cert_file} not found", HTTPStatus.NOT_FOUND
return send_file(cert_file)


@bp.route("/<system>/default/latest")
def get_latest_agent(system) -> TransferResult:
return get_installer(system, request.args["arch"], "latest")
Expand Down
19 changes: 12 additions & 7 deletions roles/oneagent/tests/component/scripts/technology/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
from typing import Any

from technology.constants import (
PLAYBOOK_TEMPLATE_FILE_NAME,
HOSTS_TEMPLATE_FILE_NAME,
ANSIBLE_USER_KEY,
ANSIBLE_CONNECTION_KEY,
ANSIBLE_PASS_KEY,
ANSIBLE_RESOURCE_DIR,
COLLECTION_DIR,
ANSIBLE_USER_KEY,
COLLECTION_NAME,
PLAYBOOK_FILE,
INVENTORY_FILE,
CREDENTIALS_FILE_NAME,
ANSIBLE_PASS_KEY,
HOSTS_TEMPLATE_FILE_NAME,
INSTALLED_COLLECTIONS_DIR,
INVENTORY_FILE,
PLAYBOOK_FILE,
PLAYBOOK_TEMPLATE_FILE_NAME,
)
from technology.deployment_config import DeploymentConfig
from util.common_utils import read_yaml_file, write_yaml_file
from util.constants.common_constants import TEST_DIRECTORY, INSTALLERS_DIRECTORY
from util.test_data_types import DeploymentPlatform, PlatformCollection


def _prepare_collection() -> None:
shutil.rmtree(TEST_DIRECTORY / "collections", ignore_errors=True)
shutil.copytree(INSTALLED_COLLECTIONS_DIR, TEST_DIRECTORY / "collections")

def _prepare_playbook_file() -> None:
shutil.copy(
str(ANSIBLE_RESOURCE_DIR / PLAYBOOK_TEMPLATE_FILE_NAME), str(TEST_DIRECTORY / PLAYBOOK_TEMPLATE_FILE_NAME)
Expand Down Expand Up @@ -80,6 +84,7 @@ def prepare_test_environment(self) -> None:
_prepare_playbook_file()
_prepare_inventory_file(self.user, self.platforms)
_prepare_credentials_file(self.user, self.password)
_prepare_collection()

def set_common_parameter(self, key: str, value: Any) -> None:
data = read_yaml_file(PLAYBOOK_FILE)
Expand Down
Loading

0 comments on commit af05e0b

Please sign in to comment.