8000 Introduce admission webhook settings page by flavio · Pull Request #590 · SUSE/velum · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Oct 29, 2019. It is now read-only.

Introduce admission webhook settings page #590

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

flavio
Copy link
Member
@flavio flavio commented Jun 19, 2018

Allow user to enable AdmissionWebhook by using a new dedicated page.

To work this requires the following PR merged into the salt repo: SUSE/caasp-salt#555

The new UI has to be improved by @vitoravelino, right now it looks something like that:

image

The workflow is the following one:

  • go this new page
  • upload key and certificate
  • enable the feature
  • deploy the cluster

Notable things missing:

  • Validate input (required)
  • Fix UI
  • Add tests
  • Fix coverage

@flavio flavio requested a review from vitoravelino June 19, 2018 14:47
@vitoravelino
Copy link
Contributor

Current state with last commit:

screenshot-20180619174743-431x277
screenshot-20180619174814-670x444
screenshot-20180619174851-673x755

@vitoravelino vitoravelino force-pushed the admission_webhook branch 2 times, most recently from c1b7c8d to b09e87f Compare June 21, 2018 14:52
@@ -11,7 +11,7 @@ $(function() {
new RegistryForm($registryForm);
}

if ($systemCertificateForm.length) {
new SystemCertificateForm($systemCertificateForm);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no SystemCertificateForm. I let this pass on a previous PR. Removed it since it was causing a js error.

@@ -0,0 +1,21 @@
# AdmissionWebhookForm represents a form for AdmissionWebhookController
class AdmissionWebhookForm
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea is to simulate a virtual model and take advantage of some nice things of a model like validation.

Copy link
Contributor

Choose a reason for hiding this comment

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

This will be useful when we introduce the validation of the certificates itself.

Copy link
Contributor
@bergmannf bergmannf Jun 27, 2018

Choose a reason for hiding this comment

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

I am wondering if parts of what this virtual model is doing should maybe be part of the certificate class, as that handles storage of uploaded certificates?

Then we might have another class to handle the keys - as not all views need both.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could include Certificate. Would that be enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the late reply: I wanted to try out the implementation in #593 first.

I guess yes - including certificate and putting the validation logic for certificates in the certificate.rb model would be enough, then we don't duplicate it.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can see the only thing that would be reused, and it would in the controller, is the Certificate.get_certificate_text method. Validation for this page has a condition and that differs from the Certificate model.

The reason for that is because the user is not forced to update both certificate and key at once. They can update one or the other or both. So I guess it's fine leaving this way, right?

We can reuse get_certificate_text after we merge #593.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now you are right - so let's leave it like this.

I assume later on the verification that the certificate is actually a certificate (X509 probably) will be part of certificate.rb, then it might be useful - but I guess we can do that once we work on that feature.

@vitoravelino vitoravelino changed the title WIP - Introduce admission webhook settings page Introduce admission webhook settings page Jun 21, 2018
@vitoravelino vitoravelino force-pushed the admission_webhook branch 3 times, most recently from b752b14 to 1a365f8 Compare June 21, 2018 17:31
@vitoravelino
Copy link
Contributor

@flavio This is good to be reviewed.

@flavio
Copy link
Member Author
flavio commented Jun 22, 2018

It looks to me, I like the workflow. However there's a bug:

  • upload key and cert
  • save
  • disable the feature
  • save -> accept the warning message from the popup window
  • reload the page
  • enable the feature -> the old key and cert are still shown

Basically we don't actually delete them from the database.

@flavio
Copy link
Member Author
flavio commented Jun 22, 2018

Also another bug: it's possible to upload empty files. The validation in place doesn't look for that

@vitoravelino vitoravelino force-pushed the admission_webhook branch 2 times, most recently from abd4fc6 to cd70225 Compare June 22, 2018 18:33
@vitoravelino
Copy link
Contributor

Fixed both cases, @flavio. Thanks!

@vitoravelino
Copy link
Contributor

screenshot-20180622141838-295x229

h2 Admission Webhook

p
| Enable Kubernetes ValidatingAdmissionWebhook admission controller. Once enabled

Choose a reason for hiding this comment

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

you need to add a space at $ or at the beginning of the next line, otherwise it reads Once enabledit is possible to...

8000

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

@key = Pillar.value(pillar: :api_admission_webhook_key)
end

def admission_webhook_params

Choose a reason for hiding this comment

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

can you still make sure to filter the cert/key from the logs in config/initializers/filter_parameter_logging.rb ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about that but for file inputs the content doesn't appear as for text inputs. I can paste the content here if you want.

If we still think that it's necessary to filter it, I can add it.

Choose a reason for hiding this comment

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

hmm in my case it appears, but it's the devenv. if it doesnt appear in production it's totally fine ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh. You mean the current_cert and current_key. Yeah, you are right. I thought that it was the key and certificate inputs. 😅

9E88 Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed!

@flavio
Copy link
Member Author
flavio commented Jun 25, 2018

I cannot be the one approving the PR because I'm the one who created it. But it LGTM

@@ -246,7 +246,7 @@ def proxy_enabled
end

def redirect_to_dashboard
redirect_to root_path if setup_done?
# redirect_to root_path if setup_done?

Choose a reason for hiding this comment

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

debug?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah... Reverted. Thanks again! 😅

notice: "Admission webhook settings successfully saved."
else
set_instance_variables
render action: :index, status: :unprocessable_entity

Choose a reason for hiding this comment

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

what about possible @errors? we should show them in an alert, would be a waste to throw them away

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed.

validates :key, presence: true, if: :current_key_blank?
validates :certificate, presence: true, if: :current_certificate_blank?

validate :cant_be_empty_file

Choose a reason for hiding this comment

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

should we at least validate the filetype as well?

def must_be_key
  `file #{path}`.include? "private key"
end

def must_be_cert
  `file #{path}`.include? "certificate"
end

otherwise i'm afraid we'll have an uncaught exception

Choose a reason for hiding this comment

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

as discussed on irc we can address this in a follow up, as we have other cert handling as well, and it should be done for all parts where we upload certs

@vitoravelino
Copy link
Contributor
vitoravelino commented Jun 28, 2018

I guess we can proceed with the merge, right? I'll give my approval on behalf of @flavio since he created the PR and can't do that.

vitoravelino
vitoravelino previously approved these changes Jun 28, 2018
@vitoravelino vitoravelino force-pushed the admission_webhook branch 2 times, most recently from 7bd68ca to 115add5 Compare July 5, 2018 17:04
@vitoravelino
Copy link
Contributor

I updated the code with with the x509 validation and added pem/der key format validation. Suggestion for wording are welcome. I also made a minor refactoring to make things more readable.

Please review it again. Thanks!

@flavio, could you play with this again?

@bergmannf
Copy link
Contributor

Just a short update to fix the merge conflicts. I still intend to setup an admission webhook and actually try out the code.

@vitoravelino
Copy link
Contributor

Just a short update to fix the merge conflicts. I still intend to setup an admission webhook and actually try out the code.

I don't see any conflicts. Is something going to change?

@bergmannf
Copy link
Contributor

Sorry - I just meant I repushed the changes after a rebase due to conflicts in app/controllers/internal_api/v1/pillars_controller.rb - the dex connector apparently added some more pillars.

require "openssl"

# Verifies that an attribute is a valid PEM/DER encoded key
class PemDerKeyValidator < ActiveModel::EachValidator
Copy link
Contributor

Choose a reason for hiding this comment

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

This validator seems to fail, when trying to upload a password protected key.

I think it is not supposed to be password-protected as a mutual TLS key, but maybe we should put this in the UI.

Allow user to enable AdmissionWebhook by using a new dedicated page.

feature#ValidatingAdmissionWebhook

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
@vitoravelino
Copy link
Contributor

I've rebased this and should be good to be reviewed again.

describe AdmissionWebhookForm do
describe "validations" do
let(:cert_file) do
Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "admin.crt"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code can just use fixture_file_upload instead of Rack::Test::UploadedFile.

@bergmannf
Copy link
Contributor

LGTM with one small change (use fixture_file_upload).

However given that the salt PR is on hold I don't think we can merge this right now.

@vitoravelino vitoravelino force-pushed the admission_webhook branch 2 times, most recently from 6d55095 to cf73dd0 Compare August 9, 2018 14:36
This is a follow-up from the previous commit improving the UI elements,
adding more validation and adding tests for all the new components
added with this new feature.

feature#ValidatingAdmissionWebhook

Signed-off-by: Vítor Avelino <vavelino@suse.com>
@MalloZup
Copy link
Contributor

This GitHub PR is unactive since 30. Is this GitHub PR still needed? Please close or update it accordingly.
This reminder is autogenerated by https://github.com/MalloZup/blacktango

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0