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

if host does not exist raise RoleNotFound #2018

Merged
merged 2 commits into from
Feb 22, 2021

Conversation

mbenita-Cyberark
Copy link
Contributor

@mbenita-Cyberark mbenita-Cyberark commented Feb 1, 2021

What does this PR do?

in k8s authenticator, raise RoleNotFound Exception if host does not exist

What ticket does this PR close?


Checklists

Change log

  • 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, and/or there is a follow-on issue to update docs, or
  • This PR does not require updating any documentation


@host = @resource_class[host_id]
unless @host
raise Errors::Authentication::Security::RoleNotFound.new(
Copy link

Choose a reason for hiding this comment

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

Provide an exception class and message as arguments to raise.

jonahx
jonahx previously approved these changes Feb 1, 2021
izgeri
izgeri previously requested changes Feb 1, 2021
Copy link
Contributor

@izgeri izgeri left a comment

Choose a reason for hiding this comment

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

If we're changing the functional behavior of the server, we should definitely have a CHANGELOG message for this change. You can see our guidelines for writing good changelog messages here. We try to write the changelog messages so they speak to the user-facing impact of the change - basically, try to explain, "If I am the user, why do I care?"

You should probably also try to write a simple test case for this change - something that would have failed before you implemented it, but would be passing now. The PR checklist is a good guide for the things to consider when submitting PRs.

Note: the PR will also need a rebase.

@andytinkham
Copy link
Contributor

I'm not sure which file changed to require quality-architects as codeowner here, but my concerns are the same as those @izgeri brought up. I have no further changes to suggest..

CHANGELOG.md Outdated
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Conjur now Throw RoleNotFound error in k8s authenticator
Copy link
Member

Choose a reason for hiding this comment

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

Conjur now raises a RoleNotFound when trying to authenticate a non-existing host in authn-k8s

@@ -170,16 +176,17 @@ def audit_success
end

def audit_failure(err)
@audit_log.log(
Audit::Event::Authn::InjectClientCert.new(

Copy link

Choose a reason for hiding this comment

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

Extra empty line detected at method body beginning.

client_ip: @client_ip,
success: false,
error_message: err.message
)
)

Copy link

Choose a reason for hiding this comment

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

Extra empty line detected at method body end.

authenticator_name: AUTHENTICATOR_NAME,
service: webservice,
role_id: host.id,
role_id: err.class == Errors::Authentication::Security::RoleNotFound ? "" : host.id,
Copy link

Choose a reason for hiding this comment

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

Align the keys of a hash literal if they span more than one line.

authenticator_name: AUTHENTICATOR_NAME,
service: webservice,
role_id: host.id,
role_id: err.class == Errors::Authentication::Security::RoleNotFound ? "" : host.id,
Copy link

Choose a reason for hiding this comment

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

Use instance_of?(Errors::Authentication::Security::RoleNotFound) instead of comparing classes.

@mbenita-Cyberark mbenita-Cyberark force-pushed the k8s_hostId_not_exist_error_log_improvement branch 3 times, most recently from bf82190 to 4428823 Compare February 21, 2021 15:30
@audit_log.log(Audit::Event::Authn::InjectClientCert.new(
authenticator_name: AUTHENTICATOR_NAME,
service: webservice,
role_id: err.instance_of?(Errors::Authentication::Security::RoleNotFound) ? "" : host.id,
Copy link

Choose a reason for hiding this comment

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

Align the keys of a hash literal if they span more than one line.

@mbenita-Cyberark mbenita-Cyberark force-pushed the k8s_hostId_not_exist_error_log_improvement branch from 4428823 to cdbbfaa Compare February 21, 2021 15:54
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Conjur now raises a RoleNotFound when trying to authenticate a non-existing host in authn-k8s
Copy link
Member

Choose a reason for hiding this comment

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

mnissing link to issue

@mbenita-Cyberark mbenita-Cyberark force-pushed the k8s_hostId_not_exist_error_log_improvement branch from cdbbfaa to d5ad4de Compare February 21, 2021 16:52
# Masking role if it doesn't exist to avoid audit pollution
# Checking @success as well to save DB call on success
def sanitized_role_id
return "not-found" unless @resource_class[host_id]
Copy link

Choose a reason for hiding this comment

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

Add empty line after guard clause.

@@ -161,7 +167,7 @@ def audit_success
Audit::Event::Authn::InjectClientCert.new(
authenticator_name: AUTHENTICATOR_NAME,
service: webservice,
role_id: host.id,
role_id: sanitized_role_id,
Copy link

Choose a reason for hiding this comment

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

Align the keys of a hash literal if they span more than one line.

@@ -174,13 +180,22 @@ def audit_failure(err)
Audit::Event::Authn::InjectClientCert.new(
authenticator_name: AUTHENTICATOR_NAME,
service: webservice,
role_id: host.id,
role_id: sanitized_role_id,
Copy link

Choose a reason for hiding this comment

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

Align the keys of a hash literal if they span more than one line.

# TODO: this logic is taken from app/models/audit/event/authn.rb.
# We should use that logic here.
# Masking role if it doesn't exist to avoid audit pollution
# Checking @success as well to save DB call on success
Copy link
Member

@orenbm orenbm Feb 22, 2021

Choose a reason for hiding this comment

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

you actually don't check @success here. Please fix comment.

- Added RoleNotFound error message in case host not exist for hostId
- Fixed bug when creating InjectClientCert inside log write command
- Added UT
@mbenita-Cyberark mbenita-Cyberark force-pushed the k8s_hostId_not_exist_error_log_improvement branch from d5ad4de to 4359d63 Compare February 22, 2021 08:56
CHANGELOG.md Outdated
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Conjur now raises a RoleNotFound when trying to authenticate a non-existing host in authn-k8s
[conjurinc/appliance#1546]https://github.com/conjurinc/appliance/issues/1546
Copy link
Member

Choose a reason for hiding this comment

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

this should be [conjurinc/appliance#1546](https://github.com/conjurinc/appliance/issues/1546)` so it is linkable in a MD file

Copy link
Member

Choose a reason for hiding this comment

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

this is not the correct issue. The issue you are fixing is that we now raise a NilError instead of an informative one. please add an issue if it's not present

Copy link
Contributor

Choose a reason for hiding this comment

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

why are we linking to an issue filed in a private repo?

Copy link
Contributor

Choose a reason for hiding this comment

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

nm - looks like this was updated later, and the changelog is current now.

- Added RoleNotFound error message in case host not exist for hostId
- Fixed bug when creating InjectClientCert inside log write command
- Added UT
@mbenita-Cyberark mbenita-Cyberark force-pushed the k8s_hostId_not_exist_error_log_improvement branch from 4b966db to 27193bb Compare February 22, 2021 09:29
@codeclimate
Copy link

codeclimate bot commented Feb 22, 2021

Code Climate has analyzed commit 27193bb and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 2

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 89.3% (0.0% change).

View more on Code Climate.

@mbenita-Cyberark mbenita-Cyberark dismissed izgeri’s stale review February 22, 2021 10:37

I implemented requested UTs and Changelog with Oren's PR approval

@mbenita-Cyberark mbenita-Cyberark merged commit 9f06ebd into master Feb 22, 2021
@mbenita-Cyberark mbenita-Cyberark deleted the k8s_hostId_not_exist_error_log_improvement branch February 22, 2021 10:38
@alexkalish
Copy link
Contributor

This is connected to #2046, yes? Please be sure to link PRs to issues, as it helps trace changes when building a release. Thank you!

@alexkalish
Copy link
Contributor

@mbenita-Cyberark @orenbm: Does this have user facing behavior change? How will users be affected? Thanks.

@orenbm
Copy link
Member

orenbm commented Mar 25, 2021

@mbenita-Cyberark @orenbm: Does this have user facing behavior change? How will users be affected? Thanks.

the change is written in the CHANGELOG: Conjur now raises a RoleNotFound when trying to authenticate a non-existing host in authn-k8s

@alexkalish
Copy link
Contributor

@orenbm: Yup, I saw that entry. However, customers typically interact with authn-k8s through the client, not the API directly. How would this change manifest in the client?

@orenbm
Copy link
Member

orenbm commented Mar 25, 2021

it won't. they will see it if they have a failure and will check the logs to find it. do instead of seeing an unhelpful nil pointer message they will see the new message.

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

Successfully merging this pull request may close these issues.

6 participants