Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to support regex extracting in hostname. #6132

Closed
sanigo opened this issue Sep 6, 2020 · 3 comments
Closed

Need to support regex extracting in hostname. #6132

sanigo opened this issue Sep 6, 2020 · 3 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@sanigo
Copy link

sanigo commented Sep 6, 2020

If the hostname support regex, we could use keywords extracted from hostname in rewriting rules. Like the following config:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
    nginx.ingress.kubernetes.io/rewrite-target: '/repository/$repo/$1 last'
    nginx.ingress.kubernetes.io/proxy-body-size: 8192m
  name: sonatype-nexus-docker
spec:
  rules:
  - host: '~^(?<repo>[^.]+)\.r\.mydomain1\.com$'
    http:
      paths:
      - backend:
          serviceName: sonatype-nexus
          servicePort: 8081
        path: '/(.*)$'
  tls:
  - hosts:
    - '*~^(?<repo>[^.]+)\.r\.mydomain1\.com$'
    secretName: r-mydomain1-cert

Then, docker-releases.r.mydomain1.com will be used as a docker registry url.

@sanigo sanigo added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 6, 2020
@sanigo sanigo changed the title Need to support regex in hostname. Need to support regex extracting in hostname. Sep 6, 2020
@aledbf
Copy link
Member

aledbf commented Sep 6, 2020

Closing. This is not supported in the Ingress Spec defined in Kubernetes.

@aledbf aledbf closed this as completed Sep 6, 2020
@sanigo
Copy link
Author

sanigo commented Sep 8, 2020

I have found a workaround for this:

    nginx.ingress.kubernetes.io/configuration-snippet: |
      location ~ ^/v2/ {
        set_by_lua_block $repo {
          local host = ngx.req.get_headers()["host"];
          local reg = "^(?<repo>[^.]+).*";
          local m = ngx.re.match(host, reg);
          return m['repo'];
        }
        rewrite ^/(.*)$ /repository/$repo/$1 last;
      }

@awoimbee
Copy link
Contributor

_by_lua_block is now blocked by default for security reasons.
IMO a better way to achieve this is by using server-alias:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/server-alias: ~^([^.]+).my-domain.co
    nginx.ingress.kubernetes.io/server-snippet: set $subdomain $1;
    nginx.ingress.kubernetes.io/permanent-redirect: https://my-domain.co/?subdomain=$subdomain
spec:
  ingressClassName: nginx-public
  rules:
    - host: unique-dummy-url-for-redirect-xyz123.example.com

This is not supported in the Ingress Spec defined in Kubernetes.

Nothing prevents ingress-nginx from extending that spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants