Skip to content

Commit a241b77

Browse files
committed
Add "--value-file" option to "sops set [...]"
This allows running "sops set [...]" without leaking secrets in process listings. To read secrets from stdin, use "/dev/stdin" as the file path. Fixes #729
1 parent 518daad commit a241b77

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cmd/sops/main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,10 @@ func main() {
13851385
Name: "output-type",
13861386
Usage: "currently json, yaml, dotenv and binary are supported. If not set, sops will use the input file's extension to determine the output format",
13871387
},
1388+
cli.BoolTFlag{
1389+
Name: "value-file",
1390+
Usage: "treat 'value' as a file to read the actual value from (avoids leaking secrets in process listings)",
1391+
},
13881392
cli.IntFlag{
13891393
Name: "shamir-secret-sharing-threshold",
13901394
Usage: "the number of master keys required to retrieve the data key with shamir",
@@ -1430,7 +1434,18 @@ func main() {
14301434
return common.NewExitError("Invalid set index format", codes.ErrorInvalidSetFormat)
14311435
}
14321436

1433-
value, err := jsonValueToTreeInsertableValue(c.Args()[2])
1437+
var data string
1438+
if c.Bool("value-file") {
1439+
filename := c.Args()[2]
1440+
content, err := os.ReadFile(filename)
1441+
if err != nil {
1442+
return toExitError(err)
1443+
}
1444+
data = string(content)
1445+
} else {
1446+
data = c.Args()[2]
1447+
}
1448+
value, err := jsonValueToTreeInsertableValue(data)
14341449
if err != nil {
14351450
return toExitError(err)
14361451
}

0 commit comments

Comments
 (0)