-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add provider ca support for jwt file base auth
Adds support for a jwt token in a file. Simply reads the file and sends the read in jwt along to the vault login. It also supports a legacy mode with the jwt string being passed directly. In which case the path is made optional.
- Loading branch information
Showing
5 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
ca: support Vault agent auto-auth config for Vault CA provider using JWT authentication. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ca | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/hashicorp/consul/agent/structs" | ||
) | ||
|
||
func NewJwtAuthClient(authMethod *structs.VaultAuthMethod) (*VaultAuthClient, error) { | ||
params := authMethod.Params | ||
|
||
role, ok := params["role"].(string) | ||
if !ok || strings.TrimSpace(role) == "" { | ||
return nil, fmt.Errorf("missing 'role' value") | ||
} | ||
|
||
authClient := NewVaultAPIAuthClient(authMethod, "") | ||
if legacyCheck(params, "jwt") { | ||
return authClient, nil | ||
} | ||
|
||
// The path is required for the auto-auth config, but this auth provider | ||
// seems to be used for jwt based auth by directly passing the jwt token. | ||
// So we only require the token file path if the token string isn't | ||
// present. | ||
tokenPath, ok := params["path"].(string) | ||
if !ok || strings.TrimSpace(tokenPath) == "" { | ||
return nil, fmt.Errorf("missing 'path' value") | ||
} | ||
authClient.LoginDataGen = JwtLoginDataGen | ||
return authClient, nil | ||
} | ||
|
||
func JwtLoginDataGen(authMethod *structs.VaultAuthMethod) (map[string]any, error) { | ||
params := authMethod.Params | ||
role := params["role"].(string) | ||
|
||
tokenPath := params["path"].(string) | ||
rawToken, err := os.ReadFile(tokenPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return map[string]any{ | ||
"role": role, | ||
"jwt": strings.TrimSpace(string(rawToken)), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters