feat: add support for using secret files for basic auth password

This commit is contained in:
Stavros
2025-07-07 23:31:51 +03:00
parent 7e604419ab
commit f48bb65d7b
2 changed files with 11 additions and 5 deletions

View File

@@ -154,9 +154,9 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
log.Debug().Str("key", key).Msg("Setting header")
c.Header(key, value)
}
if labels.Basic.Username != "" && labels.Basic.Password != "" {
if labels.Basic.Username != "" && utils.GetSecret(labels.Basic.Password.Plain, labels.Basic.Password.File) != "" {
log.Debug().Str("username", labels.Basic.Username).Msg("Setting basic auth headers")
c.Header("Authorization", fmt.Sprintf("Basic %s", utils.GetBasicAuth(labels.Basic.Username, labels.Basic.Password)))
c.Header("Authorization", fmt.Sprintf("Basic %s", utils.GetBasicAuth(labels.Basic.Username, utils.GetSecret(labels.Basic.Password.Plain, labels.Basic.Password.File))))
}
c.JSON(200, gin.H{
"status": 200,
@@ -283,9 +283,9 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
}
// Set basic auth headers if configured
if labels.Basic.Username != "" && labels.Basic.Password != "" {
if labels.Basic.Username != "" && utils.GetSecret(labels.Basic.Password.Plain, labels.Basic.Password.File) != "" {
log.Debug().Str("username", labels.Basic.Username).Msg("Setting basic auth headers")
c.Header("Authorization", fmt.Sprintf("Basic %s", utils.GetBasicAuth(labels.Basic.Username, labels.Basic.Password)))
c.Header("Authorization", fmt.Sprintf("Basic %s", utils.GetBasicAuth(labels.Basic.Username, utils.GetSecret(labels.Basic.Password.Plain, labels.Basic.Password.File))))
}
// The user is allowed to access the app

View File

@@ -109,7 +109,13 @@ type OAuthLabels struct {
// Basic auth labels for a tinyauth protected container
type BasicLabels struct {
Username string
Password string
Password PassowrdLabels
}
// PassowrdLabels is a struct that contains the password labels for a tinyauth protected container
type PassowrdLabels struct {
Plain string
File string
}
// IP labels for a tinyauth protected container