<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=Blog%3AMicroservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5</id>
	<title>Blog:Microservice中的安全策略 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=Blog%3AMicroservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5"/>
	<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=Blog:Microservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5&amp;action=history"/>
	<updated>2026-06-02T22:48:20Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=Blog:Microservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5&amp;diff=2659&amp;oldid=prev</id>
		<title>2021年7月5日 (一) 04:49 Riguz</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=Blog:Microservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5&amp;diff=2659&amp;oldid=prev"/>
		<updated>2021-07-05T04:49:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年7月5日 (一) 04:49的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l45&quot;&gt;第45行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第45行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Distributed]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Distributed]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Pinned]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Riguz</name></author>
	</entry>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=Blog:Microservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5&amp;diff=2658&amp;oldid=prev</id>
		<title>2021年4月30日 (五) 07:03 Riguz</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=Blog:Microservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5&amp;diff=2658&amp;oldid=prev"/>
		<updated>2021-04-30T07:03:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年4月30日 (五) 07:03的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l42&quot;&gt;第42行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第42行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://microservices.io/patterns/apigateway.html Pattern: API Gateway / Backends for Frontends]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://microservices.io/patterns/apigateway.html Pattern: API Gateway / Backends for Frontends]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://livebook.manning.com/book/microservices-security-in-action/welcome/v-8/  Microservices Security in Action]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://livebook.manning.com/book/microservices-security-in-action/welcome/v-8/  Microservices Security in Action]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Distributed]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Riguz</name></author>
	</entry>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=Blog:Microservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5&amp;diff=2657&amp;oldid=prev</id>
		<title>imported&gt;Riguz：​最近在思考微服务中的安全问题，在读Chris Richardson的文章的时候，发现自己对微服务有了一些新的认识和理解:p。

如图所示是一个典型的微服务架构：

![Problem](/images/microservice_security_problem.png)

这个架构下有如下的需求场景：

* 不同的APP会消费微服务，通常需求会有差别
* 有些微服务还会希望暴露给第三方的系统进行消费
* 具体的服务通常在设计API的时候会尽量考虑通用，但是实际消费服务的时候并不能完全满足需求，还需要二次加工，或者将多个服务的调用进行组合。</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=Blog:Microservice%E4%B8%AD%E7%9A%84%E5%AE%89%E5%85%A8%E7%AD%96%E7%95%A5&amp;diff=2657&amp;oldid=prev"/>
		<updated>2020-12-04T00:00:00Z</updated>

		<summary type="html">&lt;p&gt;最近在思考微服务中的安全问题，在读Chris Richardson的文章的时候，发现自己对微服务有了一些新的认识和理解:p。  如图所示是一个典型的微服务架构：  ![Problem](/images/microservice_security_problem.png)  这个架构下有如下的需求场景：  * 不同的APP会消费微服务，通常需求会有差别 * 有些微服务还会希望暴露给第三方的系统进行消费 * 具体的服务通常在设计API的时候会尽量考虑通用，但是实际消费服务的时候并不能完全满足需求，还需要二次加工，或者将多个服务的调用进行组合。&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;最近在思考微服务中的安全问题，在读Chris Richardson的文章的时候，发现自己对微服务有了一些新的认识和理解:p。&lt;br /&gt;
&lt;br /&gt;
如图所示是一个典型的微服务架构：&lt;br /&gt;
&lt;br /&gt;
[[File:microservice_security_problem.png|600px|Problem]]&lt;br /&gt;
&lt;br /&gt;
这个架构下有如下的需求场景：&lt;br /&gt;
&lt;br /&gt;
* 不同的APP会消费微服务，通常需求会有差别&lt;br /&gt;
* 有些微服务还会希望暴露给第三方的系统进行消费&lt;br /&gt;
* 具体的服务通常在设计API的时候会尽量考虑通用，但是实际消费服务的时候并不能完全满足需求，还需要二次加工，或者将多个服务的调用进行组合。&lt;br /&gt;
&lt;br /&gt;
= BFF和API Gateway=&lt;br /&gt;
在微服务架构中，有两个比较常用的概念是”API Gateway“和”Backend for Frontend(BFF)“，实际上是为了解决不同的问题而产生的解决方法：&lt;br /&gt;
&lt;br /&gt;
* API Gateway解决了消费端消费微服务没有统一的入口的问题。通过API Gateway的路由，消费者只需要一个看起来“统一”的入口就可以调用所需的服务，而不是分别调用多个服务&lt;br /&gt;
* BFF解决问题是，有一些API并不是能够直接满足需求，需要进行组合、切割以及一些额外的逻辑进行处理，但将这些操作放在客户端解决可能会存在性能问题并对前端引入额外的复杂性。尤其是对于使用Native app技术（区别于传统的server side）的应用来说，欠缺在前端处理较为复杂的业务逻辑的能力，有的时候，微服务暴露的协议可能并不能直接在浏览器中支持，这会带来更大的麻烦。这些时候，一个server side的后端是很有必要的。&lt;br /&gt;
&lt;br /&gt;
一直以来比较困扰我的是，API Gateway和BFF这两个东西究竟应该如何使用，是应该把API Gateway放在入口，让所有消费者像消费一个单体服务一样来消费微服务；还是应该将&amp;quot;BFF&amp;quot;本身作为一个微服务，跟其他服务一样藏在API gateway之后呢？&lt;br /&gt;
&lt;br /&gt;
[[File:api_gateway_bff_confused.png|600px|API Gateway vs BFF]]&lt;br /&gt;
&lt;br /&gt;
之前的实践方式通常为一个API Gateway用Zuul实现，一个BFF就是一个正常的微服务，正是受限于这种方式导致一直以来我的误解是，API Gateway和BFF是两个不同的东西，是分开部署的；而没有思考这两个东西其实是解决不同维度的问题而产生的，其实是可以共存的一个概念。&lt;br /&gt;
&lt;br /&gt;
[[File:microservice_bff_and_api_gateway.png|600px|API Gateway vs BFF]]&lt;br /&gt;
&lt;br /&gt;
如上所示，第一种方法是对于不同的应用分别定制不同的BFF，这里实际上BFF也可以充当API Gateway的作用；而第二种对于不同的APP使用相同的API Gateway，同样也可以在其中实习定制化的逻辑，为消费者提供优化后的API。&lt;br /&gt;
&lt;br /&gt;
= 安全控制=&lt;br /&gt;
&lt;br /&gt;
[[File:api_gateway_oauth.png|600px|OAuth2 in Microservices]]&lt;br /&gt;
&lt;br /&gt;
如图所示，是一个使用Oauth2标准的授权访问流程，这里有几点值得关注：&lt;br /&gt;
&lt;br /&gt;
* API Gateway负责了access_token的验证以及刷新&lt;br /&gt;
* 后端service需要通过OAuth2 Server来校验access_token，因为access_token中并不包含任何的身份信息&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- tbd --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
&lt;br /&gt;
* [https://microservices.io/patterns/apigateway.html Pattern: API Gateway / Backends for Frontends]&lt;br /&gt;
* [https://livebook.manning.com/book/microservices-security-in-action/welcome/v-8/  Microservices Security in Action]&lt;/div&gt;</summary>
		<author><name>imported&gt;Riguz</name></author>
	</entry>
</feed>