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

home-assistant整合sso

其他软件都可以通过nginx直接做代理添加鉴权,但是这个hass果然是用户安全隐私很强,做代理需要配置白名单,而且支持的三方鉴权都不太适合我的需求,非要改源码才行,后来我发现不用改源码的折中方式

参考文章

  • External Authentication
  • Authenticating with external auth and oauth2_proxy to bypass homeassistant auth
  • Authentication Providers
  • HTTP(nginx代理hass)

在containerd中部署hass并集成sso

我是部署到kubernetes中的,参考链接

本地登录hass并创建一个长期的令牌

在这里插入图片描述

hass配置文件

# 配置nginx代理
http:use_x_forwarded_for: truetrusted_proxies:- 10.234.104.88 #这个地址是nginx服务的ip地址

nginx配置文件

server {listen       86;listen  [::]:86;server_name  localhost;#替换响应中的内容,类似于string.replace函数sub_filter '<head>' '<head><script>window.externalApp={getExternalAuth:function(){window.externalAuthSetToken(true,{"access_token":"第一步创建长期的令牌","expires_in":248832000});},revokeExternalAuth:function(){window.externalAuthRevokeToken(false);}};</script>';sub_filter_once on;location / {proxy_pass http://localhost:8123;#hass地址auth_request http://xxx/sso/auth;#sso鉴权接口地址proxy_set_header Host $host;proxy_set_header Accept-Encoding "";proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection $http_connection;proxy_set_header X-Real-IP $remote_addr; # //一层代理时是用户真实ip,二层代理时是第一台nginxipproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # //一层代理时没有值,多层代理里面会存储多个ip值,第一个值就是真实用户ipproxy_set_header X-Forwarded-Proto $scheme;}location /api/websocket {proxy_pass http://localhost:8123/api/websocket;auth_request http://xxx/sso/auth;#sso鉴权接口地址proxy_set_header Host $host;proxy_set_header Accept-Encoding "";proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection $http_connection;proxy_set_header X-Real-IP $remote_addr; # //一层代理时是用户真实ip,二层代理时是第一台nginxipproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # //一层代理时没有值,多层代理里面会存储多个ip值,第一个值就是真实用户ipproxy_set_header X-Forwarded-Proto $scheme;}location /auth/authorize {# tell nginx that this request requires authentication with oauth2_proxyauth_request http://xxx/sso/auth;#sso鉴权接口地址# redirect back to the frontend and tell it to use external_authreturn 301 /?external_auth=1;}
}

格式一下:

<script>window.externalApp = {getExternalAuth: function() {window.externalAuthSetToken(true, {"access_token": "第一步创建长期的令牌","expires_in": 248832000});},revokeExternalAuth: function() {window.externalAuthRevokeToken(false);}};
</script>

执行流程

  1. 用户访问nginx的86端口
  2. nginx会首先请求http://xxx/sso/auth这个地址,进行鉴权操作,响应码是200则会把请求转发到hass地址http://localhost:8123
  3. 如果鉴权失败返回了401等未授权响应码,那么nginx会直接返回给浏览器401错误,禁止访问hass,请先去sso登录认证
  4. 这里nginx代理hass的时候替换了响应的内容,添加了sub_filter<head><script>window.externalApp.......的内容,这里就是为了告诉hass执行外部授权认证,就会执行getExternalAuth函数获取token,这里直接返回我的长期令牌。因为我们在nginx做了鉴权了,这里不再鉴权。
http://www.lryc.cn/news/97936.html

相关文章:

  • Ip-Limit: 轻量级注解式IP限流组件(二)
  • 【C++】开源:Redis数据库配置与使用
  • TCP/IP网络编程 第二十四章:制作HTTP服务器端
  • React 前端应用中快速实践 OpenTelemetry 云原生可观测性(SigNoz/K8S)
  • Linux 多线程并发Socket服务端的实现( 11 ) -【Linux通信架构系列 】
  • 2.7. Java 泛型了解么?什么是类型擦除?介绍一下常用的通配符?
  • 单例模式与构造器模式
  • SQL力扣练习(七)
  • C语言假期作业 DAY 05
  • php-golang-rpc使用roadrunner-server/goridge/v3/pkg/rpc和php的spiral/goridge3.2实践
  • API常用签名验证方法(PHP实现)
  • kotlin高阶函数
  • kotlin list集合树
  • 基于Autoencoder自编码的64QAM星座图整形调制解调通信系统性能matlab仿真
  • 【Spring】Spring 总览
  • 微软、OpenAI用上“数据永动机” 合成数据是晨曦还是暮光?
  • 简单认识Redis 数据库的高可用
  • 超级实用!,掌握这9个鲜为人知的CSS属性
  • 深圳国际新能源及智能网联汽车全产业博览会今年10月举办
  • 【具有非线性反馈的LTI系统识别】针对反馈非线性的LTI系统,提供非线性辨识方案(SimulinkMatlab代码实现)
  • Stable diffusion 和 Midjourney 怎么选?
  • c++网络编程
  • 【沁恒蓝牙mesh】数据收发接口与应用层模型传递
  • Java类关系之代理(代理模式)
  • java: 无法访问redis.clients.jedis.JedisPoolConfig
  • 基于java中学教务管理系统设计与实现
  • vscode设置java -Xmx最大堆内存
  • 组件开发系列--Apache Commons Chain
  • 60 # http 的基本概念
  • 云计算迎来中场战役,MaaS或将成为弯道超车“新赛点”