当前位置: 首页 > news >正文

[svc]logstash和filebeat之间ssl加密

cfssl生成证书

wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 -O     /usr/local/bin/cfssl
wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 -O      /usr/local/bin/cfssljson
wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 -O /usr/local/bin/cfssl-certinfo
chmod +x /usr/local/bin/cfssl*


cd;mkdir keys;cd keys
cat > ca-config.json <<EOF
{
  "signing": {
    "default": {
      "expiry": "8760h"
    },
    "profiles": {
      "app": {
        "usages": [
            "signing",
            "key encipherment",
            "server auth",
            "client auth"
        ],
        "expiry": "8760h"
      }
    }
  }
}
EOF


cat > ca-csr.json <<EOF
{
  "CN": "k8s",
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ]
}
EOF


cfssl gencert -initca ca-csr.json | cfssljson -bare ca



cd /root/keys
cat > app-csr.json <<EOF
{
  "CN": "app",
  "hosts": [
    "127.0.0.1",
    "192.168.1.11",
    "192.168.1.12"
  ],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ]
}
EOF

cfssl gencert -ca=/root/keys/ca.pem \
  -ca-key=/root/keys/ca-key.pem \
  -config=/root/keys/ca-config.json \
  -profile=app app-csr.json | cfssljson -bare app

openssl x509  -noout -text -in  app.pem

可以看到san里包含了n1 和 n2的ip. 这里计划logstash(的ip)和filebeat(的ip)使用同一套证书

实验环境

806469-20171224101505271-857910381.png

logstash&filebeat之间传数据-明文

logstash配置

cat > pipeline.conf <<EOF
input {
  beats {
    port => 5044
  }
  
  stdin {
    codec => "json"
  }
}

output {
  stdout { codec => rubydebug }
}
EOF

bin/logstash -f pipeline.conf --config.reload.automatic

filebeat多输入(不能多输出)参考: https://www.elastic.co/guide/en/beats/filebeat/current/migration-configuration.html

cat > filebeat.yml <<EOF
filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /tmp/ma.txt
- type: stdin
  
output.logstash:
  hosts: ["192.168.1.11:5044"]
# output.console:
#  pretty: true
EOF


./filebeat -e -c filebeat.yml -d "publish"

测试文字

helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld helloworld 

wireshark抓包: 不加密的时候,可以看到这玩意依稀可以看到依稀传输内容,如果互联网传输的话会有隐患.

806469-20171224101209146-458609802.png

logstash&filebeat之间传数据-ssl加密

  • logstash配置ssl

参考: https://www.elastic.co/guide/en/beats/filebeat/current/configuring-ssl-logstash.html

cat > pipeline.conf <<EOF
input {
  beats {
    port => 5044
    ssl => true
    ssl_certificate_authorities => ["/root/keys/ca.pem"]
    ssl_certificate => "/root/keys/app.pem"
    ssl_key => "/root/keys/app-key.pem"
    ssl_verify_mode => "force_peer"
  }
  
  stdin {
    codec => "json"
  }
}

output {
  stdout { codec => rubydebug }
}
EOF


bin/logstash -f pipeline.conf --config.reload.automatic
  • filebeat配置ssl
filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /tmp/ma.txt
    
output.logstash:
  hosts: ["192.168.1.12:5043"]

output.logstash.ssl.certificate_authorities: ["/root/keys/ca.pem"]
output.logstash.ssl.certificate: "/root/keys/app.pem"
output.logstash.ssl.key: "/root/keys/app-key.pem"


output.console:
  pretty: true

  
./filebeat -e -c filebeat.yml -d "publish"

wireshark抓包: 看不到任何传输内容,依稀看到证书的subject(公开的).

806469-20171224101308912-872436410.png

报错doesn't contain any IP SANs

