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

add organization ID check from JWT token for internal rules #85

Merged
merged 5 commits into from
Jul 9, 2020
Merged

add organization ID check from JWT token for internal rules #85

merged 5 commits into from
Jul 9, 2020

Conversation

Bee-lee
Copy link
Collaborator

@Bee-lee Bee-lee commented Jul 7, 2020

Description

This adds a security check for internal rules based on organization ID

Fixes #76
Blocks RedHatInsights/insights-content-service#97
Blocked by https://github.com/RedHatInsights/e2e-deploy/pull/1923

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update
  • Refactor (refactoring code, removing useless files)
  • Unit tests (no changes in the code)
  • Documentation update

Testing steps

Modified requests to contain diffferent org_ids to test manually

  • I had some timeout issues locally, so let's see what travis has to say

Copy link
Collaborator

@tisnik tisnik left a comment

Choose a reason for hiding this comment

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

LGTM, just hope the token is not sensitive.


for _, ruleIDPart := range splitRuleID {
if ruleIDPart == internalRuleStr {
isInternal = true

Choose a reason for hiding this comment

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

I'd just return true here, but it's a nitpick :)

server/server.go Outdated Show resolved Hide resolved
server/server_test.go Outdated Show resolved Hide resolved
Copy link

@Serhii1011010 Serhii1011010 left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks :)

@codecov-commenter
Copy link

Codecov Report

Merging #85 into master will increase coverage by 6.63%.
The diff coverage is 77.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #85      +/-   ##
==========================================
+ Coverage   42.09%   48.73%   +6.63%     
==========================================
  Files          11       11              
  Lines         867      911      +44     
==========================================
+ Hits          365      444      +79     
+ Misses        462      413      -49     
- Partials       40       54      +14     
Impacted Files Coverage Δ
server/server.go 50.94% <68.00%> (+3.84%) ⬆️
content/parsing.go 73.97% <73.91%> (-0.61%) ⬇️
content/content.go 67.18% <100.00%> (+0.52%) ⬆️
server/handlers.go 22.22% <100.00%> (+22.22%) ⬆️
server/router_utils.go 6.55% <0.00%> (+6.55%) ⬆️
server/errors.go 34.28% <0.00%> (+11.42%) ⬆️
server/auth.go 39.43% <0.00%> (+33.80%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 877dc2b...07021c1. Read the comment docs.

@@ -59,6 +59,15 @@ func (server HTTPServer) getContentForRule(writer http.ResponseWriter, request *
return
}

// check for internal rule permissions
if internal := content.IsRuleInternal(ruleID); internal == true {
Copy link
Collaborator

Choose a reason for hiding this comment

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

internal == true => internal

Just a nitpick

// check for internal rule permissions
if internal := content.IsRuleInternal(ruleID); internal == true {
ok := server.checkInternalRulePermissions(writer, request)
if ok != true {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ok != true => !ok

Comment on lines +133 to +158
RuleContentInternal1 = ics_content.RuleContent{
Summary: testdata.Rule1.Summary,
Reason: testdata.Rule1.Reason,
Resolution: testdata.Rule1.Resolution,
MoreInfo: testdata.Rule1.MoreInfo,
Plugin: ics_content.RulePluginInfo{
Name: testdata.Rule1.Name,
NodeID: "",
ProductCode: "",
PythonModule: internalTestRuleModule,
},
ErrorKeys: map[string]ics_content.RuleErrorKeyContent{
"ek1": {
Generic: testdata.RuleErrorKey1.Generic,
Metadata: ics_content.ErrorKeyMetadata{
Condition: testdata.RuleErrorKey1.Condition,
Description: testdata.RuleErrorKey1.Description,
Impact: testdata.ImpactIntToStr[testdata.RuleErrorKey1.Impact],
Likelihood: testdata.RuleErrorKey1.Likelihood,
PublishDate: testdata.RuleErrorKey1.PublishDate.UTC().Format(time.RFC3339),
Tags: testdata.RuleErrorKey1.Tags,
Status: "active",
},
},
},
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this definition to testdata package in insights-results-aggregator-data repository, but it can be done later

@Bee-lee Bee-lee merged commit a4bcb62 into RedHatInsights:master Jul 9, 2020
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.

Implement organization ID check for internal rules
5 participants