Skip to content

Commit

Permalink
Fixes 2450: remove org admin skip setting (#444)
Browse files Browse the repository at this point in the history
* Fixes 2450: remove org admin skip setting

* update org admin script for mac
  • Loading branch information
rverdile authored Oct 30, 2023
1 parent 148384a commit b0094d2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
5 changes: 0 additions & 5 deletions deployments/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ objects:
name: cs-pulp-admin-password
key: password
optional: true
- name: RBAC_ORG_ADMIN_SKIP
value: ${RBAC_ORG_ADMIN_SKIP}
- name: LOGGING_LEVEL
value: ${{LOGGING_LEVEL}}
- name: CLIENTS_RBAC_BASE_URL
Expand Down Expand Up @@ -413,9 +411,6 @@ parameters:
description: Whether the Admin Tasks feature should be turned on
- name: FEATURES_ADMIN_TASKS_ACCOUNTS
description: Comma separated list of account number that can access the feature
- name: RBAC_ORG_ADMIN_SKIP
description: skip rbac check if the user is an org admin
default: 'false'
- name: OPTIONS_ALWAYS_RUN_CRON_TASKS
description: Option to make testing nightly snapshotting & introspection easier
default: 'false'
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Configuration struct {
NotificationsClient cloudevents.Client `mapstructure:"notification_client"`
Tasking Tasking `mapstructure:"tasking"`
Features FeatureSet `mapstructure:"features"`
RbacOrgAdminSkip bool `mapstructure:"rbac_org_admin_skip"`
}

type Clients struct {
Expand Down Expand Up @@ -204,7 +203,6 @@ func setDefaults(v *viper.Viper) {
v.SetDefault("Loaded", true)
// In viper you have to set defaults, otherwise loading from ENV doesn't work
// without a config file present
v.SetDefault("rbac_org_admin_skip", false)
v.SetDefault("database.host", "")
v.SetDefault("database.port", "")
v.SetDefault("database.user", "")
Expand Down
7 changes: 1 addition & 6 deletions pkg/rbac/client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/RedHatInsights/rbac-client-go"
"github.com/content-services/content-sources-backend/pkg/cache"
"github.com/content-services/content-sources-backend/pkg/config"
"github.com/redhatinsights/platform-go-middlewares/identity"
"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -101,9 +100,5 @@ func (r *ClientWrapperImpl) Allowed(ctx context.Context, resource Resource, verb
}

func skipRbacCheck(ctx context.Context) bool {
if config.Get().RbacOrgAdminSkip {
return identity.Get(ctx).Identity.User.OrgAdmin
} else {
return false
}
return identity.Get(ctx).Identity.User.OrgAdmin
}
15 changes: 15 additions & 0 deletions pkg/rbac/client_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/RedHatInsights/rbac-client-go"
"github.com/content-services/content-sources-backend/pkg/cache"
"github.com/content-services/content-sources-backend/pkg/config"
test_handler "github.com/content-services/content-sources-backend/pkg/test/handler"
mocks_rbac "github.com/content-services/content-sources-backend/pkg/test/mocks/rbac"
"github.com/labstack/echo/v4"
"github.com/redhatinsights/platform-go-middlewares/identity"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -56,6 +58,7 @@ func TestRbacSuite(t *testing.T) {

func (s *RbacTestSuite) TestCachesWhenNotFound() {
ctx := context.TODO()
ctx = context.WithValue(ctx, identity.Key, test_handler.MockIdentity)
var emptyList rbac.AccessList
s.mockCache.On("GetAccessList", ctx).Return(nil, cache.NotFound)
s.mockCache.On("SetAccessList", ctx, emptyList).Return(nil, cache.NotFound)
Expand All @@ -66,10 +69,22 @@ func (s *RbacTestSuite) TestCachesWhenNotFound() {

func (s *RbacTestSuite) TestCachesWhenNotFoundAgain() {
ctx := context.TODO()
ctx = context.WithValue(ctx, identity.Key, test_handler.MockIdentity)
var emptyList rbac.AccessList

s.mockCache.On("GetAccessList", ctx).Return(emptyList, nil)
allowed, err := s.rbac.Allowed(ctx, "repositories", "read")
assert.NoError(s.T(), err)
assert.False(s.T(), allowed)
}

func (s *RbacTestSuite) TestOrgAdminSkip() {
ctx := context.TODO()
mockIdentity := test_handler.MockIdentity
mockIdentity.Identity.User.OrgAdmin = true
ctx = context.WithValue(ctx, identity.Key, mockIdentity)

allowed, err := s.rbac.Allowed(ctx, "repositories", "read")
assert.NoError(s.T(), err)
assert.True(s.T(), allowed)
}
20 changes: 10 additions & 10 deletions pkg/test/handler/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (

var MockAccountNumber = seeds.RandomAccountId()
var MockOrgId = seeds.RandomOrgId()
var MockIdentity = identity.XRHID{
Identity: identity.Identity{
AccountNumber: MockAccountNumber,
Internal: identity.Internal{
OrgID: MockOrgId,
},
Type: "Associate",
},
}

func EncodedIdentity(t *testing.T) string {
mockIdentity := identity.XRHID{
Identity: identity.Identity{
AccountNumber: MockAccountNumber,
Internal: identity.Internal{
OrgID: MockOrgId,
},
Type: "Associate",
},
}
jsonIdentity, err := json.Marshal(mockIdentity)
jsonIdentity, err := json.Marshal(MockIdentity)
if err != nil {
t.Error("Could not marshal JSON")
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/header_org_admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fi

case "$( uname -s )" in
"Darwin" )
ENC="$(echo "{\"identity\":{\"type\":\"User\",\"user\":{\"username\":\"${USER_NAME}\"},\"account_number\":\"${ACCOUNT_ID}\",\"internal\":{\"org_id\":\"${ORG_ID}\"}}}" | base64 -b 0)"
ENC="$(echo "{\"identity\":{\"type\":\"User\",\"user\":{\"is_org_admin\":true, \"username\":\"${USER_NAME}\"},\"account_number\":\"${ACCOUNT_ID}\",\"internal\":{\"org_id\":\"${ORG_ID}\"}}}" | base64 -b 0)"
;;

"Linux" | *)
Expand Down

0 comments on commit b0094d2

Please sign in to comment.