> For the complete documentation index, see [llms.txt](https://academy.cegedim.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://academy.cegedim.cloud/storage/object-storage/object-storage-get-started/manage-bucket-access.md).

# Manage Bucket access

If you want to control network accesses on objects in a **Bucket**, you will have to create a **Bucket Policy** using `aws:SourceIp` condition.

{% hint style="info" %}
We use **aws s3** and **aws`s3api`** command line tools from AWSCLIv2 on Linux.

`${S3_ENDPOINT}` and `${S3_PROFILE}` are environment variables.
{% endhint %}

Create a file with the following bucket policy:

{% code lineNumbers="true" %}

```json
{
  "Version": "2012-10-17",
  "Id": "OnlyInternal",
  "Statement": [
    {
      "Condition": {
        "NotIpAddress": {
          "aws:SourceIp": [
            "10.0.0.0/8",
            "192.168.0.0/16"
          ]
        }
      },
      "Action": "s3:*",
      "Resource": [
        "<bucket>/*",
        "<bucket>"
      ],
      "Effect": "Deny",
      "Principal": "*",
      "Sid": "BlockExternal"
    }
  ]
}
```

{% endcode %}

This will :

* **Deny** all operations from requests where the IP source address doesn't come from networks others that **10.0.0.0/8** and **192.168.0.0/16**

Change **`<bucket>`** by your bucket name.

For a complete documentation about Bucket Policy, please refer to [Bucket Policies](/storage/object-storage/object-storage-features/bucket-policies.md).

{% hint style="info" %}
cegedim.cloud Object Storage service is a **compatible S3 service**. Some specific AWS features are not supported.
{% endhint %}

## CIDR notation

With the `aws:SourceIp` condition, supports IPV4 addresses or IPV4 address ranges. IPV6 addresses are not supported.

When `aws:SourceIp` is a complete network (e.g. 10.0.0.0), you must specify the subnet mask in **CIDR** (Classless Inter-Domain Routing) format.

Example:

* 10.0.0.0/8
* 192.168.0.0/16
* 10.45.2.0/24

When `aws:SourceIp` is an IP address (e.g. 98.2.3.123), do not specify the subnet mask in CIDR (Classless Inter-Domain Routing) format.

Examples:

* 98.2.3.123
* 192.168.1.23
* 10.45.2.67

Put the the policy on your Bucket:

{% code overflow="wrap" %}

```bash
aws s3api --endpoint=${S3_ENDPOINT} put-bucket-policy --bucket bucket-test --policy file://mypolicy.json --profile ${S3_PROFILE}
```

{% endcode %}

Check if the policy is correctly set:

{% code overflow="wrap" %}

```bash
aws s3api --endpoint-url=${S3_ENDPOINT} get-bucket-policy --bucket bucket-test --profile ${S3_PROFILE}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://academy.cegedim.cloud/storage/object-storage/object-storage-get-started/manage-bucket-access.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
