rainit2006 / Certifications

0 stars 0 forks source link

AWS_Security #5

Open rainit2006 opened 3 years ago

rainit2006 commented 3 years ago

rainit2006 commented 3 years ago

rainit2006 commented 3 years ago

KMS

KMS 的key不是跨region的。

Principal

CMK for EC2 and EBS

Deleting CMK has no immediate effect on the EC2 instance or the EBS volume. The reason is that Amazon EC2 is using the plaintext data key—not the CMK—to encrypt all disk I/O while the volume is attached to the instance.

However, when the encrypted EBS volume is detached from the EC2 instance, Amazon EBS removes the plaintext key from memory. The next time the encrypted EBS volume is attached to an EC2 instance, the attachment fails, because Amazon EBS cannot use the CMK to decrypt the volume's encrypted data key

EC2 and Encrypted EBS Volumes

Solution:

Details: EC2 must be granted access to the CMK in order to use it. That access is granted by your users implicitly when launching instances that require the key. Therefore, your IAM users must have permission for the key.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [ "kms:CreateGrant" ],
      "Resource": [      
        "arn:aws:kms:REGION:123456789012:key/key-id"
      ],
      "Condition": {
        "Bool": { "kms:GrantIsForAWSResource": true }
      }
    }
  ]
}

This policy allows the user to delegate access to other AWS resources, such as EC2.

KMS grants

grant: For example, the following command calls the GenerateDataKey operation.

aws kms generate-data-key \
        --key-id 1234abcd-12ab-34cd-56ef-1234567890ab \
        --key-spec AES_256 \
        --grant-token $token

AWS KMS supports two grant constraints, EncryptionContextEquals and EncryptionContextSubset, both of which involve the encryption context in a request for a cryptographic operation.

Revoking and retiring a grant both delete the grant. But retiring is done by a principal specified in the grant. Revoking is typically done by a key administrator.

key management best practices

Use KMS automatic key rotation to replace the master key, and use this new master key for future encryption operations without re-encrypting previously encrypted data.

Connecting to AWS KMS through a VPC endpoint

When you use a VPC endpoint, communication between your VPC and AWS KMS is conducted entirely within the AWS network.

Exam

rainit2006 commented 3 years ago

CloudWatch

alarms

Treat missing data points as any of the following:

Evaluating an Alarm

EC2 and CloudWatch

Using CloudWatch Logs with Interface VPC Endpoints

file modification monitoring

Statement on the IAM policy

Troubleshooting

rainit2006 commented 3 years ago

Lambda

Lambda@Edge

Amazon CloudFrontの機能。CloudFrontのエッジロケーションにおいて、Lambdaを使って細かいルールを自由に設定できるサービスです。 Lambda@Edge lets you run Node.js and Python Lambda functions to customize content that CloudFront delivers, executing the functions in AWS locations closer to the viewer. You can use Lambda functions to change CloudFront requests and responses at the following points: 1, After CloudFront receives a request from a viewer (viewer request) 2,Before CloudFront forwards the request to the origin (origin request)

  1. After CloudFront receives the response from the origin (origin response)
  2. Before CloudFront forwards the response to the viewer (viewer response) image

You can also generate responses to viewers without ever sending the request to the origin.

rainit2006 commented 3 years ago

AWS Config

rainit2006 commented 3 years ago

S3

Metadata

  1. System-defined object metadata
  2. User-defined object metadata When you upload objects using the REST API, the optional user-defined metadata names must begin with "x-amz-meta-" to distinguish them from other HTTP headers. When you upload objects using the SOAP API, the prefix is not required.

Solution:

S3 permission

Whenever an AWS principal issues a request to S3, the authorization decision depends on the union of all the IAM policies, S3 bucket policies, and S3 ACLs that apply.

Amazon S3 Lifecycle

An S3 Lifecycle configuration is a set of rules that define actions that Amazon S3 applies to a group of objects. There are two types of actions:

  1. Transition actions
  2. Expiration actions: Amazon S3 deletes expired objects on your behalf.
rainit2006 commented 3 years ago

Data encryption

DynamoDB Encryption Client

rainit2006 commented 3 years ago

Explict allow

