Closed joshriverscambia2019 closed 1 year ago
@joshriverscambia2019 it looks to me like if encryption: aws:kms
is requested without an explicit encryption_key_id
, the bucket is still configured with aws:kms
encryption, it just uses the default AWS managed key instead of a customer managed key (see S3 User Guide). I'm not sure what's causing the error you're seeing, but the error message indicates that the requested bucket configuration is {"SSEAlgorithm": "aws:kms"}
The only thing I can add to what @hakbailey already said is that we can probably slightly increase the number of attempts here https://github.com/ansible-collections/amazon.aws/blob/68a36b274bda36756645c637181bc87e2a642642/plugins/modules/s3_bucket.py#L819 The API may be slow which is why it may take longer to update. But this is only a supposition!
I think by the time this error is seen we're in the wait_encryption_is_applied()
function which has 12 retries. I doubt we really need to increase that, and I suspect something else is going on here. I agree API slowness could be the cause, but not sure without more information. In any case I'm going to close this issue as I don't think we need to make any changes at the moment.
Sorry for the slow reply, as I was out for a few days.
Specifically, this issue was occurring while trying to "update" an existing bucket with kms set up with the account key. Running the module against that existing configuration failed as noted and we needed to re-code our role to allow it to function. I don't believe this is worth spending a lot of effort on, but I wanted to get it reported to improve the overall reliability.
@joshriverscambia2019 thank you for reporting the issue, we appreciate it! So just to make sure I understand the scenario: you have an existing bucket that uses kms encryption with a customer-managed key, and when you try to update it to use an AWS-managed key (passing no encryption_key_id
), it never completes?
@hakbailey Yes. That is the failure I ran into. Modifying the code to set encryption: AES256
resolved my issue, but it had been working for some time and it seemed to me that behavior changed with the new defaults.
@joshriverscambia2019 hmm. I'm still not able to recreate this error. The following worked fine:
tasks:
- name: Create an s3 bucket with customer managed key
amazon.aws.s3_bucket:
name: test-bucket
state: present
encryption: aws:kms
encryption_key_id: <the existing kms key id>
- name: Update bucket to use AWS managed key
amazon.aws.s3_bucket:
name: test-bucket
state: present
encryption: aws:kms
Are there other details about the existing bucket that I'm missing?
@hakbailey I can't reproduce it anymore either. Same versions and runtime environment, but I am not getting the "Bucket encryption failed to apply in the expected time" message anymore. My initial failures were spaced over 6 hours before I modified the code to encryption: AES256
which allowed it to work.
Running a test playbook now has the bucket moving between algorithms without a hitch:
% aws s3api get-bucket-encryption --bucket [MYBUCKETNAME]
{
"ServerSideEncryptionConfiguration": {
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
},
"BucketKeyEnabled": false
}
]
}
}
goes to
{
"ServerSideEncryptionConfiguration": {
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
},
"BucketKeyEnabled": false
}
]
}
}
and back.
There's some mystery here, but not an interesting one. Looks like things are functioning correctly now and there is no need to fix things in the Ansible module.
@joshriverscambia2019 well I'm glad your issue was solved! Thanks for confirming.
Summary
As noted in https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/s3_bucket.py#L64 AWS no longer supports disabling encryption for new S3 buckets.
Additionally, if
encryption: aws:kms
is requested without an explicitencryption_key_id
, the bucket will be configured withAES256
encryption. This can cause deployment to fail inwait_encryption_is_applied
as the state never aligns with the request.This is a minor behavior bug, but can be a little tricky to comprehend the failure. It might be worth either; 1) Adding parameter validation to prevent
encryption: aws:kms
from being specified withoutencryption_key_id
. 2) Updating the encryption variable to force the value to be "AES256" if it is set to aws:kms and no encryption_key_id is provided.Issue Type
Bug Report
Component Name
amazon.aws.s3_bucket
Ansible Version
$ ansible --version ansible [core 2.14.4] config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /root/.local/pipx/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /root/.local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/root/.local/pipx/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True
Collection Versions
AWS SDK versions
Configuration
OS / Environment
Debialn Bullseye
Steps to Reproduce
Expected Results
Expected success.
Actual Results
Code of Conduct