# AlertManager network policy
# Ingress: Prometheus (alert delivery), Grafana (alert UI queries)
# Egress: Mattermost webhooks (cluster-internal), DNS
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: alertmanager
  namespace: foxhunt
  labels:
    app.kubernetes.io/part-of: foxhunt
spec:
  podSelector:
    matchLabels:
      app.kubernetes.io/name: alertmanager
  policyTypes:
    - Ingress
    - Egress
  ingress:
    # Prometheus pushes alerts and scrapes metrics (9093 API, 8080 config-reloader)
    - from:
        - podSelector:
            matchLabels:
              app.kubernetes.io/name: prometheus
      ports:
        - protocol: TCP
          port: 9093
        - protocol: TCP
          port: 8080
    # Grafana queries AlertManager API for alert state/silences
    - from:
        - podSelector:
            matchLabels:
              app.kubernetes.io/name: grafana
      ports:
        - protocol: TCP
          port: 9093
  egress:
    # DNS resolution
    - to:
        - namespaceSelector: {}
      ports:
        - protocol: UDP
          port: 53
        - protocol: TCP
          port: 53
    # Mattermost incoming webhook (cluster-internal)
    - to:
        - podSelector:
            matchLabels:
              app.kubernetes.io/name: mattermost
      ports:
        - protocol: TCP
          port: 8065
    # External HTTPS (PagerDuty, email, future integrations)
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
            except:
              - 10.0.0.0/8
              - 172.16.0.0/12
              - 192.168.0.0/16
      ports:
        - protocol: TCP
          port: 443
