有没有办法限制iam:添加用户的AddUserToGroup?我想构建一个允许将任何用户添加到组的策略,除非请求者不被允许添加自己。我可以通过将请求者限制为可用资源来限制其他操作,但在这种情况下,资源是组。
答案 0 :(得分:0)
如果我错了,有人会纠正我,但我不认为在尝试从AWS控制台执行此操作时,可以限制用户可以添加到组的用户。如果您使用其他工具(如Lambda)来修改组成员身份,则可以执行此操作。
IAM权限可以用于服务和资源的操作,但不能用于这些操作的参数。如果他们这样做会很酷。 :)
例如,可以根据策略允许或限制操作AddUserToGroup
。与将应用操作的组资源相同。因此,您可以限制或允许访问特定资源(组)上的AddUserToGroup
操作,但IAM不允许您将策略条件基于操作的参数。
在这种情况下,UserName
操作上的参数AddUserToGroup
。
答案 1 :(得分:0)
结合在byumark答案评论中提到的博客文章中定义的执行角色和权限,我使用这个简单的lambda函数来自动修复我想要防止的操作类型:
'use strict';
var aws = require('aws-sdk');
var iam = new aws.IAM();
exports.handler = function(event, context) {
// Log the incoming Amazon CloudWatch Events event
console.log('Received event:', JSON.stringify(event, null, 2));
// If the caller is not an IAM user, do nothing
if (event.detail.userIdentity.type != 'IAMUser') {
context.done();
} else {
var userName = event.detail.userIdentity.userName;
// If the user is adding herself to a group
if (event.detail.eventName === "AddUserToGroup" &&
event.detail.requestParameters.userName === userName) {
// Remove the user from that group
var groupName = event.detail.requestParameters.groupName;
console.log('User adding self to group detected. Removing user',
userName, 'from group', groupName);
var params = {
GroupName: groupName,
UserName: userName
};
iam.removeUserFromGroup(params, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
}
});
}
}
}