转载自:

https://blog.csdn.net/UbuntuTouch/article/details/105527468

APM Agents 访问APM server如果不做安全的设置,那么任何一个应用都有可能把数据传输到APM server中。

如果是恶意的软件,那么我们可能得到的数据是错误的。那么怎么保证我们的安全传输呢?

答案是在传输的时候使用secret token。

Secret token 是什么?

您可以配置一个Secret token来授权对APM服务器的请求。 这样可以确保只有您的Agent才能将数据发送到您的APM服务器。

代理和APM服务器都必须配置相同的Secret toke,并且scecret token仅在与SSL/TLS结合使用时才提供安全性。

要使用Secret token 保护APM代理与APM服务器之间的通信安全:

  • 在APM服务器中启用SSL/TLS
  • 在Agent和服务器中设置Secret token
  • 在APM agent中启用HTTPS

生成证书

在Elasticsearch安装的根目录下打入如下的命令:

./bin/elasticsearch-certutil ca --pem

This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack. The 'ca' mode generates a new 'certificate authority'
This will create a new X.509 certificate and private key that can be used
to sign certificate when running in 'cert' mode. Use the 'ca-dn' option if you wish to configure the 'distinguished name'
of the certificate authority By default the 'ca' mode produces a single PKCS#12 output file which holds:
* The CA certificate
* The CA's private key If you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private key Please enter the desired output file [elastic-stack-ca.zip]:

上面的命令将会生成一个名字叫做elastic-stack-ca.zip的文件。我们接着使用如下的命令把上面的文件进行解压:

unzip elastic-stack-ca.zip
Archive: elastic-stack-ca.zip
creating: ca/
inflating: ca/ca.crt
inflating: ca/ca.key

在当前的目录下生成了一个新的目录ca,里面含有两个文件:ca.crt及ca.key。请注意这里的ca.crt证书将在我们一下的agent里将会被用到。 接下来,我们按照如下的命令来生成证书:

./bin/elasticsearch-certutil cert --ca-cert ./ca/ca.crt --ca-key ./ca/ca.key --pem --name localhost
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack. The 'cert' mode generates X.509 certificate and private keys.
* By default, this generates a single certificate and key for use
on a single instance.
* The '-multiple' option will prompt you to enter details for multiple
instances and will generate a certificate and key for each one
* The '-in' option allows for the certificate generation to be automated by describing
the details of each instance in a YAML file * An instance is any piece of the Elastic Stack that requires an SSL certificate.
Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
may all require a certificate and private key.
* The minimum required value for each instance is a name. This can simply be the
hostname, which will be used as the Common Name of the certificate. A full
distinguished name may also be used.
* A filename value may be required for each instance. This is necessary when the
name would result in an invalid file or directory name. The name provided here
is used as the directory name (within the zip) and the prefix for the key and
certificate files. The filename is required if you are prompted and the name
is not displayed in the prompt.
* IP addresses and DNS names are optional. Multiple values can be specified as a
comma separated string. If no IP addresses or DNS names are provided, you may
disable hostname verification in your SSL configuration. * All certificates generated by this tool will be signed by a certificate authority (CA).
* The tool can automatically generate a new CA for you, or you can provide your own with the
-ca or -ca-cert command line options. By default the 'cert' mode produces a single PKCS#12 output file which holds:
* The instance certificate
* The private key for the instance certificate
* The CA certificate If you specify any of the following options:
* -pem (PEM formatted output)
* -keep-ca-key (retain generated CA key)
* -multiple (generate multiple certificates)
* -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key files Please enter the desired output file [certificate-bundle.zip]: Certificates written to /Users/liuxg/elastic3/elasticsearch-7.6.2/certificate-bundle.zip This file should be properly secured as it contains the private key for
your instance. After unzipping the file, there will be a directory for each instance.
Each instance has a certificate and private key.
For each Elastic product that you wish to configure, you should copy
the certificate, key, and CA certificate to the relevant configuration directory
and then follow the SSL configuration instructions in the product guide. For client applications, you may only need to copy the CA certificate and
configure the client to trust this certificate.

在上面的命令中,我们生产一个绑定localhost的证书,也即是说这个证书只能在当前的localhost中进行使用。就像上面显示的那样,它在当前的目录中生产一个叫做certificate-bundle.zip的文件。这文件含有我们所需要的证书信息。我们使用如下的命令来解压缩这个文件:

unzip certificate-bundle.zip
Archive: certificate-bundle.zip
creating: localhost/
inflating: localhost/localhost.crt
inflating: localhost/localhost.key

它在localhost中生成了我们想要的证书文件localhost.crt及localhoset.key。我们把这两个文件拷入到我们的APM 服务器安装的根目录中。

另注:我们可以使用如下的命令把一个.crt的证书转换为一个.pem的证书:

openssl x509 -in mycert.crt -out mycert.pem -outform PEM

配置APM 服务器

为我们的APM服务器配置SSL/TLS

打开apm-server.yml文件,并把如下的配置加到该文件的最后面:

apm-server.ssl.enabled: true
apm-server.secret_token: "123456"
apm-server.ssl.key: "localhost.key"
apm-server.ssl.certificate: "ca.crt"

通过上面的配置后,我们重新启动我们的APM server:

./apm-server -e

测试APM agent

把之前生成的ca.crt证书拷入到该应用的根目录中,然后再引用的配置中新增俩参数

    serviceName: 'zipcode service',
