fix: report traefik dns-provider env vars as global keys

The dynamic `dns-provider-*` properties were reported as `--traefik-dns-provider-<env_var>`, outside the `global`/`computed` namespace every other traefik property uses, so a consumer reading the json report could not tell which of the two a key represented. They are now reported as `--traefik-global-dns-provider-<env_var>`. The `basic-auth-password` property is a credential as well and is now masked in the default report output on the same terms as the dns provider values, meaning the raw value is returned only for `--format json` or when the flag is queried by name.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-08-12 03:22:04 -04:00
1 parent adf2bd14fb
commit 81a929d768
7 files changed
+275 -24

No files matched your search

+44 -11
View File
@@ -8,6 +8,9 @@ import (
"github.com/dokku/dokku/plugins/common"
)
// valueMask is shown in place of credential values in the default stdout report
const valueMask = "*******"
// ReportSingleApp is an internal function that displays the traefik report for one or more apps
func ReportSingleApp(appName string, format string, infoFlag string) error {
if appName != "--global" {
@@ -49,20 +52,16 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
"--traefik-global-log-level": reportGlobalLogLevel,
}
// dns-provider-* env vars are dynamic; their values are masked in the default
// stdout report, but shown for --format json or when queried explicitly by name
dnsProviderVars, err := common.PropertyGetAllByPrefix("traefik", "--global", "dns-provider-")
for _, flagName := range []string{"--traefik-computed-basic-auth-password", "--traefik-global-basic-auth-password"} {
flags[flagName] = maskedReportFunc(flags[flagName], flagName, format, infoFlag)
}
dnsProviderFlags, err := dnsProviderReportFlags(format, infoFlag)
if err != nil {
return err
}
for key, value := range dnsProviderVars {
flagName := "--traefik-" + key
realValue := value
if format == "json" || infoFlag == flagName {
flags[flagName] = func(string) string { return realValue }
} else {
flags[flagName] = func(string) string { return "*******" }
}
for flagName, reportFunc := range dnsProviderFlags {
flags[flagName] = reportFunc
}
flagKeys := []string{}
@@ -84,6 +83,40 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
})
}
// maskedReportFunc hides a credential value behind valueMask so the default stdout
// report - and thus the aggregate `dokku report` - never prints it. The raw value is
// returned for machine-readable output or when the flag is requested by name.
func maskedReportFunc(fn common.ReportFunc, flagName string, format string, infoFlag string) common.ReportFunc {
if format == "json" || infoFlag == flagName {
return fn
}
return func(appName string) string {
if fn(appName) == "" {
return ""
}
return valueMask
}
}
// dnsProviderReportFlags returns report functions for the dynamic dns-provider-*
// properties, keyed by their global report flag
func dnsProviderReportFlags(format string, infoFlag string) (map[string]common.ReportFunc, error) {
flags := map[string]common.ReportFunc{}
properties, err := common.PropertyGetAllByPrefix("traefik", "--global", "dns-provider-")
if err != nil {
return flags, err
}
for property, value := range properties {
flagName := "--traefik-global-" + property
flags[flagName] = maskedReportFunc(func(string) string { return value }, flagName, format, infoFlag)
}
return flags, nil
}
func reportGlobalAPIEnabled(appName string) string {
return common.PropertyGet("traefik", "--global", "api-enabled")
}