logo NodeSeekbeta

【以Caddy为例】反代哪吒面板实现保留SSH的同时,确保探针小鸡的绝对安全

初衷

有时候鸡太多(比如我),需要保留哪吒面板端的SSH方便管理,但如果的github账户被盗,或者session泄露
那么你的小鸡仔们将被一窝端,沦为肉鸡,甚至被拿来做坏事导致灰飞烟灭
所以需要一些小措施保证以(dào)针(chù)会(xiǎn)友(bai)的同时,又能让鸡鸡们绝对安全
*附哪吒关闭ssh方法:vim /etc/systemd/system/nezha-agent.service,在 ExecStart= 行的末尾加上 --disable-command-execute

思路

通过反代屏蔽一切后台页面,只允许前台展示访问
别人点击登录,或者试图偷session,就会直接显示Block
可以给自己留一个专属后门,允许指定ip比如自己家/堡垒机登陆管理

安装caddy

  • centos
yum install -y yum-plugin-copr
yum copr enable @caddy/caddy
yum update
yum install -y caddy
  • debian/ubuntu
apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install caddy

配置cloudflare证书

  1. 进入Cloudflare,你的域名,SSL/TLS,Overview,选择Full (strict)
  2. 进入SSL/TLS,Origin Server,Creat Certificate,Host Name填入网站根域名/子域名/通配符,Create
  3. Key Format选PEM,拷贝Origin Certificate内容,并把内容在VPS上建立\root\crt\aaa.com.crt(改为你的域名以便管理)
  4. 拷贝Private Key内容,并把内容在VPS上建立\root\crt\aaa.com.crt(改为你的域名以便管理)

配置

vim /etc/caddy/caddyfile
修改内容如下

aaa.com {
	tls /root/crt/aaa.com.crt /root/crt/aaa.com.pem #此处改为你的探针域名
	@ip_whitelist {
		remote_ip 2.2.2.2 3.3.3.3 4.4.4.0/24 #这里改成你自己的IP白名单,如自家ip,堡垒机ip
	}
	route @ip_whitelist {
		reverse_proxy * 127.0.0.1:8008 #此处8008改成哪吒dashboard的网页服务端口
	}
	@path_blacklist {
		path /login* /setting* /cron* /notification* /terminal* /oauth2*
	}
	route @path_blacklist {
		#reverse_proxy * microsoft.com #也可以反代到别的网站返回404
		respond "Blocked" 403
	}
	reverse_proxy * 127.0.0.1:8008 #此处8008改成哪吒dashboard的网页服务端口
}

设置Caddy为自启动服务

systemctl enable caddy
systemctl start caddy

另外注意将小鸡防火墙的哪吒dashboard网页服务端口8008设置为屏蔽

效果

⛱️Arioc's Needle 阿里欧克之针
点击登录,返回错误

1234
  • @Emphasis6191 #29

    location / {
        try_files $uri @proxy;
    }
    
    location ~ ^/(login|setting|cron|notification|terminal|oauth2) {
        # 允许服务器ip 服务器列表中的ip
        allow 2.2.2.2;
        allow 3.3.3.3;
        allow 4.4.4.4;
        # 允许访问者ip
        allow 2.2.2.2; # 允许的IP
        allow 3.3.3.3; # 允许的IP
        allow 4.4.4.0/24; # 允许的IP段
    	
        deny all; # 拒绝所有其他请求
    
        try_files $uri @proxy;
    }
    
    location @proxy {
        proxy_pass http://127.0.0.1:8008; 
        proxy_set_header Host $host; 
        proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header REMOTE-HOST $remote_addr; 
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "upgrade"; 
        proxy_set_header X-Forwarded-Proto $scheme; 
        proxy_http_version 1.1; 
        add_header X-Cache $upstream_cache_status; 
        add_header Strict-Transport-Security "max-age=31536000"; 
    }
    

    改了一个nginx反代的配置 效果差不多吧

  • 我比較喜歡用xcaddy編譯包含cloudflare dns插件的版本,然後透過含插件的caddy直接申請LE證書,比較一勞永逸

  • 支持师傅

  • 大佬牛逼

  • @Nebulosa-Cat #1 集成cf不错,回头研究一下 xhj003

  • @xy #4
    可以參考一下我博客
    https://nebulosa-cat.com/533/host-sub-store-by-docker-compose-and-caddy/
    主要就安裝go環境比較麻煩一點,其他問題不是很大,裝完之後基本上就一勞永逸了 xhj010

  • @Nebulosa-Cat #5 感谢分享,收藏一下 xhj003

  • 哟西 xhj010

  • @xy #6 感謝支持 xhj028

  • 好东西帮顶,养鸡大户确实得注意安全

  • 老哥6的

1234

你好啊,陌生人!

我的朋友,看起来你是新来的,如果想参与到讨论中,点击下面的按钮!

📈用户数目📈

目前论坛共有15771位seeker

🎉欢迎新用户🎉