Skip to content

Commit 1a6982d

Browse files
committed
feat(trustee_quadlet): add Trustee quadlet deployment
The deployment of Trustee server includes quadlet and associated configurations. Signed-off-by: Li Tian <litian@redhat.com>
1 parent 01be895 commit 1a6982d

27 files changed

Lines changed: 213 additions & 91 deletions

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Role Name
1+
# trustee_server
22

33
[![ansible-lint.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/ansible-lint.yml) [![ansible-test.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/ansible-test.yml) [![codespell.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/codespell.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/codespell.yml) [![markdownlint.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/markdownlint.yml) [![qemu-kvm-integration-tests.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/qemu-kvm-integration-tests.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/qemu-kvm-integration-tests.yml) [![shellcheck.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/shellcheck.yml) [![tft.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/tft.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/tft.yml) [![tft_citest_bad.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/tft_citest_bad.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/tft_citest_bad.yml) [![woke.yml](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/woke.yml/badge.svg)](https://github.com/linux-system-roles/trustee_attestation_server/actions/workflows/woke.yml)
4+
![trustee_server](https://github.com/linux-system-roles/trustee_server/workflows/tox/badge.svg)
45

5-
![template](https://github.com/linux-system-roles/template/workflows/tox/badge.svg)
6-
7-
A template for an ansible role that configures some GNU/Linux subsystem or
6+
A trustee_server for an ansible role that configures some GNU/Linux subsystem or
87
service. A brief description of the role goes here.
98

109
## Requirements
@@ -34,12 +33,12 @@ A description of all input variables (i.e. variables that are defined in
3433
`defaults/main.yml`) for the role should go here as these form an API of the
3534
role. Each variable should have its own section e.g.
3635

37-
### template_foo
36+
### trustee_server_foo
3837

3938
This variable is required. It is a string that lists the foo of the role.
4039
There is no default value.
4140

42-
### template_bar
41+
### trustee_server_bar
4342

4443
This variable is optional. It is a boolean that tells the role to disable bar.
4544
The default value is `true`.
@@ -53,8 +52,8 @@ the lifetime.
5352
Example of setting the variables:
5453

5554
```yaml
56-
template_foo: "oof"
57-
template_bar: false
55+
trustee_server_foo: "oof"
56+
trustee_server_bar: false
5857
```
5958
6059
## Variables Exported by the Role
@@ -63,12 +62,12 @@ This section is optional. Some roles may export variables for playbooks to
6362
use later. These are analogous to "return values" in Ansible modules. For
6463
example, if a role performs some action that will require a system reboot, but
6564
the user wants to defer the reboot, the role might set a variable like
66-
`template_reboot_needed: true` that the playbook can use to reboot at a more
65+
`trustee_server_reboot_needed: true` that the playbook can use to reboot at a more
6766
convenient time.
6867

6968
Example:
7069

71-
### template_reboot_needed
70+
### trustee_server_reboot_needed
7271

7372
Default `false` - if `true`, this means a reboot is needed to apply the changes
7473
made by the role
@@ -79,13 +78,13 @@ Including an example of how to use your role (for instance, with variables
7978
passed in as parameters) is always nice for users too:
8079

8180
```yaml
82-
- name: Manage the template subsystem
81+
- name: Manage the trustee_server subsystem
8382
hosts: all
8483
vars:
85-
template_foo: "foo foo!"
86-
template_bar: false
84+
trustee_server_foo: "foo foo!"
85+
trustee_server_bar: false
8786
roles:
88-
- linux-system-roles.template
87+
- linux-system-roles.trustee_server
8988
```
9089

9190
More examples can be provided in the [`examples/`](examples) directory. These

defaults/main.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
# Here is the right place to put the role's input variables.
44
# This file also serves as a documentation for such a variables.
55

6-
# Examples of role input variables:
7-
template_foo: foo
8-
template_bar: true
6+
# Trustee Server Components Quadlet repository configuration
7+
trustee_server_trustee: true
8+
trustee_server_quadlet_repo_url: "https://github.com/litian1992/trustee-quadlet-rhel.git"
9+
trustee_server_quadlet_repo_path: "quadlet"
10+
trustee_server_quadlet_repo_branch: "main"
11+
trustee_server_quadlet_install_dir: "/etc/containers/systemd"
12+
trustee_attestation_server_config_dir: "/etc/trustee"
13+
14+
# Secret registration service configuration
15+
trustee_server_secret_registration_service_enabled: false
16+
17+
# SSL certificate generation (used with -config trustee_server.conf)
18+
trustee_server_ssl_bits: 4096
19+
trustee_server_ssl_md: sha256
20+
trustee_server_ssl_days: 3650
21+
trustee_server_ssl_cn: trustee-server
22+
trustee_server_ssl_org: Trustee
23+
trustee_server_ssl_country: US
24+
trustee_server_ssl_cert_path: /etc/trustee/kbs/server.crt
25+
trustee_server_ssl_key_path: /etc/trustee/kbs/server.key

examples/simple.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# SPDX-License-Identifier: MIT
22
---
3-
- name: Example template role invocation
3+
- name: Deploy Trustee Server Components using Podman Quadlets from GitHub repository
44
hosts: all
55
vars:
6-
template_foo: example variable value
7-
template_bar: false
6+
trustee_server_trustee: true
7+
trustee_server_quadlet_repo_url: "https://github.com/litian1992/trustee-quadlet-rhel.git"
8+
trustee_server_quadlet_repo_path: "quadlet"
9+
trustee_server_quadlet_repo_branch: "main"
10+
trustee_server_quadlet_install_dir: "/etc/containers/systemd"
11+
trustee_server_secret_registration_service_enabled: false
812
roles:
9-
- linux-system-roles.template
13+
- linux-system-roles.trustee-server

handlers/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: MIT
22
---
3-
- name: Handler for template to restart services
3+
- name: Handler for trustee_server to restart services
44
service:
55
name: "{{ item }}"
66
state: restarted
7-
loop: "{{ __template_services }}"
7+
loop: "{{ __trustee_server_services }}"

meta/main.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# SPDX-License-Identifier: MIT
22
---
33
galaxy_info:
4-
author: John Doe <jdoe@corp.com>
5-
description: Basic template for Linux system roles
6-
company: John Doe, Inc.
4+
author: Li Tian <litian@redhat.com>
5+
description: Deploy Trustee Server Components using Podman Quadlets from GitHub repository
6+
company: Red Hat, Inc.
77
license: MIT
88
min_ansible_version: "2.9"
99
platforms:
@@ -14,13 +14,15 @@ galaxy_info:
1414
versions:
1515
- "9"
1616
galaxy_tags:
17+
- trustee
18+
- attestation
1719
- el9
1820
- el10
1921
- fedora
2022
# Support running this role in system container environments, and enable
2123
# tests. Remove if not applicable.
22-
- container
24+
# - container
2325
# Support running this role during container builds (mostly useful for
2426
# bootc), and enable tests. Remove if not applicable.
25-
- containerbuild
27+
# - containerbuild
2628
dependencies: []

plans/README-plans.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ You can run tests locally with the `tmt try` cli or remotely in Testing Farm.
4747
$ TESTING_FARM_API_TOKEN=<your_api_token> \
4848
testing-farm request --pipeline-type="tmt-multihost" \
4949
--plan-filter="tag:playbooks_parallel" \
50+
<<<<<<< HEAD
5051
--git-url "https://github.com/<my_user>/trustee_attestation_server" \
52+
=======
53+
--git-url "https://github.com/<my_user>/trustee_server" \
54+
>>>>>>> 4efcd62 (feat(trustee_quadlet): add Trustee quadlet deployment)
5155
--git-ref "<my_branch>" \
5256
--compose CentOS-Stream-9 \
5357
-e "SYSTEM_ROLES_ONLY_TESTS=tests_default.yml" \

tasks/main.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,11 @@
44
include_tasks: tasks/set_vars.yml
55

66
# Examples of some tasks:
7-
- name: Ensure required packages are installed
8-
package:
9-
name: "{{ __template_packages }}"
10-
state: present
11-
use: "{{ (__template_is_ostree | d(false)) |
12-
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
7+
- name: Deploy Trustee Server Components using Podman Quadlets
8+
include_tasks: trustee_quadlet.yml
9+
when: trustee_server_trustee | bool
1310

14-
- name: Ensure required services are enabled and started
15-
service:
16-
name: "{{ item }}"
17-
state: started
18-
enabled: true
19-
loop: "{{ __template_services }}"
11+
- name: Create Secret Registration Service
12+
include_tasks: secret_registration_service.yml
13+
when: trustee_server_secret_registration_service_enabled | bool
2014

21-
- name: Generate /etc/{{ __template_foo_config }}
22-
template:
23-
src: "{{ __template_foo_config }}.j2"
24-
dest: /etc/{{ __template_foo_config }}
25-
backup: true
26-
mode: "0400"
27-
notify: Handler for template to restart services
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: MIT
2+
---

tasks/set_vars.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
- name: Ensure ansible_facts used by role
33
setup:
4-
gather_subset: "{{ __template_required_facts_subsets }}"
5-
when: __template_required_facts |
4+
gather_subset: "{{ __trustee_server_required_facts_subsets }}"
5+
when: __trustee_server_required_facts |
66
difference(ansible_facts.keys() | list) | length > 0
77

88
- name: Determine if system is ostree and set flag
9-
when: not __template_is_ostree is defined
9+
when: not __trustee_server_is_ostree is defined
1010
block:
1111
- name: Check if system is ostree
1212
stat:
@@ -15,7 +15,7 @@
1515

1616
- name: Set flag to indicate system is ostree
1717
set_fact:
18-
__template_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
18+
__trustee_server_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
1919

2020
- name: Set platform/version specific variables
2121
include_vars: "{{ __vars_file }}"

tasks/trustee_quadlet.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# SPDX-License-Identifier: MIT
2+
---
3+
- name: Ensure required packages are installed
4+
ansible.builtin.package:
5+
name: "{{ __trustee_server_trustee_packages }}"
6+
state: present
7+
use: "{{ (__trustee_server_is_ostree | d(false)) |
8+
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
9+
10+
- name: Ensure quadlet install directory exists
11+
ansible.builtin.file:
12+
path: "{{ trustee_server_quadlet_install_dir }}"
13+
state: directory
14+
mode: "0755"
15+
16+
- name: Create a temporary directory for the quadlet repository
17+
ansible.builtin.tempfile:
18+
state: directory
19+
register: __trustee_server_quadlet_repo_dir
20+
21+
- name: Download Trustee Server quadlet files from GitHub repository
22+
ansible.builtin.git:
23+
repo: "{{ trustee_server_quadlet_repo_url }}"
24+
dest: "{{ __trustee_server_quadlet_repo_dir.path }}"
25+
version: "{{ trustee_server_quadlet_repo_branch }}"
26+
depth: 1
27+
force: true
28+
register: quadlet_repo_download
29+
30+
- name: Find Trustee Server quadlet files in repository
31+
ansible.builtin.find:
32+
paths: "{{ __trustee_server_quadlet_repo_dir.path }}/{{ trustee_server_quadlet_repo_path }}"
33+
patterns:
34+
- "*.container"
35+
- "*.volume"
36+
- "*.network"
37+
- "*.pod"
38+
recurse: false
39+
register: quadlet_files_found
40+
41+
- name: Fail if no Trustee Server quadlet files found
42+
ansible.builtin.fail:
43+
msg: "No quadlet files found in {{ trustee_server_quadlet_repo_url }}/{{ trustee_server_quadlet_repo_path }}"
44+
when: quadlet_files_found.files | length == 0
45+
46+
- name: Copy Trustee Server quadlet files to install directory
47+
ansible.builtin.copy:
48+
src: "{{ item.path }}"
49+
dest: "{{ trustee_server_quadlet_install_dir }}/{{ item.path | basename }}"
50+
mode: "0644"
51+
remote_src: true
52+
force: true
53+
loop: "{{ quadlet_files_found.files }}"
54+
register: quadlet_files_copied
55+
56+
- name: Stat repository configs directory
57+
ansible.builtin.stat:
58+
path: "{{ __trustee_server_quadlet_repo_dir.path }}/configs"
59+
register: __repo_configs_dir
60+
61+
- name: Copy Trustee Server config files to config directory
62+
ansible.builtin.copy:
63+
src: "{{ __trustee_server_quadlet_repo_dir.path }}/configs/"
64+
dest: "{{ trustee_attestation_server_config_dir }}/"
65+
mode: "0644"
66+
remote_src: true
67+
force: true
68+
when: __repo_configs_dir.stat.exists
69+
70+
- name: Generate certificates for all components
71+
ansible.builtin.shell: |
72+
# Trustee Server SSL
73+
if [ ! -f {{ trustee_attestation_server_config_dir }}/kbs/server.crt ] || [ ! -f {{ trustee_attestation_server_config_dir }}/kbs/server.key ]; then
74+
openssl req -new -x509 -nodes -sha256 -days 3550 \
75+
-subj "/CN=$(hostname -f)/O=Red Hat" \
76+
-out {{ trustee_attestation_server_config_dir }}/kbs/server.crt -keyout {{ trustee_attestation_server_config_dir }}/kbs/server.key
77+
fi
78+
# KBS authentication key pair
79+
if [ ! -f {{ trustee_attestation_server_config_dir }}/kbs/auth.key ] || [ ! -f {{ trustee_attestation_server_config_dir }}/kbs/auth.pub ]; then
80+
openssl genpkey -algorithm ed25519 -out {{ trustee_attestation_server_config_dir }}/kbs/auth.key
81+
openssl pkey -in {{ trustee_attestation_server_config_dir }}/kbs/auth.key -pubout -out {{ trustee_attestation_server_config_dir }}/kbs/auth.pub
82+
fi
83+
# Attestation Service token signer key pair
84+
if [ ! -f {{ trustee_attestation_server_config_dir }}/as/token.key ] || [ ! -f {{ trustee_attestation_server_config_dir }}/as/token.crt ]; then
85+
openssl ecparam -name prime256v1 -genkey -noout -out {{ trustee_attestation_server_config_dir }}/as/token.key
86+
openssl req -new -x509 -key {{ trustee_attestation_server_config_dir }}/as/token.key \
87+
-out {{ trustee_attestation_server_config_dir }}/as/token.crt -days 3550 \
88+
-subj "/CN=as-token-signer/O=Red Hat"
89+
mkdir -p {{ trustee_attestation_server_config_dir }}/kbs/trusted_certs
90+
cp {{ trustee_attestation_server_config_dir }}/as/token.crt {{ trustee_attestation_server_config_dir }}/kbs/trusted_certs/token0.crt
91+
fi
92+
93+
- name: Gather service facts
94+
ansible.builtin.service_facts:
95+
96+
- name: Allow port 8080 in firewall
97+
ansible.posix.firewalld:
98+
port: "8080/tcp"
99+
permanent: true
100+
immediate: true
101+
state: enabled
102+
when: ansible_facts.services['firewalld.service'].state == 'running'
103+
104+
- name: Get the installed Trustee Server pod name
105+
ansible.builtin.find:
106+
paths: "{{ trustee_server_quadlet_install_dir }}"
107+
patterns: "*.pod"
108+
register: trustee_server_pod_name
109+
110+
- name: Enable and start Trustee Server services
111+
ansible.builtin.systemd:
112+
name: "{{ trustee_server_pod_name.files[0].path | basename | regex_replace('\\.pod$', '') }}-pod.service"
113+
enabled: true
114+
state: restarted
115+
daemon_reload: true
116+
when: trustee_server_pod_name.files | length > 0
117+
failed_when: false
118+
119+
# TODO keep the server.crt and DNS names in the role variables
120+
121+
- name: Clean up temporary repository directory
122+
ansible.builtin.file:
123+
path: "{{ __trustee_server_quadlet_repo_dir.path }}"
124+
state: absent

0 commit comments

Comments
 (0)