secretToken: '1234561', # 修改
serverUrl: 'http://localhost:8200'
verifyServerCert: true, # 新增
serverCaCertFile: "ca.crt" # 新增,最好使用绝对路径

Solutions:安全的APM服务器访问的更多相关文章

  1. Sqlserver通过链接服务器访问Oracle的那些事儿

    前言: 1.不经历风雨,怎能见彩虹. 2.充分利用BaiDu.google等搜索引擎查找资料并整合分析! 3.世上无难事只怕有心人! 本文由来:笔者在研究SQLSERVER链接服务器到oracle并使 ...

  2. 【转】Sqlserver通过链接服务器访问Oracle的那些事儿!

    原文:http://blog.sina.com.cn/s/blog_614b6f210100t80r.html 前言:1.不经历风雨,怎能见彩虹.2.充分利用BaiDu.google等搜索引擎查找资料 ...

  3. Sqlserver通过链接服务器访问Oracle的解决办法

    转自http://blog.sina.com.cn/s/blog_614b6f210100t80r.html 一.创建sqlserver链接服务(sqlserver链接oracle)  首先sqlse ...

  4. Sqlserver通过链接服务器访问Oracle

    工作中遇到的情况,win 7 64位操作系统的就安装64位的oracle 客户端,然后重启sql service服务后再创建sql 链接服务器.关于如何创建链接服务器请查看下面的大神的链接: http ...

  5. sql server 数据库创建链接服务器访问另外一个sql server 数据库

    继上篇在sql server中创建链接服务器访问oracle数据库:http://www.cnblogs.com/527289276qq/p/4770379.html 本文介绍在sql server中 ...

  6. SQL Server 2008作业失败无法确定所有者是否有服务器访问权限

    调用作业---错误提示内容 该作业失败. 无法确定所有者 WIN-3TH1KNIT12D\Administrator (拥有作业 Database_Backup.step1)是否有服务器访问权限 (原 ...

  7. SQL Server 2008作业失败:无法确定所有者是否有服务器访问权限

    转自:http://www.mzwu.com/article.asp?id=3592 下午准备将服务器数据导一份到本地,连上服务器找数据库备份文件发现最后一次备份是7月1日,竟然十几天没生成新备份,查 ...

  8. 自学Zabbix4.1 zabbix监控web服务器访问性能

    自学Zabbix4.1 zabbix监控web服务器访问性能 使用Zabbix实现对web性能的监控,通过它可以了解web站点的可用性以及性能.最终将各项指标绘制到图形中,这样我们可以了解到一个站点的 ...

  9. SQLServer跨服务器访问数据库(openrowset/opendatasource/openquery)

    SQLServer跨服务器访问数据库(openrowset/opendatasource/openquery) 1.启用Ad Hoc Distributed Queries 在使用openrowset ...

随机推荐

  1. Spring Bean 标签解析

    上一篇文章讲到了标签在 parseDefaultElement 方法中进行解析,本篇文章将讲解这部分内容 bean 标签解析 查看 processBeanDefinition 方法,针对各个操作作具体 ...

  2. 论文阅读 TEMPORAL GRAPH NETWORKS FOR DEEP LEARNING ON DYNAMIC GRAPHS

    14 TEMPORAL GRAPH NETWORKS FOR DEEP LEARNING ON DYNAMIC GRAPHS link:https://scholar.google.com.hk/sc ...

  3. 小A的柱状图_via牛客网

    题目 链接:https://ac.nowcoder.com/acm/contest/28537/Q 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语 ...

  4. 第一天python3 封装和解构

    封装 将多个值使用逗号分割,组合在一起:本质上,返回一个元组,只是省略了小括号:python特有语法,被很多语言学习和借鉴;比如javascript:t1=(1,2) 定义为元组:t2=1,2 将1和 ...

  5. Vue 状态管理之vuex && {mapState,mapGetters}

    1 # 一.理解vuex 2 1.概念:专门在Vue中实现集中式状态(数据)管理的一个Vue插件,对vue应用中多个组件的共享状态进行集中式的管理(读写),也是一种组件间通信的方式,且适用于任意组件间 ...

  6. Nginx 浏览器缓存配置指令

    # 浏览器缓存 # 当浏览器第一次访问服务器资源的时候,服务器返回到浏览器后,浏览器进行缓存 # 缓存的大概内容有: # 1.缓存过期的日期和时间 # 2.设置和缓存相关的配置信息 # 3.请求资源最 ...

  7. C#任务并行库TPL--Task应用

    一.概念 TPL的核心就是任务,一个任务代表一个异步操作,该操作可以通过多种方式运行,一个任务也可以由多个任务组成. 二.应用 1.创建任务有三种方法: var t1 = new Task(() =& ...

  8. docker容器技术基础入门

    目录 docker容器技术基础入门 容器(Container) 传统虚拟化与容器的区别 Linux容器技术 Linux Namespaces CGroups LXC docker基本概念 docker ...

  9. 万答#15,都有哪些情况可能导致MGR服务无法启动

    欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 本文转载自微信公众号 "老叶茶馆" 欢迎大家关注! 1.都有 ...

  10. 从零开始Blazor Server(10)--编辑角色

    例图 目前的样式是这样的: 其中角色在一个table里,然后可以增删改查,并且可以给指定的用户分配权限. 创建文件 首先我们在Pages/Admin目录下新建一个Role.razor.因为我们的Adm ...