내 임무는 내 계정의 모든 s3 버킷을 확인하고 기본 kms 암호화를 사용하여 암호화되지 않은 버킷을 찾는 것입니다. 각 버킷 이름을 반복하고 암호화 수준을 확인하는 루프를 사용하여 다음 두 명령의 초안을 작성했습니다.
output="$(aws s3api list-buckets --query 'Buckets[*].Name')"
for i in $output; do aws s3api get-bucket-encryption --bucket $i; done
스크립트에서 다음 오류가 발생합니다.
Invalid bucket name ""cdktoolkit-stagingbucket-30v8nlr122c0",": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:s3:[a-z\-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-]{1,63}$"
이제 첫 번째 부분에서 작동하며, 도움을 주셔서 감사합니다. 출력 변수에 더 이상 물음표가 포함되지 않습니다.
하지만 더 나아가 두 번째 cli 명령 "for i in $output; do aws s3api get-bucket-encryption --bucket $i; done"을 실행하면 또 다른 JSON 형식의 출력이 반환됩니다. AES256 암호화가 활성화되었습니다.
Jasons-Air:~ jason$ for i in $output; do aws s3api get-bucket-encryption --bucket $i; done
{
"ServerSideEncryptionConfiguration": {
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
}
]
}
}
An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found
An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found
An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found
{
"ServerSideEncryptionConfiguration": {
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
}
}
"--query 'ServerSideEncryptionConfiguration["을 추가해 보았습니다.].규칙[].ApplyServerSideEncryptionByDefault[*].SSEAlgorithm'"을 내 명령에 적용했지만 결과가 "AES256" 대신 "null"로 표시됩니다.
Jasons-Air:~ jason$ for i in $output; do aws s3api get-bucket-encryption --bucket $i --query 'ServerSideEncryptionConfiguration[*].Rules[*].ApplyServerSideEncryptionByDefault[*].SSEAlgorithm'; done
null
An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found
An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found
An error occurred (ServerSideEncryptionConfigurationNotFoundError) when calling the GetBucketEncryption operation: The server side encryption configuration was not found
null
null
null