Skip to content

Commit

Permalink
feat: add debug mode to security configuration
Browse files Browse the repository at this point in the history
- Introduced a new debug flag in the Security struct to enable detailed logging.
- Updated CloudflareAccess and OAuth2Server to utilize the debug flag for conditional logging.
- Enhanced logging in Debug methods to include a prefix for better context in log messages.
  • Loading branch information
tphakala committed Jan 9, 2025
1 parent 034475e commit b1cbffa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ type AllowCloudflareBypass struct {
// SecurityConfig handles all security-related settings and validations
// for the application, including authentication, TLS, and access control.
type Security struct {
Debug bool // true to enable debug mode

// Host is the primary hostname used for TLS certificates
// and OAuth redirect URLs. Required when using AutoTLS or
Expand Down
7 changes: 5 additions & 2 deletions internal/security/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type CloudflareAccess struct {

func NewCloudflareAccess() *CloudflareAccess {
settings := conf.GetSettings()
debug := settings.Security.Debug
cfBypass := settings.Security.AllowCloudflareBypass

return &CloudflareAccess{
Expand All @@ -55,6 +56,7 @@ func NewCloudflareAccess() *CloudflareAccess {
lastFetch: time.Time{},
},
settings: &cfBypass,
debug: debug,
}
}

Expand Down Expand Up @@ -279,10 +281,11 @@ func (ca *CloudflareAccess) GetLogoutURL() string {

func (ca *CloudflareAccess) Debug(format string, v ...interface{}) {
if !ca.debug {
prefix := "[security/cloudflare] "
if len(v) == 0 {
log.Print(format)
log.Print(prefix + format)
} else {
log.Printf(format, v...)
log.Printf(prefix+format, v...)
}
}
}
7 changes: 4 additions & 3 deletions internal/security/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type OAuth2Server struct {

func NewOAuth2Server() *OAuth2Server {
settings := conf.GetSettings()
debug := settings.Debug
debug := settings.Security.Debug

server := &OAuth2Server{
Settings: settings,
Expand Down Expand Up @@ -256,10 +256,11 @@ func (s *OAuth2Server) StartAuthCleanup(interval time.Duration) {

func (s *OAuth2Server) Debug(format string, v ...interface{}) {
if s.debug {
prefix := "[security/oauth] "
if len(v) == 0 {
log.Print(format)
log.Print(prefix + format)
} else {
log.Printf(format, v...)
log.Printf(prefix+format, v...)
}
}
}

0 comments on commit b1cbffa

Please sign in to comment.