Notice
Recent Posts
Recent Comments
Link
투케이2K
481. (javaScript) 자바스크립트 AWS IAM 정책 시뮬레이터 기능 조회 수행 - SimulatePrincipalPolicy 본문
JavaScript
481. (javaScript) 자바스크립트 AWS IAM 정책 시뮬레이터 기능 조회 수행 - SimulatePrincipalPolicy
투케이2K 2026. 1. 11. 18:04728x90
반응형
[개발 환경 설정]
개발 툴 : Edit++
개발 언어 : JavaScript

[소스 코드]
-----------------------------------------------------------------------------------------
[사전 설명 및 설정 사항]
-----------------------------------------------------------------------------------------
- 개발 환경 : Web
- 개발 기술 : JavaScript (자바스크립트) / AWS / IAM / SimulatePrincipalPolicy
- 사전) AWS IAM 자격 증명 설명 정리 :
>> AWS IAM 아이엠 계정 은 일부 AWS 서비스 및 리소스에 대한 액세스 권한을 가지고 있는 자격 증명입니다
>> IAM 아이엠 계정 은 ROOT 계정 혹은 다른 IAM 계정으로부터 권한을 부여 받을 수 있으며, 주어진 권한 내의 작업만 할 수 있습니다
>> IAM 아이엠 계정에서 할당 된 권한 외의 작업이 필요한 경우 ROOT 계정으로부터 추가 액세스 접근 권한을 부여 받아야 사용할 수 있습니다
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
[소스 코드]
-----------------------------------------------------------------------------------------
<!DOCTYPE HTML>
<html lang="ko">
<head>
<title>javaScriptTest</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 반응형 구조 만들기 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<!-- 내부 CSS 스타일 지정 -->
<style>
html, body {
width: 100%;
height: 100%;
margin : 0 auto;
padding : 0;
border : none;
background-color: #666;
}
</style>
<!-- [CDN 주소 설정] -->
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1416.0.min.js"></script>
<!-- [자바스크립트 코드 지정] -->
<script>
// --------------------------------------------------------------------------------------------------------------
// [전역 변수 선언]
const accessKey = 'AK..A6';
const secretKey = 'mP..5J';
const policySourceArn = "arn:aws:iam::123456789012:user/2k@twok.com-CLI"
// --------------------------------------------------------------------------------------------------------------
// [html 최초 로드 및 이벤트 상시 대기 실시]
window.onload = async function() {
console.log("");
console.log("=========================================");
console.log("[window onload] : [start]");
console.log("=========================================");
console.log("");
try {
// -----------------------------------------
// [AWS.config 지정]
// -----------------------------------------
AWS.config.update({
accessKeyId: accessKey,
secretAccessKey: secretKey
});
// -----------------------------------------
// [AWS 객체 생성]
// -----------------------------------------
const aws = new AWS.IAM();
// -----------------------------------------
// [요청 파라미터 생성]
// -----------------------------------------
var params = {
PolicySourceArn: policySourceArn,
// [심플 조회]
/*
ActionNames: [
"s3:PutObject",
"iot:Connect",
"iot:Publish"
],
ResourceArns: ["*"]
// */
// [* 조회]
//*
ActionNames: [
// === IAM / Security ===
"iam:*",
"sts:*",
"organizations:*",
"kms:*",
"cloudtrail:*",
"config:*",
"access-analyzer:*",
"auditmanager:*",
"securityhub:*",
"guardduty:*",
"detective:*",
"macie2:*",
"shield:*",
"waf:*",
"wafv2:*",
"secretsmanager:*",
"ssm:*",
"backup:*",
// === Storage ===
"s3:*",
"efs:*",
"fsx:*",
"storagegateway:*",
"backup-storage:*",
// === Compute ===
"ec2:*",
"lambda:*",
"autoscaling:*",
"elasticloadbalancing:*",
"batch:*",
"lightsail:*",
"outposts:*",
// === Containers ===
"ecs:*",
"eks:*",
"ecr:*",
"appmesh:*",
// === Networking ===
"route53:*",
"route53resolver:*",
"directconnect:*",
"globalaccelerator:*",
"apigateway:*",
"appsync:*",
"vpc-lattice:*",
// === Databases ===
"dynamodb:*",
"rds:*",
"redshift:*",
"elasticache:*",
"neptune:*",
"timestream:*",
"qldb:*",
"keyspaces:*",
// === Analytics / Streaming ===
"athena:*",
"glue:*",
"emr:*",
"lakeformation:*",
"kinesis:*",
"kinesisanalytics:*",
// === Kinesis Video Streams ===
"kinesisvideo:*",
"kinesisvideoarchivedmedia:*",
"kinesisvideomedia:*",
// === Messaging / Integration ===
"sns:*",
"sqs:*",
"events:*",
"eventbridge:*",
"mq:*",
"stepfunctions:*",
// === Monitoring / Ops ===
"cloudwatch:*",
"logs:*",
"xray:*",
"application-autoscaling:*",
"health:*",
// === DevOps / CI-CD ===
"cloudformation:*",
"codecommit:*",
"codedeploy:*",
"codebuild:*",
"codepipeline:*",
"codestar:*",
"codestar-connections:*",
"codestar-notifications:*",
// === AI / ML ===
"sagemaker:*",
"rekognition:*",
"comprehend:*",
"textract:*",
"polly:*",
"transcribe:*",
"translate:*",
"bedrock:*",
// === Business / End User ===
"quicksight:*",
"workspaces:*",
"workdocs:*",
"connect:*",
"chime:*",
// === IoT ===
"iot:*",
"iotanalytics:*",
"iotwireless:*",
"greengrass:*",
"freertos:*",
// === Migration / Transfer ===
"datasync:*",
"migrationhub:*",
"application-discovery:*",
"transfer:*"
],
ResourceArns: ["*"]
// */
};
// -----------------------------------------
// [SimulatePrincipalPolicy] : AWS IAM 정책 시뮬레이터 기능 조회 수행
// -----------------------------------------
// AWS 참고 사이트 : https://docs.aws.amazon.com/IAM/latest/APIReference/API_SimulatePrincipalPolicy.html
// -----------------------------------------
// 권한 요구사항: iam:SimulatePrincipalPolicy 권한이 필요.
// -----------------------------------------
// 리전 무관: 모든 리전에서 동일하게 동작.
// -----------------------------------------
aws.simulatePrincipalPolicy( params , function(err, data) {
if (err) {
console.error("");
console.error("=========================================");
console.error("[simulatePrincipalPolicy] : [Error]");
console.error("---------------------------------------");
console.error(err);
console.error("=========================================");
console.error("");
// ---------------------------------------------
// ✅ [주요 에러 정리]
// ---------------------------------------------
// InvalidInput : 400 : 파라미터가 잘못되었거나 범위를 벗어남
// NoSuchEntity : 404 : 지정된 PolicySourceArn 등에 해당 주체가 없음
// PolicyEvaluation : 500 : 정책 평가 중 내부 오류 발생
// ---------------------------------------------
// ---------------------------------------------
// [Body 표시 JSON]
// ---------------------------------------------
var errJson = {
response: "error",
data: err
}
// ---------------------------------------------
// ---------------------------------------------
// [에러 출력]
// ---------------------------------------------
document.write(JSON.stringify(errJson));
// ---------------------------------------------
} else {
console.log("");
console.log("=========================================");
console.log("[simulatePrincipalPolicy] : [Success]");
console.log("---------------------------------------");
console.log(JSON.stringify(data));
console.log("=========================================");
console.log("");
// ---------------------------------------------
// ✅ [로그 출력 예시 첨부]
// ---------------------------------------------
/*
{
"ResponseMetadata": {
"RequestId": "1b078029-d297-4755-afa2-7a7ce4fd0089"
},
"EvaluationResults": [
{
"EvalActionName": "iam:*",
"EvalResourceName": "*",
"EvalDecision": "implicitDeny",
"MatchedStatements": [],
"MissingContextValues": [
"ec2:ResourceTag/eks:eni:owner",
"iam:AWSServiceName",
"aws:username",
"events:ManagedBy",
"aws:ResourceTag/red-hat",
"aws:CalledViaLast",
"codestar-notifications:NotificationsForResource",
"iam:PassedToService"
],
"OrganizationsDecisionDetail": {
"AllowedByOrganizations": true
},
"ResourceSpecificResults": []
},
{
"EvalActionName": "waf:*",
"EvalResourceName": "*",
"EvalDecision": "implicitDeny",
"MatchedStatements": [],
"MissingContextValues": [
"ec2:ResourceTag/eks:eni:owner",
"iam:AWSServiceName",
"aws:username",
"events:ManagedBy",
"aws:ResourceTag/red-hat",
"aws:CalledViaLast",
"codestar-notifications:NotificationsForResource",
"iam:PassedToService"
],
"OrganizationsDecisionDetail": {
"AllowedByOrganizations": true
},
"ResourceSpecificResults": []
},
{
"EvalActionName": "secretsmanager:*",
"EvalResourceName": "*",
"EvalDecision": "allowed",
"MatchedStatements": [
{
"SourcePolicyId": "group_B2C_Platform_Development_Team_1-2_Custom_Add_Allow_Policy",
"SourcePolicyType": "IAM Policy",
"StartPosition": {
"Line": 3,
"Column": 16
},
"EndPosition": {
"Line": 40,
"Column": 4
}
}
],
"MissingContextValues": [],
"OrganizationsDecisionDetail": {
"AllowedByOrganizations": true
},
"ResourceSpecificResults": []
}
],
"IsTruncated": true,
"Marker": "PS:58"
}
*/
// ---------------------------------------------
// ---------------------------------------------
// [Body 표시 JSON]
// ---------------------------------------------
var resJson = {
response: "success",
data: data
}
// ---------------------------------------------
// ---------------------------------------------
// [결과 출력]
// ---------------------------------------------
document.write(JSON.stringify(resJson));
// ---------------------------------------------
}
});
}
catch (exception) {
console.error("");
console.error("=========================================");
console.error("[window onload] : [Exception] : 예외 상황 발생");
console.error("-----------------------------------------");
console.error(exception);
console.error("=========================================");
console.error("");
// ---------------------------------------------
// [Body 표시 JSON]
// ---------------------------------------------
var errJson = {
response: "exception",
data: exception.message
}
// ---------------------------------------------
// ---------------------------------------------
// [에러 출력]
// ---------------------------------------------
document.write(JSON.stringify(errJson));
// ---------------------------------------------
}
};
// --------------------------------------------------------------------------------------------------------------
</script>
</head>
<body>
</body>
</html>
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
[참고 사이트]
-----------------------------------------------------------------------------------------
[로그인 계정] ROOT 루트 계정 로그인과 IAM 아이엠 계정 로그인 차이 설명 정리
https://kkh0977.tistory.com/7618
https://blog.naver.com/kkh0977/223731955897?trackingCode=blog_bloghome_searchlist
[Aws 사이트 : SimulatePrincipalPolicy 설명 정리]
https://docs.aws.amazon.com/IAM/latest/APIReference/API_SimulatePrincipalPolicy.html
[AWS] [Lambda] 런타임 Python 3.13 - boto3 모듈 사용해 AWS STS 임시 정보 호출 람다 생성
https://blog.naver.com/kkh0977/223962739399?trackingCode=blog_bloghome_searchlist
[자바스크립트 AWS STS 임시 자격 증명 사용해 S3 Get PreSignedUrl 프리 사인 URL 주소 생성]
https://kkh0977.tistory.com/8151
https://blog.naver.com/kkh0977/223938740405
-----------------------------------------------------------------------------------------
728x90
반응형
'JavaScript' 카테고리의 다른 글
Comments