Basic rule: to allow access there must be a explict allow and no explict deny in either S3 Bucket Policy, S3 ACL, Key Policy and IAM policy.

Penetration test

Customer Service Policy for Penetration Testing

CIS benchmark

CIS benchmarks are configuration baselines and best practices for securely configuring a system. Each of the guidance recommendations references one or more CIS controls that were developed to help organizations improve their cyberdefense capabilities. CIS controls map to many established standards and regulatory frameworks, including the NIST Cybersecurity Framework (CSF) and NIST SP 800-53, the ISO 27000 series of standards, PCI DSS, HIPAA, and others.

Note: Security Hub requires AWS Config to be enabled. AWS Config must be enabled in the same account where you enabled AWS Security Hub.

rainit2006 commented 3 years ago

database credentials

rainit2006 commented 3 years ago

CloudTrail

A trail can only send events to either S3 or CloudWatch

Create your tail

For Storage location, choose Create new S3 bucket to create a bucket. When you create a bucket, CloudTrail creates and applies the required bucket policies. Give your bucket a name, such as my-bucket-for-storing-cloudtrail-logs.

CloudTrail provides 90 days of event history information for management events in the CloudTrail console without creating a trail, it is not a permanent record, and it does not provide information about all possible types of events. For an ongoing record, and for a record that contains all the event types you specify, you must create a trail, which delivers log files to an Amazon S3 bucket that you specify.

CloudTrail with S3

CloudTrail events

CloudTrail events provide a history of both API and non-API account activity made through the AWS Management Console, AWS SDKs, command line tools, and other AWS services.

There are three types of events that can be logged in CloudTrail:

  1. management events (that provide information about management operations that are performed on resources in your AWS account. These are also known as control plane operations.)
  2. data events (information about the resource operations performed on or in a resource. These are also known as data plane operations. )
  3. CloudTrail Insights events (such as the associated API, incident time, and statistics, that help you understand and act on unusual activity)

When you create a trail, you enable ongoing delivery of events as log files to an Amazon S3 bucket that you specify.

Monitoring CloudTrail Log Files with Amazon CloudWatch Logs

You can configure CloudTrail with CloudWatch Logs to monitor your trail logs and be notified when specific activity occurs.

Organization trail

you can create a trail that will log all events for all AWS accounts in that organization. This is sometimes referred to as an organization trail. When you create an organization trail, a trail with the name that you give it will be created in every AWS account that belongs to your organization.

Precondition:

  1. Your organization must have all features enabled.
  2. The management account must have the AWSServiceRoleForOrganizations role.
  3. The IAM user or role that will be used to create the organization trail in the management account must have sufficient permissions to create an organization trail. At a minimum, to create an organization trail, you must have the AWSCloudTrail_FullAccess policy or equivalent permissions applied.

By default, when you create a trail in the console, the trail logs all regions. Logging all regions in your account is a recommended best practice.

Organizations と連携した 組織レベルの CloudTrail有効化を試してみました。 - マルチアカウントの情報を 1バケットに集約できる - 組織に新しいアカウントが追加されたときの CloudTrail設定が省ける 上記メリットがあり、便利に感じました。 ### Prefix - prefix is optional, without prefix the top-level (inside bucket) will be AWSLogs (e.g. bucket_name/AWSLogs). If specified, it will be bucket_name/prefix_name/AWSLogs - A bucket policy with an incorrect prefix can prevent your trail from delivering logs to the bucket. To resolve this issue, use the Amazon S3 console to update the prefix in the bucket policy, and then use the CloudTrail console to specify the same prefix for the bucket in the trail. ### Digest file in S3 Each digest file contains the names of the log files that were delivered to your Amazon S3 bucket during the last hour, the hash values for those log files, and the digital signature of the previous digest file. The signature for the current digest file is stored in the metadata properties of the digest file object. Enabling server-side encryption encrypts the log files but not the digest files with SSE-KMS. Digest files are encrypted with Amazon S3-managed encryption keys (SSE-S3). ### CloudTrail console - View the last 90 days of recorded API activity (management events) in Event history - Event history does not show data events. To view data events, create a trail. - View trails on CloudTrail console within 90 days. (To identify AWS API activity older than 90 days use Athena on S3) ### CloudTrail userIdentity Element - type: Root,IAMUser, AssumedRole, FederatedUser - sessionContext:mfaAuthenticated ### Sending events to Amazon CloudWatch Logs When you configure your trail to send events to your CloudWatch Logs log group, CloudTrail sends only the events that you specify in your trail. ### logs encryption - By default, CloudTrail will encrypt log files delivered to your Amazon S3 bucket using Amazon S3 server-side encryption. - CloudTrail log file encryption using SSE-KMS allows you to add an additional layer of security to CloudTrail log files delivered to an Amazon S3 bucket by encrypting the log files with a KMS key. ### Troubleshoot - Two of the production accounts have trails that are not logging anything to the S3 bucket. 1. Verify that the S3 bucket policy allows access for CloudTrail from the production AWS account IDs. 2. Confirm in the CloudTrail Console that each trail is active and healthy. 3. Confirm in the CloudTrail Console that the S3 bucket name is set correctly. - Most efficient way to automate the encryption of AWS CloudTrail logs using a Customer Master Key (CMK) in AWS KMS A: Configure CloudTrail to use server-side encryption using KMS-managed keys to encrypt and decrypt CloudTrail logs.
rainit2006 commented 3 years ago

