oauth2-proxy

出自Gea-Suan Lin's Wiki
於 2023年10月24日 (二) 17:01 由 Gslin留言 | 貢獻 所做的修訂 →‎設定
跳至導覽 跳至搜尋

oauth2-proxy是一套綁定SSO(Single Sign-on)認證的工具。

安裝

這邊建議安裝在service使用者帳號下,或是/srv下:

export OAUTH2_PROXY_VERSION=7.5.1; wget -c https://github.com/oauth2-proxy/oauth2-proxy/releases/download/v${OAUTH2_PROXY_VERSION}/oauth2-proxy-v${OAUTH2_PROXY_VERSION}.linux-amd64.tar.gz; tar xvf oauth2-proxy-v${OAUTH2_PROXY_VERSION}.linux-amd64.tar.gz; mkdir oauth2-proxy; cd oauth2-proxy; ln -s ../oauth2-proxy-v${OAUTH2_PROXY_VERSION}/oauth2-proxy

設定

另外在oauth2-proxy/oauth2-proxy.conf裡面設定。其中

  • cookie_secret可以用官方建議的openssl rand -base64 32 | tr -- '+/' '-_'產生。
  • email_domains表示只有這個網段下面的使用者才能存取系統。
  • http_address表示服務的接點(像是給nginx用)。
  • upstreams表示後端的接點(像是接到etcd-adminer)。
  • client_idclient_secret則是由Google產生給的值。
#
cookie_secret = "x"
cookie_secure = true
email_domains = ["example.com"]
http_address = "127.0.0.1:8002"
upstreams = ["http://127.0.0.1:8001/"]
#
client_id = "x"
client_secret = "x"

接下來是塞systemd的設定,這邊是用user systemd的設定方式(所以是default.target),負責保護etcd-adminer,所以設定放到~/.config/systemd/user/oauth2-proxy.service這邊:

#
[Unit]
Description=oauth2-proxy for etcd-adminer

[Service]
ExecStart=/home/service-etcd-adminer/oauth2-proxy/oauth2-proxy --config=/home/service-etcd-adminer/oauth2-proxy/oauth2-proxy.conf
Restart=on-failure
RestartSec=60
Type=simple

[Install]
WantedBy=default.target
systemctl --user daemon-realod; systemctl enable --now oauth2-proxy.service

外部連結