Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[oauth2-proxy] Your applications is protected by Oauthen2(Google, GitHub,…)

Posted on July 18, 2022December 22, 2023 By nim No Comments on [oauth2-proxy] Your applications is protected by Oauthen2(Google, GitHub,…)

Contents

Toggle
  • 1) Overview
  • 2) Demo Oauthen2 Proxy
    • 2.1) Build image
    • 2.2) Provisioning Oauthen2 through Docker compose.
    • 2.3) The specific emails are permitted to access the website via Oauthen2 Proxy
  • 3) Integrate between Oauthen2 Proxy + ingress-nginx

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 sẽ thấy là người dùng từ ngoài internet trước khi đến được web thì bước qua xác của Oauthen2 Proxy
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:

Đầu tiên thì accessing sẽ đi vào Kong Gateway -> đi vào Oauthen2 để xác thực google -> Đi vào website.

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.

Bạn thấy mình export cái 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

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-rpqa4s1g19o99ljpb5c1gamf0i815djk.apps.googleusercontent.com
      OAUTH2_PROXY_CLIENT_SECRET: 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
      #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

Kubernetes & Container, OAuth2 Proxy

Post navigation

Previous Post: [Spinnaker] clouddriver.kubernetes.op.job.KubectlJobExecutor$KubectlException: Deploy failed
Next Post: [TeamCity] Getting started with TeamCity

More Related Articles

[Kubernetes] Lesson4: k8s easy – Pob Lifecycle, Image registry, init Container Kubernetes & Container
[Kubernetes] Lesson1: k8s easy – Kubernetes architecture and components Kubernetes & Container
[Docker] Comand Docker hay quên!! Docker
[kiali/istio] Fix issue Configured: configmaps “istio” not found Isito-EnvoyFilter
[Upgrade Canary Istio Cluster] Do you want to upgrade the new version for Your Multi-Cluster Isito? Welcome to Nimtechnology. Very easy!!! That right. Isito-EnvoyFilter
[ArgoCD/KSOPS] Encrypting Resource on kustomize and Argocd. ArgoCD

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Laravel] Laravel Helpful June 26, 2025
  • [VScode] Hướng dẫn điều chỉnh font cho terminal June 20, 2025
  • [WordPress] Hướng dấn gửi mail trên WordPress thông qua gmail. June 15, 2025
  • [Bitbucket] Git Clone/Pull/Push with Bitbucket through API Token. June 12, 2025
  • [Teamcity] How to transfer the value from pipeline A to pipeline B June 9, 2025

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.