mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(iam): return PermissionsBoundary from GetRole/GetUser and accept it on CreateRole/CreateUser (#4964)
CreateRole and CreateUser ignored the PermissionsBoundary parameter, and
roleXml/userXml never serialized a stored boundary, so GetRole/GetUser
(and the Create responses) returned none even after
Put{Role,User}PermissionsBoundary. Only GetAccountAuthorizationDetails
emitted it.
Emit the boundary on the detailed fragment only: ListRoles/ListUsers
document that they do not return PermissionsBoundary. The boundary is
validated before the role/user is created, so an unknown policy leaves
nothing behind. Existing createRole/createUser signatures are kept as
overloads for the CloudFormation and service-linked-role callers.
This commit is contained in:
1 parent
a4c952db54
commit
3e2d310eae
3 files changed
+194
-4
No files matched your search
@@ -278,7 +278,7 @@ public class IamQueryHandler {
|
||||
String userName = getParam(params, "UserName");
|
||||
String path = getParam(params, "Path");
|
||||
Map<String, String> tags = extractTags(params, true);
|
||||
IamUser user = iamService.createUser(userName, path);
|
||||
IamUser user = iamService.createUser(userName, path, getParam(params, "PermissionsBoundary"));
|
||||
if (!tags.isEmpty()) iamService.tagUser(userName, tags);
|
||||
user = iamService.getUser(userName);
|
||||
String result = new XmlBuilder().start("User").raw(userXml(user, true)).end("User").build();
|
||||
@@ -915,7 +915,8 @@ public class IamQueryHandler {
|
||||
String description = getParam(params, "Description");
|
||||
int maxSession = getIntParam(params, "MaxSessionDuration", 3600);
|
||||
Map<String, String> tags = extractTags(params, true);
|
||||
IamRole role = iamService.createRole(roleName, path, trustPolicy, description, maxSession, tags);
|
||||
IamRole role = iamService.createRole(roleName, path, trustPolicy, description, maxSession, tags,
|
||||
getParam(params, "PermissionsBoundary"));
|
||||
String result = new XmlBuilder().start("Role").raw(roleXml(role, true)).end("Role").build();
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateRole", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
@@ -1118,7 +1119,6 @@ public class IamQueryHandler {
|
||||
}
|
||||
return xml.end("GroupList")
|
||||
.raw(attachedManagedPoliciesXml(iamService.listAttachedUserPolicies(u.getUserName(), null)))
|
||||
.raw(permissionsBoundaryXml(u.getPermissionsBoundaryArn()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -2143,6 +2143,7 @@ public class IamQueryHandler {
|
||||
.elem("UserId", u.getUserId())
|
||||
.elem("Arn", u.getArn())
|
||||
.elem("CreateDate", isoDate(u.getCreateDate()))
|
||||
.raw(detailed ? permissionsBoundaryXml(u.getPermissionsBoundaryArn()) : "")
|
||||
.raw(detailed ? tagsElement(u.getTags()) : "")
|
||||
.build();
|
||||
}
|
||||
@@ -2175,6 +2176,7 @@ public class IamQueryHandler {
|
||||
.elem("MaxSessionDuration", (long) r.getMaxSessionDuration())
|
||||
.elem("AssumeRolePolicyDocument", r.getAssumeRolePolicyDocument())
|
||||
.elem("Description", r.getDescription())
|
||||
.raw(detailed ? permissionsBoundaryXml(r.getPermissionsBoundaryArn()) : "")
|
||||
.raw(detailed ? tagsElement(r.getTags()) : "")
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -460,6 +460,13 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
// =========================================================================
|
||||
|
||||
public IamUser createUser(String userName, String path) {
|
||||
return createUser(userName, path, null);
|
||||
}
|
||||
|
||||
public IamUser createUser(String userName, String path, String permissionsBoundaryArn) {
|
||||
if (permissionsBoundaryArn != null) {
|
||||
requirePolicy(permissionsBoundaryArn); // validate before anything is created
|
||||
}
|
||||
synchronized (resourceNameLock) {
|
||||
if (containsNameIgnoreCase(users, IamUser::getUserName, userName)) {
|
||||
throw new AwsException("EntityAlreadyExists",
|
||||
@@ -469,6 +476,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
String normalizedPath = normalizePath(path);
|
||||
String arn = iamArn("user", normalizedPath, userName);
|
||||
IamUser user = new IamUser(userId, userName, normalizedPath, arn);
|
||||
user.setPermissionsBoundaryArn(permissionsBoundaryArn);
|
||||
users.put(userName, user);
|
||||
LOG.infov("Created IAM user: {0}", userName);
|
||||
return user;
|
||||
@@ -747,6 +755,15 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
|
||||
public IamRole createRole(String roleName, String path, String assumeRolePolicyDocument,
|
||||
String description, int maxSessionDuration, Map<String, String> tags) {
|
||||
return createRole(roleName, path, assumeRolePolicyDocument, description, maxSessionDuration, tags, null);
|
||||
}
|
||||
|
||||
public IamRole createRole(String roleName, String path, String assumeRolePolicyDocument,
|
||||
String description, int maxSessionDuration, Map<String, String> tags,
|
||||
String permissionsBoundaryArn) {
|
||||
if (permissionsBoundaryArn != null) {
|
||||
requirePolicy(permissionsBoundaryArn); // validate before anything is created
|
||||
}
|
||||
synchronized (resourceNameLock) {
|
||||
if (containsNameIgnoreCase(roles, IamRole::getRoleName, roleName)) {
|
||||
throw new AwsException("EntityAlreadyExists",
|
||||
@@ -757,6 +774,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
String arn = iamArn("role", normalizedPath, roleName);
|
||||
IamRole role = new IamRole(roleId, roleName, normalizedPath, arn, assumeRolePolicyDocument);
|
||||
role.setDescription(description);
|
||||
role.setPermissionsBoundaryArn(permissionsBoundaryArn);
|
||||
if (maxSessionDuration > 0) {
|
||||
role.setMaxSessionDuration(maxSessionDuration);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user