diff --git a/agent-inject/agent/agent.go b/agent-inject/agent/agent.go index f523c247..d5b85be5 100644 --- a/agent-inject/agent/agent.go +++ b/agent-inject/agent/agent.go @@ -190,6 +190,9 @@ type Vault struct { // LogLevel sets the Vault Agent log level. Defaults to info. LogLevel string + // LogFormat sets the Vault Agent log format. Defaults to standard. + LogFormat string + // Namespace is the Vault namespace to prepend to secret paths. Namespace string @@ -249,6 +252,7 @@ func New(pod *corev1.Pod, patches []*jsonpatch.JsonPatchOperation) (*Agent, erro ClientMaxRetries: pod.Annotations[AnnotationVaultClientMaxRetries], ClientTimeout: pod.Annotations[AnnotationVaultClientTimeout], LogLevel: pod.Annotations[AnnotationVaultLogLevel], + LogFormat: pod.Annotations[AnnotationVaultLogFormat], Namespace: pod.Annotations[AnnotationVaultNamespace], Role: pod.Annotations[AnnotationVaultRole], TLSSecret: pod.Annotations[AnnotationVaultTLSSecret], diff --git a/agent-inject/agent/annotations.go b/agent-inject/agent/annotations.go index 238f79c6..fc153c71 100644 --- a/agent-inject/agent/annotations.go +++ b/agent-inject/agent/annotations.go @@ -165,6 +165,9 @@ const ( // AnnotationVaultLogLevel sets the Vault Agent log level. AnnotationVaultLogLevel = "vault.hashicorp.com/log-level" + // AnnotationVaultLogFormat sets the Vault Agent log format. + AnnotationVaultLogFormat = "vault.hashicorp.com/log-format" + // AnnotationVaultRole specifies the role to be used for the Kubernetes auto-auth // method. AnnotationVaultRole = "vault.hashicorp.com/role" @@ -290,6 +293,10 @@ func Init(pod *corev1.Pod, cfg AgentConfig) error { pod.ObjectMeta.Annotations[AnnotationVaultLogLevel] = DefaultAgentLogLevel } + if _, ok := pod.ObjectMeta.Annotations[AnnotationVaultLogFormat]; !ok { + pod.ObjectMeta.Annotations[AnnotationVaultLogFormat] = DefaultAgentLogFormat + } + if _, securityContextIsSet = pod.ObjectMeta.Annotations[AnnotationAgentSetSecurityContext]; !securityContextIsSet { pod.ObjectMeta.Annotations[AnnotationAgentSetSecurityContext] = strconv.FormatBool(cfg.SetSecurityContext) } diff --git a/agent-inject/agent/container_env.go b/agent-inject/agent/container_env.go index 21493f86..18b07796 100644 --- a/agent-inject/agent/container_env.go +++ b/agent-inject/agent/container_env.go @@ -2,6 +2,7 @@ package agent import ( "encoding/base64" + corev1 "k8s.io/api/core/v1" ) @@ -31,6 +32,13 @@ func (a *Agent) ContainerEnvVars(init bool) ([]corev1.EnvVar, error) { }) } + if a.Vault.LogFormat != "" { + envs = append(envs, corev1.EnvVar{ + Name: "VAULT_LOG_FORMAT", + Value: a.Vault.LogFormat, + }) + } + if a.ConfigMapName == "" { config, err := a.newConfig(init) if err != nil { diff --git a/agent-inject/agent/container_sidecar.go b/agent-inject/agent/container_sidecar.go index dac2f9ce..fdd6bf1b 100644 --- a/agent-inject/agent/container_sidecar.go +++ b/agent-inject/agent/container_sidecar.go @@ -18,6 +18,7 @@ const ( DefaultContainerArg = "echo ${VAULT_CONFIG?} | base64 -d > /home/vault/config.json && vault agent -config=/home/vault/config.json" DefaultRevokeGrace = 5 DefaultAgentLogLevel = "info" + DefaultAgentLogFormat = "standard" ) // ContainerSidecar creates a new container to be added