Skip to content

Commit

Permalink
test: add service infos to onboarding tests
Browse files Browse the repository at this point in the history
Test actual service infos in onboarding tests to make sure
the onboarding client has the needed SELinux permissions.

Resolves: THEEDGE-3953

Signed-off-by: Miguel Martín <[email protected]>
  • Loading branch information
mmartinv committed Oct 7, 2024
1 parent 6221456 commit 71e304e
Showing 1 changed file with 148 additions and 5 deletions.
153 changes: 148 additions & 5 deletions test/fmf/tests/onboarding/run-onboarding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ DATABASES="${MANUFACTURER_DATABASE} ${OWNER_DATABASE} ${RENDEZVOUS_DATABASE}"

OV_STORE_DRIVER="${OV_STORE_DRIVER:-Directory}"

SERVICE_INFO_ROOT_DIR="service-info/files"

DATABASE_DRIVER="None"
[ "${OV_STORE_DRIVER}" != "Postgres" ] || DATABASE_DRIVER="postgresql"
[ "${OV_STORE_DRIVER}" != "Sqlite" ] || DATABASE_DRIVER="sqlite"
Expand All @@ -41,6 +43,69 @@ generate_fdo_certificates() {
done
}

generate_serviceinfo_files() {
SERVICE_INFO_BASEDIR="/var/lib/fdo"
SERVICE_INFO_DIR="${SERVICE_INFO_BASEDIR}/${SERVICE_INFO_ROOT_DIR}"
mkdir -p ${SERVICE_INFO_DIR}/etc/{sudoers.d,pki/ca-trust/source/anchors}
cat > "${SERVICE_INFO_DIR}/etc/hosts" <<EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
EOF
cat > "${SERVICE_INFO_DIR}/etc/sudoers.d/edge" <<EOF
edge ALL=(ALL) NOPASSWD: ALL
EOF
cat > "${SERVICE_INFO_DIR}/etc/pki/ca-trust/source/anchors/edge.crt" <<EOF
-----BEGIN CERTIFICATE-----
MIIGcjCCBFqgAwIBAgIFICIEEFwwDQYJKoZIhvcNAQEMBQAwgaMxCzAJBgNVBAYT
AlVTMRcwFQYDVQQIDA5Ob3J0aCBDYXJvbGluYTEQMA4GA1UEBw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/SMw==
-----END CERTIFICATE-----
EOF

}


generate_ssh_key() {
SSH_KEY_TMP_DIR=$(mktemp -d)
SSH_KEY_FILE="${SSH_KEY_TMP_DIR}/ssh_key"
SSH_PUB_KEY_FILE="${SSH_KEY_FILE}.pub"
ssh-keygen -q -N '' -f "${SSH_KEY_FILE}"
cat "${SSH_PUB_KEY_FILE}"
rm -rf "${SSH_KEY_TMP_DIR}"
}

setup_postgresql() {
systemctl stop postgresql.service
rm -rf /var/lib/pgsql/data
Expand Down Expand Up @@ -153,11 +218,87 @@ setup_serviceinfo() {
tee "${CONF_DIR}/serviceinfo-api-server.yml" <<EOF
---
service_info:
initial_user: null
files: null
commands: null
diskencryption_clevis: null
additional_serviceinfo: null
initial_user:
username: edge
sshkeys:
- "${SSH_PUB_KEY}"
commands:
- command: touch
args:
- /etc/command-testfile1
- command: bash
args:
- -c
- echo command-testfile1-content1 > /etc/command-testfile1
- command: bash
args:
- -c
- echo command-testfile1-content2 >> /etc/command-testfile1
- command: mkdir
args:
- /etc/commands
- command: mv
args:
- /etc/command-testfile1
- /etc/commands/
- command: bash
args:
- -c
- echo command-testfile2-content1 > /etc/commands/command-testfile2
- command: bash
args:
- -c
- echo command-testfile2-content2 >> /etc/commands/command-testfile2
- command: rm
args:
- -rf
- /etc/commands
- command: find
args:
- /etc
- /var
- -type
- f
- -exec
- touch {};
- command: mkdir
args:
- -p
- /etc/sudoers.d /var/fdo /var/lib/fdo /var/fdo-test /var/lib/fdo-test
- command: /usr/bin/sed
args:
- -e
- s/^#PasswordAuthentication yes/PasswordAuthentication no/
- /etc/ssh/sshd_config
may_fail: false
return_stdout: true
return_stderr: true
- command: systemctl
args:
- restart
- sshd
return_stdout: true
return_stderr: true
- command: systemctl
args:
- daemon-reload
return_stdout: true
return_stderr: true
files:
- path: /etc/hosts
permissions: 644
source_path: ${SERVICE_INFO_ROOT_DIR}/etc/hosts
- path: /etc/sudoers.d/edge
source_path: ${SERVICE_INFO_ROOT_DIR}/etc/sudoers.d/edge
- path: /etc/pki/ca-trust/source/anchors/redhat.crt
source_path: ${SERVICE_INFO_ROOT_DIR}/etc/pki/ca-trust/source/anchors/redhat.crt
# diskencryption_clevis:
# - disk_label: /dev/vda
# binding:
# pin: test
# config: "{}"
# reencrypt: true
# after_onboarding_reboot: true
bind: 0.0.0.0:8083
service_info_auth_token: 2IOtlXsSqfcGjnhBLZjPiHIteskzZEW3lncRzpEmgqI=
admin_auth_token: Va40bSkLcxwnfml1pmIuaWaOZG96mSMB6fu0xuzcueg=
Expand Down Expand Up @@ -190,10 +331,12 @@ onboard() {

[ "${OV_STORE_DRIVER}" != "Sqlite" ] || setup_sqlite
[ "${OV_STORE_DRIVER}" != "Postgres" ] || setup_postgresql
SSH_PUB_KEY=$(generate_ssh_key)
generate_fdo_certificates
setup_manufacturing
setup_owner
setup_rendezvous
generate_serviceinfo_files
setup_serviceinfo
systemctl restart fdo-{manufacturing,owner-onboarding,rendezvous,serviceinfo-api}-server.service
# Wait for servers to be up and running
Expand Down

0 comments on commit 71e304e

Please sign in to comment.