> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# S3

> Conserva i file dei progetti e la cronologia in uno storage compatibile con S3 in un deployment Kubernetes.

I file dei progetti e la loro cronologia sono memorizzati dal servizio **history-v1**, i file dei template dal servizio **filestore**, entrambi all'interno di ogni pod di Ayakaleaf Pro. Per impostazione predefinita scrivono sul volume dei dati; con S3 scrivono nei bucket. Quali bucket e permessi sono necessari è descritto in [S3](https://ayakaleaf-pro.mintlify.site/it/on-premises/configuration/overleaf-toolkit/s3.md).

| | |
| - | - |
| Servizi | history-v1 (file dei progetti e cronologia), filestore (file dei template), in ogni pod di Ayakaleaf Pro |
| Pod → S3 | l'endpoint S3, per ogni file letto o scritto |
| Obbligatorio | per [più repliche](https://ayakaleaf-pro.mintlify.site/it/on-premises/configuration/kubernetes/horizontal-scaling.md): i loro volumi dei dati non sono condivisi, i bucket sì |
| Job periodici | nessuno |

> [!WARNING]
>
> Scegli S3 prima che gli utenti creino progetti. Un'istanza che conserva già i file sul proprio volume richiede prima la [migrazione a S3](https://ayakaleaf-pro.mintlify.site/it/on-premises/maintenance/s3-migration.md).

### Configurazione

**1. Bucket e chiavi**

Crea i tre bucket `overleaf-template-files`, `overleaf-project-blobs` e `overleaf-chunks` e i due utenti con permessi limitati nel tuo servizio S3 come descritto in [Configurazione di S3](https://ayakaleaf-pro.mintlify.site/it/on-premises/configuration/overleaf-toolkit/s3.md#s3-setup), oppure esegui Garage nel cluster come mostrato di seguito. Inserisci le quattro chiavi in un Secret:

```bash wrap theme={null}
kubectl -n overleaf create secret generic overleaf-s3 \
  --from-literal=OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID=<filestore key> \
  --from-literal=OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY=<filestore secret> \
  --from-literal=OVERLEAF_HISTORY_S3_ACCESS_KEY_ID=<history key> \
  --from-literal=OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY=<history secret>
```

**2. ConfigMap**

```yaml title="30-config.yaml (additions)" wrap theme={null}
  OVERLEAF_FILESTORE_BACKEND: s3
  OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME: overleaf-template-files
  OVERLEAF_FILESTORE_S3_REGION: eu-west-1
  OVERLEAF_HISTORY_BACKEND: s3
  OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET: overleaf-project-blobs
  OVERLEAF_HISTORY_CHUNKS_BUCKET: overleaf-chunks
  OVERLEAF_HISTORY_S3_REGION: eu-west-1
  # a self-hosted S3 service also needs its endpoint and path-style addressing
  # OVERLEAF_FILESTORE_S3_ENDPOINT: http://garage:3900
  # OVERLEAF_FILESTORE_S3_PATH_STYLE: "true"
  # OVERLEAF_HISTORY_S3_ENDPOINT: http://garage:3900
  # OVERLEAF_HISTORY_S3_PATH_STYLE: "true"
```

**3. Aggiungi il Secret al pod e riavvia**

Nel Deployment (o StatefulSet), aggiungi il Secret accanto agli altri:

```yaml theme={null}
          envFrom:
            - configMapRef: {name: overleaf-env}
            - secretRef: {name: overleaf-secrets}
            - secretRef: {name: overleaf-s3}
```

```bash theme={null}
kubectl apply -f 30-config.yaml -f 40-overleaf.yaml
kubectl -n overleaf rollout restart deployment/overleaf     # or statefulset/overleaf
```

### Garage nel cluster

Senza un servizio S3, [Garage](https://garagehq.deuxfleurs.fr/) è un piccolo server S3 che viene eseguito nel cluster. La configurazione di [Scalabilità orizzontale](https://ayakaleaf-pro.mintlify.site/it/on-premises/configuration/kubernetes/horizontal-scaling.md) è stata testata con esso. I comandi seguenti generano le chiavi e creano da soli il Secret `overleaf-s3`, quindi usali al posto del comando del Secret del passaggio 1.

> [!NOTE]
>
> MinIO, usato nell'esempio di Overleaf, non pubblica più immagini container: `minio/minio` non è più disponibile su Docker Hub e quay.io.

```yaml title="50-garage.yaml" wrap theme={null}
apiVersion: v1
kind: ConfigMap
metadata:
  name: garage-config
  namespace: overleaf
data:
  garage.toml: |
    metadata_dir = "/var/lib/garage/meta"
    data_dir = "/var/lib/garage/data"
    db_engine = "lmdb"
    replication_factor = 1
    rpc_bind_addr = "[::]:3901"
    rpc_public_addr = "127.0.0.1:3901"
    # rpc_secret and admin_token come from GARAGE_RPC_SECRET / GARAGE_ADMIN_TOKEN
    [s3_api]
    s3_region = "garage"          # Overleaf's OVERLEAF_*_S3_REGION must match
    api_bind_addr = "[::]:3900"
    [admin]
    api_bind_addr = "[::]:3903"
---
apiVersion: v1
kind: Service
metadata:
  name: garage
  namespace: overleaf
spec:
  selector:
    app: garage
  ports:
    - name: s3
      port: 3900
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: garage
  namespace: overleaf
spec:
  serviceName: garage
  replicas: 1
  selector:
    matchLabels:
      app: garage
  template:
    metadata:
      labels:
        app: garage
    spec:
      containers:
        - name: garage
          image: dxflrs/garage:v2.5.0
          env:
            - name: GARAGE_RPC_SECRET
              valueFrom: {secretKeyRef: {name: garage-secrets, key: rpc_secret}}
            - name: GARAGE_ADMIN_TOKEN
              valueFrom: {secretKeyRef: {name: garage-secrets, key: admin_token}}
          ports:
            - containerPort: 3900
          readinessProbe:
            tcpSocket:
              port: 3900
          resources:
            requests: {cpu: 50m, memory: 64Mi}
            limits: {memory: 512Mi}
          volumeMounts:
            - {name: config, mountPath: /etc/garage.toml, subPath: garage.toml}
            - {name: data, mountPath: /var/lib/garage}
      volumes:
        - name: config
          configMap:
            name: garage-config
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ReadWriteOnce]
        resources:
          requests:
            storage: 10Gi
```

Genera i secret, avvia Garage, poi crea il layout, i bucket e le due chiavi con permessi limitati. Gli ID delle chiavi Garage sono `GK` seguito da 24 caratteri esadecimali, i secret da 64 caratteri esadecimali:

```bash wrap theme={null}
kubectl -n overleaf create secret generic garage-secrets \
  --from-literal=rpc_secret="$(openssl rand -hex 32)" \
  --from-literal=admin_token="$(openssl rand -base64 32)"
kubectl -n overleaf create secret generic overleaf-s3 \
  --from-literal=OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID="GK$(openssl rand -hex 12)" \
  --from-literal=OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY="$(openssl rand -hex 32)" \
  --from-literal=OVERLEAF_HISTORY_S3_ACCESS_KEY_ID="GK$(openssl rand -hex 12)" \
  --from-literal=OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY="$(openssl rand -hex 32)"
kubectl apply -f 50-garage.yaml
kubectl -n overleaf rollout status statefulset/garage

g() { kubectl -n overleaf exec garage-0 -- /garage "$@"; }
s() { kubectl -n overleaf get secret overleaf-s3 -o jsonpath="{.data.$1}" | base64 -d; }
g layout assign -z dc1 -c 8G "$(g status 2>/dev/null | awk '/^[0-9a-f]{16}/{print $1; exit}')"
g layout apply --version 1
for b in overleaf-template-files overleaf-project-blobs overleaf-chunks; do g bucket create "$b"; done
g key import --yes -n overleaf-filestore "$(s OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID)" "$(s OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY)"
g key import --yes -n overleaf-history "$(s OVERLEAF_HISTORY_S3_ACCESS_KEY_ID)" "$(s OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY)"
g bucket allow --read --write overleaf-template-files --key overleaf-filestore
g bucket allow --read overleaf-project-blobs --key overleaf-filestore
g bucket allow --read --write overleaf-project-blobs --key overleaf-history
g bucket allow --read --write overleaf-chunks --key overleaf-history
```

I permessi corrispondono alle policy descritte in [S3](https://ayakaleaf-pro.mintlify.site/it/on-premises/configuration/overleaf-toolkit/s3.md#access-policies). Garage verifica la regione: qui è `garage`, e `OVERLEAF_*_S3_REGION` deve essere la stessa.

Con Garage, imposta nella ConfigMap l'endpoint, `PATH_STYLE: "true"` e la regione `garage` per entrambi i servizi, come in `60-config.yaml` di [Scalabilità orizzontale](https://ayakaleaf-pro.mintlify.site/it/on-premises/configuration/kubernetes/horizontal-scaling.md).

### Più repliche

Tutte le repliche devono usare gli stessi bucket e le stesse chiavi. Esegui il backup dei bucket con gli strumenti del tuo provider S3; i dischi delle repliche non contengono quindi dati che richiedano un backup.

### Testato su Kubernetes

Su Kubernetes 1.37 con tre repliche e Garage come sopra, ogni test end-to-end di queste pagine che crea progetti, carica file, usa la cronologia o pubblica template è stato superato, e in seguito i bucket `overleaf-project-blobs`, `overleaf-chunks` e `overleaf-template-files` contenevano gli oggetti, mentre la directory `/var/lib/overleaf/data/history` delle repliche è rimasta vuota.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.