Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions internal/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
//
Expand Down
17 changes: 14 additions & 3 deletions internal/compose/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand All @@ -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
Expand Down
17 changes: 13 additions & 4 deletions internal/compose/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions internal/compose/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 4 additions & 3 deletions internal/compose/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/compose/ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down