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

Authn jwt all signing key settings #2461

Merged
merged 2 commits into from
Jan 16, 2022

Conversation

sashaCher
Copy link
Contributor

Desired Outcome

JWT Authenticator is able to relate to two new variables ca-cert and public-keys. Both variables are related to signing keys settings area. Authenticator validates validity of variables permutations.
It's not full variables integration yet, so this PR does not change the behavior in this matter.

Implemented Changes

Responsibility for fetching variables values and validating and building signing key settings object is now split between two classes: FetchSigningKeyParametersFromVariables and SigningKeySettingsBuilder.
Both classes are dependency of the CreateSigningKeyProvider class, signing key providers are using signing key settings.

General and non informative InvalidUriConfiguration (CONJ00086E) error is replaced by informative InvalidSigningKeySettings (CONJ00122E) one, see spec/app/domain/authentication/authn-jwt/signing_key/signing_key_settings_builder_spec.rb file for the list of inputs and output error messages.

Connected Issue/Story

ONYX-15140

Definition of Done

  • Desired outcome is achieved
  • No integration tests are broken

Changelog

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a
    CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code
    changes, or
  • The changes in this PR do not require tests

Documentation

  • Docs (e.g. READMEs) were updated in this PR
  • A follow-up issue to update official docs has been filed here: insert issue ID
  • This PR does not require updating any documentation

Behavior

  • This PR changes product behavior and has been reviewed by a PO, or
  • These changes are part of a larger initiative that will be reviewed later, or
  • No behavior was changed with this PR

Security

  • Security architect has reviewed the changes in this PR,
  • These changes are part of a larger initiative with a separate security review, or
  • There are no security aspects to these changes

@sashaCher sashaCher requested a review from a team January 12, 2022 20:04
@sashaCher sashaCher requested a review from a team as a code owner January 12, 2022 20:04
Base automatically changed from authn-jwt-integrate-signing-key-settings to master January 12, 2022 20:49
return provider_uri if provider_uri
end

def signing_key_settings_type
Copy link

Choose a reason for hiding this comment

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

Method signing_key_settings_type has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

@@ -0,0 +1,52 @@
module Authentication
module AuthnJwt
module SigningKey
Copy link

Choose a reason for hiding this comment

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

Authentication::AuthnJwt::SigningKey has no descriptive comment

@sashaCher sashaCher force-pushed the authn-jwt-all-signing-key-settings branch from 8354e5e to 54d0c93 Compare January 13, 2022 08:18
return unless !jwks_uri && !provider_uri && !public_keys

raise Errors::Authentication::AuthnJwt::InvalidSigningKeySettings,
"One of #{JWKS_URI_RESOURCE_NAME}, #{PUBLIC_KEYS_RESOURCE_NAME}, and #{PROVIDER_URI_RESOURCE_NAME} have to be defined"
Copy link

Choose a reason for hiding this comment

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

actually this raises a good question if to leave the provider uri, as the customer will see it in the error, and will wonder what it is...
maybe we can remove it from the error?
will verify with Sharon.

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 think that we cannot remove it because it may turn troubleshooting to a nightmare...

return unless jwks_uri && public_keys && provider_uri

raise Errors::Authentication::AuthnJwt::InvalidSigningKeySettings,
"#{JWKS_URI_RESOURCE_NAME}, #{PUBLIC_KEYS_RESOURCE_NAME}, and #{PROVIDER_URI_RESOURCE_NAME} cannot be define simultaneously"
Copy link

Choose a reason for hiding this comment

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

@shulifink can you pls review the text?
these variables cannot be defined togethe.

return unless jwks_uri && provider_uri

raise Errors::Authentication::AuthnJwt::InvalidSigningKeySettings,
"#{JWKS_URI_RESOURCE_NAME} and #{PROVIDER_URI_RESOURCE_NAME} cannot be define simultaneously"
Copy link
Contributor

Choose a reason for hiding this comment

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

Cant we move this template to errors.rb?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually errors.rb contains only TrackableErrorClass instances so moving plain text messages to it feels me not right.
But I'll move those texts to consts of the same class

@sashaCher sashaCher force-pushed the authn-jwt-all-signing-key-settings branch from 54d0c93 to 3d446df Compare January 14, 2022 20:32
The class validates signing key parameters and creates a valid SigningKeySettings object from them
Two new parameters cert_store and signing_keys are added to the SigningKeySettings class
@sashaCher sashaCher force-pushed the authn-jwt-all-signing-key-settings branch from 3d446df to ba79c6f Compare January 14, 2022 20:51
@@ -0,0 +1,133 @@
module Authentication
module AuthnJwt
module SigningKey
Copy link

Choose a reason for hiding this comment

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

Authentication::AuthnJwt::SigningKey has 8 constants

check_authenticator_secret_exists: Authentication::Util::CheckAuthenticatorSecretExists.new,
fetch_authenticator_secrets: Authentication::Util::FetchAuthenticatorSecrets.new
},
inputs: %i[authenticator_input]
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe consider using delgators for
accout, service_id, authenticator_name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From one point of view let it be.
From other do we have some rule of thumb when to use delegators?

module AuthnJwt
module SigningKey

NO_SIGNING_KEYS_SOURCE = "One of #{JWKS_URI_RESOURCE_NAME}, #{PUBLIC_KEYS_RESOURCE_NAME}, and #{PROVIDER_URI_RESOURCE_NAME} have to be defined".freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

Can it sit in consts or errors.rb?

Copy link
Contributor Author

@sashaCher sashaCher Jan 16, 2022

Choose a reason for hiding this comment

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

It's too specific from my point of view.
Nobody else is using the same consts so there's no reason to split it to other files.
As I mentioned before errors.rb is a container for exceptions, not for error messages.

tzheleznyak
tzheleznyak previously approved these changes Jan 16, 2022
Copy link
Contributor

@tzheleznyak tzheleznyak left a comment

Choose a reason for hiding this comment

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

LGTM

Variables values related to signing keys fetching from one side and values validation and the settings object creation are split to two classes (parameters fetcher and settings builder) both classes are used by CreateSigningKeyProvider class
Copy link
Contributor

@tzheleznyak tzheleznyak left a comment

Choose a reason for hiding this comment

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

LGTM

@codeclimate
Copy link

codeclimate bot commented Jan 16, 2022

Code Climate has analyzed commit 5fabe9a and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 91.2% (0.1% change).

View more on Code Climate.

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

Successfully merging this pull request may close these issues.

4 participants