Andrey Smirnov 0662af19d1 chore: seed math.rand PRNG on startup in every service (#801)
This is important as otherwise `math/rand` outputs predictable sequence
each time.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-06-28 11:03:15 -07:00

68 lines
1.6 KiB
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package main
import (
"flag"
"log"
"github.com/talos-systems/talos/internal/app/trustd/internal/reg"
"github.com/talos-systems/talos/internal/pkg/constants"
"github.com/talos-systems/talos/internal/pkg/grpc/factory"
"github.com/talos-systems/talos/internal/pkg/grpc/middleware/auth/basic"
"github.com/talos-systems/talos/internal/pkg/grpc/tls"
"github.com/talos-systems/talos/internal/pkg/startup"
"github.com/talos-systems/talos/pkg/userdata"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
var (
dataPath *string
)
func init() {
log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime)
dataPath = flag.String("userdata", "", "the path to the user data")
flag.Parse()
}
func main() {
var err error
if err = startup.RandSeed(); err != nil {
log.Fatalf("startup: %s", err)
}
data, err := userdata.Open(*dataPath)
if err != nil {
log.Fatalf("credentials: %v", err)
}
config, err := tls.NewConfig(tls.ServerOnly, data.Security.OS)
if err != nil {
log.Fatalf("credentials: %v", err)
}
creds, err := basic.NewCredentials(data.Services.Trustd)
if err != nil {
log.Fatal(err)
}
err = factory.ListenAndServe(
&reg.Registrator{Data: data.Security.OS},
factory.Port(constants.TrustdPort),
factory.ServerOptions(
grpc.Creds(
credentials.NewTLS(config),
),
grpc.UnaryInterceptor(creds.UnaryInterceptor()),
),
)
if err != nil {
log.Fatalf("listen: %v", err)
}
}