예제 #1
0
        public void UpdateTest()
        {
            List <TestFirewallRule> startRules = TestFirewallManiuplator.GetRules();
            var nodes = GetNodeSettings(3, 0, true, "test.microsoft.com");

            FirewallManager.EnableFirewallSettings(nodes, true, true);
            List <TestFirewallRule> newRules   = GetRules(3, 0, true);
            List <TestFirewallRule> addedRules = TestFirewallManiuplator.GetRules();

            VerifyRulesDiff(startRules, newRules, addedRules);

            //
            // Remove a node and the corresponding firewall rules for that node.
            //
            nodes.RemoveAt(1);
            newRules.RemoveRange(35, 35);

            nodes.AddRange(GetNodeSettings(2, 3, true, "test.microsoft.com"));
            newRules.AddRange(GetRules(2, 3, true));
            FirewallManager.EnableFirewallSettings(nodes, true, true);
            addedRules = TestFirewallManiuplator.GetRules();
            VerifyRulesDiff(startRules, newRules, addedRules);
            FirewallManager.DisableFirewallSettings();
            var finalRules = TestFirewallManiuplator.GetRules();

            VerifyRulesEqual(startRules, finalRules);
        }
예제 #2
0
        public void VerifyNoChangeOnLocalhostScaleMin()
        {
            var startRules = TestFirewallManiuplator.GetRules();
            var nodes      = GetNodeSettings(3, 0, true, "localhost");
            var newRules   = GetRules(3, 0, true);

            FirewallManager.EnableFirewallSettings(nodes, true, true);
            var finalRules = TestFirewallManiuplator.GetRules();

            VerifyRulesEqual(startRules, finalRules);
        }
예제 #3
0
        public void BasicInstallationAndUninstallation()
        {
            List <TestFirewallRule> startRules = TestFirewallManiuplator.GetRules();
            var nodes = GetNodeSettings(3, 0, true, "test.microsoft.com");

            FirewallManager.EnableFirewallSettings(nodes, true, true);
            List <TestFirewallRule> newRules   = GetRules(3, 0, true);
            List <TestFirewallRule> addedRules = TestFirewallManiuplator.GetRules();

            VerifyRulesDiff(startRules, newRules, addedRules);
            FirewallManager.DisableFirewallSettings();
            List <TestFirewallRule> finalRules = TestFirewallManiuplator.GetRules();

            VerifyRulesEqual(finalRules, startRules);
        }
예제 #4
0
        public void V1RuleRemoval()
        {
            List <TestFirewallRule> startRules = TestFirewallManiuplator.GetRules();
            List <TestFirewallRule> v1Rules    = new List <TestFirewallRule>();

            TestFirewallManiuplator.AddRules(v1Rules);
            var nodes    = GetNodeSettings(3, 0, true, "test.microsoft.com");
            var newRules = GetRules(3, 0, true);

            FirewallManager.EnableFirewallSettings(nodes, true, true);
            List <TestFirewallRule> addedRules = TestFirewallManiuplator.GetRules();

            VerifyRulesDiff(startRules, newRules, addedRules);
            FirewallManager.DisableFirewallSettings();
            List <TestFirewallRule> finalRules = TestFirewallManiuplator.GetRules();

            VerifyRulesEqual(finalRules, startRules);
        }
예제 #5
0
        protected void CleanupDeployment(DeploymentParameters parameters)
        {
#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            if (AccountHelper.IsAdminUser())
            {
                CollectEventLogs();

                FabricDeployerServiceController.DisableService();
                if (!parameters.SkipFirewallConfiguration)
                {
                    FirewallManager.DisableFirewallSettings();
                }
                DeployerTrace.WriteInfo("Stopping data collectors");
                PerformanceCounters.StopDataCollector();

                DeployerTrace.WriteInfo("Deleting data collectors");
                PerformanceCounters.DeleteDataCollector();
            }
            else
            {
                DeployerTrace.WriteWarning(
                    "Deployer is not run as Administrator. Skipping Firewall Management and Performance Counter Management. Possible Post remove cleanup required");
            }

            if (FabricDeployerServiceController.IsRunning(parameters.MachineName))
            {
                throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_FabricHostStillRunning_Formatted);
            }
