More Related Content
Similar to Compliance as code jaws Oita 170826
Similar to Compliance as code jaws Oita 170826 (20)
More from Shogo Matsumoto
More from Shogo Matsumoto (6)
Compliance as code jaws Oita 170826
- 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights
reserved.
アマゾン ウェブ サービス ジャパン株式会社
セキュリティコンサルタント 松本 照吾
2017/8/26
Compliance as Code
-セキュリティとの上手な付き合い方-
- 7. AWS Configとは
• AWSリソースの構成変更をロギング
• 履歴も保存
• 構成情報は定期的にスナップショットとしてS3に保存
• 必要に応じSNSを使った通知も可能
• ログはS3に保存
• あるべき状態の評価 (Rules)
• AWSが適用するルール
• 独自のルールを適用
• コスト
• 記録される設定項目につき 0.003 USD
(1回の設定として前払いのみ)AWS Config
AWS Config Rules
- 9. AWS Config が対応しているAWSリソース
(2017/8/20現在)
http://docs.aws.amazon.com/ja_jp/config/latest/developerguide/resource-config-reference.html#supported-resources
AWS Service Resource Type Resource Type Value
AWS Certificate Manager Certificate AWS::ACM::Certificate
AWS CloudFormation Stack
1
AWS::CloudFormation::Stack
AWS CloudTrail Trail AWS::CloudTrail::Trail
Amazon CloudWatch Alarm AWS::CloudWatch::Alarm
Amazon Elastic Block Store Amazon EBS volume AWS::EC2::Volume
Amazon Elastic Compute Cloud EC2 Dedicated host
2
AWS::EC2::Host
EC2 Elastic IP (VPC only) AWS::EC2::EIP
EC2 instance AWS::EC2::Instance
EC2 network interface AWS::EC2::NetworkInterface
EC2 security group AWS::EC2::SecurityGroup
Amazon EC2 Systems Manager Managed instance inventory
3
AWS::SSM::ManagedInstanceInventory
Elastic Load Balancing Application load balancer
4
AWS::ElasticLoadBalancingV2::LoadBalancer
AWS Identity and Access Management
5
IAM user
6
AWS::IAM::User
IAM group
6
AWS::IAM::Group
IAM role
6
AWS::IAM::Role
IAM customer managed policy AWS::IAM::Policy
Amazon Redshift Cluster AWS::Redshift::Cluster
Cluster parameter group AWS::Redshift::ClusterParameterGroup
Cluster security group AWS::Redshift::ClusterSecurityGroup
Cluster snapshot AWS::Redshift::ClusterSnapshot
Cluster subnet group AWS::Redshift::ClusterSubnetGroup
Event subscription AWS::Redshift::EventSubscription
- 10. AWS Config が対応しているAWSリソース
(2017/8/20現在)
http://docs.aws.amazon.com/ja_jp/config/latest/developerguide/resource-config-reference.html#supported-resources
AWS Service Resource Type Resource Type Value
Amazon Relational Database Service RDS DB instance AWS::RDS::DBInstance
RDS DB security group AWS::RDS::DBSecurityGroup
RDS DB snapshot AWS::RDS::DBSnapshot
RDS DB subnet group AWS::RDS::DBSubnetGroup
Event subscription AWS::RDS::EventSubscription
Amazon Simple Storage Service Amazon S3 bucket
7
AWS::S3::Bucket
Amazon Virtual Private Cloud Customer gateway AWS::EC2::CustomerGateway
Internet gateway AWS::EC2::InternetGateway
Network access control list (ACL) AWS::EC2::NetworkAcl
Route table AWS::EC2::RouteTable
Subnet AWS::EC2::Subnet
Virtual private cloud (VPC) AWS::EC2::VPC
VPN connection AWS::EC2::VPNConnection
VPN gateway AWS::EC2::VPNGateway
- 31. Blue Print Code(スクラッチで作る場合は通常Config用Blue printを利用)
# Custom AWS Config Rule - Blueprint Code
#
import boto3, json
def evaluate_compliance(config_item, r_id):
return 'NONCOMPLIANT'
def lambda_handler(event, context):
# Create AWS SDK clients & initialize custom rule parameters
config = boto3.client('config')
invoking_event = json.loads(event['invokingEvent'])
compliance_value = 'NOT_APPLICABLE'
resource_id = invoking_event['configurationItem']['resourceId']
compliance_value = evaluate_compliance(invoking_event['configurationItem'], resource_id)
response = config.put_evaluations(
Evaluations=[
{
'ComplianceResourceType': invoking_event['configurationItem']['resourceType'],
'ComplianceResourceId': resource_id,
'ComplianceType': compliance_value,
'Annotation': 'Insert text here to detail why control passed/failed',
'OrderingTimestamp': invoking_event['notificationCreationTime']
},
],
ResultToken=event['resultToken'])
https://aws.amazon.com/jp/blogs/security/how-to-audit-your-aws-
resources-for-security-compliance-by-using-custom-aws-config-rules/
自分の作成したロジックを定義し、compliance_value
に結果を格納
結果をAWS Configに渡す。結果はAWS Configのコン
ソールから確認可能
Annotationパラメータによって準拠評価に対する補足を
表記
イベントハンドラー
- 32. IAM Role作成
ConfigからVPC Flow logsにアク
セスを行うための権限付与
以下のManaged policyをRoleに
付与
• AmazonEC2ReadOnlyAccess
• AWSLambdaExecute
• AWSConfigRulesExecutionRole
- 35. 追記部分の解説
import boto3, json
def evaluate_compliance(config_item, r_id):
if (config_item['resourceType'] != 'AWS::EC2::VPC'):
return 'NOT_APPLICABLE'
elif is_flow_logs_enabled(r_id):
return 'COMPLIANT'
else:
return 'NON_COMPLIANT'
def is_flow_logs_enabled(vpc_id):
ec2 = boto3.client('ec2')
response = ec2.describe_flow_logs(
Filter=[
{
'Name': 'resource-id',
'Values': [
vpc_id,
]
},
],
)
if len(response[u'FlowLogs']) != 0: return True
実際の評価を定義
評価対象が正しいか(間違ったリソースを指定していな
いか)
評価結果が正しいか(VPC IDごとに準拠か非準拠か)
ec2.describe_flow_logsを実行し、実行結果を’ResourceId’のみにフィル
タする。
http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#
EC2.Client.describe_flow_logs
結果に文字列が含まれているかを評価し、含まれているならTrueをかえす。
- 36. 追記部分の解説
def lambda_handler(event, context):
# Create AWS SDK clients & initialize custom rule parameters
config = boto3.client('config')
invoking_event = json.loads(event['invokingEvent'])
compliance_value = 'NOT_APPLICABLE'
resource_id = invoking_event['configurationItem']['resourceId']
compliance_value = evaluate_compliance(invoking_event['configurationItem'], resource_id)
response = config.put_evaluations(
Evaluations=[
{
'ComplianceResourceType': invoking_event['configurationItem']['resourceType'],
'ComplianceResourceId': resource_id,
'ComplianceType': compliance_value,
'Annotation': 'CIS 4.3 VPC Flow Logs',
'OrderingTimestamp': invoking_event['notificationCreationTime']
},
],
ResultToken=event['resultToken'])
Annotationを変えているだけ
- 40. Codeを書くためのステップ
Codeを書くことは目的にしない
• Managed Ruleを活用
• 画面を見てしまえば終わり、という場合もある
• 書ける人が書く(協力の文化)
車輪の再発明はいらない
• Managed Ruleにあるものは不要
• AWSが公開しているCustom ruleもチェック
真似ることが大事
• やりたいことに似ているCustom ruleを探してたたき台に。
• AWSが公開しているGithubのリポジトリを参照
• https://github.com/awslabs/aws-config-rules