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

Kubernetes: Allow generating secured Ingress resources #26443

Merged
merged 1 commit into from Aug 9, 2022

Conversation

Sgitario
Copy link
Contributor

@Sgitario Sgitario commented Jun 29, 2022

Kubernetes exposes applications using https://kubernetes.io/docs/concepts/services-networking/ingress[Ingress resources]. To generate the Ingress resource, just apply the following configuration:

quarkus.kubernetes.ingress.expose=true

This would generate the following Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    app.quarkus.io/commit-id: a58d2211c86f07a47d4b073ea9ce000d2c6828d5
    app.quarkus.io/build-timestamp: 2022-06-29 - 13:22:41 +0000
  labels:
    app.kubernetes.io/name: kubernetes-with-ingress
    app.kubernetes.io/version: 0.1-SNAPSHOT
  name: kubernetes-with-ingress
spec:
  rules:
    - http:
        paths:
          - backend:
              service:
                name: kubernetes-with-ingress
                port:
                  name: http
            path: /
            pathType: Prefix

After deploying these resources to Kubernetes, the Ingress resource will allow unsecured connections to reach out your application.

To secure the incoming connections, Kubernetes allows enabling https://kubernetes.io/docs/concepts/services-networking/ingress/#tls[TLS] within the Ingress resource by specifying a Secret that contains a TLS private key and certificate. You can generate a secured Ingress resource by simply adding the "tls.secret-name" properties:

quarkus.kubernetes.ingress.expose=true
## Ingress TLS configuration:
quarkus.kubernetes.ingress.tls.my-secret.enabled=true

This configuration will generate the following secured Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  ...
  name: kubernetes-with-secure-ingress
spec:
  rules:
    ...
  tls:
    - secretName: my-secret

Now, Kubernetes will validate all the incoming connections using SSL with the certificates provided within the secret with name "my-secret".

NOTE: More information about how to create the secret in https://kubernetes.io/docs/concepts/services-networking/ingress/#tls[here].

* If true, it will use the TLS configuration in the generated Ingress resource.
*/
@ConfigItem
boolean enabled;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like having to add this enabled field... However, I didn't see any workaround for #7862 (this issue is closed, but having optional nested in other optional objects is not working).

Copy link
Contributor

@iocanel iocanel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -74,10 +74,6 @@ public interface PlatformConfiguration extends EnvVarHolder {

ResourcesConfig getResources();

default Optional<ExpositionConfig> getExposition() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No one used this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is not a generic code anymore, it's used in specific platforms only.

@@ -436,18 +435,6 @@ private static List<DecoratorBuildItem> createAnnotationDecorators(Optional<Proj
now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd - HH:mm:ss Z")), new String[0]))));
}

if (config.getExposition().isPresent() && config.getExposition().get().expose) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, we moved the generic code from common to platform specific processors. Makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

@ebullient ebullient added this to Reviewer approved in Quarkus Documentation Jul 11, 2022
@gsmet
Copy link
Member

gsmet commented Jul 19, 2022

Unfortunately, there is now a conflict. Any chance you could rebase and ping me loudly when done? Thanks!

Kubernetes exposes applications using https://kubernetes.io/docs/concepts/services-networking/ingress[Ingress resources]. To generate the Ingress resource, just apply the following configuration:

[source]
----
quarkus.kubernetes.ingress.expose=true
----

This would generate the following Ingress resource:

[source, yaml]
----
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    app.quarkus.io/commit-id: a58d221
    app.quarkus.io/build-timestamp: 2022-06-29 - 13:22:41 +0000
  labels:
    app.kubernetes.io/name: kubernetes-with-ingress
    app.kubernetes.io/version: 0.1-SNAPSHOT
  name: kubernetes-with-ingress
spec:
  rules:
    - http:
        paths:
          - backend:
              service:
                name: kubernetes-with-ingress
                port:
                  name: http
            path: /
            pathType: Prefix
----

After deploying these resources to Kubernetes, the Ingress resource will allow unsecured connections to reach out your application.

To secure the incoming connections, Kubernetes allows enabling https://kubernetes.io/docs/concepts/services-networking/ingress/#tls[TLS] within the Ingress resource by specifying a Secret that contains a TLS private key and certificate. You can generate a secured Ingress resource by simply adding the "tls.secret-name" properties:

[source]
----
quarkus.kubernetes.ingress.expose=true
quarkus.kubernetes.ingress.tls.my-secret.enabled=true
----

This configuration will generate the following secured Ingress resource:

[source, yaml]
----
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  ...
  name: kubernetes-with-secure-ingress
spec:
  rules:
    ...
  tls:
    - secretName: my-secret
----

Now, Kubernetes will validate all the incoming connections using SSL with the certificates provided within the secret with name "my-secret".

[NOTE]
====
More information about how to create the secret in https://kubernetes.io/docs/concepts/services-networking/ingress/#tls[here].
====

asd
@Sgitario
Copy link
Contributor Author

Unfortunately, there is now a conflict. Any chance you could rebase and ping me loudly when done? Thanks!

PR updated and conflicts resolved!

@gsmet gsmet merged commit 3a836b8 into quarkusio:main Aug 9, 2022
Quarkus Documentation automation moved this from Reviewer approved to Done Aug 9, 2022
@quarkus-bot quarkus-bot bot added this to the 2.12 - main milestone Aug 9, 2022
@gsmet
Copy link
Member

gsmet commented Aug 9, 2022

Merged, thank you!

@Sgitario Sgitario deleted the k8s_support_tls branch August 10, 2022 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants