Skip to content

Git push fails with "Permission denied" on tmp_objdir in rootless Gitea on Kubernetes with old Longhorn CSI driver #35032

Open
@PatrickHuetter

Description

@PatrickHuetter

Description

Environment

  • Gitea Version: 1.24.2-rootless
  • Deployment Method: Official Helm Chart v12.1.1
  • Kubernetes: K3s
  • Storage: Longhorn volumes
  • Container Runtime: Running as uid=1000(git) gid=1000(git)

Problem Description

When pushing repositories with more than ~30 files via HTTPS, git push consistently fails with:

remote: fatal: could not open '/data/git/gitea-repositories/myorg/myrepo.git/./objects/tmp_objdir-incoming-[random]/pack/tmp_pack_[random]' for reading: Permission denied
error: unpack failed: index-pack abnormal exit
To https://git.example.com/myorg/myrepo.git
 ! [remote rejected] main -> main (unpacker error)
error: failed to push some refs to 'https://git.example.com/myorg/myrepo.git'

Small commits (1-5 files) usually work without issues. The error occurs consistently with larger pushes.

What I've Tried

1. Security Context Configuration

Added comprehensive security contexts to ensure proper permissions:

podSecurityContext:
  fsGroup: 1000
  fsGroupChangePolicy: "Always"  # Also tried "OnRootMismatch"
  runAsUser: 1000
  runAsGroup: 1000
  runAsNonRoot: true

containerSecurityContext:
  allowPrivilegeEscalation: false
  capabilities:
    drop:
      - ALL
  privileged: false
  readOnlyRootFilesystem: false
  runAsGroup: 1000
  runAsNonRoot: true
  runAsUser: 1000

2. Init Container for Permission Fixes

Attempted to fix permissions via initPreScript:

initPreScript: |
  # Create required directories with proper permissions
  mkdir -p /data/gitea/tmp || true
  chmod 1777 /data/gitea/tmp || true
  mkdir -p /tmp/gitea || true
  chmod 1777 /tmp/gitea || true
  # Fix repository permissions if needed
  find /data/git/gitea-repositories -type d -name objects -exec chmod 775 {} \; 2>/dev/null || true

3. Resource Limits

Increased resources to rule out memory/CPU constraints:

resources:
  limits:
    cpu: 2000m
    memory: 4Gi
  requests:
    cpu: 500m
    memory: 1Gi

4. Repository Configuration

Tried setting custom temp path:

gitea:
  config:
    repository:
      TEMP_PATH: /data/gitea/tmp

Observations

  1. The pod is running with correct user/group (1000:1000)
  2. Directory permissions look correct:
    drwxrwsr-x    5 git      git           4096 Jul 10 12:11 /data/git
    drwxrwsr-x   43 git      git           4096 Apr 27 16:34 /data/git/gitea-repositories
    drwxr-sr-x    7 git      git           4096 Jul  9 09:46 /data/git/gitea-repositories/myorg/myrepo.git
    drwxr-sr-x    4 git      git           4096 Jul 10 12:14 /data/git/gitea-repositories/myorg/myrepo.git/objects
    
  3. The error occurs when git-receive-pack creates temporary directories during object unpacking
  4. The temporary directories (tmp_objdir-incoming-*) appear to be created with incorrect permissions

Questions

  1. Is this a known issue with the rootless image when handling large git pushes?
  2. Are there specific volume mount options or security contexts required for rootless Gitea on Kubernetes?
  3. Would switching to the non-rootless image be the recommended solution?
  4. Are there any git configuration options that could help with the temporary directory permissions?

Additional Information

  • The volume is a Longhorn PVC mounted at /data
  • The issue is reproducible across pod restarts
  • SSH git operations have not been tested yet
  • No relevant error messages in Gitea logs besides the git-receive-pack output

Any help or guidance would be greatly appreciated!

Gitea Version

1.24.2

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

NixOS with k3s (Kubernetes) with Longhorn and gitea as container

How are you running Gitea?

NixOS with k3s (Kubernetes) with Longhorn and gitea as container

Database

PostgreSQL

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/workaroundit is or has a workaroundtype/upstreamThis is an issue in one of Gitea's dependencies and should be reported there

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions