-
Notifications
You must be signed in to change notification settings - Fork 283
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
Enable deletion of Assertion with delete {domain}:assertion.{assertionId} permission #2902
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,14 +152,16 @@ resource Assertion PUT "/domain/{domainName}/policy/{policyName}/version/{versio | |
|
||
//Delete the specified policy assertion. Upon successful completion of this delete | ||
//request, the server will return NO_CONTENT status code without any data (no | ||
//object will be returned). | ||
//object will be returned). The required authorization includes three options: | ||
// 1. ("update", "{domainName}:policy.{policyName}") | ||
// 2. ("delete", "{domainName}:policy.{policyName}.assertion.{assertionId}") | ||
resource Assertion DELETE "/domain/{domainName}/policy/{policyName}/assertion/{assertionId}" { | ||
DomainName domainName; //name of the domain | ||
EntityName policyName; //name of the policy | ||
Int64 assertionId; //assertion id | ||
String auditRef (header="Y-Audit-Ref"); //Audit param required(not empty) if domain auditEnabled is true. | ||
String resourceOwner (header="Athenz-Resource-Owner"); //Resource owner for the request | ||
authorize ("update", "{domainName}:policy.{policyName}"); | ||
authenticate; | ||
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. please update the comment section for the block to include what type of authorization statements will be carried out within the code. |
||
expected NO_CONTENT; | ||
exceptions { | ||
ResourceError NOT_FOUND; | ||
|
@@ -173,15 +175,17 @@ resource Assertion DELETE "/domain/{domainName}/policy/{policyName}/assertion/{a | |
|
||
//Delete the specified policy version assertion. Upon successful completion of this delete | ||
//request, the server will return NO_CONTENT status code without any data (no | ||
//object will be returned). | ||
//object will be returned). The required authorization includes three options: | ||
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. two options |
||
// 1. ("update", "{domainName}:policy.{policyName}") | ||
// 2. ("delete", "{domainName}:policy.{policyName}.assertion.{assertionId}") | ||
resource Assertion DELETE "/domain/{domainName}/policy/{policyName}/version/{version}/assertion/{assertionId}" (name=deleteAssertionPolicyVersion) { | ||
DomainName domainName; //name of the domain | ||
EntityName policyName; //name of the policy | ||
SimpleName version; //name of the version | ||
Int64 assertionId; //assertion id | ||
String auditRef (header="Y-Audit-Ref"); //Audit param required(not empty) if domain auditEnabled is true. | ||
String resourceOwner (header="Athenz-Resource-Owner"); //Resource owner for the request | ||
authorize ("update", "{domainName}:policy.{policyName}"); | ||
authenticate; | ||
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. please update the comment section for the block to include what type of authorization statements will be carried out within the code. |
||
expected NO_CONTENT; | ||
exceptions { | ||
ResourceError NOT_FOUND; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ public class ZMSImpl implements Authorizer, KeyStore, ZMSHandler { | |
|
||
private static final String ROLE_PREFIX = "role."; | ||
private static final String POLICY_PREFIX = "policy."; | ||
private static final String ASSERTION_PREFIX = "assertion."; | ||
|
||
private static final String ADMIN_POLICY_NAME = "admin"; | ||
private static final String ADMIN_ROLE_NAME = "admin"; | ||
|
@@ -6073,6 +6074,8 @@ public void deleteAssertion(ResourceContext ctx, String domainName, String polic | |
setRequestDomain(ctx, domainName); | ||
policyName = policyName.toLowerCase(); | ||
|
||
final Principal principal = ((RsrcCtxWrapper) ctx).principal(); | ||
|
||
// we are not going to allow any user to update | ||
// the admin policy since that is required | ||
// for standard domain operations */ | ||
|
@@ -6094,6 +6097,12 @@ public void deleteAssertion(ResourceContext ctx, String domainName, String polic | |
throw ZMSUtils.notFoundError("Invalid policy name specified", caller); | ||
} | ||
|
||
// authorization check which also automatically updates | ||
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. what is the "automatically update the active and approved flags for the request" referring to in the comments? |
||
// the active and approved flags for the request | ||
if (!isAllowedDeleteAssertion(principal, domain, policyName, assertionId)) { | ||
throw ZMSUtils.forbiddenError("deleteAssertion: principal is not authorized to delete assertion", caller); | ||
} | ||
|
||
try { | ||
ResourceOwnership.verifyPolicyAssertionsDeleteResourceOwnership(policy, resourceOwner, caller); | ||
} catch (ServerResourceException ex) { | ||
|
@@ -6128,6 +6137,8 @@ public void deleteAssertionPolicyVersion(ResourceContext ctx, String domainName, | |
policyName = policyName.toLowerCase(); | ||
version = version.toLowerCase(); | ||
|
||
final Principal principal = ((RsrcCtxWrapper) ctx).principal(); | ||
|
||
// we are not going to allow any user to update | ||
// the admin policy since that is required | ||
// for standard domain operations */ | ||
|
@@ -6139,6 +6150,13 @@ public void deleteAssertionPolicyVersion(ResourceContext ctx, String domainName, | |
// verify that request is properly authenticated for this request | ||
|
||
verifyAuthorizedServiceOperation(((RsrcCtxWrapper) ctx).principal().getAuthorizedService(), caller); | ||
AthenzDomain domain = getAthenzDomain(domainName, false); | ||
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. on line 6152 since we already have a principal object can simplify the verifyAuthorizedServiceOperation call and use the principal object directly |
||
|
||
// authorization check which also automatically updates | ||
// the active and approved flags for the request | ||
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. same comment here - not sure what the comment is referring to |
||
if (!isAllowedDeleteAssertion(principal, domain, policyName, assertionId)) { | ||
throw ZMSUtils.forbiddenError("deleteAssertion: principal is not authorized to delete assertios", caller); | ||
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. minor spelling fix in the error - assertions |
||
} | ||
|
||
dbService.executeDeleteAssertion(ctx, domainName, policyName, version, assertionId, auditRef, caller); | ||
} | ||
|
@@ -10589,6 +10607,16 @@ boolean isAllowedDeletePendingMembership(Principal principal, final String domai | |
return pendingMember != null && principal.getFullName().equals(pendingMember.getRequestPrincipal()); | ||
} | ||
|
||
boolean isAllowedDeleteAssertion(Principal principal, final AthenzDomain domain, final String policyName, final Long assertionId) { | ||
if (hasAccess(domain, "update", ResourceUtils.policyResourceName(domain.getName(), policyName), principal, null) == AccessStatus.ALLOWED) { | ||
return true; | ||
} | ||
if (hasAccess(domain, "delete", ResourceUtils.assertionResourceName(domain.getName(), policyName, assertionId), principal, null) == AccessStatus.ALLOWED) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public DomainRoleMembership getPendingDomainRoleMembersList(ResourceContext ctx, String principal, String domainName) { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two options and not three