Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Add from capability#154
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Add from capability #154
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
97bc8eb
send from event to entity calls
withinboredom a68af98
allow orchestrations to work
withinboredom a8379d7
handle the go side
withinboredom fcd3556
fix withDelay
withinboredom 9093267
fix orchestration context
withinboredom a3b2a09
allow fine-grained access control in php
withinboredom 59172fa
add id kinds for api and system
withinboredom e2bf46f
fix warning operations
withinboredom 5b811d5
fix attribute
withinboredom 90d1d93
add tests
withinboredom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -46,14 +46,16 @@ import ( | ||
| // - WantTo: checks if the current user can perform the given operation on the resource. | ||
| // - Grant: grants a share to the resource. | ||
| type Resource struct { | ||
| Owners map[UserId]struct{} `json:"owner"` | ||
| Shares []Share `json:"Shares"` | ||
| Mode Mode `json:"mode"` | ||
| mu sync.RWMutex | ||
| kv jetstream.KeyValue | ||
| id *ids.StateId | ||
| Expires time.Time | ||
| revision uint64 | ||
| Owners map[UserId]struct{} `json:"owner"` | ||
| Shares []Share `json:"Shares"` | ||
| Mode Mode `json:"mode"` | ||
| mu sync.RWMutex | ||
| kv jetstream.KeyValue | ||
| id *ids.StateId | ||
| AllowedFromTypes []string `json:"allowed_from_types"` | ||
| AllowedFromIds []*ids.StateId `json:"allowed_from_ids"` | ||
| Expires time.Time | ||
| revision uint64 | ||
| } | ||
| // NewResourcePermissions creates a new Resource with the specified owner and mode. If the owner is nil, the resource | ||
| @@ -101,7 +103,7 @@ func (r *Resource) ShareOwnership(newUser UserId, currentUser *User, keepPermiss | ||
| r.mu.Lock() | ||
| defer r.mu.Unlock() | ||
| if currentUser != nil && !keepPermissions { | ||
| if !keepPermissions { | ||
| delete(r.Owners, currentUser.UserId) | ||
| } | ||
| r.Owners[newUser] = struct{}{} | ||
| @@ -123,13 +125,13 @@ func (r *Resource) ApplyPerms(id *ids.StateId, ctx context.Context, logger *zap. | ||
| } | ||
| // CanCreate Load permissions from cache if available, otherwise fetch from external source | ||
| func (r *Resource) CanCreate(id *ids.StateId, ctx context.Context, logger *zap.Logger) bool { | ||
| func (r *Resource) CanCreate(id *ids.StateId, from *ids.StateId, ctx context.Context, logger *zap.Logger) bool { | ||
| perms, err := r.getOrCreatePermissions(id, ctx, logger) | ||
| if err != nil { | ||
| logger.Error("failed to create permissions", zap.Error(err)) | ||
| return false | ||
| } | ||
| return r.isUserPermitted(perms, ctx) | ||
| return r.isUserPermitted(perms, ctx) && r.AllowedFrom(from) | ||
| } | ||
| func (r *Resource) getOrCreatePermissions(id *ids.StateId, ctx context.Context, logger *zap.Logger) (CreatePermissions, error) { | ||
| @@ -146,7 +148,7 @@ func (r *Resource) getOrCreatePermissions(id *ids.StateId, ctx context.Context, | ||
| glu := glue.NewGlue(ctx.Value("bootstrap").(string), glue.GetPermissions, make([]any, 0), result.Name()) | ||
| env := map[string]string{"STATE_ID": id.String()} | ||
| _, headers, _, _ := glu.Execute(ctx, make(http.Header), logger, env, nil, id) | ||
| _, headers, _, _ := glu.Execute(ctx, make(http.Header), logger, env, nil, id, ids.SystemSource) | ||
| data := headers.Get("Permissions") | ||
| if err = json.Unmarshal([]byte(data), &perms); err != nil { | ||
| return perms, err | ||
| @@ -158,6 +160,10 @@ func (r *Resource) getOrCreatePermissions(id *ids.StateId, ctx context.Context, | ||
| func (r *Resource) isUserPermitted(perms CreatePermissions, ctx context.Context) bool { | ||
| r.Mode = perms.Mode | ||
| for _, p := range perms.FromId { | ||
| r.AllowedFromIds = append(r.AllowedFromIds, ids.ParseStateId(p)) | ||
| } | ||
| r.AllowedFromTypes = perms.FromType | ||
| r.Expires = time.Now().Add(time.Duration(perms.TimeToLive) * time.Nanosecond) | ||
| switch perms.Mode { | ||
| case AnonymousMode: | ||
| @@ -219,6 +225,29 @@ func (r *Resource) IsOwner(ctx context.Context) bool { | ||
| return false | ||
| } | ||
| func (r *Resource) AllowedFrom(from *ids.StateId) bool { | ||
| if len(r.AllowedFromIds) == 0 && len(r.AllowedFromTypes) == 0 { | ||
| return true | ||
| } | ||
| for _, id := range r.AllowedFromIds { | ||
| if id.Kind == from.Kind && id.Id == from.Id { | ||
| return true | ||
| } | ||
| } | ||
| for _, t := range r.AllowedFromTypes { | ||
| if ent, found := from.ToEntityId(); found && ent.Name == t { | ||
| return true | ||
| } | ||
| if orch, found := from.ToOrchestrationId(); found && orch.InstanceId == t { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
withinboredom marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // WantTo determines if the user is able to perform the specified operation on the resource. | ||
| // It accepts the operation to be performed and the context containing the user information. | ||
| // If the resource mode is set to AnonymousMode, it allows any operation. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,8 +12,20 @@ const ( | ||
| Activity IdKind = "activity" | ||
| Entity IdKind = "entity" | ||
| Orchestration IdKind = "orchestration" | ||
| API IdKind = "--api--" | ||
| SYSTEM IdKind = "--system--" | ||
| ) | ||
| var ApiSource *StateId = &StateId{ | ||
| Id: "--api--", | ||
| Kind: "--api--", | ||
| } | ||
withinboredom marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| var SystemSource *StateId = &StateId{ | ||
| Id: "--system--", | ||
| Kind: "--system--", | ||
| } | ||
| // subjects | ||
| type Subject struct { | ||
| @@ -73,12 +85,12 @@ func (id StateId) String() string { | ||
| return fmt.Sprintf("%s:%s", id.Kind, id.Id) | ||
| } | ||
| func (id StateId) Name() string { | ||
| func (id StateId) Name() IdKind { | ||
| if before, _, found := strings.Cut(id.Id, ":"); found { | ||
| return before | ||
| return IdKind(before) | ||
| } | ||
| return string(Activity) | ||
| return Activity | ||
| } | ||
| func (id StateId) ToEntityId() (*EntityId, bool) { | ||
| @@ -174,6 +186,6 @@ func (id *OrchestrationId) ToStateId() *StateId { | ||
| } | ||
| type StateId struct { | ||
| Id string | ||
| Kind IdKind | ||
| Id string `json:"id,omitempty"` | ||
| Kind IdKind `json:"kind,omitempty"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.