AWS Cognito

Cognito group

### password length policy - Update the password length policy in the Amazon Cognito configuration. - Adding User Pool Password Requirements:Minimum length,Require numbers, Require a special character,Require uppercase letters,Require lowercase letters.
rainit2006 commented 3 years ago

GuardDuty

It uses threat intelligence feeds, such as lists of malicious IP addresses and domains, and machine learning to identify unexpected and potentially unauthorized and malicious activity within your AWS environment.

Data sources:

DNS logs:

Trusted IP list and Threat lists

Exam

rainit2006 commented 3 years ago

AWS WAF

WAF vs Shield

AWS Firewall Manager

AWS Firewall Manager を使用すると、AWS WAF ルール、AWS Shield Advanced 保護、Amazon VPC セキュリティグループで管理およびメンテナンスタスクを簡略化できます。

Use AWS Firewall Manager to create a security group policy, enable the policy feature to identify and revert local changes, and enable automatic remediation.

WAF -- web ACL

A web access control list (web ACL) gives you fine-grained control over the web requests that your protected resource responds to. After you create your web ACL, you can associate it with one or more AWS resources.

Logging: You can enable logging to get detailed information about traffic that is analyzed by your web ACL. You send logs from your web ACL to an Amazon Kinesis Data Firehose with a configured storage destination. After you enable logging, AWS WAF delivers logs to your storage destination through the HTTPS endpoint of Kinesis Data Firehose.

Another ways

rainit2006 commented 3 years ago

S3

Data encryption

  1. In-transit (1)Using Secure Socket Layer/Transport Layer Security (SSL/TLS) OR (2)client-side encryption.
  2. At rest (1)Server-Side Encryption -- When you use Server-Side Encryption with Amazon S3-Managed Keys (SSE-S3), each object is encrypted with a unique key. -- SSE-KMS is similar to SSE-S3. but with some additional benefits and charges for using this service

(2) Client-Side Encryption

Default

rainit2006 commented 3 years ago

AWS Certificate Manager (ACM)

Using a custom SSL certificate for my CloudFront distribution

https://aws.amazon.com/premiumsupport/knowledge-center/custom-ssl-certificate-cloudfront/

  1. To assign an ACM certificate to a CloudFront distribution, must request or import the certificate in the US East (N. Virginia) Region.
  2. be sure that the status of the certificate is Issued.
  3. The certificate must be a 2048-bit RSA certificate or smaller
  4. Prerequisites for importing certificates,including cryptographic algorithm and a key size, SSL/TLS X.509 version 3 certificate, the private key must be unencrypted, Private Key is .pem encoded.

Using a certificate imported to IAM

  1. must provide the correct path so that CloudFront can use the certificate.
    aws iam upload-server-certificate --server-certificate-name CertificateName
    --certificate-body file://public_key_certificate_file --private-key file://privatekey.pem 
    --certificate-chain file://certificate_chain_file --path /cloudfront/DistributionName/

HTTPS traffic

rainit2006 commented 3 years ago

AWS Organization

SCP (service control policy)

