Passwords Ansible or mas-cli would misread are caught
- 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 <noreply@anthropic.com>
This commit is contained in:
1 parent
336b52bc66
commit
ec1f489385
4 files changed
+26
-4
No files matched your search
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user