2022-05-23 05:36:54 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2022-06-15 10:00:48 -04:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2022-05-23 05:36:54 -04:00
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/activation/kms"
|
|
|
|
"github.com/edgelesssys/constellation/activation/kubeadm"
|
2022-06-02 09:58:19 -04:00
|
|
|
"github.com/edgelesssys/constellation/activation/kubernetesca"
|
2022-05-23 05:36:54 -04:00
|
|
|
"github.com/edgelesssys/constellation/activation/server"
|
|
|
|
"github.com/edgelesssys/constellation/activation/validator"
|
|
|
|
"github.com/edgelesssys/constellation/activation/watcher"
|
2022-06-01 09:08:42 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/atls"
|
2022-05-23 05:36:54 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/constants"
|
|
|
|
"github.com/edgelesssys/constellation/internal/file"
|
2022-06-13 05:40:27 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/grpc/atlscredentials"
|
2022-06-28 10:51:30 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/logger"
|
2022-05-23 05:36:54 -04:00
|
|
|
"github.com/spf13/afero"
|
2022-06-28 10:51:30 -04:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
2022-05-23 05:36:54 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
provider := flag.String("cloud-provider", "", "cloud service provider this binary is running on")
|
|
|
|
kmsEndpoint := flag.String("kms-endpoint", "", "endpoint of Constellations key management service")
|
2022-06-28 10:51:30 -04:00
|
|
|
verbosity := flag.Int("v", 0, "log verbosity in zap logging levels. Use -1 for debug information, 0 for info, 1 for warn, 2 for error")
|
2022-05-23 05:36:54 -04:00
|
|
|
|
|
|
|
flag.Parse()
|
2022-06-28 10:51:30 -04:00
|
|
|
log := logger.New(logger.JSONLog, zapcore.Level(*verbosity))
|
2022-06-15 10:00:48 -04:00
|
|
|
|
2022-06-28 10:51:30 -04:00
|
|
|
log.With(zap.String("version", constants.VersionInfo), zap.String("cloudProvider", *provider)).
|
|
|
|
Infof("Constellation Node Activation Service")
|
2022-05-23 05:36:54 -04:00
|
|
|
|
|
|
|
handler := file.NewHandler(afero.NewOsFs())
|
|
|
|
|
2022-06-28 10:51:30 -04:00
|
|
|
validator, err := validator.New(log.Named("validator"), *provider, handler)
|
2022-05-23 05:36:54 -04:00
|
|
|
if err != nil {
|
|
|
|
flag.Usage()
|
2022-06-28 10:51:30 -04:00
|
|
|
log.With(zap.Error(err)).Fatalf("Failed to create validator")
|
2022-05-23 05:36:54 -04:00
|
|
|
}
|
|
|
|
|
2022-06-13 05:40:27 -04:00
|
|
|
creds := atlscredentials.New(nil, []atls.Validator{validator})
|
2022-05-23 05:36:54 -04:00
|
|
|
|
2022-06-28 10:51:30 -04:00
|
|
|
kubeadm, err := kubeadm.New(log.Named("kubeadm"))
|
2022-05-23 05:36:54 -04:00
|
|
|
if err != nil {
|
2022-06-28 10:51:30 -04:00
|
|
|
log.With(zap.Error(err)).Fatalf("Failed to create kubeadm")
|
2022-05-23 05:36:54 -04:00
|
|
|
}
|
2022-06-28 10:51:30 -04:00
|
|
|
kms := kms.New(log.Named("kms"), *kmsEndpoint)
|
2022-05-23 05:36:54 -04:00
|
|
|
|
2022-06-28 10:51:30 -04:00
|
|
|
server := server.New(
|
|
|
|
log.Named("server"),
|
|
|
|
handler,
|
|
|
|
kubernetesca.New(log.Named("certificateAuthority"), handler),
|
|
|
|
kubeadm,
|
|
|
|
kms,
|
|
|
|
)
|
2022-05-23 05:36:54 -04:00
|
|
|
|
2022-06-28 10:51:30 -04:00
|
|
|
watcher, err := watcher.New(log.Named("fileWatcher"), validator)
|
2022-05-23 05:36:54 -04:00
|
|
|
if err != nil {
|
2022-06-28 10:51:30 -04:00
|
|
|
log.With(zap.Error(err)).Fatalf("Failed to create watcher for measurements updates")
|
2022-05-23 05:36:54 -04:00
|
|
|
}
|
|
|
|
defer watcher.Close()
|
|
|
|
|
|
|
|
go func() {
|
2022-06-28 10:51:30 -04:00
|
|
|
log.Infof("starting file watcher for measurements file %s", filepath.Join(constants.ActivationBasePath, constants.ActivationMeasurementsFilename))
|
2022-06-15 10:00:48 -04:00
|
|
|
if err := watcher.Watch(filepath.Join(constants.ActivationBasePath, constants.ActivationMeasurementsFilename)); err != nil {
|
2022-06-28 10:51:30 -04:00
|
|
|
log.With(zap.Error(err)).Fatalf("Failed to watch measurements file")
|
2022-05-23 05:36:54 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-06-15 10:00:48 -04:00
|
|
|
if err := server.Run(creds, strconv.Itoa(constants.ActivationServicePort)); err != nil {
|
2022-06-28 10:51:30 -04:00
|
|
|
log.With(zap.Error(err)).Fatalf("Failed to run server")
|
2022-05-23 05:36:54 -04:00
|
|
|
}
|
|
|
|
}
|