Compare commits
No commits in common. "e8cef9b66e76958b17ec8f1770d39bfccca1688e" and "b55602ce23936ffa2988e1c8f2540cf2d26da47c" have entirely different histories.
e8cef9b66e
...
b55602ce23
|
|
@ -2,7 +2,6 @@ package openbao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -46,8 +45,6 @@ var decryptRecovery = func(identityPath, bundlePath string) ([]byte, error) {
|
||||||
|
|
||||||
var openBaoStatus = getStatus
|
var openBaoStatus = getStatus
|
||||||
|
|
||||||
var commandTimeout = time.Minute
|
|
||||||
|
|
||||||
func EnsureRecoveryIdentity(identityPath string) (string, error) {
|
func EnsureRecoveryIdentity(identityPath string) (string, error) {
|
||||||
if _, err := os.Stat(identityPath); os.IsNotExist(err) {
|
if _, err := os.Stat(identityPath); os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll(filepath.Dir(identityPath), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(identityPath), 0700); err != nil {
|
||||||
|
|
@ -254,7 +251,7 @@ func waitForPod(kubeconfig string) error {
|
||||||
|
|
||||||
func getStatus(kubeconfig string) (status, error) {
|
func getStatus(kubeconfig string) (status, error) {
|
||||||
command := []string{"--kubeconfig", kubeconfig, "-n", "openbao", "exec", "openbao-0", "--", "bao", "status", "-format=json"}
|
command := []string{"--kubeconfig", kubeconfig, "-n", "openbao", "exec", "openbao-0", "--", "bao", "status", "-format=json"}
|
||||||
output, err := commandOutput(nil, "kubectl", command...)
|
output, err := exec.Command("kubectl", command...).Output()
|
||||||
if err != nil && !json.Valid(output) {
|
if err != nil && !json.Valid(output) {
|
||||||
return status{}, fmt.Errorf("get OpenBao status: %w", err)
|
return status{}, fmt.Errorf("get OpenBao status: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -414,27 +411,17 @@ func encryptRecovery(recipient, bundlePath string, plaintext []byte) error {
|
||||||
|
|
||||||
var execInPod = func(kubeconfig string, input []byte, args ...string) ([]byte, error) {
|
var execInPod = func(kubeconfig string, input []byte, args ...string) ([]byte, error) {
|
||||||
command := append([]string{"--kubeconfig", kubeconfig, "-n", "openbao", "exec", "-i", "openbao-0", "--"}, args...)
|
command := append([]string{"--kubeconfig", kubeconfig, "-n", "openbao", "exec", "-i", "openbao-0", "--"}, args...)
|
||||||
return commandOutput(input, "kubectl", command...)
|
cmd := exec.Command("kubectl", command...)
|
||||||
|
cmd.Stdin = bytes.NewReader(input)
|
||||||
|
return cmd.CombinedOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
var execInUnsealController = func(kubeconfig, script string) ([]byte, error) {
|
var execInUnsealController = func(kubeconfig, script string) ([]byte, error) {
|
||||||
command := []string{"--kubeconfig", kubeconfig, "-n", "openbao", "exec", "deployment/openbao-unseal", "--", "sh", "-ec", script}
|
command := []string{"--kubeconfig", kubeconfig, "-n", "openbao", "exec", "deployment/openbao-unseal", "--", "sh", "-ec", script}
|
||||||
return commandOutput(nil, "kubectl", command...)
|
return exec.Command("kubectl", command...).CombinedOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
var kubectlOutput = func(kubeconfig string, args ...string) ([]byte, error) {
|
var kubectlOutput = func(kubeconfig string, args ...string) ([]byte, error) {
|
||||||
command := append([]string{"--kubeconfig", kubeconfig}, args...)
|
command := append([]string{"--kubeconfig", kubeconfig}, args...)
|
||||||
return commandOutput(nil, "kubectl", command...)
|
return exec.Command("kubectl", command...).Output()
|
||||||
}
|
|
||||||
|
|
||||||
func commandOutput(input []byte, name string, args ...string) ([]byte, error) {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), commandTimeout)
|
|
||||||
defer cancel()
|
|
||||||
cmd := exec.CommandContext(ctx, name, args...)
|
|
||||||
cmd.Stdin = bytes.NewReader(input)
|
|
||||||
output, err := cmd.CombinedOutput()
|
|
||||||
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
|
|
||||||
return output, fmt.Errorf("%s timed out after %s", name, commandTimeout)
|
|
||||||
}
|
|
||||||
return output, err
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue