# GetBucketVersioning

GetBucketVersioning returns a bucket's versioning state - whether overwriting or deleting an
object keeps the earlier versions. Every STRG bucket is versioned from the moment it is
created and stays that way, so the answer is always `Enabled` and there is nothing to set up
first. [PutBucketVersioning](https://docs.strg.com/s3-api/PutBucketVersioning) is its counterpart.

**Info: Good to know on STRG**

- `Status` is always `Enabled`, for a bucket that was never configured too. It is never
  `Suspended` and never absent, so a client always gets the same clear answer.
- `MfaDelete` is never part of the answer: STRG has no MFA delete.
- `x-amz-expected-bucket-owner` is welcome and has nothing to check.

Because every bucket keeps every version, overwriting or deleting an object leaves its earlier
versions in place: a delete writes a delete marker, and every version stays billed as stored data
until it is permanently deleted or a [lifecycle policy](https://docs.strg.com/lifecycle-policies) removes it.

## When you'd use it

- Backup tools often check that a bucket is versioned before they write to it, since versioning
  is what lets a backup be rolled back. STRG answers `Enabled`, so they carry on as usual.
- Infrastructure-as-code tools read a bucket's versioning state to compare it with the
  configuration they manage. With versioning described as `Enabled`, the bucket matches from the
  start.
- An agent about to overwrite a file in a bucket can call GetBucketVersioning to confirm the
  previous version stays recoverable, and tell the person it is working for so.

## Request

```http
GET /?versioning HTTP/1.1
Host: my-bucket.s3.eu-central-1.strg.com
Authorization: AWS4-HMAC-SHA256 Credential=...
x-amz-date: 20260926T120000Z
x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
```

Path-style, the same request is `GET /my-bucket?versioning` on `s3.eu-central-1.strg.com`.
[Addressing](https://docs.strg.com/s3-api/overview#addressing) describes both styles.

### Permissions

The access key needs **Read bucket settings** (`buckets:read-config`). Every access key holds it:
the dashboard shows it among the permissions [always included](https://docs.strg.com/access-keys#always-included)
in a key, rather than as a choice. A key limited to certain buckets reaches only those buckets.
[Access keys](https://docs.strg.com/access-keys) has the details.

### URI parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Bucket` | String | Yes | The bucket whose versioning state is read. |
| `versioning` | Flag | Yes | Selects the versioning subresource. Sent without a value. |

Any other query parameter is answered `501 NotImplemented`, so a client knows straight away that
it has no effect here.

### Request headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-amz-expected-bucket-owner` | String | No | Welcome, and has nothing to check: an access key only ever reaches its own account's buckets. |

### Request body

None.

## Response

A successful request answers `200 OK` with the versioning configuration as XML.

### Response headers

| Name | Description |
| --- | --- |
| `x-amz-request-id` | The request ID, for support requests. |

### Response body

The configuration is short, and its elements are these.

| Element | Type | Description |
| --- | --- | --- |
| `VersioningConfiguration` | Container | The root element. |
| `Status` | String | Always `Enabled`. |
| `MfaDelete` | String | Never returned: STRG has no MFA delete. |

```xml
<?xml version="1.0" encoding="UTF-8"?>
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Status>Enabled</Status>
</VersioningConfiguration>
```

## Errors

These are the errors this operation can answer, and the situation behind each.

| Code | HTTP status | When |
| --- | --- | --- |
| `NoSuchBucket` | 404 | The bucket does not exist, it is in a region other than the endpoint's, or your account has no storage in this endpoint's region yet. |
| `AccessDenied` | 403 | The access key is limited to buckets that do not include this one, or your account is not active. |
| `InvalidAccessKeyId` | 403 | The access key does not exist, has expired or been revoked, or was created so recently that it is not yet usable in this endpoint's region - a moment later it is. |
| `SignatureDoesNotMatch` | 403 | The request signature is wrong. |
| `RequestTimeTooSkewed` | 403 | The request time is more than 15 minutes from the server's. |
| `AuthorizationHeaderMalformed` | 400 | The signature's credential scope names a region other than the endpoint's. |
| `NotImplemented` | 501 | The request carries a query parameter this operation does not accept. |
| `SlowDown` | 503 | Too many requests at once; a retry after the `Retry-After` interval goes through. |
| `ServiceUnavailable` | 503 | A temporary failure; a retry usually succeeds. |

## Differences from Amazon S3

A few things work a little differently on STRG, each listed here with what it means for your
requests.

| Aspect | Amazon S3 | STRG |
| --- | --- | --- |
| New bucket | Unversioned: `Status` is absent until versioning is first enabled | Versioned from creation: `Status` is `Enabled` straight away, with nothing to turn on |
| `Suspended` | Returned after versioning is suspended | Never returned: versioning stays on for good - [PutBucketVersioning](https://docs.strg.com/s3-api/PutBucketVersioning) has the details |
| `MfaDelete` | Returned if the bucket was ever configured with MFA delete | Never returned: STRG has no MFA delete |
| Permission | Bucket owner only | Any access key that reaches the bucket |
| Bucket in another region | `301` redirect with `x-amz-bucket-region` | `404 NoSuchBucket`, also from a region where your account stores nothing yet. Each bucket answers on its own regional endpoint |
| `x-amz-expected-bucket-owner` | Checked against the bucket owner | Welcome, with nothing to check: a key only ever reaches buckets of its own account |

## Examples

Each example reads the versioning state of `my-bucket`; the SDK examples print its status.

**AWS CLI**

```bash
aws s3api get-bucket-versioning \
  --bucket my-bucket \
  --endpoint-url https://s3.eu-central-1.strg.com \
  --region eu-central-1
```

**Python (boto3)**

```python
import boto3

s3 = boto3.client(
    "s3",
    endpoint_url="https://s3.eu-central-1.strg.com",
    region_name="eu-central-1",
)

response = s3.get_bucket_versioning(Bucket="my-bucket")
print(response.get("Status"))
```

**JavaScript (AWS SDK v3)**

```javascript
import { GetBucketVersioningCommand, S3Client } from "@aws-sdk/client-s3";

const client = new S3Client({
  endpoint: "https://s3.eu-central-1.strg.com",
  region: "eu-central-1",
});

const response = await client.send(new GetBucketVersioningCommand({ Bucket: "my-bucket" }));
console.log(response.Status);
```

## Related

- [PutBucketVersioning](https://docs.strg.com/s3-api/PutBucketVersioning)
- [ListObjectVersions](https://docs.strg.com/s3-api/ListObjectVersions) - every version and delete marker
- [DeleteObject](https://docs.strg.com/s3-api/DeleteObject) - delete markers and permanent deletes
- [Lifecycle policies](https://docs.strg.com/lifecycle-policies) - removing old versions automatically, as in
  [Keeping 30 days of old versions](https://docs.strg.com/lifecycle-policies#keeping-30-days-of-old-versions)
- [Access keys](https://docs.strg.com/access-keys)
- [S3 API overview](https://docs.strg.com/s3-api/overview)
