Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vault agent annotation 'log-format' #200

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions agent-inject/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ type Agent struct {
// SetSecurityContext controls whether the injected containers have a
// SecurityContext set.
SetSecurityContext bool
// ExtraSecret is the Kubernetes secret to mount as a volume in the Vault agent container

// ExtraSecret is the Kubernetes secret to mount as a volume in the Vault agent container
// which can be referenced by the Agent config for secrets. Mounted at /vault/custom/
ExtraSecret string
}
Expand Down Expand Up @@ -185,6 +185,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

Expand Down Expand Up @@ -243,6 +246,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],
Expand Down
7 changes: 7 additions & 0 deletions agent-inject/agent/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -285,6 +288,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)
}
Expand Down
8 changes: 8 additions & 0 deletions agent-inject/agent/container_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"encoding/base64"

corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions agent-inject/agent/container_sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down