#else
            DeployerTrace.WriteInfo("CoreClr: Skipping Firewall Management and Performance Counter Management cleanup on CoreClr.");
#endif
            string targetInformationFileName = Path.Combine(parameters.FabricDataRoot, Constants.FileNames.TargetInformation);
            DeleteTargetInformationFile(targetInformationFileName);

#if DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            bool skipDeleteFabricDataRoot = Utility.GetSkipDeleteFabricDataRoot() ||
                                            (parameters.SkipDeleteFabricDataRoot != null && string.Equals(parameters.SkipDeleteFabricDataRoot, "true", StringComparison.OrdinalIgnoreCase));
#else
            bool skipDeleteFabricDataRoot = Utility.GetSkipDeleteFabricDataRoot() ||
                                            (parameters.SkipDeleteFabricDataRoot != null && string.Equals(parameters.SkipDeleteFabricDataRoot, "true", StringComparison.InvariantCultureIgnoreCase));
#endif

            if (skipDeleteFabricDataRoot)
            {
                DeployerTrace.WriteInfo("Skipping deletion of Data Root.");
            }
            else
            {
                NetCloseResource(parameters.FabricDataRoot);
                SafeDeleteDirectory(parameters.FabricDataRoot, parameters.FabricLogRoot, Path.Combine(parameters.FabricDataRoot, Constants.FileNames.FabricHostSettings));
                List <SettingsTypeSection> sections = new List <SettingsTypeSection>();
                sections.Add(new SettingsTypeSection()
                {
                    Name = Constants.SectionNames.Setup
                });
                WriteFabricHostSettingsFile(parameters.FabricDataRoot, new SettingsType()
                {
                    Section = sections.ToArray()
                }, parameters.MachineName);
            }

#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            SpnManager.CleanupSpn();
#else
            DeployerTrace.WriteInfo("CoreClrLinux: SPN cleanning skipped for Linux");
#endif
#if !DotNetCoreClrIOT
            new DockerDnsHelper(parameters, string.Empty).CleanupAsync().GetAwaiter().GetResult();

            // Clean up docker network set up
            var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
            containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName);
#endif
        }
