12.7. EventPolicy 적용


이 섹션에서는 이벤트 전달을 보호하기 위해 EventPolicy를 적용하기 위한 엔드 투 엔드 단계에 대해 설명합니다. 다음 참조 예에서 namespace-1 의 Broker는 다른 네임스페이스 네임스페이스-2 에서 실행되는 PingSource 의 이벤트만 허용하도록 구성됩니다.

사전 요구 사항

  • OpenShift Serverless Operator 및 Knative Eventing이 OpenShift Container Platform 클러스터에 설치되어 있습니다.
  • authentication-oidc 기능을 활성화했습니다.

프로세스

  1. 다음 예에 표시된 대로 두 네임스페이스를 생성하고 namespace-1 에 Broker를 배포하고 각 네임스페이스에서 하나의 PingSource 를 구성합니다.

    apiVersion: v1
    kind: Namespace
    metadata:
      name: namespace-1
    ---
    apiVersion: v1
    kind: Namespace
    metadata:
      name: namespace-2
    ---
    apiVersion: eventing.knative.dev/v1
    kind: Broker
    metadata:
      name: broker
      namespace: namespace-1
    ---
    # PingSource in namespace-1
    apiVersion: sources.knative.dev/v1
    kind: PingSource
    metadata:
      name: pingsource-1
      namespace: namespace-1
    spec:
      data: '{"message": "Hi from pingsource-1 from namespace-1"}'
      schedule: '*/1 * * * *'
      sink:
        ref:
          apiVersion: eventing.knative.dev/v1
          kind: Broker
          name: broker
          namespace: namespace-1
    ---
    # PingSource in namespace-2
    apiVersion: sources.knative.dev/v1
    kind: PingSource
    metadata:
      name: pingsource-2
      namespace: namespace-2
    spec:
      data: '{"message": "Hi from pingsource-2 from namespace-2"}'
      schedule: '*/1 * * * *'
      sink:
        ref:
          apiVersion: eventing.knative.dev/v1
          kind: Broker
          name: broker
          namespace: namespace-1
    Copy to Clipboard Toggle word wrap
  2. 다음 예와 같이 event-display 서비스를 생성하여 수신 이벤트를 표시하고 Trigger를 추가하여 브로커에 연결합니다.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: event-display
      namespace: namespace-1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: event-display
      template:
        metadata:
          labels:
            app: event-display
        spec:
          containers:
            - name: event-display
              image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display
              ports:
              - containerPort: 8080
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: event-display
      namespace: namespace-1
    spec:
      selector:
        app: event-display
      ports:
        - name: http
          port: 80
          targetPort: 8080
    ---
    apiVersion: eventing.knative.dev/v1
    kind: Trigger
    metadata:
      name: trigger
      namespace: namespace-1
    spec:
      broker: broker
      subscriber:
        ref:
          apiVersion: v1
          kind: Service
          name: event-display
    Copy to Clipboard Toggle word wrap

    이 단계에서는 OIDC가 비활성화되고 EventPolicy가 적용되지 않으므로 event-display 서비스는 PingSources의 이벤트를 표시합니다.

  3. Knative Eventing에서 OIDC를 활성화하고 다음 예제 명령을 실행하여 EventPolicy를 생성합니다.

    $ oc -n knative-eventing patch KnativeEventing knative-eventing \
      --type merge \
      -p '{"spec":{"config":{"features":{"authentication-oidc":"enabled"}}}}'
    Copy to Clipboard Toggle word wrap
  4. OIDC가 활성화되면 다음 예와 같이 namespace-2 에서 PingSource만 권한을 부여하는 EventPolicy를 생성합니다.

    apiVersion: eventing.knative.dev/v1alpha1
    kind: EventPolicy
    metadata:
      name: event-policy
      namespace: namespace-1
    spec:
      to:
        - ref:
            apiVersion: eventing.knative.dev/v1
            kind: Broker
            name: broker
      from:
        - ref:
            apiVersion: sources.knative.dev/v1
            kind: PingSource
            name: pingsource-2
            namespace: namespace-2
    Copy to Clipboard Toggle word wrap

검증

  1. 다음 명령을 실행하여 브로커 상태를 확인하려면 EventPolicy를 확인합니다.

    $ oc -n namespace-1 get broker broker -o yaml
    Copy to Clipboard Toggle word wrap
  2. event-display 서비스에서 로그를 보고 다음 명령을 실행하여 pingsource-2 이벤트만 도착했는지 확인합니다.

    $ oc -n namespace-1 logs -f -l app=event-display
    Copy to Clipboard Toggle word wrap
  3. 다음 명령을 실행하여 EventPolicy를 삭제합니다.

    $ oc -n namespace-1 delete eventpolicy event-policy
    Copy to Clipboard Toggle word wrap
  4. 다음 명령을 실행하여 Broker 상태를 확인하여 기본 allow-same-namespace 모드로 반환되었는지 확인합니다.

    $ oc -n namespace-1 get broker broker -o yaml
    Copy to Clipboard Toggle word wrap
  5. event-display 서비스 로그를 보고 다음 명령을 실행하여 동일한 네임스페이스의 pingsource-1 이벤트만 표시되는지 확인합니다.

    $ oc -n namespace-1 logs -f -l app=event-display
    Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat