<p>I want to prevent unsafe requested to reach my application running in GCP GKE with Google Ingress (not nginx) and trying to do this using path rules.
I know nginx Ingress can configure paths using regex but I don know the best way to do with Google Ingress.
Right now I am just duplicating the same rules change the path prefix like this:</p>
<pre><code>spec:
  rules:
  - http:
      paths:
      - backend:
          service:
            name: my-api-service
            port:
              number: 80
        path: /api
        pathType: Prefix
      - backend:
          service:
            name: my-api-service
            port:
              number: 80
        path: /auth
        pathType: Prefix
      - backend:
          service:
            name: my-api-service
            port:
              number: 80
        path: /admin
        pathType: Prefix
</code></pre>
<p>Is there a better way to do this?</p>

nsbm
<p>Everything you're looking for is covered in <a href="https://cloud.google.com/load-balancing/docs/url-map-concepts#pm-constraints" rel="nofollow noreferrer">this</a> document. As GKE ingress is essentially a GCP Load Balancer, the <code>path</code> key is using a <code>url-map</code> to configure and route the traffic to what you've specified in the config. As you'd be able to see there, regexs are not allowed in <code>Path</code> keys.</p>
<p>One option if you're using Helm is to make use of the templates to generate this automatically from a variable. Given the following variable in your <code>values.yaml</code> file:</p>
<pre><code>paths:
 - name: /api
 - name: /admin
 - name: /auth
</code></pre>
<p>Then in your ingress YAML definition you can do the following:</p>
<pre><code>spec:
  rules:
  - http:
      paths:
{{ range $paths := .Values.paths }}
      - backend:
          service:
            name: my-api-service
            port:
              number: 80
        path: {{ .name }}
        pathType: Prefix
{{ end }}
</code></pre>
