From 07a6e0c7403a056a388df0225707c89e63dd805c Mon Sep 17 00:00:00 2001 From: e-carlin Date: Wed, 31 Jan 2024 21:58:23 +0000 Subject: [PATCH] Fix #435: various fixes for vm_devbox - make sure username is usable as a hostname - install run_d (/srv/vm_devbox_) --- rsconf/component/vm_devbox.py | 8 ++++++++ rsconf/package_data/vm_devbox/start.sh.jinja | 2 +- tests/pkcli/build_data/1.in/db/000.yml | 4 ++-- .../v9.radia.run/vm_devbox/{user_1 => user-1}/host_key | 0 .../vm_devbox/{user_1 => user-1}/host_key.pub | 0 .../v9.radia.run/vm_devbox/{user_1 => user-1}/identity | 0 .../vm_devbox/{user_1 => user-1}/identity.pub | 0 .../build_data/1.out/srv/host/v9.radia.run/000.sh | 2 +- .../srv/{vm_devbox_user_1 => vm_devbox_user-1}/start | 6 +++--- .../1.out/srv/host/v9.radia.run/vm_devbox_user-1.sh | 10 ++++++++++ .../1.out/srv/host/v9.radia.run/vm_devbox_user_1.sh | 8 -------- 11 files changed, 25 insertions(+), 15 deletions(-) rename tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/{user_1 => user-1}/host_key (100%) rename tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/{user_1 => user-1}/host_key.pub (100%) rename tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/{user_1 => user-1}/identity (100%) rename tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/{user_1 => user-1}/identity.pub (100%) rename tests/pkcli/build_data/1.out/srv/host/v9.radia.run/srv/{vm_devbox_user_1 => vm_devbox_user-1}/start (96%) create mode 100644 tests/pkcli/build_data/1.out/srv/host/v9.radia.run/vm_devbox_user-1.sh delete mode 100644 tests/pkcli/build_data/1.out/srv/host/v9.radia.run/vm_devbox_user_1.sh diff --git a/rsconf/component/vm_devbox.py b/rsconf/component/vm_devbox.py index 1626e78d..d26cafcd 100644 --- a/rsconf/component/vm_devbox.py +++ b/rsconf/component/vm_devbox.py @@ -9,12 +9,18 @@ from pykern.pkdebug import pkdp from rsconf import component from rsconf import systemd +import re + +# Allowable pattern enforced by vagrant +_VM_HOSTNAME_RE = "[a-z0-9][a-z0-9.-]*" class T(component.T): def internal_build_compile(self): def _create_user_instances(): for u in self.hdb.vm_devbox.users: + if not re.match(_VM_HOSTNAME_RE, u): + raise AssertionError(f"usernmae={u} must match /{_VM_HOSTNAME_RE}/") self.buildt.build_component( T( f"{self.module_name}_{u}", @@ -46,6 +52,8 @@ def internal_build_write(self): return jc = self.j2_ctx z = jc[self.name] + self.install_access(mode="700", owner=z.run_u) + self.install_directory(z.run_d) self.install_access(mode="500", owner=z.run_u) self.install_resource("vm_devbox/start.sh", host_path=z.start_f) self.install_access(mode="444", owner=jc.rsconf_db.root_u) diff --git a/rsconf/package_data/vm_devbox/start.sh.jinja b/rsconf/package_data/vm_devbox/start.sh.jinja index 331d5904..27547752 100644 --- a/rsconf/package_data/vm_devbox/start.sh.jinja +++ b/rsconf/package_data/vm_devbox/start.sh.jinja @@ -1,7 +1,7 @@ #!/bin/bash set -eou pipefail -vm_devbox_first_start() { +vm_devbox_create_vm() { if [[ -e Vagrantfile ]]; then return fi diff --git a/tests/pkcli/build_data/1.in/db/000.yml b/tests/pkcli/build_data/1.in/db/000.yml index 0d9c8aec..2f7267ba 100644 --- a/tests/pkcli/build_data/1.in/db/000.yml +++ b/tests/pkcli/build_data/1.in/db/000.yml @@ -227,7 +227,7 @@ default: timezone: America/Phoenix vm_devbox_users: spec: - user_1: + user-1: ssh_port: 11110 channel: @@ -611,7 +611,7 @@ host: vm_devbox: vm_parent_domain: radia.run users: - - user_1 + - user-1 # testing named needs build-perl-rpms.sh # - bivio_named diff --git a/tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user_1/host_key b/tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user-1/host_key similarity index 100% rename from tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user_1/host_key rename to tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user-1/host_key diff --git a/tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user_1/host_key.pub b/tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user-1/host_key.pub similarity index 100% rename from tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user_1/host_key.pub rename to tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user-1/host_key.pub diff --git a/tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user_1/identity b/tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user-1/identity similarity index 100% rename from tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user_1/identity rename to tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user-1/identity diff --git a/tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user_1/identity.pub b/tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user-1/identity.pub similarity index 100% rename from tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user_1/identity.pub rename to tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/user-1/identity.pub diff --git a/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/000.sh b/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/000.sh index d9bbfc67..a46c9c36 100644 --- a/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/000.sh +++ b/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/000.sh @@ -35,5 +35,5 @@ rsconf_require sirepo_jupyterhub rsconf_require sirepo_job_supervisor rsconf_require sirepo rsconf_require sirepo_test_http -rsconf_require vm_devbox_user_1 +rsconf_require vm_devbox_user-1 rsconf_require vm_devbox diff --git a/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/srv/vm_devbox_user_1/start b/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/srv/vm_devbox_user-1/start similarity index 96% rename from tests/pkcli/build_data/1.out/srv/host/v9.radia.run/srv/vm_devbox_user_1/start rename to tests/pkcli/build_data/1.out/srv/host/v9.radia.run/srv/vm_devbox_user-1/start index 23e2627d..3348fb8f 100644 --- a/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/srv/vm_devbox_user_1/start +++ b/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/srv/vm_devbox_user-1/start @@ -1,15 +1,15 @@ #!/bin/bash set -eou pipefail -vm_devbox_first_start() { +vm_devbox_create_vm() { if [[ -e Vagrantfile ]]; then return fi - curl 'https://radia.run' | vagrant_dev_vm_devbox=1 bash -s vagrant-sirepo-dev 'user_1.radia.run' + curl 'https://radia.run' | vagrant_dev_vm_devbox=1 bash -s vagrant-sirepo-dev 'user-1.radia.run' } vm_devbox_main() { - cd /srv/vm_devbox_user_1 + cd /srv/vm_devbox_user-1 vm_devbox_create_vm vm_devbox_set_forwarded_port vm_devbox_set_ssh_config diff --git a/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/vm_devbox_user-1.sh b/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/vm_devbox_user-1.sh new file mode 100644 index 00000000..7937bbc8 --- /dev/null +++ b/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/vm_devbox_user-1.sh @@ -0,0 +1,10 @@ +#!/bin/bash +vm_devbox_user-1_rsconf_component() { +rsconf_service_prepare 'vm_devbox_user-1' '/etc/systemd/system/vm_devbox_user-1.service' '/etc/systemd/system/vm_devbox_user-1.service.d' '/srv/vm_devbox_user-1/start' +rsconf_install_access '700' 'vagrant' 'vagrant' +rsconf_install_directory '/srv/vm_devbox_user-1' +rsconf_install_access '500' 'vagrant' 'vagrant' +rsconf_install_file '/srv/vm_devbox_user-1/start' '46de8c2ad8e5fcb3d074110e25d70136' +rsconf_install_access '444' 'root' 'root' +rsconf_install_file '/etc/systemd/system/vm_devbox_user-1.service' '1bd0318206a0d747ce7ab0247d1d6b39' +} diff --git a/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/vm_devbox_user_1.sh b/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/vm_devbox_user_1.sh deleted file mode 100644 index 50485113..00000000 --- a/tests/pkcli/build_data/1.out/srv/host/v9.radia.run/vm_devbox_user_1.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -vm_devbox_user_1_rsconf_component() { -rsconf_service_prepare 'vm_devbox_user_1' '/etc/systemd/system/vm_devbox_user_1.service' '/etc/systemd/system/vm_devbox_user_1.service.d' '/srv/vm_devbox_user_1/start' -rsconf_install_access '500' 'vagrant' 'vagrant' -rsconf_install_file '/srv/vm_devbox_user_1/start' '1129bf3bb403b2afd58c5bcd6f62d151' -rsconf_install_access '444' 'root' 'root' -rsconf_install_file '/etc/systemd/system/vm_devbox_user_1.service' '3c65a04296d9a4798a9d48c4ddeb322c' -}