github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/cmd/fleetspeak_config/fleetspeak_config.go (about)

     1  // Copyright 2019 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //   https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package main implements a configuration tool which (partially) automates the
    16  // configuration of a Fleetspeak installation. Advanced users may want to
    17  // perform these steps manually, especially with regards to key management.
    18  package main
    19  
    20  import (
    21  	"flag"
    22  	"io/ioutil"
    23  
    24  	log "github.com/golang/glog"
    25  	"google.golang.org/protobuf/encoding/prototext"
    26  
    27  	"github.com/google/fleetspeak/fleetspeak/src/config/certs"
    28  	"github.com/google/fleetspeak/fleetspeak/src/config/client"
    29  	"github.com/google/fleetspeak/fleetspeak/src/config/server"
    30  
    31  	cpb "github.com/google/fleetspeak/fleetspeak/src/config/proto/fleetspeak_config"
    32  )
    33  
    34  var configFile = flag.String("config", "", "Configuration file to read. Should contain a text format fleetspeak.config.Config protocol buffer. See /etc/fleetspeak-server/configurator.config as a starting point.")
    35  
    36  func main() {
    37  	flag.Parse()
    38  
    39  	b, err := ioutil.ReadFile(*configFile)
    40  	if err != nil {
    41  		log.Exitf("Unable to read configuration file [%s]: %v", *configFile, err)
    42  	}
    43  
    44  	cfg := &cpb.Config{}
    45  	if err := prototext.Unmarshal(b, cfg); err != nil {
    46  		log.Exitf("Unable to parse config file [%s]: %v", *configFile, err)
    47  	}
    48  
    49  	if cfg.ConfigurationName == "" {
    50  		log.Exitf("configuration_name required, not found in [%s]", *configFile)
    51  	}
    52  
    53  	caCert, caKey, caPEM, err := certs.GetTrustedCert(cfg)
    54  	if err != nil {
    55  		log.Exit(err)
    56  	}
    57  
    58  	serverCert, serverKey, err := certs.GetServerCert(cfg, caCert, caKey)
    59  	if err != nil {
    60  		log.Exit(err)
    61  	}
    62  
    63  	if err := server.WriteConfig(cfg, serverCert, serverKey); err != nil {
    64  		log.Exit(err)
    65  	}
    66  
    67  	if err := client.WriteLinuxConfig(cfg, caPEM); err != nil {
    68  		log.Exit(err)
    69  	}
    70  
    71  	if err := client.WriteDarwinConfig(cfg, caPEM); err != nil {
    72  		log.Exit(err)
    73  	}
    74  
    75  	if err := client.WriteWindowsConfig(cfg, caPEM); err != nil {
    76  		log.Exit(err)
    77  	}
    78  }