4.11. 권한 부여 정책 추가
Layer 7(L7) 권한 부여 정책을 사용하여 curl 서비스가 다른 모든 작업을 차단하면서 GET 요청을 productpage 서비스에 보낼 수 있도록 합니다.
프로세스
다음 예와 유사한 권한 부여 정책을 생성합니다.
설정 예
apiVersion: security.istio.io/v1 kind: AuthorizationPolicy metadata: name: productpage-waypoint namespace: info spec: targetRefs: - kind: Service group: "" name: productpage action: ALLOW rules: - from: - source: principals: - cluster.local/ns/curl/sa/curl to: - operation: methods: ["GET"]다음 명령을 실행하여 권한 부여 정책을 적용합니다.
$ oc apply -f authorization-policy.yaml
targetRefs 필드는 waypoint 프록시의 권한 부여 정책에서 대상으로 하는 서비스를 지정합니다.
검증
다음 명령을 실행하여
curl클라이언트의 네임스페이스를 생성합니다.$ oc create namespace curl다음 명령을 실행하여
curl클라이언트를 배포합니다.$ oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yaml다음 명령을 실행하여 앰비언트 모드의 레이블을
curl네임스페이스에 적용합니다.$ oc label namespace curl istio.io/dataplane-mode=ambient다음 명령을 실행하여
productpage서비스에 대한GET요청이default/curl포드에서 만들 때 HTTP 200 응답으로 성공했는지 확인합니다.$ oc -n curl exec deploy/curl -- sh -c \ 'curl -s -o /dev/null -w "HTTP %{http_code}\n" http://productpage.info.svc.cluster.local:9080/productpage'다음 명령을 실행하여 적용된 권한 부여 정책으로 인해 HTTP 403 응답으로 동일한 서비스에 대한
POST요청이 거부되었는지 확인합니다.$ oc -n curl exec deploy/curl -- sh -c \ 'curl -s -o /dev/null -w "HTTP %{http_code}\n" -X POST http://productpage.info.svc.cluster.local:9080/productpage'다음 명령을 실행하여
info네임스페이스의평가Pod와 같은 다른 서비스의GET요청이RBAC: access denied에서도 거부되었는지 확인합니다.$ oc exec "$(oc get pod -l app=ratings -n info \ -o jsonpath='{.items[0].metadata.name}')" \ -c ratings -n info \ -- curl -sS productpage:9080/productpage다음 명령을 실행하여 리소스를 정리합니다.
다음 명령을 실행하여
curl애플리케이션을 삭제합니다.$ oc delete -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yaml다음 명령을 실행하여
curl네임스페이스를 삭제합니다.$ oc delete namespace curl