paasta-tools 1.21.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- k8s_itests/__init__.py +0 -0
- k8s_itests/test_autoscaling.py +23 -0
- k8s_itests/utils.py +38 -0
- paasta_tools/__init__.py +20 -0
- paasta_tools/adhoc_tools.py +142 -0
- paasta_tools/api/__init__.py +13 -0
- paasta_tools/api/api.py +330 -0
- paasta_tools/api/api_docs/swagger.json +2323 -0
- paasta_tools/api/client.py +106 -0
- paasta_tools/api/settings.py +33 -0
- paasta_tools/api/tweens/__init__.py +6 -0
- paasta_tools/api/tweens/auth.py +125 -0
- paasta_tools/api/tweens/profiling.py +108 -0
- paasta_tools/api/tweens/request_logger.py +124 -0
- paasta_tools/api/views/__init__.py +13 -0
- paasta_tools/api/views/autoscaler.py +100 -0
- paasta_tools/api/views/exception.py +45 -0
- paasta_tools/api/views/flink.py +73 -0
- paasta_tools/api/views/instance.py +395 -0
- paasta_tools/api/views/pause_autoscaler.py +71 -0
- paasta_tools/api/views/remote_run.py +113 -0
- paasta_tools/api/views/resources.py +76 -0
- paasta_tools/api/views/service.py +35 -0
- paasta_tools/api/views/version.py +25 -0
- paasta_tools/apply_external_resources.py +79 -0
- paasta_tools/async_utils.py +109 -0
- paasta_tools/autoscaling/__init__.py +0 -0
- paasta_tools/autoscaling/autoscaling_service_lib.py +57 -0
- paasta_tools/autoscaling/forecasting.py +106 -0
- paasta_tools/autoscaling/max_all_k8s_services.py +41 -0
- paasta_tools/autoscaling/pause_service_autoscaler.py +77 -0
- paasta_tools/autoscaling/utils.py +52 -0
- paasta_tools/bounce_lib.py +184 -0
- paasta_tools/broadcast_log_to_services.py +62 -0
- paasta_tools/cassandracluster_tools.py +210 -0
- paasta_tools/check_autoscaler_max_instances.py +212 -0
- paasta_tools/check_cassandracluster_services_replication.py +35 -0
- paasta_tools/check_flink_services_health.py +203 -0
- paasta_tools/check_kubernetes_api.py +57 -0
- paasta_tools/check_kubernetes_services_replication.py +141 -0
- paasta_tools/check_oom_events.py +244 -0
- paasta_tools/check_services_replication_tools.py +324 -0
- paasta_tools/check_spark_jobs.py +234 -0
- paasta_tools/cleanup_kubernetes_cr.py +138 -0
- paasta_tools/cleanup_kubernetes_crd.py +145 -0
- paasta_tools/cleanup_kubernetes_jobs.py +344 -0
- paasta_tools/cleanup_tron_namespaces.py +96 -0
- paasta_tools/cli/__init__.py +13 -0
- paasta_tools/cli/authentication.py +85 -0
- paasta_tools/cli/cli.py +260 -0
- paasta_tools/cli/cmds/__init__.py +13 -0
- paasta_tools/cli/cmds/autoscale.py +143 -0
- paasta_tools/cli/cmds/check.py +334 -0
- paasta_tools/cli/cmds/cook_image.py +147 -0
- paasta_tools/cli/cmds/get_docker_image.py +76 -0
- paasta_tools/cli/cmds/get_image_version.py +172 -0
- paasta_tools/cli/cmds/get_latest_deployment.py +93 -0
- paasta_tools/cli/cmds/info.py +155 -0
- paasta_tools/cli/cmds/itest.py +117 -0
- paasta_tools/cli/cmds/list.py +66 -0
- paasta_tools/cli/cmds/list_clusters.py +42 -0
- paasta_tools/cli/cmds/list_deploy_queue.py +171 -0
- paasta_tools/cli/cmds/list_namespaces.py +84 -0
- paasta_tools/cli/cmds/local_run.py +1396 -0
- paasta_tools/cli/cmds/logs.py +1601 -0
- paasta_tools/cli/cmds/mark_for_deployment.py +1988 -0
- paasta_tools/cli/cmds/mesh_status.py +174 -0
- paasta_tools/cli/cmds/pause_service_autoscaler.py +107 -0
- paasta_tools/cli/cmds/push_to_registry.py +275 -0
- paasta_tools/cli/cmds/remote_run.py +252 -0
- paasta_tools/cli/cmds/rollback.py +347 -0
- paasta_tools/cli/cmds/secret.py +549 -0
- paasta_tools/cli/cmds/security_check.py +59 -0
- paasta_tools/cli/cmds/spark_run.py +1400 -0
- paasta_tools/cli/cmds/start_stop_restart.py +401 -0
- paasta_tools/cli/cmds/status.py +2302 -0
- paasta_tools/cli/cmds/validate.py +1012 -0
- paasta_tools/cli/cmds/wait_for_deployment.py +275 -0
- paasta_tools/cli/fsm/__init__.py +13 -0
- paasta_tools/cli/fsm/autosuggest.py +82 -0
- paasta_tools/cli/fsm/template/README.md +8 -0
- paasta_tools/cli/fsm/template/cookiecutter.json +7 -0
- paasta_tools/cli/fsm/template/{{cookiecutter.service}}/kubernetes-PROD.yaml +91 -0
- paasta_tools/cli/fsm/template/{{cookiecutter.service}}/monitoring.yaml +20 -0
- paasta_tools/cli/fsm/template/{{cookiecutter.service}}/service.yaml +8 -0
- paasta_tools/cli/fsm/template/{{cookiecutter.service}}/smartstack.yaml +6 -0
- paasta_tools/cli/fsm_cmd.py +121 -0
- paasta_tools/cli/paasta_tabcomplete.sh +23 -0
- paasta_tools/cli/schemas/adhoc_schema.json +199 -0
- paasta_tools/cli/schemas/autoscaling_schema.json +91 -0
- paasta_tools/cli/schemas/autotuned_defaults/cassandracluster_schema.json +37 -0
- paasta_tools/cli/schemas/autotuned_defaults/kubernetes_schema.json +89 -0
- paasta_tools/cli/schemas/deploy_schema.json +173 -0
- paasta_tools/cli/schemas/eks_schema.json +970 -0
- paasta_tools/cli/schemas/kubernetes_schema.json +970 -0
- paasta_tools/cli/schemas/rollback_schema.json +160 -0
- paasta_tools/cli/schemas/service_schema.json +25 -0
- paasta_tools/cli/schemas/smartstack_schema.json +322 -0
- paasta_tools/cli/schemas/tron_schema.json +699 -0
- paasta_tools/cli/utils.py +1118 -0
- paasta_tools/clusterman.py +21 -0
- paasta_tools/config_utils.py +385 -0
- paasta_tools/contrib/__init__.py +0 -0
- paasta_tools/contrib/bounce_log_latency_parser.py +68 -0
- paasta_tools/contrib/check_manual_oapi_changes.sh +24 -0
- paasta_tools/contrib/check_orphans.py +306 -0
- paasta_tools/contrib/create_dynamodb_table.py +35 -0
- paasta_tools/contrib/create_paasta_playground.py +105 -0
- paasta_tools/contrib/emit_allocated_cpu_metrics.py +50 -0
- paasta_tools/contrib/get_running_task_allocation.py +346 -0
- paasta_tools/contrib/habitat_fixer.py +86 -0
- paasta_tools/contrib/ide_helper.py +316 -0
- paasta_tools/contrib/is_pod_healthy_in_proxy.py +139 -0
- paasta_tools/contrib/is_pod_healthy_in_smartstack.py +50 -0
- paasta_tools/contrib/kill_bad_containers.py +109 -0
- paasta_tools/contrib/mass-deploy-tag.sh +44 -0
- paasta_tools/contrib/mock_patch_checker.py +86 -0
- paasta_tools/contrib/paasta_update_soa_memcpu.py +520 -0
- paasta_tools/contrib/render_template.py +129 -0
- paasta_tools/contrib/rightsizer_soaconfigs_update.py +348 -0
- paasta_tools/contrib/service_shard_remove.py +157 -0
- paasta_tools/contrib/service_shard_update.py +373 -0
- paasta_tools/contrib/shared_ip_check.py +77 -0
- paasta_tools/contrib/timeouts_metrics_prom.py +64 -0
- paasta_tools/delete_kubernetes_deployments.py +89 -0
- paasta_tools/deployment_utils.py +44 -0
- paasta_tools/docker_wrapper.py +234 -0
- paasta_tools/docker_wrapper_imports.py +13 -0
- paasta_tools/drain_lib.py +351 -0
- paasta_tools/dump_locally_running_services.py +71 -0
- paasta_tools/eks_tools.py +119 -0
- paasta_tools/envoy_tools.py +373 -0
- paasta_tools/firewall.py +504 -0
- paasta_tools/firewall_logging.py +154 -0
- paasta_tools/firewall_update.py +172 -0
- paasta_tools/flink_tools.py +345 -0
- paasta_tools/flinkeks_tools.py +90 -0
- paasta_tools/frameworks/__init__.py +0 -0
- paasta_tools/frameworks/adhoc_scheduler.py +71 -0
- paasta_tools/frameworks/constraints.py +87 -0
- paasta_tools/frameworks/native_scheduler.py +652 -0
- paasta_tools/frameworks/native_service_config.py +301 -0
- paasta_tools/frameworks/task_store.py +245 -0
- paasta_tools/generate_all_deployments +9 -0
- paasta_tools/generate_authenticating_services.py +94 -0
- paasta_tools/generate_deployments_for_service.py +255 -0
- paasta_tools/generate_services_file.py +114 -0
- paasta_tools/generate_services_yaml.py +30 -0
- paasta_tools/hacheck.py +76 -0
- paasta_tools/instance/__init__.py +0 -0
- paasta_tools/instance/hpa_metrics_parser.py +122 -0
- paasta_tools/instance/kubernetes.py +1362 -0
- paasta_tools/iptables.py +240 -0
- paasta_tools/kafkacluster_tools.py +143 -0
- paasta_tools/kubernetes/__init__.py +0 -0
- paasta_tools/kubernetes/application/__init__.py +0 -0
- paasta_tools/kubernetes/application/controller_wrappers.py +476 -0
- paasta_tools/kubernetes/application/tools.py +90 -0
- paasta_tools/kubernetes/bin/__init__.py +0 -0
- paasta_tools/kubernetes/bin/kubernetes_remove_evicted_pods.py +164 -0
- paasta_tools/kubernetes/bin/paasta_cleanup_remote_run_resources.py +135 -0
- paasta_tools/kubernetes/bin/paasta_cleanup_stale_nodes.py +181 -0
- paasta_tools/kubernetes/bin/paasta_secrets_sync.py +758 -0
- paasta_tools/kubernetes/remote_run.py +558 -0
- paasta_tools/kubernetes_tools.py +4679 -0
- paasta_tools/list_kubernetes_service_instances.py +128 -0
- paasta_tools/list_tron_namespaces.py +60 -0
- paasta_tools/long_running_service_tools.py +678 -0
- paasta_tools/mac_address.py +44 -0
- paasta_tools/marathon_dashboard.py +0 -0
- paasta_tools/mesos/__init__.py +0 -0
- paasta_tools/mesos/cfg.py +46 -0
- paasta_tools/mesos/cluster.py +60 -0
- paasta_tools/mesos/exceptions.py +59 -0
- paasta_tools/mesos/framework.py +77 -0
- paasta_tools/mesos/log.py +48 -0
- paasta_tools/mesos/master.py +306 -0
- paasta_tools/mesos/mesos_file.py +169 -0
- paasta_tools/mesos/parallel.py +52 -0
- paasta_tools/mesos/slave.py +115 -0
- paasta_tools/mesos/task.py +94 -0
- paasta_tools/mesos/util.py +69 -0
- paasta_tools/mesos/zookeeper.py +37 -0
- paasta_tools/mesos_maintenance.py +848 -0
- paasta_tools/mesos_tools.py +1051 -0
- paasta_tools/metrics/__init__.py +0 -0
- paasta_tools/metrics/metastatus_lib.py +1110 -0
- paasta_tools/metrics/metrics_lib.py +217 -0
- paasta_tools/monitoring/__init__.py +13 -0
- paasta_tools/monitoring/check_k8s_api_performance.py +110 -0
- paasta_tools/monitoring_tools.py +652 -0
- paasta_tools/monkrelaycluster_tools.py +146 -0
- paasta_tools/nrtsearchservice_tools.py +143 -0
- paasta_tools/nrtsearchserviceeks_tools.py +68 -0
- paasta_tools/oom_logger.py +321 -0
- paasta_tools/paasta_deploy_tron_jobs +3 -0
- paasta_tools/paasta_execute_docker_command.py +123 -0
- paasta_tools/paasta_native_serviceinit.py +21 -0
- paasta_tools/paasta_service_config_loader.py +201 -0
- paasta_tools/paastaapi/__init__.py +29 -0
- paasta_tools/paastaapi/api/__init__.py +3 -0
- paasta_tools/paastaapi/api/autoscaler_api.py +302 -0
- paasta_tools/paastaapi/api/default_api.py +569 -0
- paasta_tools/paastaapi/api/remote_run_api.py +604 -0
- paasta_tools/paastaapi/api/resources_api.py +157 -0
- paasta_tools/paastaapi/api/service_api.py +1736 -0
- paasta_tools/paastaapi/api_client.py +818 -0
- paasta_tools/paastaapi/apis/__init__.py +22 -0
- paasta_tools/paastaapi/configuration.py +455 -0
- paasta_tools/paastaapi/exceptions.py +137 -0
- paasta_tools/paastaapi/model/__init__.py +5 -0
- paasta_tools/paastaapi/model/adhoc_launch_history.py +176 -0
- paasta_tools/paastaapi/model/autoscaler_count_msg.py +176 -0
- paasta_tools/paastaapi/model/deploy_queue.py +178 -0
- paasta_tools/paastaapi/model/deploy_queue_service_instance.py +194 -0
- paasta_tools/paastaapi/model/envoy_backend.py +185 -0
- paasta_tools/paastaapi/model/envoy_location.py +184 -0
- paasta_tools/paastaapi/model/envoy_status.py +181 -0
- paasta_tools/paastaapi/model/flink_cluster_overview.py +188 -0
- paasta_tools/paastaapi/model/flink_config.py +173 -0
- paasta_tools/paastaapi/model/flink_job.py +186 -0
- paasta_tools/paastaapi/model/flink_job_details.py +192 -0
- paasta_tools/paastaapi/model/flink_jobs.py +175 -0
- paasta_tools/paastaapi/model/float_and_error.py +173 -0
- paasta_tools/paastaapi/model/hpa_metric.py +176 -0
- paasta_tools/paastaapi/model/inline_object.py +170 -0
- paasta_tools/paastaapi/model/inline_response200.py +170 -0
- paasta_tools/paastaapi/model/inline_response2001.py +170 -0
- paasta_tools/paastaapi/model/instance_bounce_status.py +200 -0
- paasta_tools/paastaapi/model/instance_mesh_status.py +186 -0
- paasta_tools/paastaapi/model/instance_status.py +220 -0
- paasta_tools/paastaapi/model/instance_status_adhoc.py +187 -0
- paasta_tools/paastaapi/model/instance_status_cassandracluster.py +173 -0
- paasta_tools/paastaapi/model/instance_status_flink.py +173 -0
- paasta_tools/paastaapi/model/instance_status_kafkacluster.py +173 -0
- paasta_tools/paastaapi/model/instance_status_kubernetes.py +263 -0
- paasta_tools/paastaapi/model/instance_status_kubernetes_autoscaling_status.py +187 -0
- paasta_tools/paastaapi/model/instance_status_kubernetes_v2.py +197 -0
- paasta_tools/paastaapi/model/instance_status_tron.py +204 -0
- paasta_tools/paastaapi/model/instance_tasks.py +182 -0
- paasta_tools/paastaapi/model/integer_and_error.py +173 -0
- paasta_tools/paastaapi/model/kubernetes_container.py +178 -0
- paasta_tools/paastaapi/model/kubernetes_container_v2.py +219 -0
- paasta_tools/paastaapi/model/kubernetes_healthcheck.py +176 -0
- paasta_tools/paastaapi/model/kubernetes_pod.py +201 -0
- paasta_tools/paastaapi/model/kubernetes_pod_event.py +176 -0
- paasta_tools/paastaapi/model/kubernetes_pod_v2.py +213 -0
- paasta_tools/paastaapi/model/kubernetes_replica_set.py +185 -0
- paasta_tools/paastaapi/model/kubernetes_version.py +202 -0
- paasta_tools/paastaapi/model/remote_run_outcome.py +189 -0
- paasta_tools/paastaapi/model/remote_run_start.py +185 -0
- paasta_tools/paastaapi/model/remote_run_stop.py +176 -0
- paasta_tools/paastaapi/model/remote_run_token.py +173 -0
- paasta_tools/paastaapi/model/resource.py +187 -0
- paasta_tools/paastaapi/model/resource_item.py +187 -0
- paasta_tools/paastaapi/model/resource_value.py +176 -0
- paasta_tools/paastaapi/model/smartstack_backend.py +191 -0
- paasta_tools/paastaapi/model/smartstack_location.py +181 -0
- paasta_tools/paastaapi/model/smartstack_status.py +181 -0
- paasta_tools/paastaapi/model/task_tail_lines.py +176 -0
- paasta_tools/paastaapi/model_utils.py +1879 -0
- paasta_tools/paastaapi/models/__init__.py +62 -0
- paasta_tools/paastaapi/rest.py +287 -0
- paasta_tools/prune_completed_pods.py +220 -0
- paasta_tools/puppet_service_tools.py +59 -0
- paasta_tools/py.typed +1 -0
- paasta_tools/remote_git.py +127 -0
- paasta_tools/run-paasta-api-in-dev-mode.py +57 -0
- paasta_tools/run-paasta-api-playground.py +51 -0
- paasta_tools/secret_providers/__init__.py +66 -0
- paasta_tools/secret_providers/vault.py +214 -0
- paasta_tools/secret_tools.py +277 -0
- paasta_tools/setup_istio_mesh.py +353 -0
- paasta_tools/setup_kubernetes_cr.py +412 -0
- paasta_tools/setup_kubernetes_crd.py +138 -0
- paasta_tools/setup_kubernetes_internal_crd.py +154 -0
- paasta_tools/setup_kubernetes_job.py +353 -0
- paasta_tools/setup_prometheus_adapter_config.py +1028 -0
- paasta_tools/setup_tron_namespace.py +248 -0
- paasta_tools/slack.py +75 -0
- paasta_tools/smartstack_tools.py +676 -0
- paasta_tools/spark_tools.py +283 -0
- paasta_tools/synapse_srv_namespaces_fact.py +42 -0
- paasta_tools/tron/__init__.py +0 -0
- paasta_tools/tron/client.py +158 -0
- paasta_tools/tron/tron_command_context.py +194 -0
- paasta_tools/tron/tron_timeutils.py +101 -0
- paasta_tools/tron_tools.py +1448 -0
- paasta_tools/utils.py +4307 -0
- paasta_tools/yaml_tools.py +44 -0
- paasta_tools-1.21.3.data/scripts/apply_external_resources.py +79 -0
- paasta_tools-1.21.3.data/scripts/bounce_log_latency_parser.py +68 -0
- paasta_tools-1.21.3.data/scripts/check_autoscaler_max_instances.py +212 -0
- paasta_tools-1.21.3.data/scripts/check_cassandracluster_services_replication.py +35 -0
- paasta_tools-1.21.3.data/scripts/check_flink_services_health.py +203 -0
- paasta_tools-1.21.3.data/scripts/check_kubernetes_api.py +57 -0
- paasta_tools-1.21.3.data/scripts/check_kubernetes_services_replication.py +141 -0
- paasta_tools-1.21.3.data/scripts/check_manual_oapi_changes.sh +24 -0
- paasta_tools-1.21.3.data/scripts/check_oom_events.py +244 -0
- paasta_tools-1.21.3.data/scripts/check_orphans.py +306 -0
- paasta_tools-1.21.3.data/scripts/check_spark_jobs.py +234 -0
- paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_cr.py +138 -0
- paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_crd.py +145 -0
- paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_jobs.py +344 -0
- paasta_tools-1.21.3.data/scripts/create_dynamodb_table.py +35 -0
- paasta_tools-1.21.3.data/scripts/create_paasta_playground.py +105 -0
- paasta_tools-1.21.3.data/scripts/delete_kubernetes_deployments.py +89 -0
- paasta_tools-1.21.3.data/scripts/emit_allocated_cpu_metrics.py +50 -0
- paasta_tools-1.21.3.data/scripts/generate_all_deployments +9 -0
- paasta_tools-1.21.3.data/scripts/generate_authenticating_services.py +94 -0
- paasta_tools-1.21.3.data/scripts/generate_deployments_for_service.py +255 -0
- paasta_tools-1.21.3.data/scripts/generate_services_file.py +114 -0
- paasta_tools-1.21.3.data/scripts/generate_services_yaml.py +30 -0
- paasta_tools-1.21.3.data/scripts/get_running_task_allocation.py +346 -0
- paasta_tools-1.21.3.data/scripts/habitat_fixer.py +86 -0
- paasta_tools-1.21.3.data/scripts/ide_helper.py +316 -0
- paasta_tools-1.21.3.data/scripts/is_pod_healthy_in_proxy.py +139 -0
- paasta_tools-1.21.3.data/scripts/is_pod_healthy_in_smartstack.py +50 -0
- paasta_tools-1.21.3.data/scripts/kill_bad_containers.py +109 -0
- paasta_tools-1.21.3.data/scripts/kubernetes_remove_evicted_pods.py +164 -0
- paasta_tools-1.21.3.data/scripts/mass-deploy-tag.sh +44 -0
- paasta_tools-1.21.3.data/scripts/mock_patch_checker.py +86 -0
- paasta_tools-1.21.3.data/scripts/paasta_cleanup_remote_run_resources.py +135 -0
- paasta_tools-1.21.3.data/scripts/paasta_cleanup_stale_nodes.py +181 -0
- paasta_tools-1.21.3.data/scripts/paasta_deploy_tron_jobs +3 -0
- paasta_tools-1.21.3.data/scripts/paasta_execute_docker_command.py +123 -0
- paasta_tools-1.21.3.data/scripts/paasta_secrets_sync.py +758 -0
- paasta_tools-1.21.3.data/scripts/paasta_tabcomplete.sh +23 -0
- paasta_tools-1.21.3.data/scripts/paasta_update_soa_memcpu.py +520 -0
- paasta_tools-1.21.3.data/scripts/render_template.py +129 -0
- paasta_tools-1.21.3.data/scripts/rightsizer_soaconfigs_update.py +348 -0
- paasta_tools-1.21.3.data/scripts/service_shard_remove.py +157 -0
- paasta_tools-1.21.3.data/scripts/service_shard_update.py +373 -0
- paasta_tools-1.21.3.data/scripts/setup_istio_mesh.py +353 -0
- paasta_tools-1.21.3.data/scripts/setup_kubernetes_cr.py +412 -0
- paasta_tools-1.21.3.data/scripts/setup_kubernetes_crd.py +138 -0
- paasta_tools-1.21.3.data/scripts/setup_kubernetes_internal_crd.py +154 -0
- paasta_tools-1.21.3.data/scripts/setup_kubernetes_job.py +353 -0
- paasta_tools-1.21.3.data/scripts/setup_prometheus_adapter_config.py +1028 -0
- paasta_tools-1.21.3.data/scripts/shared_ip_check.py +77 -0
- paasta_tools-1.21.3.data/scripts/synapse_srv_namespaces_fact.py +42 -0
- paasta_tools-1.21.3.data/scripts/timeouts_metrics_prom.py +64 -0
- paasta_tools-1.21.3.dist-info/LICENSE +201 -0
- paasta_tools-1.21.3.dist-info/METADATA +74 -0
- paasta_tools-1.21.3.dist-info/RECORD +348 -0
- paasta_tools-1.21.3.dist-info/WHEEL +5 -0
- paasta_tools-1.21.3.dist-info/entry_points.txt +20 -0
- paasta_tools-1.21.3.dist-info/top_level.txt +2 -0
paasta_tools/firewall.py
ADDED
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
import hashlib
|
|
3
|
+
import io
|
|
4
|
+
import ipaddress
|
|
5
|
+
import itertools
|
|
6
|
+
import json
|
|
7
|
+
import logging
|
|
8
|
+
import os.path
|
|
9
|
+
import re
|
|
10
|
+
from contextlib import contextmanager
|
|
11
|
+
|
|
12
|
+
from paasta_tools import iptables
|
|
13
|
+
from paasta_tools.cli.utils import get_instance_config
|
|
14
|
+
from paasta_tools.long_running_service_tools import get_all_namespaces_for_service
|
|
15
|
+
from paasta_tools.utils import get_running_mesos_docker_containers
|
|
16
|
+
from paasta_tools.utils import load_system_paasta_config
|
|
17
|
+
from paasta_tools.utils import NoConfigurationForServiceError
|
|
18
|
+
from paasta_tools.utils import timed_flock
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
INBOUND_PRIVATE_IP_RANGES = (
|
|
22
|
+
"127.0.0.0/255.0.0.0",
|
|
23
|
+
"169.254.0.0/255.255.0.0",
|
|
24
|
+
)
|
|
25
|
+
OUTBOUND_PRIVATE_IP_RANGES = (
|
|
26
|
+
"127.0.0.0/255.0.0.0",
|
|
27
|
+
"10.0.0.0/255.0.0.0",
|
|
28
|
+
"172.16.0.0/255.240.0.0",
|
|
29
|
+
"192.168.0.0/255.255.0.0",
|
|
30
|
+
"169.254.0.0/255.255.0.0",
|
|
31
|
+
)
|
|
32
|
+
DEFAULT_SYNAPSE_SERVICE_DIR = "/var/run/synapse/services"
|
|
33
|
+
DEFAULT_FIREWALL_FLOCK_PATH = "/var/lib/paasta/firewall.flock"
|
|
34
|
+
DEFAULT_FIREWALL_FLOCK_TIMEOUT_SECS = 5
|
|
35
|
+
|
|
36
|
+
RESOLV_CONF = "/etc/resolv.conf"
|
|
37
|
+
# not exactly correct, but sufficient to filter out ipv6 or other weird things
|
|
38
|
+
IPV4_REGEX = re.compile(r"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
log = logging.getLogger(__name__)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ServiceGroup(collections.namedtuple("ServiceGroup", ("service", "instance"))):
|
|
45
|
+
"""A service group.
|
|
46
|
+
|
|
47
|
+
:param service: service name
|
|
48
|
+
:param instance: instance name
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
__slots__ = ()
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def chain_name(self):
|
|
55
|
+
"""Return iptables chain name.
|
|
56
|
+
|
|
57
|
+
Chain names are limited to 28 characters, so we have to trim quite a
|
|
58
|
+
bit. To attempt to ensure we don't have collisions due to shortening,
|
|
59
|
+
we append a hash to the end.
|
|
60
|
+
"""
|
|
61
|
+
chain = "PAASTA.{}".format(self.service[:10])
|
|
62
|
+
chain += "." + hashlib.sha256(json.dumps(self).encode("utf8")).hexdigest()[:10]
|
|
63
|
+
assert len(chain) <= 28, len(chain)
|
|
64
|
+
return chain
|
|
65
|
+
|
|
66
|
+
def get_rules(self, soa_dir, synapse_service_dir):
|
|
67
|
+
try:
|
|
68
|
+
conf = get_instance_config(
|
|
69
|
+
self.service,
|
|
70
|
+
self.instance,
|
|
71
|
+
load_system_paasta_config().get_cluster(),
|
|
72
|
+
load_deployments=False,
|
|
73
|
+
soa_dir=soa_dir,
|
|
74
|
+
)
|
|
75
|
+
except NotImplementedError:
|
|
76
|
+
# PAASTA-11414: new instance types may not provide this configuration information;
|
|
77
|
+
# we don't want to break all of the firewall infrastructure when that happens
|
|
78
|
+
return ()
|
|
79
|
+
except NoConfigurationForServiceError:
|
|
80
|
+
# PAASTA-12050: a deleted service may still have containers running on PaaSTA hosts
|
|
81
|
+
# for several minutes after the directory disappears from soa-configs.
|
|
82
|
+
return ()
|
|
83
|
+
|
|
84
|
+
rules = list()
|
|
85
|
+
|
|
86
|
+
if conf.get_outbound_firewall():
|
|
87
|
+
rules.extend(_default_rules(conf, self.log_prefix))
|
|
88
|
+
rules.extend(_well_known_rules(conf))
|
|
89
|
+
rules.extend(_smartstack_rules(conf, soa_dir, synapse_service_dir))
|
|
90
|
+
rules.extend(_cidr_rules(conf))
|
|
91
|
+
|
|
92
|
+
return tuple(rules)
|
|
93
|
+
|
|
94
|
+
def update_rules(self, soa_dir, synapse_service_dir):
|
|
95
|
+
iptables.ensure_chain(
|
|
96
|
+
self.chain_name, self.get_rules(soa_dir, synapse_service_dir)
|
|
97
|
+
)
|
|
98
|
+
iptables.reorder_chain(self.chain_name)
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def log_prefix(self):
|
|
102
|
+
# log-prefix is limited to 29 characters total
|
|
103
|
+
# space at the end is necessary to separate it from the rest of the line
|
|
104
|
+
# no restrictions on any particular characters afaict
|
|
105
|
+
return f"paasta.{self.service}"[:28] + " "
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _default_rules(conf, log_prefix):
|
|
109
|
+
log_rule = iptables.Rule(
|
|
110
|
+
protocol="ip",
|
|
111
|
+
src="0.0.0.0/0.0.0.0",
|
|
112
|
+
dst="0.0.0.0/0.0.0.0",
|
|
113
|
+
target="LOG",
|
|
114
|
+
target_parameters=(("log-prefix", (log_prefix,)),),
|
|
115
|
+
matches=(("limit", (("limit", ("1/sec",)), ("limit-burst", ("1",)))),),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
policy = conf.get_outbound_firewall()
|
|
119
|
+
if policy == "block":
|
|
120
|
+
return (
|
|
121
|
+
iptables.Rule(
|
|
122
|
+
protocol="ip",
|
|
123
|
+
src="0.0.0.0/0.0.0.0",
|
|
124
|
+
dst="0.0.0.0/0.0.0.0",
|
|
125
|
+
target="REJECT",
|
|
126
|
+
matches=(),
|
|
127
|
+
target_parameters=((("reject-with", ("icmp-port-unreachable",))),),
|
|
128
|
+
),
|
|
129
|
+
log_rule,
|
|
130
|
+
)
|
|
131
|
+
elif policy == "monitor":
|
|
132
|
+
return (log_rule,)
|
|
133
|
+
else:
|
|
134
|
+
raise AssertionError(policy)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _well_known_rules(conf):
|
|
138
|
+
# Allow access to certain resources for all services by default.
|
|
139
|
+
yield iptables.Rule(
|
|
140
|
+
protocol="ip",
|
|
141
|
+
src="0.0.0.0/0.0.0.0",
|
|
142
|
+
dst="0.0.0.0/0.0.0.0",
|
|
143
|
+
target="PAASTA-COMMON",
|
|
144
|
+
matches=(),
|
|
145
|
+
target_parameters=(),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
for dep in conf.get_dependencies() or ():
|
|
149
|
+
resource = dep.get("well-known")
|
|
150
|
+
if resource == "internet":
|
|
151
|
+
yield iptables.Rule(
|
|
152
|
+
protocol="ip",
|
|
153
|
+
src="0.0.0.0/0.0.0.0",
|
|
154
|
+
dst="0.0.0.0/0.0.0.0",
|
|
155
|
+
target="PAASTA-INTERNET",
|
|
156
|
+
matches=(),
|
|
157
|
+
target_parameters=(),
|
|
158
|
+
)
|
|
159
|
+
elif resource is not None:
|
|
160
|
+
# TODO: handle better
|
|
161
|
+
raise AssertionError(resource)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _synapse_backends(synapse_service_dir, namespace):
|
|
165
|
+
# Return the contents of the synapse JSON file for a particular service namespace
|
|
166
|
+
# e.g. /var/run/synapse/services/example_happyhour.main.json
|
|
167
|
+
with open(
|
|
168
|
+
os.path.join(synapse_service_dir, namespace + ".json")
|
|
169
|
+
) as synapse_backend_file:
|
|
170
|
+
synapse_backend_json = json.load(synapse_backend_file)
|
|
171
|
+
return synapse_backend_json
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _yocalhost_rule(port, comment, protocol="tcp"):
|
|
175
|
+
"""Return an iptables rule allowing access to a yocalhost port."""
|
|
176
|
+
return iptables.Rule(
|
|
177
|
+
protocol=protocol,
|
|
178
|
+
src="0.0.0.0/0.0.0.0",
|
|
179
|
+
dst="169.254.255.254/255.255.255.255",
|
|
180
|
+
target="ACCEPT",
|
|
181
|
+
matches=(
|
|
182
|
+
("comment", (("comment", (comment,)),)),
|
|
183
|
+
(protocol, (("dport", (str(port),)),)),
|
|
184
|
+
),
|
|
185
|
+
target_parameters=(),
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _smartstack_rules(conf, soa_dir, synapse_service_dir):
|
|
190
|
+
for dep in conf.get_dependencies() or ():
|
|
191
|
+
namespace = dep.get("smartstack")
|
|
192
|
+
if namespace is None:
|
|
193
|
+
continue
|
|
194
|
+
|
|
195
|
+
# TODO: support wildcards
|
|
196
|
+
|
|
197
|
+
# synapse backends
|
|
198
|
+
try:
|
|
199
|
+
backends = _synapse_backends(synapse_service_dir, namespace)
|
|
200
|
+
except (OSError, IOError, ValueError):
|
|
201
|
+
# Don't fatal if something goes wrong loading the synapse files
|
|
202
|
+
log.exception(f"Unable to load backend {namespace}")
|
|
203
|
+
backends = ()
|
|
204
|
+
|
|
205
|
+
for backend in backends:
|
|
206
|
+
yield iptables.Rule(
|
|
207
|
+
protocol="tcp",
|
|
208
|
+
src="0.0.0.0/0.0.0.0",
|
|
209
|
+
dst="{}/255.255.255.255".format(backend["host"]),
|
|
210
|
+
target="ACCEPT",
|
|
211
|
+
matches=(
|
|
212
|
+
("comment", (("comment", ("backend " + namespace,)),)),
|
|
213
|
+
("tcp", (("dport", (str(backend["port"]),)),)),
|
|
214
|
+
),
|
|
215
|
+
target_parameters=(),
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
# synapse-haproxy proxy_port
|
|
219
|
+
service, _ = namespace.split(".", 1)
|
|
220
|
+
service_namespaces = get_all_namespaces_for_service(service, soa_dir=soa_dir)
|
|
221
|
+
port = dict(service_namespaces)[namespace]["proxy_port"]
|
|
222
|
+
yield _yocalhost_rule(port, "proxy_port " + namespace)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _ports_valid(ports):
|
|
226
|
+
for port in ports:
|
|
227
|
+
try:
|
|
228
|
+
port = int(port)
|
|
229
|
+
except ValueError:
|
|
230
|
+
log.exception(f"Unable to parse port: {port}")
|
|
231
|
+
return False
|
|
232
|
+
|
|
233
|
+
if not 1 <= port <= 65535:
|
|
234
|
+
log.error(f"Bogus port number: {port}")
|
|
235
|
+
return False
|
|
236
|
+
else:
|
|
237
|
+
return True
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _cidr_rules(conf):
|
|
241
|
+
for dep in conf.get_dependencies() or ():
|
|
242
|
+
cidr = dep.get("cidr")
|
|
243
|
+
port_str = dep.get("port")
|
|
244
|
+
|
|
245
|
+
if cidr is None:
|
|
246
|
+
continue
|
|
247
|
+
|
|
248
|
+
try:
|
|
249
|
+
network = ipaddress.IPv4Network(cidr)
|
|
250
|
+
except ipaddress.AddressValueError:
|
|
251
|
+
log.exception(f"Unable to parse IP network: {cidr}")
|
|
252
|
+
continue
|
|
253
|
+
|
|
254
|
+
if port_str is not None:
|
|
255
|
+
# port can be either a single port like "443" or a range like "1024:65535"
|
|
256
|
+
ports = str(port_str).split(":")
|
|
257
|
+
|
|
258
|
+
if len(ports) > 2:
|
|
259
|
+
log.error(
|
|
260
|
+
f'"port" must be either a single value or a range like "1024:65535": {port_str}'
|
|
261
|
+
)
|
|
262
|
+
continue
|
|
263
|
+
|
|
264
|
+
if not _ports_valid(ports):
|
|
265
|
+
continue
|
|
266
|
+
|
|
267
|
+
# Set up an ip rule if no port, or a tcp/udp rule if there is a port
|
|
268
|
+
dst = f"{network.network_address.exploded}/{network.netmask}"
|
|
269
|
+
if port_str is None:
|
|
270
|
+
yield iptables.Rule(
|
|
271
|
+
protocol="ip",
|
|
272
|
+
src="0.0.0.0/0.0.0.0",
|
|
273
|
+
dst=dst,
|
|
274
|
+
target="ACCEPT",
|
|
275
|
+
matches=(("comment", (("comment", (f"allow {network}:*",)),)),),
|
|
276
|
+
target_parameters=(),
|
|
277
|
+
)
|
|
278
|
+
else:
|
|
279
|
+
for proto in ("tcp", "udp"):
|
|
280
|
+
yield iptables.Rule(
|
|
281
|
+
protocol=proto,
|
|
282
|
+
src="0.0.0.0/0.0.0.0",
|
|
283
|
+
dst=dst,
|
|
284
|
+
target="ACCEPT",
|
|
285
|
+
matches=(
|
|
286
|
+
("comment", (("comment", (f"allow {network}:{port_str}",)),)),
|
|
287
|
+
(proto, (("dport", (str(port_str),)),)),
|
|
288
|
+
),
|
|
289
|
+
target_parameters=(),
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def services_running_here():
|
|
294
|
+
"""Generator helper that yields (service, instance, mac address) of both
|
|
295
|
+
mesos tasks.
|
|
296
|
+
"""
|
|
297
|
+
for container in get_running_mesos_docker_containers():
|
|
298
|
+
if container["HostConfig"]["NetworkMode"] != "bridge":
|
|
299
|
+
continue
|
|
300
|
+
|
|
301
|
+
service = container["Labels"].get("paasta_service")
|
|
302
|
+
instance = container["Labels"].get("paasta_instance")
|
|
303
|
+
|
|
304
|
+
if service is None or instance is None:
|
|
305
|
+
continue
|
|
306
|
+
|
|
307
|
+
network_info = container["NetworkSettings"]["Networks"]["bridge"]
|
|
308
|
+
|
|
309
|
+
mac = network_info["MacAddress"]
|
|
310
|
+
ip = network_info["IPAddress"]
|
|
311
|
+
yield service, instance, mac, ip
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def active_service_groups():
|
|
315
|
+
"""Return active service groups."""
|
|
316
|
+
service_groups = collections.defaultdict(set)
|
|
317
|
+
for service, instance, mac, ip in services_running_here():
|
|
318
|
+
# TODO: only include macs that start with MAC_ADDRESS_PREFIX?
|
|
319
|
+
service_groups[ServiceGroup(service, instance)].add(mac)
|
|
320
|
+
return service_groups
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def _dns_servers():
|
|
324
|
+
with io.open(RESOLV_CONF) as f:
|
|
325
|
+
for line in f:
|
|
326
|
+
parts = line.split()
|
|
327
|
+
if (
|
|
328
|
+
len(parts) == 2
|
|
329
|
+
and parts[0] == "nameserver"
|
|
330
|
+
and IPV4_REGEX.match(parts[1])
|
|
331
|
+
):
|
|
332
|
+
yield parts[1]
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def ensure_shared_chains():
|
|
336
|
+
_ensure_dns_chain()
|
|
337
|
+
_ensure_internet_chain()
|
|
338
|
+
_ensure_common_chain()
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _ensure_common_chain():
|
|
342
|
+
"""The common chain allows access for all services to certain resources."""
|
|
343
|
+
iptables.ensure_chain(
|
|
344
|
+
"PAASTA-COMMON",
|
|
345
|
+
(
|
|
346
|
+
# Allow return traffic for incoming connections
|
|
347
|
+
iptables.Rule(
|
|
348
|
+
protocol="ip",
|
|
349
|
+
src="0.0.0.0/0.0.0.0",
|
|
350
|
+
dst="0.0.0.0/0.0.0.0",
|
|
351
|
+
target="ACCEPT",
|
|
352
|
+
matches=(("conntrack", (("ctstate", ("ESTABLISHED",)),)),),
|
|
353
|
+
target_parameters=(),
|
|
354
|
+
),
|
|
355
|
+
_yocalhost_rule(1463, "scribed"),
|
|
356
|
+
_yocalhost_rule(8125, "metrics-relay", protocol="udp"),
|
|
357
|
+
_yocalhost_rule(3030, "sensu"),
|
|
358
|
+
iptables.Rule(
|
|
359
|
+
protocol="ip",
|
|
360
|
+
src="0.0.0.0/0.0.0.0",
|
|
361
|
+
dst="0.0.0.0/0.0.0.0",
|
|
362
|
+
target="PAASTA-DNS",
|
|
363
|
+
matches=(),
|
|
364
|
+
target_parameters=(),
|
|
365
|
+
),
|
|
366
|
+
),
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def _ensure_dns_chain():
|
|
371
|
+
iptables.ensure_chain(
|
|
372
|
+
"PAASTA-DNS",
|
|
373
|
+
tuple(
|
|
374
|
+
itertools.chain.from_iterable(
|
|
375
|
+
(
|
|
376
|
+
iptables.Rule(
|
|
377
|
+
protocol="udp",
|
|
378
|
+
src="0.0.0.0/0.0.0.0",
|
|
379
|
+
dst=f"{dns_server}/255.255.255.255",
|
|
380
|
+
target="ACCEPT",
|
|
381
|
+
matches=(("udp", (("dport", ("53",)),)),),
|
|
382
|
+
target_parameters=(),
|
|
383
|
+
),
|
|
384
|
+
# DNS goes over TCP sometimes, too!
|
|
385
|
+
iptables.Rule(
|
|
386
|
+
protocol="tcp",
|
|
387
|
+
src="0.0.0.0/0.0.0.0",
|
|
388
|
+
dst=f"{dns_server}/255.255.255.255",
|
|
389
|
+
target="ACCEPT",
|
|
390
|
+
matches=(("tcp", (("dport", ("53",)),)),),
|
|
391
|
+
target_parameters=(),
|
|
392
|
+
),
|
|
393
|
+
)
|
|
394
|
+
for dns_server in _dns_servers()
|
|
395
|
+
)
|
|
396
|
+
),
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def _ensure_internet_chain():
|
|
401
|
+
iptables.ensure_chain(
|
|
402
|
+
"PAASTA-INTERNET",
|
|
403
|
+
(
|
|
404
|
+
iptables.Rule(
|
|
405
|
+
protocol="ip",
|
|
406
|
+
src="0.0.0.0/0.0.0.0",
|
|
407
|
+
dst="0.0.0.0/0.0.0.0",
|
|
408
|
+
target="ACCEPT",
|
|
409
|
+
matches=(),
|
|
410
|
+
target_parameters=(),
|
|
411
|
+
),
|
|
412
|
+
)
|
|
413
|
+
+ tuple(
|
|
414
|
+
iptables.Rule(
|
|
415
|
+
protocol="ip",
|
|
416
|
+
src="0.0.0.0/0.0.0.0",
|
|
417
|
+
dst=ip_range,
|
|
418
|
+
target="RETURN",
|
|
419
|
+
matches=(),
|
|
420
|
+
target_parameters=(),
|
|
421
|
+
)
|
|
422
|
+
for ip_range in OUTBOUND_PRIVATE_IP_RANGES
|
|
423
|
+
),
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def ensure_service_chains(service_groups, soa_dir, synapse_service_dir):
|
|
428
|
+
"""Ensure service chains exist and have the right rules.
|
|
429
|
+
|
|
430
|
+
service_groups is a dict {ServiceGroup: set([mac_address..])}
|
|
431
|
+
|
|
432
|
+
Returns dictionary {[service chain] => [list of mac addresses]}.
|
|
433
|
+
"""
|
|
434
|
+
chains = {}
|
|
435
|
+
for service, macs in service_groups.items():
|
|
436
|
+
service.update_rules(soa_dir, synapse_service_dir)
|
|
437
|
+
chains[service.chain_name] = macs
|
|
438
|
+
return chains
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
def dispatch_rule(chain, mac):
|
|
442
|
+
return iptables.Rule(
|
|
443
|
+
protocol="ip",
|
|
444
|
+
src="0.0.0.0/0.0.0.0",
|
|
445
|
+
dst="0.0.0.0/0.0.0.0",
|
|
446
|
+
target=chain,
|
|
447
|
+
matches=(("mac", (("mac-source", (mac.upper(),)),)),),
|
|
448
|
+
target_parameters=(),
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def ensure_dispatch_chains(service_chains):
|
|
453
|
+
paasta_rules = set(
|
|
454
|
+
itertools.chain.from_iterable(
|
|
455
|
+
(dispatch_rule(chain, mac) for mac in macs)
|
|
456
|
+
for chain, macs in service_chains.items()
|
|
457
|
+
)
|
|
458
|
+
)
|
|
459
|
+
iptables.ensure_chain("PAASTA", paasta_rules)
|
|
460
|
+
|
|
461
|
+
jump_to_paasta = iptables.Rule(
|
|
462
|
+
protocol="ip",
|
|
463
|
+
src="0.0.0.0/0.0.0.0",
|
|
464
|
+
dst="0.0.0.0/0.0.0.0",
|
|
465
|
+
target="PAASTA",
|
|
466
|
+
matches=(),
|
|
467
|
+
target_parameters=(),
|
|
468
|
+
)
|
|
469
|
+
iptables.ensure_rule("INPUT", jump_to_paasta)
|
|
470
|
+
iptables.ensure_rule("FORWARD", jump_to_paasta)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def garbage_collect_old_service_chains(desired_chains):
|
|
474
|
+
current_paasta_chains = {
|
|
475
|
+
chain for chain in iptables.all_chains() if chain.startswith("PAASTA.")
|
|
476
|
+
}
|
|
477
|
+
for chain in current_paasta_chains - set(desired_chains):
|
|
478
|
+
iptables.delete_chain(chain)
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def general_update(soa_dir, synapse_service_dir):
|
|
482
|
+
"""Update iptables to match the current PaaSTA state."""
|
|
483
|
+
ensure_shared_chains()
|
|
484
|
+
service_chains = ensure_service_chains(
|
|
485
|
+
active_service_groups(), soa_dir, synapse_service_dir
|
|
486
|
+
)
|
|
487
|
+
ensure_dispatch_chains(service_chains)
|
|
488
|
+
garbage_collect_old_service_chains(service_chains)
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
def prepare_new_container(soa_dir, synapse_service_dir, service, instance, mac):
|
|
492
|
+
"""Update iptables to include rules for a new (not yet running) MAC address"""
|
|
493
|
+
ensure_shared_chains() # probably already set, but just to be safe
|
|
494
|
+
service_group = ServiceGroup(service, instance)
|
|
495
|
+
service_group.update_rules(soa_dir, synapse_service_dir)
|
|
496
|
+
iptables.insert_rule("PAASTA", dispatch_rule(service_group.chain_name, mac))
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
@contextmanager
|
|
500
|
+
def firewall_flock(flock_path=DEFAULT_FIREWALL_FLOCK_PATH):
|
|
501
|
+
"""Grab an exclusive flock to avoid concurrent iptables updates"""
|
|
502
|
+
with io.FileIO(flock_path, "w") as f:
|
|
503
|
+
with timed_flock(f, seconds=DEFAULT_FIREWALL_FLOCK_TIMEOUT_SECS):
|
|
504
|
+
yield
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import signal
|
|
5
|
+
import socket
|
|
6
|
+
import socketserver
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
import syslogmp
|
|
10
|
+
|
|
11
|
+
from paasta_tools.firewall import services_running_here
|
|
12
|
+
from paasta_tools.utils import _log
|
|
13
|
+
from paasta_tools.utils import configure_log
|
|
14
|
+
from paasta_tools.utils import load_system_paasta_config
|
|
15
|
+
|
|
16
|
+
DEFAULT_NUM_WORKERS = 5
|
|
17
|
+
|
|
18
|
+
log = logging.getLogger(__name__)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SyslogUDPHandler(socketserver.BaseRequestHandler):
|
|
22
|
+
def setup(self):
|
|
23
|
+
configure_log()
|
|
24
|
+
self.cluster = load_system_paasta_config().get_cluster()
|
|
25
|
+
|
|
26
|
+
def handle(self):
|
|
27
|
+
data, socket = self.request
|
|
28
|
+
syslog_to_paasta_log(data, self.cluster)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def syslog_to_paasta_log(data, cluster):
|
|
32
|
+
iptables_log = parse_syslog(data)
|
|
33
|
+
if iptables_log is None:
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
service, instance = lookup_service_instance_by_ip(iptables_log["SRC"])
|
|
37
|
+
if service is None or instance is None:
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
# prepend hostname
|
|
41
|
+
log_line = iptables_log["hostname"] + ": " + iptables_log["message"]
|
|
42
|
+
|
|
43
|
+
_log(
|
|
44
|
+
service=service,
|
|
45
|
+
component="security",
|
|
46
|
+
level="debug",
|
|
47
|
+
cluster=cluster,
|
|
48
|
+
instance=instance,
|
|
49
|
+
line=log_line,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def parse_syslog(data):
|
|
54
|
+
parsed_data = syslogmp.parse(data)
|
|
55
|
+
try:
|
|
56
|
+
full_message = parsed_data.message.decode()
|
|
57
|
+
except UnicodeDecodeError:
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
if not full_message.startswith("kernel: ["):
|
|
61
|
+
# Not a kernel message
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
close_bracket = full_message.find("]")
|
|
65
|
+
if close_bracket == -1:
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
iptables_message = full_message[close_bracket + 1 :].strip()
|
|
69
|
+
parts = iptables_message.split(" ")
|
|
70
|
+
|
|
71
|
+
# parts[0] is the log-prefix
|
|
72
|
+
# parts[1..] is either KEY=VALUE or just KEY
|
|
73
|
+
if not parts[1].startswith("IN="):
|
|
74
|
+
# not an iptables message
|
|
75
|
+
return None
|
|
76
|
+
|
|
77
|
+
fields = {k: v for k, _, v in (field.partition("=") for field in parts[1:])}
|
|
78
|
+
|
|
79
|
+
fields["hostname"] = parsed_data.hostname
|
|
80
|
+
fields["message"] = iptables_message
|
|
81
|
+
return fields
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def lookup_service_instance_by_ip(ip_lookup):
|
|
85
|
+
for service, instance, mac, ip in services_running_here():
|
|
86
|
+
if ip == ip_lookup:
|
|
87
|
+
return (service, instance)
|
|
88
|
+
log.info(f"Unable to find container for ip {ip_lookup}")
|
|
89
|
+
return (None, None)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def parse_args(argv=None):
|
|
93
|
+
parser = argparse.ArgumentParser(
|
|
94
|
+
description="Adapts iptables syslog messages into scribe"
|
|
95
|
+
)
|
|
96
|
+
parser.add_argument(
|
|
97
|
+
"-v", "--verbose", action="store_true", dest="verbose", default=False
|
|
98
|
+
)
|
|
99
|
+
parser.add_argument(
|
|
100
|
+
"-l", "--listen-host", help="Default %(default)s", default="127.0.0.1"
|
|
101
|
+
)
|
|
102
|
+
parser.add_argument(
|
|
103
|
+
"-p", "--listen-port", type=int, help="Default %(default)s", default=1516
|
|
104
|
+
)
|
|
105
|
+
parser.add_argument(
|
|
106
|
+
"-w",
|
|
107
|
+
"--num-workers",
|
|
108
|
+
type=int,
|
|
109
|
+
help="Default %(default)s",
|
|
110
|
+
default=DEFAULT_NUM_WORKERS,
|
|
111
|
+
)
|
|
112
|
+
args = parser.parse_args(argv)
|
|
113
|
+
return args
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def setup_logging(verbose):
|
|
117
|
+
if verbose:
|
|
118
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
119
|
+
else:
|
|
120
|
+
logging.basicConfig(level=logging.WARNING)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class MultiUDPServer(socketserver.UDPServer):
|
|
124
|
+
# UDPServer with SO_REUSEPORT enabled so that incoming packets are
|
|
125
|
+
# load-balanced across listeners
|
|
126
|
+
def server_bind(self):
|
|
127
|
+
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
|
128
|
+
# UDPServer is old-style class so can't use super
|
|
129
|
+
socketserver.UDPServer.server_bind(self)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def run_server(listen_host, listen_port):
|
|
133
|
+
server = MultiUDPServer((listen_host, listen_port), SyslogUDPHandler)
|
|
134
|
+
server.serve_forever()
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def main(argv=None):
|
|
138
|
+
args = parse_args(argv)
|
|
139
|
+
setup_logging(args.verbose)
|
|
140
|
+
|
|
141
|
+
assert args.num_workers > 0
|
|
142
|
+
|
|
143
|
+
# start n-1 separate processes, then run_server() on this one
|
|
144
|
+
num_forks = args.num_workers - 1
|
|
145
|
+
for x in range(num_forks):
|
|
146
|
+
if os.fork() == 0:
|
|
147
|
+
run_server(args.listen_host, args.listen_port)
|
|
148
|
+
|
|
149
|
+
# propagate SIGTERM to all my children then exit
|
|
150
|
+
signal.signal(
|
|
151
|
+
signal.SIGTERM, lambda signum, _: os.killpg(os.getpid(), signum) or sys.exit(1)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
run_server(args.listen_host, args.listen_port)
|