Debian Codegraph @

docs/source/guide/security.rst

raw
1 .. _guide_security:
2
3 Security
4 ========
5
6 Cloud security at Amazon Web Services (AWS) is the highest priority. As an AWS
7 customer, you benefit from a data center and network architecture that is built to meet the
8 requirements of the most security-sensitive organizations. Security is a shared responsibility
9 between AWS and you. The `Shared Responsibility Model <https://aws.amazon.com/compliance/shared-responsibility-model/>`_
10 describes this as Security of the Cloud and Security in the Cloud.
11
12 **Security of the Cloud** – AWS is responsible for
13 protecting the infrastructure that runs all of the services offered in the AWS Cloud and
14 providing you with services that you can use securely. Our security responsibility is the
15 highest priority at AWS, and the effectiveness of our security is regularly tested and
16 verified by third-party auditors as part of the `AWS Compliance Programs <https://aws.amazon.com/compliance/programs/>`_.
17
18 **Security in the Cloud** – Your responsibility is
19 determined by the AWS service you are using, and other factors including the sensitivity of
20 your data, your organization’s requirements, and applicable laws and regulations.
21
22 Boto3 follows the `shared responsibility model <https://aws.amazon.com/compliance/shared-responsibility-model>`_
23 through the specific AWS services it supports. For AWS service security information, see the
24 `AWS service security documentation page <https://aws.amazon.com/security/?id=docs_gateway#aws-security>`_
25 and `AWS services that are in scope of AWS compliance efforts by compliance program <https://aws.amazon.com/compliance/services-in-scope/>`_.
26
27 .. _data_protection_intro:
28
29 Data protection
30 ---------------
31
32 The AWS `shared responsibility model <https://aws.amazon.com/compliance/shared-responsibility-model>`_
33 applies to data protection in AWS SDK for Python (Boto3). As described in this model,
34 AWS is responsible for protecting the global infrastructure that runs all of the AWS
35 Cloud. You are responsible for maintaining control over your content that is hosted on
36 this infrastructure. This content includes the security configuration and management
37 tasks for the AWS services that you use. For more information about data privacy, see
38 the `Data Privacy FAQ <https://aws.amazon.com/compliance/data-privacy-faq>`_.
39
40 For data protection purposes, we recommend that you protect AWS account credentials and set up individual user accounts with
41 AWS Identity and Access Management (IAM), so that each user is given only the permissions necessary to fulfill their job duties. We also recommend that
42 you secure your data in the following ways:
43
44 * Use multi-factor authentication (MFA) with each account.
45 * Use SSL/TLS to communicate with AWS resources. To use minimum TLS version of 1.2, see `Enforcing TLS 1.2`_
46 * Set up API and user activity logging with AWS CloudTrail.
47 * Use AWS encryption solutions, along with all default security controls within AWS services.
48 * Use advanced managed security services such as Amazon Macie, which assists in discovering and securing personal data that
49 is stored in Amazon S3.
50
51 We strongly recommend that you never put sensitive identifying information, such as your customers' account numbers, into
52 free-form fields such as a **Name** field. This includes when you work with Boto3 or other AWS services
53 using the console, API, AWS CLI, or AWS SDKs. Any data that you enter into Boto3 or other services might get picked up
54 for inclusion in diagnostic logs. When you provide a URL to an external server, don't include credentials information in the URL
55 to validate your request to that server.
56
57 .. _identity_and_access_management_intro:
58
59 Identity and access management
60 ------------------------------
61
62 AWS Identity and Access Management (IAM) is an AWS service that helps an administrator securely control access to AWS resources.
63 IAM administrators control who can be *authenticated* (signed in) and *authorized* (have permissions) to use AWS resources. IAM is an AWS service that you can use at no additional charge.
64 For details about working with IAM, see `AWS Identity and Access Management <https://aws.amazon.com/iam/>`_. We also strongly recommend reviewing the `Security best practices in IAM <https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html>`_.
65
66
67 To use Boto3 to access AWS, you need an AWS account and AWS credentials. For more information on credentials
68 see `AWS security credentials <https://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html>`_
69 in the `AWS General Reference <https://docs.aws.amazon.com/general/latest/gr/>`_.
70
71 .. _compliance_validation_intro:
72
73 Compliance validation
74 ---------------------
75
76 The security and compliance of AWS services is assessed by third-party auditors as part
77 of multiple AWS compliance programs. These include SOC, PCI, FedRAMP, HIPAA, and others.
78 AWS provides a frequently updated list of AWS services in scope of specific compliance programs at
79 `AWS Services in Scope by Compliance Program <https://aws.amazon.com/compliance/services-in-scope/>`_.
80
81 Third-party audit reports are available for you to download using AWS Artifact. For more information, see
82 `Downloading Reports in AWS Artifact <https://docs.aws.amazon.com/artifact/latest/ug/downloading-documents.html>`_.
83
84 For more information about AWS compliance programs, see `AWS Compliance Programs <https://aws.amazon.com/compliance/programs/>`_.
85
86 Your compliance responsibility when using Boto3 to access an AWS service is determined by the sensitivity of your data, your organization’s compliance objectives,
87 and applicable laws and regulations. If your use of an AWS service is subject to compliance with standards such as HIPAA, PCI, or FedRAMP, AWS provides resources to help:
88
89 * `Security and Compliance Quick Start Guides <https://aws.amazon.com/quickstart/?quickstart-all.sort-by=item.additionalFields.updateDate&quickstart-all.sort-order=desc&awsf.quickstart-homepage-filter=categories%23security-identity-compliance>`_ –
90 Deployment guides that discuss architectural considerations and provide steps for deploying security-focused and compliance-focused baseline environments on AWS.
91 * `Architecting for HIPAA Security and Compliance Whitepaper <https://d0.awsstatic.com/whitepapers/compliance/AWS_HIPAA_Compliance_Whitepaper.pdf>`_ –
92 A whitepaper that describes how companies can use AWS to create HIPAA-compliant applications.
93 * `AWS Compliance Resources <https://aws.amazon.com/compliance/resources/>`_ – A collection of workbooks and guides that might apply to your industry and location.
94 * `AWS Config <https://aws.amazon.com/config/>`_ – A service that assesses how well your resource configurations comply with
95 internal practices, industry guidelines, and regulations.
96 * `AWS Security Hub <https://aws.amazon.com/security-hub>`_ – A comprehensive view of your security state within AWS that helps
97 you check your compliance with security industry standards and best practices.
98
99 .. _resilience_intro:
100
101 Resilience
102 ----------
103
104 The AWS global infrastructure is built around AWS Regions and Availability Zones.
105
106 AWS Regions provide multiple physically separated and isolated Availability Zones, which are connected with low-latency, high-throughput, and highly redundant networking.
107
108 With Availability Zones, you can design and operate applications and databases that automatically fail over between Availability Zones without interruption.
109 Availability Zones are more highly available, fault tolerant, and scalable than traditional single or multiple data center infrastructures.
110
111 For more information about AWS Regions and Availability Zones, see `AWS Global Infrastructure <https://aws.amazon.com/about-aws/global-infrastructure/>`_.
112
113 .. _infrastructure_security_intro:
114
115 Infrastructure security
116 -----------------------
117
118 For information about AWS security processes, see the `AWS: Overview of Security Processes <https://d0.awsstatic.com/whitepapers/Security/AWS_Security_Whitepaper.pdf>`_ whitepaper.
119
120 .. _enforcing_tls_12_intro:
121
122 Enforcing TLS 1.2
123 ------------------
124
125 To ensure the AWS SDK for Python uses no TLS version earlier than TLS 1.2, you might need to recompile OpenSSL to enforce this minimum and then recompile Python to use the recompiled OpenSSL.
126
127 Determining supported protocols
128 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129
130 First, create a self-signed certificate to use for the test server and the SDK using OpenSSL::
131
132 openssl req -subj '/CN=localhost' -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365
133
134 Then spin up a test server using OpenSSL::
135
136 openssl s_server -key key.pem -cert cert.pem -www
137
138 In a new terminal window, create a virtual environment and install the SDK::
139
140 python3 -m venv test-env
141 source test-env/bin/activate
142 pip install botocore
143
144
145 Create a new Python script called ``check.py`` that will use the SDK’s underlying HTTP library::
146
147 import urllib3
148 URL = 'https://localhost:4433/'
149
150 http = urllib3.PoolManager(
151 ca_certs='cert.pem',
152 cert_reqs='CERT_REQUIRED',
153 )
154 r = http.request('GET', URL)
155 print(r.data.decode('utf-8'))
156
157 Run the script::
158
159 python check.py
160
161 This will give details about the connection made. Search for ``Protocol :`` in the output. If the output is ``TLSv1.2`` or later, the SDK will default to TLS v1.2 and later. If it's earlier, you need to recompile OpenSSL and then recompile Python.
162
163 However, even if your installation of Python defaults to TLS v1.2 or later, it's still possible for Python to renegotiate to a version earlier than TLS v1.2 if the server doesn't support TLS v1.2+. To check that Python will not automatically renegotiate to these earlier versions, restart the test server with the following::
164
165 openssl s_server -key key.pem -cert cert.pem -no_tls1_3 -no_tls1_2 -www
166
167 .. note::
168
169 If you are using an older version of OpenSSL, you might not have the ``-no_tls_3`` flag available.
170 In this case, just remove the flag because the version of OpenSSL you are using doesn't support TLS v1.3.
171
172 Rerun the Python script::
173
174 python check.py
175
176 If your installation of Python correctly does not renegotiate for versions earlier than TLS 1.2, you should receive an SSL error::
177
178 urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='localhost', port=4433): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1108)')))
179
180 If you are able to make a connection, you need to recompile OpenSSL and Python to disable negotiation of protocols earlier than TLS v1.2.
181
182 Compile OpenSSL and Python
183 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
184
185 To ensure the SDK or CLI does not negotiate for anything earlier than TLS 1.2, you need to recompile OpenSSL and Python. First copy the following content to create a script and run it::
186
187
188 #!/usr/bin/env bash
189 set -e
190
191 OPENSSL_VERSION="1.1.1m"
192 OPENSSL_PREFIX="/opt/openssl-with-min-tls1_2"
193 PYTHON_VERSION="3.9.10"
194 PYTHON_PREFIX="/opt/python-with-min-tls1_2"
195
196
197 curl -O "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz"
198 tar -xzf "openssl-$OPENSSL_VERSION.tar.gz"
199 cd openssl-$OPENSSL_VERSION
200 ./config --prefix=$OPENSSL_PREFIX no-ssl3 no-tls1 no-tls1_1 no-shared
201 make > /dev/null
202 sudo make install_sw > /dev/null
203
204
205 cd /tmp
206 curl -O "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz"
207 tar -xzf "Python-$PYTHON_VERSION.tgz"
208 cd Python-$PYTHON_VERSION
209 ./configure --prefix=$PYTHON_PREFIX --with-openssl=$OPENSSL_PREFIX --disable-shared > /dev/null
210 make > /dev/null
211 sudo make install > /dev/null
212
213
214 This will compile a version of Python that has a statically linked OpenSSL that will not automatically negotiate anything earlier than TLS 1.2. This will also install OpenSSL in the directory: ``/opt/openssl-with-min-tls1_2`` and install Python in the directory: ``/opt/python-with-min-tls1_2``.
215
216 After you run this script, you should be able to use this newly installed version of Python::
217
218 /opt/python-with-min-tls1_2/bin/python3 --version
219
220 This should print out::
221
222 Python 3.9.10
223
224 To confirm this new version of Python does not negotiate a version earlier than TLS 1.2, rerun the steps from `Determining Supported Protocols`_ using the newly installed Python version (that is, ``/opt/python-with-min-tls1_2/bin/python3``).
225
226 Enforcing TLS 1.3
227 ------------------
228
229 .. note::
230 Some AWS Services do not yet support TLS 1.3, configuring this as your minimum version may affect SDK interoperability.
231 We recommend testing this change with each service prior to production deployment.
232
233
234 The process of ensuring the AWS SDK for Python uses no TLS version earlier than TLS 1.3 is the same as the instructions in the `Enforcing TLS 1.2`_ section with some minor modifications, primarily adding the ``no-tls1_2`` flag to the openssl build configuration.
235
236 The following are the modified build instructions::
237
238
239 #!/usr/bin/env bash
240 set -e
241
242 OPENSSL_VERSION="1.1.1m"
243 OPENSSL_PREFIX="/opt/openssl-with-min-tls1_3"
244 PYTHON_VERSION="3.9.10"
245 PYTHON_PREFIX="/opt/python-with-min-tls1_3"
246
247
248 curl -O "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz"
249 tar -xzf "openssl-$OPENSSL_VERSION.tar.gz"
250 cd openssl-$OPENSSL_VERSION
251 ./config --prefix=$OPENSSL_PREFIX no-ssl3 no-tls1 no-tls1_1 no-tls1_2 no-shared
252 make > /dev/null
253 sudo make install_sw > /dev/null
254
255
256 cd /tmp
257 curl -O "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz"
258 tar -xzf "Python-$PYTHON_VERSION.tgz"
259 cd Python-$PYTHON_VERSION
260 ./configure --prefix=$PYTHON_PREFIX --with-openssl=$OPENSSL_PREFIX --disable-shared > /dev/null
261 make > /dev/null
262 sudo make install > /dev/null