Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

JINIers

[Qwiklabs]Networking in Google Cloud _User Authentication: Identity-Aware Proxy 본문

GCP/Qwiklabs

[Qwiklabs]Networking in Google Cloud _User Authentication: Identity-Aware Proxy

JINIers 2022. 2. 28. 15:49

개 요

IAP(Identity-Aware Proxy)를 사용하여 애플리케이션에 대한 액세스를 제한하고 애플리케이션에 사용자 id 정보를 제공하는 방법을 살펴본다.

 

  • python 이용 간단한 app engine 앱 작성 및 배포
  • 앱에 대한 액세스를 제한하기 위해 IAP 활성화 및 비활성화 방법
  • IAP에서 앱으로 사용자 ID 정보를 가져오는 방법
  • 스푸핑으로부터 보호하기 위해 IAP의 정보를 암호화 방식으로 확인하는 방법

IAP(Identity-Aware Proxy)란?

IAP(Identity-Aware Proxy)는 애플리케이션으로 전송된 웹 요청을 가로채고 google id 서비스를 사용하여 요청하는 사용자를 인증하며 승인한 사용자가 보낸 요청인 경우에만 요청을 통과하도록 허용해주는 google cloud 서비스

인증된 사용자에 대한 정보를 포함하도록 요청헤더 수정가능

 


1. 설정 및 요구사항


코드 다운로드
gsutil cp gs://spls/gsp499/user-authentication-with-iap.zip .

unzip user-authentication-with-iap.zip

cd user-authentication-with-iap


2. 애플리케이션 배포 및 iap로 보호


cd 1-HelloWorld

** main.py : 응용프로그램 코드
** requirements.txt : 애플리케이션에서 사용하는 기본이 아닌 모든 python 라이브러리 나열
** app.yaml : python app engine 애플리케이션임을 알려줌

cat main.py

[app engine에 배포]

 

gcloud app deploy
17 [central1-a]
y

gcloud app browse                                                            // 앱 찾아보기

링크 클릭 > hello world 뜨면 성공!

 

hello world!!

 

 

 

[IAP로 액세스 제한]
security > Identity-Aware Proxy > enable api > go to identity-aware proxy > configure consent screen


OAuth consent screen 생성
- user type : interal
- user support email : 오른쪽에 있는 화살표 눌러서 나오는거 눌러
- Application home page : [gcloud app browse] 명령어 이용 링크 확인 후 추가
- Application privacy Policy link : https:// ~ /privacy
- Authorized domains : +add domain 후 링크에서 [https://], [/(링크끝)] 제거
- Developer Contact Information : 아무거나 적어

1-1. OAuth consent screen 생성
1-2. OAuth consent screen 생성
1-3. OAuth consent screen 생성완료

 

 

 

 

gcloud services disable appengineflex.googleapis.com                             // flex api 사용중지

iam&admin > IAP > iap : turn on > 새탭 > url 접속 > iap 켜져 있는지 테스트 > 접속 거부

iap turn on 전

 

iap turn on
iap turn on 후
접근거부

 

 

iam&admin > IAP > app engine app 체크박스 허용하면 오른쪽 나옴 > add principal > qwiklabs 이메일 주소 입력 > cloud iap/iap-secured web app user 추가

 

접근허용하기

 

IAP-secured Web App User 추가

 

 

웹페이지 새로고침 > 'hello world' 나오면 성공!

 


3. 사용자 id 정보에 액세스


cd ~/user-authentication-with-iap/2-HelloUser

gcloud app deploy

y

 


[응용프로그램 파일 검사]
gcloud app browse

-> 업데이트 된 iap 테스트 확인할 수 있음


iap off > 새로고침 > 확인

iap off 후 새로고침 한 홈페이지


curl -X GET https://qwiklabs-gcp-03-fcbbf304ce50.uc.r.appspot.com/ -H "X-Goog-Authenticated-User-Email: totally fake email"

내용 확인 > 애플리케이션이 보호되지 않기 때문에 사용자는 iap를 통과한 것처럼 보이는 웹 요청을 보낼 수 있다.
** 애플리케이션이 iap가 비활성화 되었거나 우회되었음을 알 수 있는 방법이 없음

 

curl -X GET ~ 명령어 실행


4. 암호화 확인 사용


cd ~/user-authentication-with-iap/3-HelloVerifiedUser
gcloud app deploy
y

 

[응용프로그램 파일 검사]

def user():
    assertion = request.headers.get('X-Goog-IAP-JWT-Assertion')
    if assertion is None:
        return None, None
    info = jwt.decode(
        assertion,
        keys(),
        algorithms=['ES256'],
        audience=audience()
    )
    return info['email'], info['sub']



[암호화 검증 테스트]
gcloud app browse

탭 새로고침해서 확인

 

iap off 
iap on 

 

Comments