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

Allow reading configuration from Kubernetes secrets #10939

Merged
merged 3 commits into from
Jul 30, 2020

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Jul 23, 2020

@geoand, @iocanel, this is a follow-up to #8644 as discussed in https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/Using.20k8s.20secrets.20as.20a.20configuration.20source. See commit messages for details.

I'm creating this as a draft so that CI can run in my fork, and also because:

  • this needs Dekorate release with role binding names dekorateio/dekorate#594;
  • I need to write some documentation;
  • there's one TODO in the code that I'd like to discuss with you guys;
  • I added a test, but if you guys think more tests are needed, I'd be happy to add them.

@boring-cyborg boring-cyborg bot added area/dependencies Pull requests that update a dependency file area/kubernetes labels Jul 23, 2020
@Ladicek
Copy link
Contributor Author

Ladicek commented Jul 23, 2020

Ah, and one more important thing that also needs a bit of a discussion: this PR contains an SPI breaking change. I renamed KubernetesRoleBuildItem to KubernetesRoleBindingBuildItem (because that's what it does) and created a new KubernetesRoleBuildItem (which no longer creates role bindings, but roles). If you think that's not acceptable, I'm happy to move back, but would need a good name for a build item that requests creating a role.

(Also, I originally envisioned a generic build item that would carry arbitrary Kubernetes resources, but that would require exposing Dekorate as public SPI. Which is probably a bad idea at this point. So I went with adding a build item for the one Kubernetes resource type I needed, which is a role.)

@Ladicek Ladicek requested review from geoand and iocanel July 23, 2020 15:33
@geoand
Copy link
Contributor

geoand commented Jul 23, 2020

Cool, thanks @Ladicek ! I'll have a look tomorrow

@geoand
Copy link
Contributor

geoand commented Jul 24, 2020

Although breaking the SPI is obviously something we don't want to do, I think in this case it's warranted. The new names make perfect sense and furthermore it's very unlikely that any piece of code outside this extension depends on the changed build item.

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

I really like this and would definitely want to have it in for 1.7

@@ -732,11 +736,16 @@ private void applyBuildItems(Session session,
.forEach(p -> session.configurators().add(new AddPort(p)));

//Handle RBAC
// TODO why this condition?
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember TBH... To me it doesn't seem reasonable (it might have made sense in the past?).

@iocanel do you remember?

Copy link
Contributor

Choose a reason for hiding this comment

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

The condition seems wrong. The actual condition should be when kubernetes-client is added to the project or something like that.

@@ -145,7 +145,7 @@
<aws-alexa-sdk.version>2.30.0</aws-alexa-sdk.version>
<azure-functions-java-library.version>1.3.0</azure-functions-java-library.version>
<kotlin.version>1.3.72</kotlin.version>
<dekorate.version>0.12.6</dekorate.version>
<dekorate.version>0.12-SNAPSHOT</dekorate.version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not forget to change this one :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea. Hopefully dekorateio/dekorate#594 will get some attention :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I pinged @iocanel on this

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll release later today

import io.dekorate.kubernetes.decorator.ResourceProvidingDecorator;
import io.quarkus.kubernetes.spi.KubernetesRoleBuildItem;

class AddRoleResourceDecorator extends ResourceProvidingDecorator<KubernetesListBuilder> {
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, but this is one that @iocanel will have to give the OK for

@Ladicek Ladicek force-pushed the kubernetes-config-secrets branch from 9ffc17d to 74eb333 Compare July 24, 2020 08:39
&& !buildTimeConfig.secretsEnabled) {
log.warn("Configuration is read from Secrets " + config.secrets.get()
+ ", but quarkus.kubernetes-config.secrets.enabled is false."
+ " Check if your application's service account has enough permissions to read secrets.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it just me, or does the last sentence seem out of place?

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 wanted to say that what the user ultimately needs to do is not setting our config property, but make sure that the app's service account has access to secrets.

Obviously quarkus.kubernetes-config.secrets.enabled is the easiest way, if people use the Kubernetes extension. But that doesn't always have to be the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay

@Ladicek Ladicek force-pushed the kubernetes-config-secrets branch from 74eb333 to dfc1f6e Compare July 24, 2020 09:08
@Ladicek
Copy link
Contributor Author

Ladicek commented Jul 24, 2020

Added docs.

@Ladicek Ladicek force-pushed the kubernetes-config-secrets branch from dfc1f6e to 412d10a Compare July 24, 2020 12:48
@geoand
Copy link
Contributor

geoand commented Jul 28, 2020

@iocanel can you please take a look at this? It would be nice to have it in for 1.7

@iocanel
Copy link
Contributor

iocanel commented Jul 28, 2020

Will look later today

@gsmet gsmet changed the title allow reading configuration from Kubernetes secrets Allow reading configuration from Kubernetes secrets Jul 28, 2020
@gsmet gsmet added this to the 1.7.0 - master milestone Jul 28, 2020
@geoand
Copy link
Contributor

geoand commented Jul 29, 2020

@iocanel @Ladicek do you think we can get this one in for 1.7 (CR1 is tomorrow)?

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

@geoand
Copy link
Contributor

geoand commented Jul 29, 2020

We'll obviously need a dekorate release and a rebase to fix the confict.

@Ladicek
Copy link
Contributor Author

Ladicek commented Jul 29, 2020

If we can get a Dekorate release, I think this can go into 1.7, yea.

@Ladicek Ladicek force-pushed the kubernetes-config-secrets branch from 412d10a to a19aab0 Compare July 29, 2020 14:30
@Ladicek
Copy link
Contributor Author

Ladicek commented Jul 29, 2020

Rebased and resolved the conflict.

@geoand
Copy link
Contributor

geoand commented Jul 29, 2020

Great, so all we need is a dekorate release and we're good

@iocanel
Copy link
Contributor

iocanel commented Jul 29, 2020

@Ladicek @geoand: dekorate 0.12.7 is out and includes the desired fix.

@geoand
Copy link
Contributor

geoand commented Jul 29, 2020

Excellent, thank you both for driving this one home!

@Ladicek Ladicek force-pushed the kubernetes-config-secrets branch from a19aab0 to 29c6d11 Compare July 29, 2020 14:50
@Ladicek
Copy link
Contributor Author

Ladicek commented Jul 29, 2020

Updated PR, will let CI run in my fork and then un-WIP.

This reverts commit 0c71c47
and adds a couple of cleanups. Most importantly, the issue
which caused this functionality to be removed remains:
the application by default runs under a role that doesn't have
access to secrets. This is marked with one TODO in the code
and will be addressed in a subsequent commit.
Ladicek added 2 commits July 29, 2020 18:12
The `kubernetes` extension automatically generates a RoleBinding
that refers to the `view` ClusterRole. This ClusterRole doesn't
allow access to secrets. This commit therefore adds a configuration
property which, when enabled, makes the `kubernetes` extension
generate a special Role `view-secrets` and a second RoleBinding
referring to that role. This configuration property is build-time
only and has no other effect.

With this configuration in place, there's nothing preventing
the application from reading Secrets directly from the API server.

For convenience, a warning is printed at runtime if configuration
is read from Secrets yet the property is disabled.
@Ladicek Ladicek force-pushed the kubernetes-config-secrets branch from c33bc0c to 571aaef Compare July 29, 2020 16:12
@Ladicek Ladicek marked this pull request as ready for review July 29, 2020 16:12
@Ladicek
Copy link
Contributor Author

Ladicek commented Jul 29, 2020

Fixed a failing unit test (I didn't run it locally before, just the integration tests) and un-WIP-ed.

@geoand
Copy link
Contributor

geoand commented Jul 30, 2020

There is a weird CI failure that is almost certainly a system failure, but because it happened on the Kubernetes tests, I want to avoid any surprises, so I'll restart CI

@gsmet gsmet merged commit f538ba5 into quarkusio:master Jul 30, 2020
@gsmet
Copy link
Member

gsmet commented Jul 30, 2020

And merged! Thanks!

@geoand
Copy link
Contributor

geoand commented Jul 30, 2020

🎉

@Ladicek Ladicek deleted the kubernetes-config-secrets branch July 30, 2020 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dependencies Pull requests that update a dependency file area/documentation area/kubernetes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants