Skip to content

Commit

Permalink
Merge pull request #6 from connectedcars/auth-wrapper-quiet
Browse files Browse the repository at this point in the history
auth-wrapper: add AUTH_WRAPPER_QUIET env support
  • Loading branch information
Viterkim authored Jun 23, 2022
2 parents 433da82 + f3a70b2 commit 5ea7294
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ To configure a SSH server to trust the signing server CA for a specific user:
cert-authority,principals="user1,serverType:gw" ssh-rsa AAAA...(copy from output of signing server) ca key
```


## Use Examples
```
auth-wrapper ssh user@ip
auth-wrapper ssh user@ip 'echo hello'
```


## Options

### Arguments
Expand Down
14 changes: 10 additions & 4 deletions cmd/authwrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,22 @@ func main() {
if err != nil {
log.Fatalf("Failed to list sshAgent keys: %v", err)
}
fmt.Fprintf(os.Stderr, "Loaded keys:\n")
for _, key := range keyList {
fmt.Fprintf(os.Stderr, "%s %s\n", strings.TrimSuffix(string(ssh.MarshalAuthorizedKey(key)), "\n"), key.Comment)

if config.AuthWrapperQuiet == false {
fmt.Fprintf(os.Stderr, "Loaded keys:\n")

for _, key := range keyList {
fmt.Fprintf(os.Stderr, "%s %s\n", strings.TrimSuffix(string(ssh.MarshalAuthorizedKey(key)), "\n"), key.Comment)
}
}

exitCode, err := runCommandWithSSHAgent(agent, config.Command, config.Args)
if err != nil {
log.Fatalf("runCommandWithSSHAgent: %v", err)
}

fmt.Fprintf(os.Stderr, "exit code: %v\n", exitCode)
if config.AuthWrapperQuiet == false {
fmt.Fprintf(os.Stderr, "exit code: %v\n", exitCode)
}
os.Exit(exitCode)
}
6 changes: 6 additions & 0 deletions cmd/authwrapper/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Config struct {
SSHCaAuthorizedKeysPath string
SSHSigningServerAddress string
SSHAgentSocket string
AuthWrapperQuiet bool
}

var principalsFlag = flag.String("principals", "", "requested principals")
Expand All @@ -38,6 +39,9 @@ func parseEnvironment() (*Config, error) {
flag.Parse()
args := flag.Args()

// TODO: Do a proper check here (AUTH_WRAPPER_QUIET=false still is true)
_, isAuthWrapperQuiet := os.LookupEnv("AUTH_WRAPPER_QUIET")

config := &Config{
Command: os.Getenv("WRAP_COMMAND"),
Args: args,
Expand All @@ -51,6 +55,7 @@ func parseEnvironment() (*Config, error) {
SSHCaAuthorizedKeysPath: os.Getenv("SSH_CA_AUTHORIZED_KEYS_PATH"),
SSHSigningServerAddress: os.Getenv("SSH_SIGNING_SERVER_LISTEN_ADDRESS"),
SSHAgentSocket: os.Getenv("SSH_AUTH_SOCK"),
AuthWrapperQuiet: isAuthWrapperQuiet,
}
os.Unsetenv("WRAP_COMMAND")
os.Unsetenv("SSH_KEY_PATH")
Expand All @@ -60,6 +65,7 @@ func parseEnvironment() (*Config, error) {
os.Unsetenv("SSH_CA_KEY_PASSWORD")
os.Unsetenv("SSH_SIGNING_SERVER_LISTEN_ADDRESS")
os.Unsetenv("SSH_AUTH_SOCK")
os.Unsetenv("AUTH_WRAPPER_QUIET")

if *principalsFlag != "" {
config.RequestedPrincipals = strings.Split(*principalsFlag, ",")
Expand Down
1 change: 1 addition & 0 deletions cmd/authwrapper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func runCommandWithSSHAgent(agent agent.ExtendedAgent, command string, args []st
if err != nil {
return 255, fmt.Errorf("Failed to start ssh agent server: %v", err)
}

os.Setenv("SSH_AUTH_SOCK", sshAuthSock)

// Do string replacement for SSH_AUTH_SOCK
Expand Down

0 comments on commit 5ea7294

Please sign in to comment.