diff --git a/CHANGELOG.md b/CHANGELOG.md index b2ad5bb..98d9a97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,8 @@ - **The RTE is the Runner written in Go, on Docker and Podman**: it starts each playbook in a container of its own from `ansibleforms-rte-full`, through the engine's socket, which gives it that engine's rights on the server. An upgrade switches an existing RTE in place, under the same - name, token and runner; `data/ansible`, the SSH key and the pip libraries still reach every job. + name, token and runner; `data/ansible`, the SSH key and the pip libraries still reach every job, + and so do the vars files and uploads, read-only, at their paths in the app. ### Fixed diff --git a/internal/compose/compose.go b/internal/compose/compose.go index b2a10f5..7c29f13 100644 --- a/internal/compose/compose.go +++ b/internal/compose/compose.go @@ -493,8 +493,8 @@ const runnerCompose = `# AnsibleForms RTE Runner, written by the AnsibleForms in # It starts each job in a container of its own from RTE_IMAGE, through the engine's socket # (ENGINE_SOCKET in .env), which gives it that engine's full rights on this server. The job's # files come from the app with each job ; ./data keeps what is not acked yet (rte-spool), the -# files received (rte-files), and the ansible.cfg, roles, collections, SSH key and python -# libraries every job gets (RTE_JOB_MOUNTS). +# files received (rte-files), and the ansible.cfg, roles, collections, SSH key, python +# libraries, vars files and uploads every job gets (RTE_JOB_MOUNTS). # Inbound, it serves HTTPS (HTTPS=1 in .env) with the certificate in ./data/certificates. services: rte: @@ -528,13 +528,16 @@ services: // jobMounts is what every job gets from ./data, as the playbooks had it in the RTE's own // container before 7.9.0 : the ansible.cfg, roles and collections, the SSH key and the git -// settings, and the libraries the pip install playbook adds. +// settings, the libraries the pip install playbook adds, and the vars files and uploads +// (read-only, at their paths in the app). const jobMounts = "/app/dist/persistent/ansible/ansible.cfg:/etc/ansible/ansible.cfg," + "/app/dist/persistent/ansible/roles:/etc/ansible/roles," + "/app/dist/persistent/ansible/collections:/etc/ansible/collections," + "/app/dist/persistent/ssh:/home/node/.ssh:rw," + "/app/dist/persistent/git/.gitconfig:/home/node/.gitconfig," + - "/app/dist/persistent/python:/app/dist/persistent/python:rw" + "/app/dist/persistent/python:/app/dist/persistent/python:rw," + + "/app/dist/persistent/vars:/app/dist/persistent/vars," + + "/app/dist/persistent/uploads:/app/dist/persistent/uploads" // runnerComposeFor is a runner's compose file for a version and an instance. // diff --git a/internal/compose/engine.go b/internal/compose/engine.go index a0450d1..82d024d 100644 --- a/internal/compose/engine.go +++ b/internal/compose/engine.go @@ -95,8 +95,9 @@ func (a engineAccess) env() map[string]string { } // prepareEngine readies an installation folder for the Runner: the engine's settings in its -// .env, and data/python/lib, the folder every job gets for the libraries the pip install -// playbook adds (made here, so the engine does not make it as root). +// .env, and the folders every job gets that may not be there yet (made here, so the engine +// does not make them as root): data/python/lib for the libraries the pip install playbook +// adds, data/vars for the vars files and data/uploads for the files uploaded with the forms. // // Args: // @@ -120,9 +121,19 @@ func prepareEngine(ctx context.Context, r system.Runtime, dir string) error { if err := os.WriteFile(envPath, []byte(SetEnv(string(env), a.env())), 0o600); err != nil { return err } - return os.MkdirAll(filepath.Join(dir, "data", "python", "lib"), 0o755) + // Step: make each folder the jobs get that may be missing + for _, d := range jobDirs { + if err := os.MkdirAll(filepath.Join(dir, "data", filepath.FromSlash(d)), 0o755); err != nil { + return err + } + } + return nil } +// jobDirs are the folders under data that every job gets (RTE_JOB_MOUNTS) and that the app +// may not have made yet, by their path in the data folder. +var jobDirs = []string{"python/lib", "vars", "uploads"} + // ─── compose on Podman ──────────────────────────────────────────────────────── // // "podman compose" runs a provider of its own choice: podman-compose, or Docker's compose diff --git a/internal/compose/engine_test.go b/internal/compose/engine_test.go index d97b336..7162cc1 100644 --- a/internal/compose/engine_test.go +++ b/internal/compose/engine_test.go @@ -56,8 +56,9 @@ func TestSocketGID(t *testing.T) { } } -// TestPrepareEngine checks the .env gets the engine's settings and data/python/lib is made, and -// that a folder without a .env, or whose .env cannot be written, stops it. +// TestPrepareEngine checks the .env gets the engine's settings and the jobs' folders are made +// (data/python/lib, data/vars, data/uploads), and that a folder without a .env, whose .env +// cannot be written, or whose data folder cannot take them, stops it. func TestPrepareEngine(t *testing.T) { newHost(t) ctx := context.Background() @@ -72,8 +73,16 @@ func TestPrepareEngine(t *testing.T) { t.Errorf(".env lacks %s: %s", want, env) } } - if info, err := os.Stat(filepath.Join(dir, "data", "python", "lib")); err != nil || !info.IsDir() { - t.Error("no data/python/lib") + for _, d := range []string{"python/lib", "vars", "uploads"} { + if info, err := os.Stat(filepath.Join(dir, "data", d)); err != nil || !info.IsDir() { + t.Errorf("no data/%s", d) + } + } + blocked := t.TempDir() + _ = os.WriteFile(filepath.Join(blocked, ".env"), nil, 0o600) + _ = os.WriteFile(filepath.Join(blocked, "data"), nil, 0o644) + if err := prepareEngine(ctx, system.Docker, blocked); err == nil { + t.Error("a data folder that is a file") } if err := prepareEngine(ctx, system.Docker, t.TempDir()); err == nil { t.Error("no .env") diff --git a/internal/compose/migrate_test.go b/internal/compose/migrate_test.go index 43b6a2c..0174564 100644 --- a/internal/compose/migrate_test.go +++ b/internal/compose/migrate_test.go @@ -111,6 +111,12 @@ func TestPrepareMigrationOutbound(t *testing.T) { if !strings.Contains(compose, "written by the AnsibleForms installer") || !strings.Contains(compose, "container_name: af_rte") || !strings.Contains(compose, "ansibleforms-rte-full:7.3.0") { t.Errorf("compose file:\n%s", compose) } + // the vars files and uploads reach every job read-only, at their paths in the app + for _, m := range []string{",/app/dist/persistent/vars:/app/dist/persistent/vars,", ",/app/dist/persistent/uploads:/app/dist/persistent/uploads\n"} { + if !strings.Contains(compose, m) { + t.Errorf("RTE_JOB_MOUNTS lacks %q", m) + } + } if _, err := os.Stat(filepath.Join(st.Dir, "docker-compose.override.yml")); !os.IsNotExist(err) { t.Errorf("the old override is still read by compose") } diff --git a/internal/compose/ops.go b/internal/compose/ops.go index d5faca0..c06e90d 100644 --- a/internal/compose/ops.go +++ b/internal/compose/ops.go @@ -293,13 +293,14 @@ func Upgrade(ctx context.Context, st *state.State, to string, prep *Prep) (*Undo return undo, err } } - // from 7.9.0 the RTE is the Go Runner: the engine's socket in the .env, data/python/lib - // made and given to the containers' user (a builder starts no job and has no data folder) + // from 7.9.0 the RTE is the Go Runner: the engine's socket in the .env, the folders the + // jobs get (data/python, data/vars, data/uploads) made and given to the containers' user + // (a builder starts no job and has no data folder) if st.Role != RoleBuilder { if err := prepareEngine(ctx, system.Runtime(st.Runtime), st.Dir); err != nil { return undo, err } - if err := ownData(ctx, system.Runtime(st.Runtime), filepath.Join(st.Dir, "data", "python")); err != nil { + if err := own(ctx, system.Runtime(st.Runtime), filepath.Join(st.Dir, "data"), true, []string{"python", "vars", "uploads"}); err != nil { return undo, err } } diff --git a/internal/compose/ops_test.go b/internal/compose/ops_test.go index 3eefd5b..4d25c16 100644 --- a/internal/compose/ops_test.go +++ b/internal/compose/ops_test.go @@ -258,7 +258,7 @@ func TestUpgradeFails(t *testing.T) { socketGID = func(string) (int, error) { return 0, errors.New("no socket") } return nil }, - "own python": func(t *testing.T, h *host, st *state.State) *Prep { + "own job folders": func(t *testing.T, h *host, st *state.State) *Prep { t.Setenv("FAIL", "docker run") return nil },