-
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 auth support for kubernetes
Adds support for Kubernetes jwt/token file based auth. Only needs to read the file and save the contents as the jwt/token.
- Loading branch information
Showing
4 changed files
with
123 additions
and
13 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
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,47 @@ | ||
package ca | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/hashicorp/consul/agent/structs" | ||
) | ||
|
||
func NewK8sAuthClient(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") | ||
} | ||
// don't check for `token_path` as it is optional | ||
|
||
authClient := NewVaultAPIAuthClient(authMethod, "") | ||
// Note the `jwt` can be passed directly in the authMethod as a Param value | ||
// is a freeform map in the config where they could hardcode it. | ||
if legacyCheck(params, "jwt") { | ||
return authClient, nil | ||
} | ||
|
||
authClient.LoginDataGen = K8sLoginDataGen | ||
return authClient, nil | ||
} | ||
|
||
func K8sLoginDataGen(authMethod *structs.VaultAuthMethod) (map[string]any, error) { | ||
params := authMethod.Params | ||
role := params["role"].(string) | ||
|
||
// read token from file on path | ||
tokenPath, ok := params["token_path"].(string) | ||
if !ok || strings.TrimSpace(tokenPath) == "" { | ||
tokenPath = defaultK8SServiceAccountTokenPath | ||
} | ||
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