Skip to content
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: 4 additions & 4 deletions cmd/argocd-dex/commands/argocd_dex.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func NewRunDexCommand() *cobra.Command {
}

clientConfig = cli.AddKubectlFlagsToCmd(&command)
command.Flags().StringVar(&cmdutil.LogFormat, "logformat", "text", "Set the logging format. One of: text|json")
command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().StringVar(&cmdutil.LogFormat, "logformat", env.StringFromEnv("ARGOCD_DEX_SERVER_LOGFORMAT", "text"), "Set the logging format. One of: text|json")
command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", env.StringFromEnv("ARGOCD_DEX_SERVER_LOGLEVEL", "info"), "Set the logging level. One of: debug|info|warn|error")
command.Flags().BoolVar(&disableTLS, "disable-tls", env.ParseBoolFromEnv("ARGOCD_DEX_SERVER_DISABLE_TLS", false), "Disable TLS on the HTTP endpoint")
return &command
}
Expand Down Expand Up @@ -204,8 +204,8 @@ func NewGenDexConfigCommand() *cobra.Command {
}

clientConfig = cli.AddKubectlFlagsToCmd(&command)
command.Flags().StringVar(&cmdutil.LogFormat, "logformat", "text", "Set the logging format. One of: text|json")
command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().StringVar(&cmdutil.LogFormat, "logformat", env.StringFromEnv("ARGOCD_DEX_SERVER_LOGFORMAT", "text"), "Set the logging format. One of: text|json")
command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", env.StringFromEnv("ARGOCD_DEX_SERVER_LOGLEVEL", "info"), "Set the logging level. One of: debug|info|warn|error")
command.Flags().StringVarP(&out, "out", "o", "", "Output to the specified file instead of stdout")
command.Flags().BoolVar(&disableTLS, "disable-tls", env.ParseBoolFromEnv("ARGOCD_DEX_SERVER_DISABLE_TLS", false), "Disable TLS on the HTTP endpoint")
return &command
Expand Down
5 changes: 5 additions & 0 deletions docs/operator-manual/argocd-cmd-params-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ data:
# Include hidden directories from Git
reposerver.include.hidden.directories: "false"


# Set the logging format. One of: text|json (default "text")
dexserver.log.format: "text"
# Set the logging level. One of: debug|info|warn|error (default "info")
dexserver.log.level: "info"
# Disable TLS on the HTTP endpoint
dexserver.disable.tls: "false"

Expand Down
12 changes: 12 additions & 0 deletions manifests/base/dex/argocd-dex-server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ spec:
imagePullPolicy: Always
command: [/shared/argocd-dex, rundex]
env:
- name: ARGOCD_DEX_SERVER_LOGFORMAT
valueFrom:
configMapKeyRef:
key: dexserver.log.format
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_DEX_SERVER_LOGLEVEL
valueFrom:
configMapKeyRef:
key: dexserver.log.level
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_DEX_SERVER_DISABLE_TLS
valueFrom:
configMapKeyRef:
Expand Down
12 changes: 12 additions & 0 deletions manifests/ha/install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions manifests/ha/namespace-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions manifests/install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions manifests/namespace-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions util/dex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package dex

import (
"fmt"
"os"

"sigs.k8s.io/yaml"

"github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/util/settings"

log "github.com/sirupsen/logrus"
)

func GenerateDexConfigYAML(argocdSettings *settings.ArgoCDSettings, disableTls bool) ([]byte, error) {
Expand Down Expand Up @@ -38,6 +41,20 @@ func GenerateDexConfigYAML(argocdSettings *settings.ArgoCDSettings, disableTls b
}
}

if loggerCfg, found := dexCfg["logger"].(map[string]interface{}); found {
if _, found := loggerCfg["level"]; !found {
loggerCfg["level"] = slogLevelFromLogrus(os.Getenv(common.EnvLogLevel))
}
if _, found := loggerCfg["format"]; !found {
loggerCfg["format"] = os.Getenv(common.EnvLogFormat)
}
} else {
dexCfg["logger"] = map[string]interface{}{
"level": slogLevelFromLogrus(os.Getenv(common.EnvLogLevel)),
"format": os.Getenv(common.EnvLogFormat),
}
}

