Skip to content

Commit db7f0df

Browse files
committed
fix(veracrypt): Insert password flags before positional arguments
VeraCrypt CLI expects: veracrypt -t -p <password> --non-interactive [Volume path] [Mount point] The provisioner was appending flags AFTER positional args, causing 'Unexpected parameter' error. Fix: Insert -p <password> --non-interactive before first positional argument (arg not starting with '-').
1 parent 5575fbe commit db7f0df

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

plugins/veracrypt/volume_password.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,23 @@ func (p volumePasswordProv) Provision(ctx context.Context, in sdk.ProvisionInput
5454
out.CommandLine = []string{}
5555
return
5656
}
57-
out.AddArgs("-p", password, "--non-interactive")
57+
args := []string{"-p", password, "--non-interactive"}
58+
if len(out.CommandLine) == 0 {
59+
out.CommandLine = args
60+
return
61+
}
62+
insertAt := len(out.CommandLine)
63+
for i, arg := range out.CommandLine {
64+
if len(arg) > 0 && arg[0] != '-' {
65+
insertAt = i
66+
break
67+
}
68+
}
69+
newCmd := make([]string, 0, len(out.CommandLine)+len(args))
70+
newCmd = append(newCmd, out.CommandLine[:insertAt]...)
71+
newCmd = append(newCmd, args...)
72+
newCmd = append(newCmd, out.CommandLine[insertAt:]...)
73+
out.CommandLine = newCmd
5874
}
5975

6076
func (p volumePasswordProv) Deprovision(ctx context.Context, in sdk.DeprovisionInput, out *sdk.DeprovisionOutput) {

plugins/veracrypt/volume_password_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ import (
1010

1111
func TestVolumePasswordProvisioner(t *testing.T) {
1212
plugintest.TestProvisioner(t, VolumePassword().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13-
"password flag injection": {
13+
"password flag inserted before positional args": {
1414
ItemFields: map[sdk.FieldName]string{
1515
fieldname.Password: "TestPassword123!",
1616
},
17+
CommandLine: []string{"-t", "--mount", "/tmp/vol", "/mnt/point"},
1718
ExpectedOutput: sdk.ProvisionOutput{
18-
CommandLine: []string{"-p", "TestPassword123!", "--non-interactive"},
19+
CommandLine: []string{"-t", "--mount", "-p", "TestPassword123!", "--non-interactive", "/tmp/vol", "/mnt/point"},
1920
},
2021
},
21-
"includes non-interactive flag": {
22+
"flags inserted before mount point": {
2223
ItemFields: map[sdk.FieldName]string{
2324
fieldname.Password: "Secret456!",
2425
},
26+
CommandLine: []string{"--dismount", "/mnt/point"},
2527
ExpectedOutput: sdk.ProvisionOutput{
26-
CommandLine: []string{"-p", "Secret456!", "--non-interactive"},
28+
CommandLine: []string{"--dismount", "-p", "Secret456!", "--non-interactive", "/mnt/point"},
2729
},
2830
},
2931
"empty password returns error": {
@@ -44,8 +46,17 @@ func TestVolumePasswordProvisioner(t *testing.T) {
4446
fieldname.Password: "VolumePass789!",
4547
"Volume": "/path/to/volume.tc",
4648
},
49+
CommandLine: []string{"-t", "--mount"},
4750
ExpectedOutput: sdk.ProvisionOutput{
48-
CommandLine: []string{"-p", "VolumePass789!", "--non-interactive"},
51+
CommandLine: []string{"-t", "--mount", "-p", "VolumePass789!", "--non-interactive"},
52+
},
53+
},
54+
"no command line uses flags as provided": {
55+
ItemFields: map[sdk.FieldName]string{
56+
fieldname.Password: "MySecret123!",
57+
},
58+
ExpectedOutput: sdk.ProvisionOutput{
59+
CommandLine: []string{"-p", "MySecret123!", "--non-interactive"},
4960
},
5061
},
5162
})

0 commit comments

Comments
 (0)