Skip to content

Commit

Permalink
radius: Make secret actually configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
the-maldridge committed Jan 21, 2023
1 parent 2954efb commit 6017a9b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func main() {
}
nacl.SetServiceName("netradius")

srvr, err := radius.New(radius.WithLogger(appLogger), radius.WithNetAuth(nacl))
srvr, err := radius.New(
radius.WithLogger(appLogger),
radius.WithNetAuth(nacl),
radius.WithSecret(os.Getenv("NETAUTH_RADIUS_SECRET")),
)
if err != nil {
appLogger.Error("Error initializing", "error", err)
os.Exit(1)
Expand Down
8 changes: 8 additions & 0 deletions radius/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ func WithNetAuth(n netauth) Option {
return nil
}
}

// WithSecret sets the RADIUS secret for the server.
func WithSecret(scrt string) Option {
return func(s *Server) error {
s.secret = scrt
return nil
}
}
2 changes: 1 addition & 1 deletion radius/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Server) handler(w radius.ResponseWriter, r *radius.Request) {
func (s *Server) Serve() error {
server := radius.PacketServer{
Handler: radius.HandlerFunc(s.handler),
SecretSource: radius.StaticSecretSource([]byte("secret")),
SecretSource: radius.StaticSecretSource([]byte(s.secret)),
}
s.radsrv = server

Expand Down
2 changes: 2 additions & 0 deletions radius/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Server struct {
n netauth

radsrv radius.PacketServer

secret string
}

// Option enables passing of various options to the server on startup.
Expand Down

0 comments on commit 6017a9b

Please sign in to comment.