2017/12/24 02:33:59.242540 output.go:74: ERR Failed to connect: x509: cannot validate certificate for 192.168.1.11 because it doesn't contain any IP SANs
2017/12/24 02:34:15.289558 output.go:74: ERR Failed to connect: x509: cannot validate certificate for 192.168.1.11 because it doesn't contain any IP SANs

ssl验证流程:

806469-20171224103952928-506861902.png

报错原因: 我生成证书请求的时候 hosts字段(即san)为空.

cd /root/keys
cat > app-csr.json <<EOF
{
  "CN": "192.168.1.12",
  "hosts": [],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ]
}
EOF

cfssl gencert -ca=/root/keys/ca.pem \
  -ca-key=/root/keys/ca-key.pem \
  -config=/root/keys/ca-config.json \
  -profile=app app-csr.json | cfssljson -bare app

openssl x509  -noout -text -in  app.pem

相关文章:

  • 将手机替换为*号
  • python入门之路 一
  • 网络数据抓取
  • Xcode 7 制作 framework
  • WARNING Uninstalling will remove the application data!
  • 新手 php连接数据库大概。简单过程浅析以及遇到的问题分析
  • Django 配置文件 settings.py
  • CORS FOR AspNetCore
  • spark shell的学习
  • 安卓模拟器BlueStacks+TCPdump对APP抓包分析
  • maven scope含义的说明
  • Javac编译器源代码分析
  • 物极必反,滥用闭包的结果就是回归结构化编程
  • 2017 年终总结 —— 在路上
  • 加密算法(对称加密)AES、DES (非对称加密)RSA、DSA
  • [数据结构]链表的实现在PHP中
  • [译]Python中的类属性与实例属性的区别
  • 【划重点】MySQL技术内幕:InnoDB存储引擎
  • C++回声服务器_9-epoll边缘触发模式版本服务器
  • HTTP请求重发
  • JavaScript标准库系列——Math对象和Date对象(二)
  • Linux快速复制或删除大量小文件
  • Stream流与Lambda表达式(三) 静态工厂类Collectors
  • vue--为什么data属性必须是一个函数
  • Vue学习第二天
  • 个人博客开发系列:评论功能之GitHub账号OAuth授权
  • 两列自适应布局方案整理
  • 每天一个设计模式之命令模式
  • 如何打造100亿SDK累计覆盖量的大数据系统
  • 事件委托的小应用
  • 腾讯视频格式如何转换成mp4 将下载的qlv文件转换成mp4的方法
  • 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
  • 在Mac OS X上安装 Ruby运行环境
  • d²y/dx²; 偏导数问题 请问f1 f2是什么意思
  • # 飞书APP集成平台-数字化落地
  • ###C语言程序设计-----C语言学习(3)#
  • #define用法
  • #绘制圆心_R语言——绘制一个诚意满满的圆 祝你2021圆圆满满
  • #数学建模# 线性规划问题的Matlab求解
  • #我与Java虚拟机的故事#连载19:等我技术变强了,我会去看你的 ​
  • (DenseNet)Densely Connected Convolutional Networks--Gao Huang
  • (附源码)springboot电竞专题网站 毕业设计 641314
  • (附源码)springboot青少年公共卫生教育平台 毕业设计 643214
  • (附源码)ssm基于jsp高校选课系统 毕业设计 291627
  • (原创)攻击方式学习之(4) - 拒绝服务(DOS/DDOS/DRDOS)
  • (转载)OpenStack Hacker养成指南
  • .net core开源商城系统源码,支持可视化布局小程序
  • .net on S60 ---- Net60 1.1发布 支持VS2008以及新的特性
  • .NET Remoting学习笔记(三)信道
  • .NET 读取 JSON格式的数据
  • .NET/C# 阻止屏幕关闭,阻止系统进入睡眠状态
  • .NET开发不可不知、不可不用的辅助类(三)(报表导出---终结版)
  • @ModelAttribute 注解
  • @property python知乎_Python3基础之:property
  • [145] 二叉树的后序遍历 js