Beispiel #1
0
 def testGenClientConfig_ignoreBuilderContext(self):
     with test_lib.PreserveConfig():
         # Define a secondary config with special values for the ClientBuilder
         # context.
         str_override = """
     Test Context:
       Client.labels: [label0, label1]
       ClientBuilder Context:
         Client.labels: [build-label0, build-label1]
   """
         override = config_lib.YamlParser(data=str_override).RawData()
         config.CONFIG.MergeData(override)
         # Sanity-check that the secondary config was merged into the global
         # config.
         self.assertEqual(config.CONFIG["Client.labels"],
                          ["label0", "label1"])
         repacker = build.ClientRepacker()
         context = [
             "Test Context", "ClientBuilder Context", "Client Context"
         ]
         str_client_config = repacker.GetClientConfig(context)
         client_config = config_lib.YamlParser(
             data=str_client_config).RawData()
         # Settings particular to the ClientBuilder context should not carry over
         # into the generated client config.
         self.assertEqual(client_config["Client.labels"],
                          ["label0", "label1"])
Beispiel #2
0
  def testGenClientConfig(self):
    with test_lib.ConfigOverrider({"Client.build_environment": "test_env"}):

      deployer = build.ClientRepacker()
      data = deployer.GetClientConfig(["Client Context"], validate=True)

      parser = config_lib.YamlParser(data=data)
      raw_data = parser.RawData()

      self.assertIn("Client.deploy_time", raw_data)
Beispiel #3
0
    def testRepackerDummyClientConfig(self):
        """Ensure our dummy client config can pass validation.

    This config is used to exercise repacking code in integration testing, here
    we just make sure it will pass validation.
    """
        new_config = config.CONFIG.MakeNewConfig()
        new_config.Initialize()
        new_config.LoadSecondaryConfig(
            os.path.join(config.CONFIG["Test.data_dir"], "dummyconfig.yaml"))
        build.ClientRepacker().ValidateEndConfig(new_config)
Beispiel #4
0
    def testRepackAll(self):
        """Test repacking all binaries."""
        self.executables_dir = package.ResourcePath("grr-response-core",
                                                    "executables")
        with utils.TempDirectory() as tmp_dir:
            new_dir = os.path.join(tmp_dir, "grr", "executables")
            os.makedirs(new_dir)

            # Copy unzipsfx so it can be used in repacking/
            shutil.copy(
                os.path.join(self.executables_dir,
                             "windows/templates/unzipsfx/unzipsfx-i386.exe"),
                new_dir)
            shutil.copy(
                os.path.join(self.executables_dir,
                             "windows/templates/unzipsfx/unzipsfx-amd64.exe"),
                new_dir)

            with test_lib.ConfigOverrider({
                    "ClientBuilder.executables_dir":
                    new_dir,
                    "ClientBuilder.unzipsfx_stub_dir":
                    new_dir
            }):
                repacking.TemplateRepacker().RepackAllTemplates()

            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.deb"))), 2)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.rpm"))), 2)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.exe"))), 4)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.pkg"))), 1)

            # Validate the config appended to the OS X package.
            zf = zipfile.ZipFile(glob.glob(
                os.path.join(new_dir, "installers/*.pkg")).pop(),
                                 mode="r")
            fd = zf.open("config.yaml")

            # We can't load the included build.yaml because the package hasn't been
            # installed.
            loaded = yaml.safe_load(fd)
            loaded.pop("Config.includes")

            packaged_config = config.CONFIG.MakeNewConfig()
            data = yaml.safe_dump(loaded)
            packaged_config.Initialize(parser=config_lib.YamlParser,
                                       data=data.decode("utf-8"))
            packaged_config.Validate(
                sections=build.ClientRepacker.CONFIG_SECTIONS)
            repacker = build.ClientRepacker()
            repacker.ValidateEndConfig(packaged_config)
Beispiel #5
0
    def WriteClientConfig(self):
        repacker = build.ClientRepacker(context=self.context)
        repacker.context = self.context

        # Generate a config file.
        with open(
                os.path.join(
                    self.target_binary_dir,
                    config.CONFIG.Get("ClientBuilder.config_filename",
                                      context=self.context)), "wb") as fd:
            fd.write(
                repacker.GetClientConfig(["Client Context"] + self.context,
                                         validate=False))
Beispiel #6
0
def GetClientConfig(filename):
    """Write client config to filename."""
    config_lib.SetPlatformArchContext()
    config_lib.ParseConfigCommandLine()
    context = list(grr_config.CONFIG.context)
    context.append("Client Context")
    deployer = build.ClientRepacker()
    # Disable timestamping so we can get a reproducible and cachable config file.
    config_data = deployer.GetClientConfig(context,
                                           validate=True,
                                           deploy_timestamp=False)
    builder = build.ClientBuilder()
    with open(filename, "w") as fd:
        fd.write(config_data)
        builder.WriteBuildYaml(fd, build_timestamp=False)
def main(argv):
    del argv  # Unused.

    if not flags.FLAGS.dest_server_config_path:
        raise ValueError("dest_server_config_path flag has to be provided.")

    if not flags.FLAGS.dest_client_config_path:
        raise ValueError("dest_client_config_path flag has to be provided.")

    admin_ui_port = portpicker.pick_unused_port()
    frontend_port = portpicker.pick_unused_port()
    datastore_port = portpicker.pick_unused_port()

    source_server_config_path = package.ResourcePath(
        "grr-response-core", "install_data/etc/grr-server.yaml")
    config_lib.LoadConfig(config.CONFIG, source_server_config_path)
    config.CONFIG.SetWriteBack(flags.FLAGS.dest_server_config_path)

    config.CONFIG.Set("Datastore.implementation", "SharedFakeDataStore")
    config.CONFIG.Set("SharedFakeDataStore.port", datastore_port)
    config.CONFIG.Set("AdminUI.port", admin_ui_port)
    config.CONFIG.Set("AdminUI.headless", True)
    config.CONFIG.Set("Frontend.bind_address", "127.0.0.1")
    config.CONFIG.Set("Frontend.bind_port", frontend_port)
    config.CONFIG.Set("Server.initialized", True)
    config.CONFIG.Set("Client.poll_max", 1)
    config.CONFIG.Set("Client.server_urls",
                      ["http://localhost:%d/" % frontend_port])

    config_updater_keys_util.GenerateKeys(config.CONFIG)
    config.CONFIG.Write()

    config_lib.SetPlatformArchContext()
    context = list(config.CONFIG.context)
    context.append("Client Context")
    deployer = build.ClientRepacker()
    config_data = deployer.GetClientConfig(context,
                                           validate=False,
                                           deploy_timestamp=False)
    with io.open(flags.FLAGS.dest_client_config_path, "w") as fd:
        fd.write(config_data)