Skip to content

Commit 6017a9b

Browse files
committed
radius: Make secret actually configurable
1 parent 2954efb commit 6017a9b

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ func main() {
5656
}
5757
nacl.SetServiceName("netradius")
5858

59-
srvr, err := radius.New(radius.WithLogger(appLogger), radius.WithNetAuth(nacl))
59+
srvr, err := radius.New(
60+
radius.WithLogger(appLogger),
61+
radius.WithNetAuth(nacl),
62+
radius.WithSecret(os.Getenv("NETAUTH_RADIUS_SECRET")),
63+
)
6064
if err != nil {
6165
appLogger.Error("Error initializing", "error", err)
6266
os.Exit(1)

radius/option.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ func WithNetAuth(n netauth) Option {
1919
return nil
2020
}
2121
}
22+
23+
// WithSecret sets the RADIUS secret for the server.
24+
func WithSecret(scrt string) Option {
25+
return func(s *Server) error {
26+
s.secret = scrt
27+
return nil
28+
}
29+
}

radius/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (s *Server) handler(w radius.ResponseWriter, r *radius.Request) {
4242
func (s *Server) Serve() error {
4343
server := radius.PacketServer{
4444
Handler: radius.HandlerFunc(s.handler),
45-
SecretSource: radius.StaticSecretSource([]byte("secret")),
45+
SecretSource: radius.StaticSecretSource([]byte(s.secret)),
4646
}
4747
s.radsrv = server
4848

radius/type.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type Server struct {
1313
n netauth
1414

1515
radsrv radius.PacketServer
16+
17+
secret string
1618
}
1719

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

0 commit comments

Comments
 (0)