dexCfg["grpc"] = map[string]interface{}{
"addr": "0.0.0.0:5557",
}
Expand Down Expand Up @@ -130,3 +147,23 @@ func needsRedirectURI(connectorType string) bool {
}
return false
}

func slogLevelFromLogrus(level string) string {
logrusLevel, err := log.ParseLevel(level)
if err != nil {
return level
}

switch logrusLevel {
case log.DebugLevel, log.TraceLevel:
return "DEBUG"
case log.InfoLevel:
return "INFO"
case log.WarnLevel:
return "WARN"
case log.ErrorLevel, log.FatalLevel, log.PanicLevel:
return "ERROR"
}
// return the logrus level and let slog parse it
return level
}
90 changes: 89 additions & 1 deletion util/dex/dex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"strings"
"testing"

log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/yaml"

// "github.com/argoproj/argo-cd/common"
"github.com/argoproj/argo-cd/v2/common"
utillog "github.com/argoproj/argo-cd/v2/util/log"
"github.com/argoproj/argo-cd/v2/util/settings"
)

Expand Down Expand Up @@ -142,6 +144,33 @@ connectors:
nameAttr: cn
`

var goodDexConfigWithLogger = `
logger:
level: debug
other: value
connectors:
# GitHub example
- type: github
id: github
name: GitHub
config:
clientID: aabbccddeeff00112233
clientSecret: $dex.github.clientSecret
orgs:
- name: your-github-org

# GitHub enterprise example
- type: github
id: acme-github
name: Acme GitHub
config:
hostName: github.acme.example.com
clientID: abcdefghijklmnopqrst
clientSecret: $dex.acme.clientSecret
orgs:
- name: your-github-org
`

var goodSecrets = map[string]string{
"dex.github.clientSecret": "foobar",
"dex.acme.clientSecret": "barfoo",
Expand Down Expand Up @@ -272,6 +301,65 @@ func Test_GenerateDexConfig(t *testing.T) {
}
})

t.Run("Logging level", func(t *testing.T) {
s := settings.ArgoCDSettings{
URL: "http://localhost",
DexConfig: goodDexConfig,
}
t.Setenv(common.EnvLogLevel, log.WarnLevel.String())
t.Setenv(common.EnvLogFormat, utillog.JsonFormat)

config, err := GenerateDexConfigYAML(&s, false)
require.NoError(t, err)
assert.NotNil(t, config)
var dexCfg map[string]interface{}
err = yaml.Unmarshal(config, &dexCfg)
if err != nil {
panic(err.Error())
}
loggerCfg, ok := dexCfg["logger"].(map[string]interface{})
assert.True(t, ok)

level, ok := loggerCfg["level"].(string)
assert.True(t, ok)
assert.Equal(t, "WARN", level)

format, ok := loggerCfg["format"].(string)
assert.True(t, ok)
assert.Equal(t, "json", format)
})

t.Run("Logging level with config", func(t *testing.T) {
s := settings.ArgoCDSettings{
URL: "http://localhost",
DexConfig: goodDexConfigWithLogger,
}
t.Setenv(common.EnvLogLevel, log.WarnLevel.String())
t.Setenv(common.EnvLogFormat, utillog.JsonFormat)

config, err := GenerateDexConfigYAML(&s, false)
require.NoError(t, err)
assert.NotNil(t, config)
var dexCfg map[string]interface{}
err = yaml.Unmarshal(config, &dexCfg)
if err != nil {
panic(err.Error())
}
loggerCfg, ok := dexCfg["logger"].(map[string]interface{})
assert.True(t, ok)

level, ok := loggerCfg["level"].(string)
assert.True(t, ok)
assert.Equal(t, "debug", level)

format, ok := loggerCfg["format"].(string)
assert.True(t, ok)
assert.Equal(t, "json", format)

_, ok = loggerCfg["other"].(string)
assert.True(t, ok)
})

t.Run("Redirect config", func(t *testing.T) {
types := []string{"oidc", "saml", "microsoft", "linkedin", "gitlab", "github", "bitbucket-cloud", "openshift", "gitea", "google", "oauth"}
for _, c := range types {
Expand Down