Solution for restrict usage of member root user accounts:

rainit2006 commented 3 years ago

AWS Systems Manager Session Manager

Shell Access to EC2 Instances

SSM parameter store

rainit2006 commented 3 years ago

VPC

Issue:Unable to connect to an Amazon EC2

Reason:

  1. The NACL denies inbound/outbound traffic
  2. SG don't allow inbound traffic
  3. The route table is missing a route to the internet gateway.
  4. The host-based firewall is denying xxx protocl

Issue:EC2 instances in different subnets cannot connect to each other

Check:

  1. Security groups have valid ALLOW rules in place to permit this traffic.
  2. Check inbound and outbound Network ACL rules, looking for DENY rules

ACL:

An outbound rule must be added to the network ACL to allow the response to be sent to the client on the ephemeral port range.

rainit2006 commented 3 years ago

CloudFront

CloudFront key pair

  1. Signed URL: for individual file
  2. Signed Cookies: for all files like video.

origin access identity (OAI)

Requiring HTTPS for Communication Between Viewers and CloudFront

Requiring HTTPS for Communication Between CloudFront and Your Custom Origin

  1. Use the default CloudFront domain name
    • Change the Origin Protocol Policy setting for specific origins in your distribution
    • Install an SSL/TLS certificate on your custom origin server (this isn't required when you use an Amazon S3 origin)
    • Origin Protocol Policy: HTTPS Only , Match Viewer
  2. Use an alternate domain name
rainit2006 commented 3 years ago

IAM:

rainit2006 commented 3 years ago

AWS Trusted Advisor

Trusted Advisor for Best practices. AWS Trusted Advisor is an AWS tool that provides you real-time assistance to help you provision your resources following AWS best practices.

Four categories: Cost Optimization, Performance, Security, Fault Tolerance, Trusted Advisor は無料で使えます。

Trusted Advisor, Security Hub, Config

Organization with GuardDuty, Security Hub

it's like Security hub , guarduty in organization, you send an invitation if the account isn't member of guarduty.

rainit2006 commented 3 years ago

Application Load Balancer (ALB)

Target group + Router

rainit2006 commented 3 years ago

SSL certificates

rainit2006 commented 3 years ago

EC2

If SSH key was comprimised...

You can't launch a new instance using a deleted key pair, but you can continue to connect to any instances that you launched using a deleted key pair, as long as you still have the private key (.pem) file. (Even if you delete the key pair the backup key will remain in EC2)

You should use the EC2 RunCommand to modify the authorized_keys file on any EC2 instance that is using the key. Modify authorized_keys with new key. It will save lot of time and there will be no need to stop the running instance.

Storage

rainit2006 commented 3 years ago

IAM

Troubleshooting

A2: (1)Create IAM roles with permissions corresponding to each Active Directory group. (2)Create a SAML provider with IAM. (3)Configure AWS as a trusted relying party for the Active Directory。

Relying party trust (証明書利用者信頼))

Relying party trust is a term used in Microsoft Windows Server system to identify service providers that can communicate with an AD FS endpoint.

rainit2006 commented 3 years ago

Troubleshooting

rainit2006 commented 3 years ago

203(不能选A:无法edit既存的VPC flow format)

https://www.examtopics.com/exams/amazon/aws-certified-security-specialty/view/12/ 10,14,16,20,23,33、 42, 51(root does not apply to roles, it applies to IAM users and root user), 72(You can use this connection to send logs to CloudWatch Logs without sending them through the internet.), 81,98, 99, 103,104,110, 118, 126, 128, 136(Place all the files in the same S3 bucket. Use server-side encryption with AWS KMS-managed keys (SSE-KMS) to encrypt the data.) 141, 143, 154, ⭐️166(VPN over DX connection using public VIF), 169(!), 171(!), 173, 178(EC2 Auto Scaling groups + KMS), 179(!), 181 (没个靠谱的答案), 183(route table in VPC peering), 189,191, 201(Edit the existing trail in the Organizations master account and apply it to the organization.), 208(Systems Manager Agent), 209(Use AWS Firewall Manager for SG setting and automatic remediation.), 233(!), 237,

rainit2006 commented 3 years ago

AWS Secrets Manager

Rotating Your AWS Secrets Manager Secrets