@@ -4,20 +4,22 @@ import (
44 "bufio"
55 "bytes"
66 "errors"
7- "filippo.io/age/plugin"
87 "fmt"
98 "io"
109 "os"
10+ "os/exec"
1111 "path/filepath"
1212 "runtime"
1313 "strings"
1414
1515 "filippo.io/age"
1616 "filippo.io/age/agessh"
1717 "filippo.io/age/armor"
18+ "filippo.io/age/plugin"
1819 "github.com/sirupsen/logrus"
1920
2021 "github.com/getsops/sops/v3/logging"
22+ "github.com/kballard/go-shellquote"
2123)
2224
2325const (
@@ -27,6 +29,9 @@ const (
2729 // SopsAgeKeyFileEnv can be set as an environment variable pointing to an
2830 // age keys file.
2931 SopsAgeKeyFileEnv = "SOPS_AGE_KEY_FILE"
32+ // SopsAgeKeyCmdEnv can be set as an environment variable with a command
33+ // to execute that returns the age keys.
34+ SopsAgeKeyCmdEnv = "SOPS_AGE_KEY_CMD"
3035 // SopsAgeSshPrivateKeyFileEnv can be set as an environment variable pointing to
3136 // a private SSH key file.
3237 SopsAgeSshPrivateKeyFileEnv = "SOPS_AGE_SSH_PRIVATE_KEY_FILE"
@@ -310,6 +315,18 @@ func (key *MasterKey) loadIdentities() (ParsedIdentities, error) {
310315 readers [SopsAgeKeyFileEnv ] = f
311316 }
312317
318+ if ageKeyCmd , ok := os .LookupEnv (SopsAgeKeyCmdEnv ); ok {
319+ args , err := shellquote .Split (ageKeyCmd )
320+ if err != nil {
321+ return nil , fmt .Errorf ("failed to parse command %s: %w" , ageKeyCmd , err )
322+ }
323+ out , err := exec .Command (args [0 ], args [1 :]... ).Output ()
324+ if err != nil {
325+ return nil , fmt .Errorf ("failed to execute command %s: %w" , ageKeyCmd , err )
326+ }
327+ readers [SopsAgeKeyCmdEnv ] = bytes .NewReader (out )
328+ }
329+
313330 userConfigDir , err := getUserConfigDir ()
314331 if err != nil && len (readers ) == 0 && len (identities ) == 0 {
315332 return nil , fmt .Errorf ("user config directory could not be determined: %w" , err )
0 commit comments