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

Feature rebac admin #1351

Merged
merged 60 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
eefd981
Add a noop rebac admin api server + GH auth to devenv
pkulik0 Jul 4, 2024
db97d34
Merge branch 'canonical:v3' into CSS-9387-add-rebac-admin-backend-server
pkulik0 Jul 4, 2024
0286dcc
Add test for rebac admin server
pkulik0 Jul 4, 2024
9e02193
PR comments + remove gh secrets thanks to repo visiblity change
pkulik0 Jul 16, 2024
57d20d5
Rename rebac pkg to rebac_admin, move backend setup to that pkg
pkulik0 Jul 18, 2024
b2d3ec6
Merge pull request #1262 from pkulik0/CSS-9387-add-rebac-admin-backen…
pkulik0 Jul 19, 2024
ddd14ae
CSS-9389 Implement the `EntitlementsService` interface (#1277)
SimoneDutto Jul 22, 2024
4d7fea5
Move `CofgaParamsToJIMMOpenFGAParams` to `jimmtest`, don't move servi…
pkulik0 Jul 23, 2024
3bffb8a
Change status code in rebac admin api test
pkulik0 Jul 23, 2024
1c71976
Sort imports in jimmtest auth.go
pkulik0 Jul 23, 2024
ae194e4
Revert changes to service.go & related, add some logging to rebac aut…
pkulik0 Jul 24, 2024
0ad483b
Change httptest recorder to a dummyWriter
pkulik0 Jul 24, 2024
6a30014
Reorganize imports
pkulik0 Jul 24, 2024
ce5300f
CSS-9834 groups skeleton (#1281)
kian99 Jul 25, 2024
df1cc23
Merge branch 'v3' into merge-v3-rebac
kian99 Jul 25, 2024
ff1ae01
Change rebac admin api auth approach to middleware
pkulik0 Jul 25, 2024
451e52e
Merge branch 'feature-rebac-admin' into CSS-9386-rebac-auth-interface
pkulik0 Jul 25, 2024
fdd2349
Merge pull request #1282 from kian99/merge-v3-rebac
kian99 Jul 25, 2024
85ac569
Merge branch 'feature-rebac-admin' into CSS-9386-rebac-auth-interface
pkulik0 Jul 26, 2024
bbd1c36
Change oauth authenticator mock args in test
pkulik0 Jul 26, 2024
48a63b0
CSS-9828 group pagination (#1284)
kian99 Jul 29, 2024
4e82025
Merge branch 'feature-rebac-admin' into CSS-9386-rebac-auth-interface
pkulik0 Jul 29, 2024
b0f06a9
Move auth middleware to a separate pkg
pkulik0 Jul 29, 2024
2c85222
Add more asserts in auth middleware test
pkulik0 Jul 29, 2024
95f29f8
CSS-9908: move relations methods from juju api to jimm package (#1280)
SimoneDutto Jul 29, 2024
6054007
Split auth middleware into two layers
pkulik0 Jul 29, 2024
e137f05
Rename rebac auth middleware test
pkulik0 Jul 29, 2024
975cf02
Merge branch 'feature-rebac-admin' into CSS-9386-rebac-auth-interface
babakks Jul 30, 2024
6451a48
Update go doc of AuthenticateBrowserSession of the mocked authenticator
pkulik0 Jul 30, 2024
6f54e8f
Merge pull request #1279 from pkulik0/CSS-9386-rebac-auth-interface
pkulik0 Jul 30, 2024
dfb1d6e
Upgrade to `[email protected]` (#1291)
babakks Jul 30, 2024
4166b03
Merge branch 'v3' into merge-v3
kian99 Aug 1, 2024
a05c83b
Merge pull request #1294 from kian99/merge-v3
kian99 Aug 1, 2024
658e785
Avoid use of auth client outside of jimm
kian99 Aug 1, 2024
f27392f
Merge pull request #1295 from kian99/avoid-openfga-client-access
kian99 Aug 2, 2024
e1301f2
Merge branch 'v3' into merge-v3
kian99 Aug 5, 2024
40be819
fix conflicts
kian99 Aug 5, 2024
fbfdd83
Merge pull request #1301 from kian99/merge-v3
kian99 Aug 5, 2024
3aea2c7
Css 9953/identity crudi (#1292)
SimoneDutto Aug 5, 2024
ca3516c
CSS-9827 group crud (#1296)
kian99 Aug 6, 2024
8677009
CSS-9829 group identities (#1303)
kian99 Aug 6, 2024
2941687
Merge branch 'v3' into merge-v3
kian99 Aug 8, 2024
d30e349
Merge pull request #1308 from kian99/merge-v3
kian99 Aug 8, 2024
9cadede
Css 9959/identity rels (#1305)
SimoneDutto Aug 9, 2024
713dbe5
Remove db from jujuapi (#1297)
kian99 Aug 15, 2024
c6c28c0
CSS-9830 Implement GetGroupEntitlements (#1315)
kian99 Aug 21, 2024
adb7aea
CSS-9830 patch group entitlements (#1318)
kian99 Aug 23, 2024
c51ea1d
Css 10074/ids entitlements (#1324)
SimoneDutto Aug 27, 2024
36f8f4b
Merge branch 'v3' into merge-v3-feature-rebac-admin
kian99 Sep 2, 2024
ff488d9
fix issues
kian99 Sep 2, 2024
f26f3a5
fix linting issues
kian99 Sep 2, 2024
cc0cf5a
ignore integer conversion linting errors
kian99 Sep 3, 2024
8b2e86f
fix test
kian99 Sep 3, 2024
8766152
Merge pull request #1339 from kian99/merge-v3-feature-rebac-admin
kian99 Sep 3, 2024
f0c184b
Css 9402/resources (#1347)
SimoneDutto Sep 4, 2024
3ac2615
Merge branch 'v3' into merge-v3-feature-rebac-admin
kian99 Sep 4, 2024
5d2faa0
fix missing docstring
kian99 Sep 4, 2024
abc1aed
Merge pull request #1350 from kian99/merge-v3-feature-rebac-admin
kian99 Sep 4, 2024
9b24af6
Merge branch 'v3' into merge-v3-feature-rebac-admin
kian99 Sep 5, 2024
dbb1f38
Merge pull request #1352 from kian99/merge-v3-feature-rebac-admin
kian99 Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/jimmctl/cmd/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ type listGroupsCommand struct {

store jujuclient.ClientStore
dialOpts *jujuapi.DialOpts

limit int
offset int
}

// Info implements the cmd.Command interface.
Expand All @@ -349,6 +352,8 @@ func (c *listGroupsCommand) SetFlags(f *gnuflag.FlagSet) {
"yaml": cmd.FormatYaml,
"json": cmd.FormatJson,
})
f.IntVar(&c.limit, "limit", 0, "The maximum number of groups to return")
f.IntVar(&c.offset, "offset", 0, "The offset to use when requesting groups")
}

// Run implements Command.Run.
Expand All @@ -364,7 +369,8 @@ func (c *listGroupsCommand) Run(ctxt *cmd.Context) error {
}

client := api.NewClient(apiCaller)
groups, err := client.ListGroups()
req := apiparams.ListGroupsRequest{Limit: c.limit, Offset: c.offset}
groups, err := client.ListGroups(&req)
if err != nil {
return errors.E(err)
}
Expand Down
22 changes: 22 additions & 0 deletions cmd/jimmctl/cmd/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (

"github.com/juju/cmd/v3/cmdtesting"
gc "gopkg.in/check.v1"
"gopkg.in/yaml.v3"

"github.com/canonical/jimm/v3/cmd/jimmctl/cmd"
"github.com/canonical/jimm/v3/internal/cmdtest"
"github.com/canonical/jimm/v3/internal/dbmodel"
"github.com/canonical/jimm/v3/internal/jimmtest"
"github.com/canonical/jimm/v3/pkg/api/params"
)

type groupSuite struct {
Expand Down Expand Up @@ -116,6 +118,26 @@ func (s *groupSuite) TestListGroupsSuperuser(c *gc.C) {
c.Assert(strings.Contains(output, "test-group2"), gc.Equals, true)
}

func (s *groupSuite) TestListGroupsLimitSuperuser(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin(c, "alice")

for i := 0; i < 3; i++ {
_, err := s.JimmCmdSuite.JIMM.Database.AddGroup(context.TODO(), fmt.Sprint("test-group", i))
c.Assert(err, gc.IsNil)
}

ctx, err := cmdtesting.RunCommand(c, cmd.NewListGroupsCommandForTesting(s.ClientStore(), bClient), "test-group", "--limit", "1", "--offset", "1")
c.Assert(err, gc.IsNil)
output := cmdtesting.Stdout(ctx)
groups := []params.Group{}
err = yaml.Unmarshal([]byte(output), &groups)
c.Assert(err, gc.IsNil)
c.Assert(groups, gc.HasLen, 1)
c.Assert(groups[0].Name, gc.Equals, "test-group1")
c.Assert(groups[0].UUID, gc.Not(gc.Equals), "")
}

func (s *groupSuite) TestListGroups(c *gc.C) {
// bob is not superuser
bClient := jimmtest.NewUserSessionLogin(c, "bob")
Expand Down
6 changes: 3 additions & 3 deletions cmd/jimmctl/cmd/relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (s *relationSuite) TestRemoveRelationViaFileSuperuser(c *gc.C) {
func (s *relationSuite) TestRemoveRelation(c *gc.C) {
// bob is not superuser
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewRemoveRelationCommandForTesting(s.ClientStore(), bClient), "test-group1#member", "member", "test-group2")
_, err := cmdtesting.RunCommand(c, cmd.NewRemoveRelationCommandForTesting(s.ClientStore(), bClient), "group-testGroup1#member", "member", "group-testGroup2")
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}

Expand Down Expand Up @@ -440,9 +440,9 @@ func (s *relationSuite) TestListRelationsWithError(c *gc.C) {

ctx := context.Background()
group := &dbmodel.GroupEntry{Name: "group-1"}
err = s.JIMM.DB().GetGroup(ctx, group)
err = s.JIMM.Database.GetGroup(ctx, group)
c.Assert(err, gc.IsNil)
err = s.JIMM.DB().RemoveGroup(ctx, group)
err = s.JIMM.Database.RemoveGroup(ctx, group)
c.Assert(err, gc.IsNil)

expectedData := apiparams.ListRelationshipTuplesResponse{
Expand Down
9 changes: 9 additions & 0 deletions cmd/jimmsrv/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ import (
"github.com/canonical/jimm/v3/internal/jujuapi"
"github.com/canonical/jimm/v3/internal/jujuclient"
"github.com/canonical/jimm/v3/internal/logger"
"github.com/canonical/jimm/v3/internal/middleware"
"github.com/canonical/jimm/v3/internal/openfga"
ofganames "github.com/canonical/jimm/v3/internal/openfga/names"
"github.com/canonical/jimm/v3/internal/pubsub"
"github.com/canonical/jimm/v3/internal/rebac_admin"
"github.com/canonical/jimm/v3/internal/vault"
"github.com/canonical/jimm/v3/internal/wellknownapi"
)
Expand Down Expand Up @@ -386,6 +388,11 @@ func NewService(ctx context.Context, p Params) (*Service, error) {
return nil, errors.E(op, err, "failed to parse final redirect url for the dashboard")
}

rebacBackend, err := rebac_admin.SetupBackend(ctx, &s.jimm)
if err != nil {
return nil, errors.E(op, err)
}

// Setup CORS middleware
corsOpts := cors.New(cors.Options{
AllowedOrigins: p.CorsAllowedOrigins,
Expand All @@ -401,6 +408,8 @@ func NewService(ctx context.Context, p Params) (*Service, error) {

s.mux.Mount("/metrics", promhttp.Handler())

s.mux.Mount("/rebac", middleware.AuthenticateRebac(rebacBackend.Handler(""), &s.jimm))

mountHandler(
"/debug",
debugapi.NewDebugHandler(
Expand Down
23 changes: 23 additions & 0 deletions cmd/jimmsrv/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,29 @@ func TestPublicKey(t *testing.T) {
c.Assert(string(data), qt.Equals, `{"PublicKey":"izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk="}`)
}

func TestRebacAdminApi(t *testing.T) {
c := qt.New(t)

_, _, cofgaParams, err := jimmtest.SetupTestOFGAClient(c.Name())
c.Assert(err, qt.IsNil)

p := jimmtest.NewTestJimmParams(c)
p.InsecureSecretStorage = true
p.OpenFGAParams = cofgaParamsToJIMMOpenFGAParams(*cofgaParams)

svc, err := jimmsvc.NewService(context.Background(), p)
c.Assert(err, qt.IsNil)
defer svc.Cleanup()

srv := httptest.NewTLSServer(svc)
c.Cleanup(srv.Close)

response, err := srv.Client().Get(srv.URL + "/rebac/v1/swagger.json")
c.Assert(err, qt.IsNil)
defer response.Body.Close()
c.Assert(response.StatusCode, qt.Equals, 401)
}

func TestThirdPartyCaveatDischarge(t *testing.T) {
c := qt.New(t)

Expand Down
19 changes: 15 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ require (
require (
github.com/antonlindstrom/pgstore v0.0.0-20220421113606-e3a6e3fed12a
github.com/canonical/ofga v0.10.0
github.com/canonical/rebac-admin-ui-handlers v0.1.0
github.com/coreos/go-oidc/v3 v3.9.0
github.com/dustinkirkland/golang-petname v0.0.0-20231002161417-6a283f1aaaf2
github.com/go-chi/chi/v5 v5.0.8
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/render v1.0.2
github.com/gorilla/sessions v1.2.1
github.com/hashicorp/golang-lru/v2 v2.0.7
Expand All @@ -64,6 +65,7 @@ require (
gopkg.in/errgo.v1 v1.0.1
gopkg.in/httprequest.v1 v1.2.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -85,6 +87,7 @@ require (
github.com/Rican7/retry v0.3.1 // indirect
github.com/adrg/xdg v0.3.3 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.24.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.26.2 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.16.13 // indirect
Expand Down Expand Up @@ -119,17 +122,22 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/tcell/v2 v2.5.1 // indirect
github.com/getkin/kin-openapi v0.125.0 // indirect
github.com/go-goose/goose/v5 v5.0.0-20230421180421-abaee9096e3a // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-macaroon-bakery/macaroonpb v1.0.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/swag v0.22.8 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/gofrs/flock v0.8.1 // indirect
Expand All @@ -156,6 +164,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/im7mortal/kmutex v1.0.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand Down Expand Up @@ -211,6 +220,7 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.5 // indirect
Expand Down Expand Up @@ -251,10 +261,12 @@ require (
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/oracle/oci-go-sdk/v65 v65.55.0 // indirect
github.com/packethost/packngo v0.28.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.6 // indirect
Expand Down Expand Up @@ -314,7 +326,6 @@ require (
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.0 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/apimachinery v0.29.0 // indirect
Expand Down
Loading
Loading