-
Notifications
You must be signed in to change notification settings - Fork 10
add accounts.anon_rbac_policies_json #789
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,19 +160,32 @@ func (p *Processor) CreateOrUpdateAccount(ctx context.Context, account keppel.Ac | |
| replicationStrategy = rp.Strategy | ||
| } | ||
|
|
||
| // validate RBAC policies | ||
| // validate RBAC policies, and fill AnonymousRBACPoliciesJSON with just the RBAC policies for anonymous users | ||
| if len(account.RBACPolicies) == 0 { | ||
| targetAccount.RBACPoliciesJSON = "" | ||
| targetAccount.AnonymousRBACPoliciesJSON = "" | ||
| } else { | ||
| anonPolicies := []keppel.AnonymousRBACPolicy{} | ||
| for idx, policy := range account.RBACPolicies { | ||
| err := policy.ValidateAndNormalize(replicationStrategy) | ||
| anonPolicy, err := policy.ValidateAndNormalize(replicationStrategy) | ||
| if err != nil { | ||
| return models.Account{}, keppel.AsRegistryV2Error(err).WithStatus(http.StatusUnprocessableEntity) | ||
| } | ||
| account.RBACPolicies[idx] = policy | ||
|
|
||
| if policy, ok := anonPolicy.Unpack(); ok { | ||
| anonPolicies = append(anonPolicies, policy) | ||
| } | ||
| } | ||
| buf, _ := json.Marshal(account.RBACPolicies) | ||
| targetAccount.RBACPoliciesJSON = string(buf) | ||
|
|
||
| buf, err := json.Marshal(anonPolicies) | ||
|
majewsky marked this conversation as resolved.
|
||
| if err == nil && len(buf) <= models.AnonymousRBACPoliciesJSONMaxLength { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use some other estimation to end the loop early if it is likely to big? Right now we would build the entire string up to all to only throw it away if it is longer than 64 chars. Maybe we use an amount and say no more than 5 entries?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is during PutAccount, which is a rare operation, so I find this acceptable. (Also, we're handling all the RBAC policies anyway, so it's only causing more work proportional to the existing amount of work.) The optimization target is to avoid loading lots of data in ReducedAccount when not necessary. |
||
| targetAccount.AnonymousRBACPoliciesJSON = string(buf) | ||
| } else { | ||
| targetAccount.AnonymousRBACPoliciesJSON = "" | ||
| } | ||
| } | ||
|
|
||
| // validate validation policy | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.