From e2b0734e1f9c4dcab11d10605c1ce6d6f43305b3 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Wed, 20 Nov 2024 14:43:30 -0300 Subject: [PATCH] Update documentation about DEFULT_FILE_STORAGE/STORAGES --- .../configure-pulp/configure-storages.md | 146 ++++++++++++++++++ .../index.md} | 0 docs/admin/reference/settings.md | 54 +++++-- 3 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 docs/admin/guides/configure-pulp/configure-storages.md rename docs/admin/guides/{configure-pulp.md => configure-pulp/index.md} (100%) diff --git a/docs/admin/guides/configure-pulp/configure-storages.md b/docs/admin/guides/configure-pulp/configure-storages.md new file mode 100644 index 00000000000..75a22a2ad60 --- /dev/null +++ b/docs/admin/guides/configure-pulp/configure-storages.md @@ -0,0 +1,146 @@ +# Configure Storage Backend + +Pulp uses [django-storages](https://django-storages.readthedocs.io) to support multiple storage backends. +See the reference for the [`STORAGES` settings](site:pulpcore/docs/admin/reference/settings.md). + +## Local Filesystem + +This is the default storage backend Pulp will use if another is not specified. + +### Configure + +Configure the `BACKEND` and `OPTIONS` for the default django storage. + +Example configuration: + +```python +STORAGES = { + "default": { + "BACKEND": "storages.backends.s3.S3Storage", + "OPTIONS": { + "file_permissions_mode": 0o600, + "directory_permissions_mode": 0o600, + }, + }, +} +``` + +Compreheensive options for Local Filesystem can be found in +[Django docs](https://docs.djangoproject.com/en/4.2/ref/files/storage/#django.core.files.storage.FileSystemStorage). + +### Further notes + +- Read about how Pulp's modifies `MEDIA_ROOT` defaults [here](). +- Other relevant settings (module-scope settings) that are left as Django default's: + * `MEDIA_URL` + * `FILE_UPLOAD_PERMISSIONS` + * `FILE_UPLOAD_DIRECTORY_PERMISSIONS` + +## Amazon S3 + +### Amazon Setup + +Before you can configure Amazon S3 storage to use with Pulp, ensure that you complete the following steps. +To complete these steps, consult the official Amazon S3 documentation. + +1. Set up an AWS account. +2. Create an S3 bucket for Pulp to use. +3. In AWS Identity and Access Management (IAM), create a user that Pulp can use to access your S3 bucket. +4. Save the access key id and secret access key. + +### Pulp Setup + +**TODO: learn how that works for oci-images and operator and provide links** + +To have Pulp use S3, complete the following steps. +This assumes a simple install. For oci-images: +* ... +* ... + +#### Install Python Dependencies + +Ensure you have `django-storages` and `boto3` in your environement. + +For example: + +```bash +pip install django-storages[boto3] +``` + +#### Configure + +Configure the `BACKEND` and `OPTIONS` for the default django storage. + +Here is an example configuration that will use a bucket called `pulp3` that is hosted in +region `eu-central-1`: + +```python +STORAGES = { + "default": { + "BACKEND": "storages.backends.s3.S3Storage", + "OPTIONS": { + "access_key": 'AKIAIT2Z5TDYPX3ARJBA', + "secret_key": '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', + "bucket_name": 'pulp3', + "signature_version": "s3v4", + "addressing_style": "path", + "region_name": "eu-central-1", + }, + }, +} +MEDIA_ROOT = "" +``` + +Compreheensive options for Amazon S3 can be found in +[`django-storages` docs](https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#configuration-settings). + +#### Further notes + +- You can omit `access_key` and `secret_key` if the following are true: + * The system that hosts Pulp is running in AWS + * The [`instance_profile`](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html) provides access to the S3 bucket + +## Azure Blob storage + +### Azure Setup + +Before you can configure Azure Blob storage to use with Pulp, ensure that you complete the following steps. +To complete these steps, consult the official Azure Blob documentation. + +1. Set up an Azure account and create a storage account. +2. In your storage account, create a container under `Blob` service. +3. Obtain the access credentials so that you can later configure Pulp to access your Azure Blob storage. You can find the access credentials + at the storage account level, at Access keys (these are automatically generated). + +### Pulp Setup + +#### Install Python Dependencies + +Ensure you have `django-storages[azure]` in your environement: + +```bash +pip install django-storages[azure] +``` + +#### Configure + +```python +STORAGES = { + "default": { + "BACKEND": "storages.backends.azure_storage.AzureStorage", + "OPTIONS": { + "account_name": '', + "container": '', # As created within the blob service of your storage account + "account_key": '', # From the access keys of your storage account + "url_expiration_secs": 60, + "overwrite_files": 'True', + "location": '' # The folder within the container where your pulp objects will be stored + }, + }, +} +MEDIA_ROOT = "" +``` + +Compreheensive options for Azure Blob can be found in +[`django-storages` docs](https://django-storages.readthedocs.io/en/latest/backends/azure.html#configuration-settings). + diff --git a/docs/admin/guides/configure-pulp.md b/docs/admin/guides/configure-pulp/index.md similarity index 100% rename from docs/admin/guides/configure-pulp.md rename to docs/admin/guides/configure-pulp/index.md diff --git a/docs/admin/reference/settings.md b/docs/admin/reference/settings.md index 6efffd6cd2b..ea07c8125bf 100644 --- a/docs/admin/reference/settings.md +++ b/docs/admin/reference/settings.md @@ -71,18 +71,51 @@ For a zero downtime key rotation you can follow the slightly more complex recipe By default Pulp uses PostgreSQL on localhost. PostgreSQL is the only supported database. For instructions on how to configure the database, refer to `database installation `. -### DEFAULT_FILE_STORAGE +### STORAGES + +!!! warning "Changed in `3.70`" + This replaces `DEFAULT_FILE_STORAGE` which [was deprecated in django `4.2`](https://docs.djangoproject.com/en/4.2/ref/settings/#default-file-storage). + +Pulp uses [django-storages](https://django-storages.readthedocs.io/en/latest/index.html) to support multiple storage backends. +If no backend is configured, Pulp will by default use the local filesystem (`pulpcore.app.models.storage.FileSystem`). + +To use another backend storage, you'll need to: + +- 1. Setup your storage and gather required credentials and specific configs. +- 1. Ensure the `django-storage[ s3 | google | azure ]` python package is installed. This depends on the installation method. On +- 1. Configure the default `BACKEND` storage class. +- 1. Configure available `OPTIONS` for that backend. + +An Amazon S3 might look like this: + +```python +STORAGES = { + "default": { + "BACKEND": "storages.backends.s3.S3Storage", + "OPTIONS": { + "access_key": 'AKIAIT2Z5TDYPX3ARJBA', + "secret_key": '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', + "bucket_name": 'pulp3', + "signature_version": "s3v4", + "addressing_style": "path", + "region_name": "eu-central-1", + }, + }, +} +``` + +Overview of the integration with Pulp: -By default, Pulp uses the local filesystem to store files. The default option which -uses the local filesystem is `pulpcore.app.models.storage.FileSystem`. +- **Supported**: We support (test) Amazon S3 and Azure. You can find more detailed information about it in +[Configure Storages](site:pulpcore/docs/admin/guides/configure-pulp/configure-storages.md) guide. +- **Untested**: Other backends provided by `django-storages` should work as well, but we provide no guarantee. +- **Known caveat**: Using SFTP Storage is not recommended in Pulp's current state, and doing so can lead to file corruption. This is because Pulp currently uses coroutines that seem to be incompatible with Django's SFTPStorage implementation. -For more information about different Pulp storage options, see the -`storage documentation `. ### REDIRECT_TO_OBJECT_STORAGE When set to `True` access to artifacts is redirected to the corresponding Cloud storage -configured in `DEFAULT_FILE_STORAGE` using pre-authenticated URLs. When set to `False` +configured in `STORAGES['default']` using pre-authenticated URLs. When set to `False` artifacts are always served by the content app instead. Defaults to `True`; ignored for local file storage. @@ -91,9 +124,10 @@ Defaults to `True`; ignored for local file storage. The location where Pulp will store files. By default this is `/var/lib/pulp/media`. -This only affects storage location when `DEFAULT_FILE_STORAGE` is set to -`pulpcore.app.models.storage.FileSystem`. See the `storage documentation ` for -more info. +This only affects storage location when `STORAGES['default']` is set to +`pulpcore.app.models.storage.FileSystem`. + +See the [storage documentation](site:pulpcore/docs/admin/guides/configure-pulp/configure-storages.md) for more info. It should have permissions of: @@ -188,7 +222,7 @@ It should have permissions of: ### CHUNKED_UPLOAD_DIR A relative path inside the DEPLOY_ROOT directory used exclusively for uploaded chunks. The -uploaded chunks are stored in the default storage specified by `DEFAULT_FILE_STORAGE`. This +uploaded chunks are stored in the default storage specified by `STORAGES['default']`. This option allows users to customize the actual place where chunked uploads should be stored within the declared storage. The default, `upload`, is sufficient for most use cases. A change to this setting only applies to uploads created after the change.