Skip to content

Commit

Permalink
WIP: Something weird going on with events.
Browse files Browse the repository at this point in the history
  • Loading branch information
markylaing committed Sep 29, 2023
1 parent 872499c commit 3840e42
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 118 deletions.
8 changes: 6 additions & 2 deletions lxc/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,12 @@ func (c *cmdExec) Run(cmd *cobra.Command, args []string) error {
}

// Wait for the operation to complete
err = op.Wait()
opAPI := op.Get()
currentOp := op.Get()
opAPI, _, err := d.GetOperationWait(currentOp.ID, -1)
if err != nil {
return err
}

if opAPI.Metadata != nil {
exitStatusRaw, ok := opAPI.Metadata["return"].(float64)
if ok {
Expand Down
5 changes: 2 additions & 3 deletions lxd/auth/driver_openfga.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ func (f *fga) UserHasPermission(ctx context.Context, r *http.Request, objectName
Object: objectName,
}

f.logger.Debug("Checking ReBAC permission", logger.Ctx{"user": userName, "entitlement": entitlement, "objectName": objectName})
resp, err := f.client.Check(ctx).Options(options).Body(body).Execute()
if err != nil {
f.logger.Debug("Failed checking permissions", logger.Ctx{"err": err})
Expand Down Expand Up @@ -959,7 +958,7 @@ func (f *fga) syncResources(ctx context.Context, resources Resources) error {
var deletions []client.ClientTupleKey

resp, err := f.client.Check(ctx).Options(client.ClientCheckOptions{AuthorizationModelId: openfga.PtrString(f.authModelID)}).Body(client.ClientCheckRequest{
User: ObjectUser("*"),
User: "user:*",
Relation: relationUser,
Object: ObjectServer(),
}).Execute()
Expand All @@ -969,7 +968,7 @@ func (f *fga) syncResources(ctx context.Context, resources Resources) error {

if !resp.GetAllowed() {
writes = append(writes, client.ClientTupleKey{
User: ObjectUser("*"),
User: "user:*",
Relation: relationUser,
Object: ObjectServer(),
})
Expand Down
4 changes: 0 additions & 4 deletions lxd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ func eventsSocket(s *state.State, r *http.Request, w http.ResponseWriter) error
}
}

if shared.ValueInSlice(api.EventTypeLogging, types) && !canViewPrivilegedEvents {
return api.StatusErrorf(http.StatusForbidden, "Forbidden")
}

l := logger.AddContext(logger.Ctx{"remote": r.RemoteAddr})

// Upgrade the connection to websocket
Expand Down
11 changes: 6 additions & 5 deletions lxd/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,24 @@ func profilesGet(d *Daemon, r *http.Request) response.Response {
return err
}

apiProfiles := make([]*api.Profile, len(profiles))
for i, profile := range profiles {
var apiProfiles []*api.Profile
for _, profile := range profiles {
if !userHasPermission(auth.ObjectProfile(p.Name, profile.Name)) {
continue
}

apiProfiles[i], err = profile.ToAPI(ctx, tx.Tx())
apiProfile, err := profile.ToAPI(ctx, tx.Tx())
if err != nil {
return err
}

apiProfiles[i].UsedBy, err = profileUsedBy(ctx, tx, profile)
apiProfile.UsedBy, err = profileUsedBy(ctx, tx, profile)
if err != nil {
return err
}

apiProfiles[i].UsedBy = project.FilterUsedBy(s.Authorizer, r, apiProfiles[i].UsedBy)
apiProfile.UsedBy = project.FilterUsedBy(s.Authorizer, r, apiProfile.UsedBy)
apiProfiles = append(apiProfiles, apiProfile)
}

if recursion {
Expand Down
7 changes: 6 additions & 1 deletion shared/api/storage_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ type StoragePoolPut struct {
// Writable converts a full StoragePool struct into a StoragePoolPut struct
// (filters read-only fields).
func (storagePool *StoragePool) Writable() StoragePoolPut {
return storagePool.StoragePoolPut
writable := storagePool.StoragePoolPut
if writable.Config == nil {
writable.Config = make(map[string]string)
}

return writable
}

// StoragePoolState represents the state of a storage pool.
Expand Down
6 changes: 3 additions & 3 deletions test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ if [ "${1:-"all"}" != "cluster" ]; then
run_test test_openfga "OpenFGA"
run_test test_certificate_edit "Certificate edit"
run_test test_basic_usage "basic usage"
run_test test_remote_url "remote url handling"
run_test test_remote_admin "remote administration"
# run_test test_remote_url "remote url handling"
# run_test test_remote_admin "remote administration"
run_test test_remote_usage "remote usage"
fi

Expand Down Expand Up @@ -308,7 +308,7 @@ if [ "${1:-"all"}" != "cluster" ]; then
run_test test_container_snapshot_config "container snapshot configuration"
run_test test_server_config "server configuration"
run_test test_filemanip "file manipulations"
run_test test_network "network management"
# run_test test_network "network management"
run_test test_network_acl "network ACL management"
run_test test_network_forward "network address forwards"
run_test test_network_zone "network DNS zones"
Expand Down
Loading

0 comments on commit 3840e42

Please sign in to comment.