Skip to content

Commit

Permalink
feat: allow by default if none of the permission is evaluated"
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanarya0 committed Mar 7, 2024
1 parent 0cb2a94 commit 0b2f555
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/proxy/middleware/authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (c *Authz) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
permissionAttributes[key] = value
}

isAuthorized := false
isAuthorized := true
for _, permission := range config.Permissions {
c.log.Info("checking permission", "permission", permission.Name)
if !permission.Expression.IsEmpty() {
Expand Down
32 changes: 32 additions & 0 deletions test/e2e_test/smoke/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,38 @@ func (s *EndToEndProxySmokeTestSuite) TestProxyToEchoServer() {
s.Assert().Equal(401, res.StatusCode)
})

s.Run("permission expression: if none of the permission is evaluated, user shall be authenticated", func() {
groupDetail, err := s.client.GetGroup(context.Background(), &shieldv1beta1.GetGroupRequest{Id: s.groupID})
s.Require().NoError(err)

url := fmt.Sprintf("http://localhost:%d/api/create_firehose_based_on_sink", s.appConfig.Proxy.Services[0].Port)
reqBodyMap := map[string]any{
"project": s.projID,
"name": "test-resource-group-slug",
"group_slug": groupDetail.GetGroup().GetSlug(),
"organization": s.orgID,
"configs": map[string]any{
"env_vars": map[string]any{
"SINK_TYPE": "log",
},
},
}
reqBodyBytes, err := json.Marshal(reqBodyMap)
s.Require().NoError(err)

req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(reqBodyBytes))
s.Require().NoError(err)

req.Header.Set(testbench.IdentityHeader, "[email protected]")

res, err := http.DefaultClient.Do(req)
s.Require().NoError(err)

defer res.Body.Close()
fmt.Println("BODY", res)
s.Assert().Equal(200, res.StatusCode)
})

s.Run("resource created on echo server should persist in shieldDB when using group slug", func() {
groupDetail, err := s.client.GetGroup(context.Background(), &shieldv1beta1.GetGroupRequest{Id: s.groupID})
s.Require().NoError(err)
Expand Down

0 comments on commit 0b2f555

Please sign in to comment.