Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 1 deletion internal/bootstrap/app_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ func (app *BootstrapApp) Setup() error {
}

// Get cookie domain
cookieDomain, err := utils.GetCookieDomain(app.context.appUrl)
cookieDomainResolver := utils.GetCookieDomain
if !app.config.Auth.SubdomainsEnabled {
tlog.App.Info().Msg("Subdomains disabled, automatic authentication for proxied apps will not work")
cookieDomainResolver = utils.GetStandaloneCookieDomain
}

cookieDomain, err := cookieDomainResolver(app.context.appUrl)

if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func NewDefaultConfiguration() *Config {
Address: "0.0.0.0",
},
Auth: AuthConfig{
SubdomainsEnabled: true,
SessionExpiry: 86400, // 1 day
SessionMaxLifetime: 0, // disabled
LoginTimeout: 300, // 5 minutes
Expand Down Expand Up @@ -116,6 +117,7 @@ type AuthConfig struct {
IP IPConfig `description:"IP whitelisting config options." yaml:"ip"`
Users []string `description:"Comma-separated list of users (username:hashed_password)." yaml:"users"`
UsersFile string `description:"Path to the users file." yaml:"usersFile"`
SubdomainsEnabled bool `description:"Enable subdomains support." yaml:"subdomainsEnabled"`
SecureCookie bool `description:"Enable secure cookies." yaml:"secureCookie"`
SessionExpiry int `description:"Session expiry time in seconds." yaml:"sessionExpiry"`
SessionMaxLifetime int `description:"Maximum session lifetime in seconds." yaml:"sessionMaxLifetime"`
Expand Down
9 changes: 9 additions & 0 deletions internal/utils/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ func GetCookieDomain(u string) (string, error) {
return domain, nil
}

func GetStandaloneCookieDomain(u string) (string, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs tests to cover the scenarios it may be used in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean do we really need testing? It's just URL parse and the stdlib is tested so what should we test? If it parses example.com and fails example? Because that's already covered.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my take is that if it's a straightforward test to write, it's worth having. Especially if it's edge case config. Better to catch a regression in a test that have a user report their tinyauth is broken. Your call, though.

parsed, err := url.Parse(u)
if err != nil {
return "", err
}

return parsed.Hostname(), nil
}

func ParseFileToLine(content string) string {
lines := strings.Split(content, "\n")
users := make([]string, 0)
Expand Down