From ec1f48938534ee6563a07f74c676d3377ba01565 Mon Sep 17 00:00:00 2001 From: Narrator Date: Thu, 29 Oct 2026 19:33:38 +0100 Subject: [PATCH] Passwords Ansible or mas-cli would misread are caught MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ansible runs every value through Jinja, so an admin or sudo password with "{{" or "{%" failed the deploy, and one with "{#…#}" was quietly shortened, creating the admin with a password other than the one saved. Missing() now names them before the deploy starts. - mas-cli read a new password starting with "-" as an option. The password goes as --password=… and the user name after "--". Co-Authored-By: Claude Opus 5.5 --- internal/config/config.go | 7 +++++++ internal/config/tuning_test.go | 14 ++++++++++++++ internal/deploy/users_mas.go | 5 +++-- internal/deploy/users_mas_test.go | 4 ++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 301f3a6..d21e7d0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -331,6 +331,13 @@ func (c *Config) Missing() []string { if c.Target.Mode == "ssh" && c.Target.Host == "" { out = append(out, "Server: SSH host") } + // Ansible runs every value through Jinja: "{{" or "{%" fails the + // deploy, and "{#…#}" quietly drops part of the password. + for _, p := range [][2]string{{"Server: sudo password", c.Target.BecomePass}, {"Admin: password", c.AdminPassword}} { + if strings.Contains(p[1], "{{") || strings.Contains(p[1], "{%") || strings.Contains(p[1], "{#") { + out = append(out, p[0]+" can't contain {{, {% or {#") + } + } if c.SSL.Mode == "custom" && (c.SSL.CertPath == "" || c.SSL.KeyPath == "") { out = append(out, "Server: certificate and key paths") } diff --git a/internal/config/tuning_test.go b/internal/config/tuning_test.go index 4e9bb6f..6a2b53b 100644 --- a/internal/config/tuning_test.go +++ b/internal/config/tuning_test.go @@ -3,6 +3,7 @@ package config import ( "os" "path/filepath" + "slices" "strings" "testing" @@ -271,3 +272,16 @@ func TestCloneSharesNothing(t *testing.T) { t.Errorf("clone shares state with the original: %+v", c) } } + +func TestMissingTemplatePasswords(t *testing.T) { + c := Default() + c.Domain = "example.org" + c.AdminPassword = "a{#b#}c" + if !slices.ContainsFunc(c.Missing(), func(s string) bool { return strings.HasPrefix(s, "Admin: password") }) { + t.Errorf("a password Jinja would change passed: %v", c.Missing()) + } + c.AdminPassword = "plain{x}" + if slices.ContainsFunc(c.Missing(), func(s string) bool { return strings.HasPrefix(s, "Admin: password") }) { + t.Errorf("a plain password was refused") + } +} diff --git a/internal/deploy/users_mas.go b/internal/deploy/users_mas.go index 55a65e7..263dcb9 100644 --- a/internal/deploy/users_mas.go +++ b/internal/deploy/users_mas.go @@ -140,7 +140,8 @@ func masUpdate(ctx context.Context, c *config.Config, userID string, body map[st _, err := masRun(ctx, c, false, "unlock-user", "--reactivate", user) return err case body["logout_devices"] != nil: - if _, err := masRun(ctx, c, true, "set-password", "--ignore-complexity", user, pw); err != nil { + // "--" and "=": a password starting with "-" isn't an option. + if _, err := masRun(ctx, c, true, "set-password", "--ignore-complexity", "--", user, pw); err != nil { return err } _, err := masRun(ctx, c, false, "kill-sessions", user) @@ -150,7 +151,7 @@ func masUpdate(ctx context.Context, c *config.Config, userID string, body map[st if admin { flag = "--admin" } - _, err := masRun(ctx, c, true, "register-user", "--yes", "--ignore-password-complexity", "--password", pw, flag, user) + _, err := masRun(ctx, c, true, "register-user", "--yes", "--ignore-password-complexity", "--password="+pw, flag, "--", user) return err case setAdmin: cmd := "demote-admin" diff --git a/internal/deploy/users_mas_test.go b/internal/deploy/users_mas_test.go index b5fedf5..10e4977 100644 --- a/internal/deploy/users_mas_test.go +++ b/internal/deploy/users_mas_test.go @@ -45,8 +45,8 @@ func TestMASUpdate(t *testing.T) { {map[string]any{"deactivated": false}, [][]string{{"unlock-user", "--reactivate", "bob"}}, false}, {map[string]any{"admin": true}, [][]string{{"promote-admin", "bob"}}, false}, {map[string]any{"admin": false}, [][]string{{"demote-admin", "bob"}}, false}, - {map[string]any{"password": "pw", "logout_devices": true}, [][]string{{"set-password", "--ignore-complexity", "bob", "pw"}, {"kill-sessions", "bob"}}, true}, - {map[string]any{"password": "pw", "admin": true}, [][]string{{"register-user", "--yes", "--ignore-password-complexity", "--password", "pw", "--admin", "bob"}}, true}, + {map[string]any{"password": "pw", "logout_devices": true}, [][]string{{"set-password", "--ignore-complexity", "--", "bob", "pw"}, {"kill-sessions", "bob"}}, true}, + {map[string]any{"password": "pw", "admin": true}, [][]string{{"register-user", "--yes", "--ignore-password-complexity", "--password=pw", "--admin", "--", "bob"}}, true}, } { calls := fakeMAS(t, "") if err := UpdateUser(context.Background(), masConfig(), &AdminLogin{}, "@bob:example.org", tc.body); err != nil {