1) Overview
Mình có rất nhiều services hay webs được public internet. Nhưng không phải ứng dụng nào cũng có Two Factor Authentication, or 2FA
Ví dụ như bạn thấy bạn có thể login lazada, shoppe, tiki, vân vân. bằng tài khoản google, github,….
Nếu web đó của bạn không hỗ trợ login bằng Oauthen2 thì bạn làm sao nhỉ?

Bạn cần phải có 1 bưới sác thực với google.
Sau đây là dường link mà mình lượn nhắt được:
https://github.com/oauth2-proxy/oauth2-proxy
https://qiita.com/hoto17296/items/7f78416965e4ae289de0
https://developer.okta.com/blog/2022/07/14/add-auth-to-any-app-with-oauth2-proxy (Bài này thì có example với nginx)
https://github.com/oktadev/okta-oauth2-proxy-example
Hiện mình đang sửa KongAPI để Public các web của mình.
Mình sẽ thêm vào oauthen2-proxy và structure như sau:

Bạn sẽ thấy mô hình trên của mình sẽ cần phải đi qua hai proxy nên latency chắc chắn sẽ cao hơn bình thường 1 ít. Nên cách trên sẽ không phù hợp cho streamming remote desktop như là guamole.
Và mô hình trên thì mình không thể chạy với web app sử dụng https.
==> nếu bạn có cách j hay chỉ cho Nim nhé!
2) Demo Oauthen2 Proxy
2.1) Build image
Mình dựng docker-compose cho các thành phần của Oauthen2-Proxy
cat proxy/Dockerfile
>>>>>>>>
FROM alpine
ARG VERSION=v7.3.0
RUN wget -q https://github.com/oauth2-proxy/oauth2-proxy/releases/download/${VERSION}/oauth2-proxy-${VERSION}.linux-amd64.tar.gz
RUN tar xzf oauth2-proxy-${VERSION}.linux-amd64.tar.gz
RUN mv oauth2-proxy-${VERSION}.linux-amd64/oauth2-proxy /bin/
RUN rm -rf oauth2-proxy-${VERSION}*
CMD ["/bin/oauth2-proxy"]
Mặc dù là họ đã có săn image rồi nhưng mình vẫn build cho ngầu.
2.2) Provisioning Oauthen2 through Docker compose.
cat docker-compose.yml
version: '3'
services:
proxy:
build: proxy
ports:
- 8084:4180
environment:
OAUTH2_PROXY_HTTP_ADDRESS: 0.0.0.0:4180
OAUTH2_PROXY_PROVIDER: google
OAUTH2_PROXY_CLIENT_ID: 506853153623-xxxxxxxxxxxxxxxx.apps.googleusercontent.com
OAUTH2_PROXY_CLIENT_SECRET: GOCSPX-ycjSROdHM8_xxxxxxxxxxxxxxxxx
OAUTH2_PROXY_EMAIL_DOMAINS: gmail.com
OAUTH2_PROXY_UPSTREAMS: http://192.168.101.34:8084/
OAUTH2_PROXY_COOKIE_SECRET: Tg06aGvkpWU2S_sryFWGYg==
OAUTH2_PROXY_SESSION_STORE_TYPE: redis
OAUTH2_PROXY_REDIS_CONNECTION_URL: redis://redis/
OAUTH2_PROXY_COOKIE_SECURE: 'false'
OAUTH2_PROXY_REDIRECT_URL: https://private-note.nimtechnology.com/oauth2/callback
redis:
image: redis
volumes:
- redis:/data
volumes:
redis:
Đây là phần lưu ý của mình
OAUTH2_PROXY_PROVIDER: google OAUTH2_PROXY_CLIENT_ID: 506853153623-xxxxxxxxxxxxxxxx.apps.googleusercontent.com OAUTH2_PROXY_CLIENT_SECRET: GOCSPX-ycjSROdHM8_xxxxxxxxxxxxxxxxx
Để config oauthen với google thì bạn thể sem tạm ở đây:
https://nimtechnology.com/2021/11/28/kiali-config-authentication-on-kiali/#11_Config_google
OAUTH2_PROXY_UPSTREAMS: http://192.168.101.34:8084/
Đâu là ip/port của web-app của mình
Chỗ này kiểu filter domain.
với config bên trên thì chỉ có user mail có dạng là: nimtechnology@gmail.com hay nim@gmail.com
===> thì sẽ login vào được!
Trên Công thì mình config uptream xuống oauthen2-proxy.


Nếu Login trở lại, bạn sẽ thấy oauthen2-proxy đòi bạn đăng nhập

2.3) The specific emails are permitted to access the website via Oauthen2 Proxy
Bạn có thể tham khảo
https://github.com/oauth2-proxy/oauth2-proxy/issues/73
Giờ là file config
Nhớ bỏ OAUTH2_PROXY_EMAIL_DOMAINS: gmail.com
cat oauth2-proxy
mr.nim94@gmail.com
cat docker-compose.yml
version: '3'
services:
proxy:
build: proxy
ports:
- 8084:4180
environment:
OAUTH2_PROXY_HTTP_ADDRESS: 0.0.0.0:4180
OAUTH2_PROXY_PROVIDER: google
OAUTH2_PROXY_CLIENT_ID: 506853153623-xxxxxx.apps.googleusercontent.com
OAUTH2_PROXY_CLIENT_SECRET: GOCSPX-xxxx_zqIwzqhAi2wIpRZ5-
#OAUTH2_PROXY_EMAIL_DOMAINS: gmail.com
OAUTH2_PROXY_UPSTREAMS: http://192.168.101.34:8084/
OAUTH2_PROXY_COOKIE_SECRET: Tg06aGvkpWU2S_sryFWGYg==
OAUTH2_PROXY_SESSION_STORE_TYPE: redis
OAUTH2_PROXY_REDIS_CONNECTION_URL: redis://redis/
OAUTH2_PROXY_COOKIE_SECURE: 'false'
OAUTH2_PROXY_REDIRECT_URL: https://private-note.nimtechnology.com/oauth2/callback
OAUTH2_PROXY_AUTHENTICATED_EMAILS_FILE: /home/auth_users
volumes:
- ./oauth2-proxy:/home/auth_users
redis:
image: redis
volumes:
- redis:/data
volumes:
redis:
3) Integrate between Oauthen2 Proxy + ingress-nginx
Bài này khá là hay bạn có thể tham khảo.
https://oak-tree.tech/blog/k8s-nginx-oauth2-gitlab