예제 #6
0
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            var isRunningAsAdmin = AccountHelper.IsAdminUser();

            if (!isRunningAsAdmin)
            {
                DeployerTrace.WriteWarning(StringResources.Warning_DeployerNotRunAsAdminSkipFirewallAndPerformanceCounter);
                return;
            }

            if (clusterManifest == null)
            {
                DeployerTrace.WriteError(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
                throw new ArgumentException(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
            }

            this.parameters      = parameters;
            this.manifest        = clusterManifest;
            this.infrastructure  = infrastructure;
            this.fabricValidator = new FabricValidatorWrapper(parameters, manifest, infrastructure);
            fabricValidator.ValidateAndEnsureDefaultImageStore();

            if (!parameters.SkipFirewallConfiguration)
            {
                var securitySection = manifest.FabricSettings.FirstOrDefault(fabSetting => fabSetting.Name.Equals(Constants.SectionNames.Security, StringComparison.OrdinalIgnoreCase));

#if DotNetCoreClrLinux
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux;
#else
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer;
#endif

                    var nodeSettings = GetNodeSettings();
                    var isScaleMin   = currentInfrastructure.IsScaleMin;
                    FirewallManager.EnableFirewallSettings(nodeSettings, isScaleMin, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, isScaleMin);
                }
                else if (isRunningAsAdmin)
                {
                    var nodeSettings = GetNodeSettings();
                    FirewallManager.EnableFirewallSettings(nodeSettings, false, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, false);
                }
            }

#if !DotNetCoreClrIOT && !DotNetCoreClrLinux
            ResetNetworks(parameters, clusterManifest, infrastructure);
#endif

#if !DotNetCoreClrIOT
            if (parameters.ContainerDnsSetup == ContainerDnsSetup.Allow || parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
            {
                try
                {
                    string currentNodeIPAddressOrFQDN = string.Empty;
                    if ((infrastructure != null) && (infrastructure.InfrastructureNodes != null))
                    {
                        foreach (var infraNode in infrastructure.InfrastructureNodes)
                        {
                            DeployerTrace.WriteInfo("Infra node <{0}> params.NodeName <{1}>", infraNode.NodeName, parameters.NodeName);
                            if (NetworkApiHelper.IsAddressForThisMachine(infraNode.IPAddressOrFQDN))
                            {
                                currentNodeIPAddressOrFQDN = infraNode.IPAddressOrFQDN;
                                DeployerTrace.WriteInfo("Found node IPAddressOrFQDN <{0}>", currentNodeIPAddressOrFQDN);
                                break;
                            }
                        }
                    }

                    new DockerDnsHelper(parameters, currentNodeIPAddressOrFQDN).SetupAsync().GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    if (parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
                    {
                        DeployerTrace.WriteError(
                            StringResources.Error_FabricDeployer_DockerDnsSetup_ErrorNotContinuing,
                            Constants.ParameterNames.ContainerDnsSetup,
                            parameters.ContainerDnsSetup,
                            ex);
                        throw;
                    }

                    DeployerTrace.WriteWarning(
                        StringResources.Warning_FabricDeployer_DockerDnsSetup_ErrorContinuing,
                        Constants.ParameterNames.ContainerDnsSetup,
                        parameters.ContainerDnsSetup,
                        ex);
                }
            }
            else if (parameters.ContainerDnsSetup == ContainerDnsSetup.Disallow)
            {
                // cleanupasync catches all exceptions
                new DockerDnsHelper(parameters, string.Empty).CleanupAsync().GetAwaiter().GetResult();
            }
#endif

#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            if (!PerformanceCounters.StartCollection(clusterManifest.FabricSettings, parameters.DeploymentSpecification))
            {
                DeployerTrace.WriteWarning(StringResources.Error_FabricDeployer_StartCounterCollectionFailed_Formatted);
            }

            if (fabricValidator.ShouldRegisterSpnForMachineAccount)
            {
                if (!SpnManager.EnsureSpn())
                {
                    throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_FailedToRegisterSpn_Formatted);
                }
            }
#endif
        }
예제 #7
0
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            var isRunningAsAdmin = AccountHelper.IsAdminUser();

            if (!isRunningAsAdmin)
            {
                DeployerTrace.WriteWarning(StringResources.Warning_DeployerNotRunAsAdminSkipFirewallAndPerformanceCounter);
                return;
            }

            if (clusterManifest == null)
            {
                DeployerTrace.WriteError(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
                throw new ArgumentException(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
            }

            this.parameters      = parameters;
            this.manifest        = clusterManifest;
            this.infrastructure  = infrastructure;
            this.fabricValidator = new FabricValidatorWrapper(parameters, manifest, infrastructure);
            fabricValidator.ValidateAndEnsureDefaultImageStore();

            if (!parameters.SkipFirewallConfiguration)
            {
                var securitySection = manifest.FabricSettings.FirstOrDefault(fabSetting => fabSetting.Name.Equals(Constants.SectionNames.Security, StringComparison.OrdinalIgnoreCase));

#if DotNetCoreClrLinux
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux;
#else
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer;
#endif

                    var nodeSettings = GetNodeSettings();
                    var isScaleMin   = currentInfrastructure.IsScaleMin;
                    FirewallManager.EnableFirewallSettings(nodeSettings, isScaleMin, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, isScaleMin);
                }
                else if (isRunningAsAdmin)
                {
                    var nodeSettings = GetNodeSettings();
                    FirewallManager.EnableFirewallSettings(nodeSettings, false, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, false);
                }
            }

#if !DotNetCoreClrIOT && !DotNetCoreClrLinux
            #region Container Network Reset
            // CreateOrUpdate operation inherits from RestartOperation.
            // This check will invoke network reset only in the restart case.
            // This is a work around to handle the case where the flat network was not usable after VM reboot.
            if (parameters.Operation == DeploymentOperations.None)
            {
                if (!parameters.SkipContainerNetworkResetOnReboot)
                {
                    var lastBootUpTimeFromRegistry = Utility.GetNodeLastBootUpTimeFromRegistry();
                    var lastBootUpTimeFromSystem   = Utility.GetNodeLastBootUpTimeFromSystem();
                    DeployerTrace.WriteInfo("Last boot up time from registry:{0} from system:{1}", lastBootUpTimeFromRegistry, lastBootUpTimeFromSystem);

                    if (!string.Equals(lastBootUpTimeFromRegistry.ToString(), lastBootUpTimeFromSystem.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        DeployerTrace.WriteInfo("Invoking container network reset.");

                        // This check is needed to allow clean up on azure. This is symmetrical to the set up condition.
                        if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure ||
                            clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)
                        {
                            var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
                            containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, parameters.Operation);
                        }

                        if (parameters.ContainerNetworkSetup)
                        {
                            // set up docker network.
                            var containerNetworkSetupOperation = new ContainerNetworkSetupOperation();
                            containerNetworkSetupOperation.ExecuteOperation(parameters, clusterManifest, infrastructure);
                        }

                        // Record last boot up time
                        Utility.SaveNodeLastBootUpTimeToRegistry(lastBootUpTimeFromSystem);
                    }
                }
                else
                {
                    DeployerTrace.WriteInfo("Skipping container network reset on reboot because SkipContainerNetworkResetOnReboot flag is enabled.");
                }
            }
            #endregion
#endif

#if !DotNetCoreClrIOT
            if (parameters.ContainerDnsSetup == ContainerDnsSetup.Allow || parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
            {
                try
                {
                    string currentNodeIPAddressOrFQDN = string.Empty;
                    if ((infrastructure != null) && (infrastructure.InfrastructureNodes != null))
                    {
                        foreach (var infraNode in infrastructure.InfrastructureNodes)
                        {
                            DeployerTrace.WriteInfo("Infra node <{0}> params.NodeName <{1}>", infraNode.NodeName, parameters.NodeName);
                            if (NetworkApiHelper.IsAddressForThisMachine(infraNode.IPAddressOrFQDN))
                            {
                                currentNodeIPAddressOrFQDN = infraNode.IPAddressOrFQDN;
                                DeployerTrace.WriteInfo("Found node IPAddressOrFQDN <{0}>", currentNodeIPAddressOrFQDN);
                                break;
                            }
                        }
                    }

                    new DockerDnsHelper(parameters, currentNodeIPAddressOrFQDN).SetupAsync().GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    if (parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
                    {
                        DeployerTrace.WriteError(
                            StringResources.Error_FabricDeployer_DockerDnsSetup_ErrorNotContinuing,
                            Constants.ParameterNames.ContainerDnsSetup,
                            parameters.ContainerDnsSetup,
                            ex);
                        throw;
                    }

                    DeployerTrace.WriteWarning(
                        StringResources.Warning_FabricDeployer_DockerDnsSetup_ErrorContinuing,
                        Constants.ParameterNames.ContainerDnsSetup,
                        parameters.ContainerDnsSetup,
                        ex);
                }
            }
            else if (parameters.ContainerDnsSetup == ContainerDnsSetup.Disallow)
            {
                // cleanupasync catches all exceptions
                new DockerDnsHelper(parameters, string.Empty).CleanupAsync().GetAwaiter().GetResult();
            }
#endif

#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            if (!PerformanceCounters.StartCollection(clusterManifest.FabricSettings, parameters.DeploymentSpecification))
            {
                DeployerTrace.WriteWarning(StringResources.Error_FabricDeployer_StartCounterCollectionFailed_Formatted);
            }

            if (fabricValidator.ShouldRegisterSpnForMachineAccount)
            {
                if (!SpnManager.EnsureSpn())
                {
                    throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_FailedToRegisterSpn_Formatted);
                }
            }
#endif
        }
예제 #8
0
 public void Cleanup()
 {
     FirewallManager.DisableFirewallSettings();
     TestFirewallManiuplator.Enable();
 }