Mesos源码分析(3): Mesos Master的启动之二

2. process::firewall::install(move(rules));如果有参数--firewall_rules则会添加规则

 

对应的代码如下:

  1. // Initialize firewall rules.
  2. if (flags.firewall_rules.isSome()) {
  3.   vector<Owned<FirewallRule>> rules;
  4.  
  5.   const Firewall firewall = flags.firewall_rules.get();
  6.  
  7.   if (firewall.has_disabled_endpoints()) {
  8.     hashset<string> paths;
  9.  
  10.     foreach (const string& path, firewall.disabled_endpoints().paths()) {
  11.       paths.insert(path);
  12.     }
  13.  
  14.     rules.emplace_back(new DisabledEndpointsFirewallRule(paths));
  15.   }
  16.  
  17.   process::firewall::install(move(rules));
  18. }

 

对应的命令行参数如下:

 

 

这个参数的主要作用为,并不是Mesos的每一个API都想暴露出来,disabled_endpoints里面就是不能访问的API。

 

上面的install的代码会做下面的事情

 

 

最终会放到环境变量firewallRules里面。

 

那这些firewall是什么事情起作用的呢?

 

在3rdparty/libprocess/src/process.cpp里面有函数

 

  1. synchronized (firewall_mutex) {
  2.   // Don't use a const reference, since it cannot be guaranteed
  3.   // that the rules don't keep an internal state.
  4.   foreach (Owned<firewall::FirewallRule>& rule, firewallRules) {
  5.     Option<Response> rejection = rule->apply(socket, *request);
  6.     if (rejection.isSome()) {
  7.       VLOG(1) << "Returning '"<< rejection.get().status << "' for '"
  8.               << request->url.path << "' (firewall rule forbids request)";
  9.  
  10.       // TODO(arojas): Get rid of the duplicated code to return an
  11.       // error.
  12.  
  13.       // Get the HttpProxy pid for this socket.
  14.       PID<HttpProxy> proxy = socket_manager->proxy(socket);
  15.  
  16.       // Enqueue the response with the HttpProxy so that it respects
  17.       // the order of requests to account for HTTP/1.1 pipelining.
  18.       dispatch(
  19.           proxy,
  20.           &HttpProxy::enqueue,
  21.           rejection.get(),
  22.           *request);
  23.  
  24.       // Cleanup request.
  25.       delete request;
  26.       return;
  27.     }
  28.   }
  29. }

 

posted @   popsuper1982  阅读(751)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
历史上的今天:
2014-07-24 Data Center手册(3): Load Balancer
2014-07-24 Data Center手册(2): 安全性
点击右上角即可分享
微信分享提示